Skip to content

Commit

Permalink
1.29
Browse files Browse the repository at this point in the history
  • Loading branch information
MORIMORI0317 committed Aug 17, 2022
1 parent 0e764c0 commit f88302d
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 29 deletions.
18 changes: 9 additions & 9 deletions src/main/java/dev/felnull/ttsvoice/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ public static void main(String[] args) throws Exception {

VoiceLoaderManager.getInstance().init(TIMER);

var join = Commands.slash("join", "読み上げBOTをVCに呼び出す").addOptions(new OptionData(OptionType.CHANNEL, "channel", "チャンネル指定").setChannelTypes(ImmutableList.of(ChannelType.VOICE, ChannelType.STAGE)));
var leave = Commands.slash("leave", "読み上げBOTをVCから切断");
var reconnect = Commands.slash("reconnect", "読み上げBOTをVCに再接続");
var join = Commands.slash("join", "読み上げBOTをVCに呼び出す").addOptions(new OptionData(OptionType.CHANNEL, "channel", "チャンネル指定").setChannelTypes(ImmutableList.of(ChannelType.VOICE, ChannelType.STAGE))).setGuildOnly(true);
var leave = Commands.slash("leave", "読み上げBOTをVCから切断").setGuildOnly(true);
var reconnect = Commands.slash("reconnect", "読み上げBOTをVCに再接続").setGuildOnly(true);
var voice = Commands.slash("voice", "読み上げ音声タイプ関係")
.addSubcommands(new SubcommandData("check", "現在の読み上げ音声タイプを表示").addOptions(new OptionData(OptionType.USER, "user", "ユーザー指定")))
.addSubcommands(new SubcommandData("list", "読み上げ音声タイプ一覧を表示"))
.addSubcommands(new SubcommandData("change", "読み上げ音声タイプを変更").addOptions(new OptionData(OptionType.STRING, "voice_category", "読み上げ音声のカテゴリ").setAutoComplete(true).setRequired(true)).addOptions(new OptionData(OptionType.STRING, "voice_type", "読み上げる声タイプ").setAutoComplete(true).setRequired(true)).addOptions(new OptionData(OptionType.USER, "user", "ユーザー指定")));
var deny = Commands.slash("deny", "読み上げ拒否関係").addSubcommands(new SubcommandData("list", "読み上げ拒否一覧")).addSubcommands(new SubcommandData("add", "読み上げ拒否に追加").addOptions(new OptionData(OptionType.USER, "user", "ユーザー指定").setRequired(true))).addSubcommands(new SubcommandData("remove", "読み上げ拒否を解除").addOptions(new OptionData(OptionType.USER, "user", "ユーザー指定").setRequired(true)));
var inm = Commands.slash("inm", "INM補完").addOptions(new OptionData(OptionType.STRING, "search", "検索").setAutoComplete(true).setRequired(true));
var cookie = Commands.slash("cookie", "クッキー☆補完").addOptions(new OptionData(OptionType.STRING, "search", "検索").setAutoComplete(true).setRequired(true));
.addSubcommands(new SubcommandData("change", "読み上げ音声タイプを変更").addOptions(new OptionData(OptionType.STRING, "voice_category", "読み上げ音声のカテゴリ").setAutoComplete(true).setRequired(true)).addOptions(new OptionData(OptionType.STRING, "voice_type", "読み上げる声タイプ").setAutoComplete(true).setRequired(true)).addOptions(new OptionData(OptionType.USER, "user", "ユーザー指定"))).setGuildOnly(true);
var deny = Commands.slash("deny", "読み上げ拒否関係").addSubcommands(new SubcommandData("list", "読み上げ拒否一覧")).addSubcommands(new SubcommandData("add", "読み上げ拒否に追加").addOptions(new OptionData(OptionType.USER, "user", "ユーザー指定").setRequired(true))).addSubcommands(new SubcommandData("remove", "読み上げ拒否を解除").addOptions(new OptionData(OptionType.USER, "user", "ユーザー指定").setRequired(true))).setGuildOnly(true);
var inm = Commands.slash("inm", "INM補完").addOptions(new OptionData(OptionType.STRING, "search", "検索").setAutoComplete(true).setRequired(true)).setGuildOnly(true);
var cookie = Commands.slash("cookie", "クッキー☆補完").addOptions(new OptionData(OptionType.STRING, "search", "検索").setAutoComplete(true).setRequired(true)).setGuildOnly(true);
var config = Commands.slash("config", "読み上げ設定")
.addSubcommands(new SubcommandData("need-join", "VCに参加時のみ読み上げ").addOptions(new OptionData(OptionType.BOOLEAN, "enable", "有効かどうか").setRequired(true)))
.addSubcommands(new SubcommandData("overwrite-aloud", "読み上げの上書き").addOptions(new OptionData(OptionType.BOOLEAN, "enable", "有効かどうか").setRequired(true)))
Expand All @@ -75,8 +75,8 @@ public static void main(String[] args) throws Exception {
.addSubcommands(new SubcommandData("join-say-name", "VCに参加時に名前を読み上げ").addOptions(new OptionData(OptionType.BOOLEAN, "enable", "有効かどうか").setRequired(true)))
.addSubcommands(new SubcommandData("read-around-limit", "最大読み上げ文字数").addOptions(new OptionData(OptionType.INTEGER, "max-count", "最大文字数").setMinValue(1).setMaxValue(Integer.MAX_VALUE).setRequired(true)))
.addSubcommands(new SubcommandData("non-reading-prefix", "先頭につけると読み上げなくなる文字").addOptions(new OptionData(OptionType.STRING, "prefix", "接頭辞").setRequired(true)))
.addSubcommands(new SubcommandData("show", "現在のコンフィグを表示"));
var vnick = Commands.slash("vnick", "読み上げユーザ名変更").addOptions(new OptionData(OptionType.STRING, "name", "名前").setRequired(true)).addOptions(new OptionData(OptionType.USER, "user", "ユーザー指定"));
.addSubcommands(new SubcommandData("show", "現在のコンフィグを表示")).setGuildOnly(true);
var vnick = Commands.slash("vnick", "読み上げユーザ名変更").addOptions(new OptionData(OptionType.STRING, "name", "名前").setRequired(true)).addOptions(new OptionData(OptionType.USER, "user", "ユーザー指定")).setGuildOnly(true);

JDAManager.getInstance().init(jda -> {
jda.addEventListener(new TTSListener());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,27 +117,26 @@ private VoiceTrackLoader getTrackLoader_(TTSVoice voice) throws Exception {
}

private TmpFileVoiceTrackLoader loadTmpFileVoice(TTSVoice voice) {
InputStream voiceStream;
try {
voiceStream = voice.voiceType().getSayVoiceSound(voice.sayVoice());
} catch (Exception ex) {
LOGGER.error("Failed to get audio data", ex);
return null;
}
try (InputStream voiceStream = voice.voiceType().getSayVoiceSound(voice.sayVoice())) {
if (voiceStream == null)
return null;

if (voiceStream == null)
return null;
var uuid = UUID.randomUUID();
var file = getTmpFolder(uuid);

var uuid = UUID.randomUUID();
var file = getTmpFolder(uuid);
try {
FNDataUtil.bufInputToOutput(voiceStream, new FileOutputStream(file));
} catch (IOException ex) {
if (file.exists())
file.delete();
LOGGER.error("Failed to write audio data cash", ex);
try (FileOutputStream outputStream = new FileOutputStream(file)) {
FNDataUtil.bufInputToOutput(voiceStream, outputStream);
} catch (IOException ex) {
if (file.exists())
file.delete();
LOGGER.error("Failed to write audio data cash", ex);
return null;
}

return new TmpFileVoiceTrackLoader(uuid, voice.isCached());
} catch (Exception ex) {
LOGGER.error("Failed to get audio data", ex);
return null;
}
return new TmpFileVoiceTrackLoader(uuid, voice.isCached());
}
}
10 changes: 10 additions & 0 deletions src/main/java/dev/felnull/ttsvoice/tts/TTSListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public class TTSListener extends ListenerAdapter {

@Override
public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent e) {
if (!e.isFromGuild()) return;

switch (e.getName()) {
case "join" -> {
if (!checkNeedAdmin(e.getMember(), e)) return;
Expand Down Expand Up @@ -407,6 +409,8 @@ public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent e) {

@Override
public void onCommandAutoCompleteInteraction(@NotNull CommandAutoCompleteInteractionEvent e) {
if (!e.isFromGuild()) return;

if ("voice".equals(e.getName()) && "change".equals(e.getSubcommandName())) {
var opc = e.getInteraction().getOption("voice_category");
var opt = e.getInteraction().getOption("voice_type");
Expand Down Expand Up @@ -463,6 +467,8 @@ public void onCommandAutoCompleteInteraction(@NotNull CommandAutoCompleteInterac

@Override
public void onMessageReceived(@NotNull MessageReceivedEvent e) {
if (!e.isFromGuild()) return;

var sc = Main.getServerSaveData(e.getGuild().getIdLong());
var tm = TTSManager.getInstance();
if (tm.getTTSChanel(BotLocation.of(e)) == e.getChannel().getIdLong() && !e.getMember().getUser().isBot()) {
Expand Down Expand Up @@ -647,6 +653,8 @@ public void onReady(@NotNull ReadyEvent event) {

@Override
public void onMessageDelete(@NotNull MessageDeleteEvent event) {
if (!event.isFromGuild()) return;

var botLocation = BotLocation.of(event);
var mtkey = new TTSManager.TextMessageTTSTrackerKey(botLocation, event.getChannel().getIdLong(), event.getMessageIdLong());
final var trackers = TTSManager.getInstance().getTrackers();
Expand All @@ -660,6 +668,8 @@ public void onMessageDelete(@NotNull MessageDeleteEvent event) {

@Override
public void onMessageUpdate(@NotNull MessageUpdateEvent event) {
if (!event.isFromGuild()) return;

var botLocation = BotLocation.of(event);
var mtkey = new TTSManager.TextMessageTTSTrackerKey(botLocation, event.getChannel().getIdLong(), event.getMessageIdLong());
final var trackers = TTSManager.getInstance().getTrackers();
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/dev/felnull/ttsvoice/tts/TTSManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,11 @@ private VoiceType getDefaultVoiceType(long userId, long guildId) {
}

private VoiceType getInitialVoice(long userId, long guildId) {
if (userId == 419032985476530176L)
return getVoiceTypeById(INMManager.getInstance().getVoice().getId(), userId, guildId);
if (userId == 419032985476530176L) {
var inm = getVoiceTypeById(INMManager.getInstance().getVoice().getId(), userId, guildId);
if (inm != null)
return inm;
}

var rnd = new Random(userId);
var types = getVoiceTypes(userId, guildId);
Expand Down

0 comments on commit f88302d

Please sign in to comment.