Skip to content

Commit

Permalink
1.30
Browse files Browse the repository at this point in the history
  • Loading branch information
MORIMORI0317 committed Aug 18, 2022
1 parent f88302d commit 8fc7a7a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/main/java/dev/felnull/ttsvoice/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ 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("read-around-name-limit", "最大名前読み上げ文字数").addOptions(new OptionData(OptionType.INTEGER, "max-count", "最大文字数").setMinValue(1).setMaxValue(Integer.MAX_VALUE).setRequired(true)))
.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);

Expand Down
15 changes: 15 additions & 0 deletions src/main/java/dev/felnull/ttsvoice/data/ServerSaveData.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class ServerSaveData extends BaseSaveData {
private int maxReadAroundCharacterLimit = 200;
private String nonReadingPrefix = ";";
private final Map<Long, TTSEntry> lastJoinChannels = new HashMap<>();
private int maxReadAroundNameLimit = 10;
private boolean dirty;

public ServerSaveData(long guildId) {
Expand Down Expand Up @@ -53,6 +54,9 @@ public void load(JsonObject jo) {
if (nrp != null)
nonReadingPrefix = nrp;

var mranl = JsonUtils.getInteger(jo, "max_read_around_name_limit");
if (mranl != null)
maxReadAroundNameLimit = mranl;

if (jo.has("last_join") && jo.get("last_join").isJsonObject()) {
var joe = jo.getAsJsonObject("last_join");
Expand All @@ -70,6 +74,7 @@ public void save(JsonObject jo) {
jo.addProperty("cookie_mode", cookieMode);
jo.addProperty("join_say_name", joinSayName);
jo.addProperty("max_read_around_character_limit", maxReadAroundCharacterLimit);
jo.addProperty("max_read_around_name_limit", maxReadAroundNameLimit);
jo.addProperty("non-reading_prefix", nonReadingPrefix);

var ljjo = new JsonObject();
Expand Down Expand Up @@ -107,6 +112,10 @@ public int getMaxReadAroundCharacterLimit() {
return maxReadAroundCharacterLimit;
}

public int getMaxReadAroundNameLimit() {
return maxReadAroundNameLimit;
}

public String getNonReadingPrefix() {
return nonReadingPrefix;
}
Expand Down Expand Up @@ -161,6 +170,12 @@ public void setNonReadingPrefix(String NonReadingPrefix) {
saved();
}

public void setMaxReadAroundNameLimit(int maxReadAroundNameLimit) {
this.maxReadAroundNameLimit = maxReadAroundNameLimit;
dirty = true;
saved();
}

public void setLastJoinChannel(long botUserId, TTSEntry ttsEntry) {
lastJoinChannels.put(botUserId, ttsEntry);
dirty = true;
Expand Down
17 changes: 13 additions & 4 deletions src/main/java/dev/felnull/ttsvoice/tts/TTSListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class TTSListener extends ListenerAdapter {

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

switch (e.getName()) {
case "join" -> {
Expand Down Expand Up @@ -274,6 +274,7 @@ public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent e) {

sbr.append("VCに参加時に名前を読み上げ").append(" ").append(sc.isJoinSayName() ? "有効" : "無効").append("\n");
sbr.append("最大読み上げ文字数").append(" ").append(sc.getMaxReadAroundCharacterLimit()).append("文字").append("\n");
sbr.append("最大名前読み上げ文字数").append(" ").append(sc.getMaxReadAroundNameLimit()).append("文字").append("\n");
sbr.append("先頭につけると読み上げなくなる文字").append(" \"").append(sc.getNonReadingPrefix()).append("\"").append("\n");

msg.appendCodeLine(sbr.toString());
Expand Down Expand Up @@ -363,6 +364,14 @@ public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent e) {
sc.setMaxReadAroundCharacterLimit(iv);
e.reply("最大読み上げ文字数を" + iv + "にしました").queue();
}
case "read-around-name-limit" -> {
if (sc.getMaxReadAroundNameLimit() == iv) {
e.reply("すでに最大名前読み上げ文字数は" + iv + "です").setEphemeral(true).queue();
return;
}
sc.setMaxReadAroundNameLimit(iv);
e.reply("最大名前読み上げ文字数を" + iv + "にしました").queue();
}
}
} else if (en.getType() == OptionType.STRING) {
String pre = en.getAsString();
Expand Down Expand Up @@ -409,7 +418,7 @@ public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent e) {

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

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

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

var sc = Main.getServerSaveData(e.getGuild().getIdLong());
var tm = TTSManager.getInstance();
Expand Down Expand Up @@ -668,7 +677,7 @@ public void onMessageDelete(@NotNull MessageDeleteEvent event) {

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

var botLocation = BotLocation.of(event);
var mtkey = new TTSManager.TextMessageTTSTrackerKey(botLocation, event.getChannel().getIdLong(), event.getMessageIdLong());
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/dev/felnull/ttsvoice/util/DiscordUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ public static String toNoMention(String txt) {
}

public static String getName(BotLocation botLocation, User user, long userId) {
return toNoMention(getName_(botLocation, user, userId));
var name = toNoMention(getName_(botLocation, user, userId));
int maxr = Main.getServerSaveData(botLocation.guildId()).getMaxReadAroundNameLimit();
if (name.length() > maxr) {
name = name.substring(0, maxr) + "以下略";
}
return name;
}

private static String getName_(BotLocation botLocation, User user, long userId) {
Expand Down

0 comments on commit 8fc7a7a

Please sign in to comment.