diff --git a/build.gradle b/build.gradle index 56c3f8e6b..fa7623556 100644 --- a/build.gradle +++ b/build.gradle @@ -28,7 +28,7 @@ repositories { dependencies { // discord/jda related - implementation('net.dv8tion:JDA:4.2.0_241') { + implementation('com.github.DV8FromTheWorld:JDA:0363076696') { exclude group: 'club.minnced', module: 'opus-java' } implementation 'com.jagrosh:jda-utilities:3.0.5' diff --git a/src/main/java/de/kittybot/kittybot/commands/admin/KickCommand.java b/src/main/java/de/kittybot/kittybot/commands/admin/KickCommand.java index 0e95d22fd..de8c7ddb1 100644 --- a/src/main/java/de/kittybot/kittybot/commands/admin/KickCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/admin/KickCommand.java @@ -1,11 +1,11 @@ package de.kittybot.kittybot.commands.admin; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.Category; import de.kittybot.kittybot.slashcommands.application.RunGuildCommand; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionString; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionUser; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; import de.kittybot.kittybot.utils.MessageUtils; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.utils.MarkdownSanitizer; @@ -23,26 +23,26 @@ public KickCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ - if(!ia.getSelfMember().hasPermission(Permission.KICK_MEMBERS)){ - ia.error("I don't have the required permission to kick members"); + public void run(Options options, GuildCommandContext ctx){ + if(!ctx.getSelfMember().hasPermission(Permission.KICK_MEMBERS)){ + ctx.error("I don't have the required permission to kick members"); return; } var user = options.getUser("user"); - if(user.getIdLong() == ia.getUserId()){ - ia.error("You can't kick yourself"); + if(user.getIdLong() == ctx.getUserId()){ + ctx.error("You can't kick yourself"); } var member = options.getMember("user"); if(member != null){ - if(!ia.getSelfMember().canInteract(member)){ - ia.error("I can't interact with this member"); + if(!ctx.getSelfMember().canInteract(member)){ + ctx.error("I can't interact with this member"); return; } } - var reason = options.getOrDefault("reason", "Kicked by " + ia.getMember().getAsMention()); - ia.getGuild().kick(user.getId(), reason).reason(reason).queue(success -> - ia.reply("Kicked `" + MarkdownSanitizer.escape(user.getAsTag()) + "`(`" + user.getId() + "`).\nReason: " + reason), - error -> ia.error("Failed to kick " + user.getAsMention() + ".\nReason: `" + error.getMessage() + "`") + var reason = options.getString("reason", "Kicked by " + ctx.getMember().getAsMention()); + ctx.getGuild().kick(user.getId(), reason).reason(reason).queue(success -> + ctx.reply("Kicked `" + MarkdownSanitizer.escape(user.getAsTag()) + "`(`" + user.getId() + "`).\nReason: " + reason), + error -> ctx.error("Failed to kick " + user.getAsMention() + ".\nReason: `" + error.getMessage() + "`") ); } diff --git a/src/main/java/de/kittybot/kittybot/commands/admin/RestrictEmoteCommand.java b/src/main/java/de/kittybot/kittybot/commands/admin/RestrictEmoteCommand.java index 5650dd52e..1ec42db76 100644 --- a/src/main/java/de/kittybot/kittybot/commands/admin/RestrictEmoteCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/admin/RestrictEmoteCommand.java @@ -1,12 +1,12 @@ package de.kittybot.kittybot.commands.admin; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.Category; import de.kittybot.kittybot.slashcommands.application.Command; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionEmote; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionRole; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Role; @@ -47,21 +47,21 @@ public SetCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ - if(!ia.getSelfMember().hasPermission(Permission.MANAGE_EMOTES)){ - ia.error("I can't manage emotes due to lack of permissions. Please give me the `MANAGE_EMOTES` permission to use this command."); + public void run(Options options, GuildCommandContext ctx){ + if(!ctx.getSelfMember().hasPermission(Permission.MANAGE_EMOTES)){ + ctx.error("I can't manage emotes due to lack of permissions. Please give me the `MANAGE_EMOTES` permission to use this command."); return; } - var emoteAction = options.getEmote(ia.getGuild(), "emote"); + var emoteAction = options.getEmote(ctx.getGuild(), "emote"); if(emoteAction == null){ - ia.error("Failed to parse emote: `" + options.getString("emote") + "`"); + ctx.error("Failed to parse emote: `" + options.getString("emote") + "`"); return; } - emoteAction.queue(emote -> emote.getManager().setRoles(getRoles(ia.getGuild(), options, "role1", "role2", "role3", "role4", "role5", "role6", "role7", "role8", "role9")).queue( - success -> ia.reply("Successfully set roles"), - error -> ia.error("Failed to set roles") + emoteAction.queue(emote -> emote.getManager().setRoles(getRoles(ctx.getGuild(), options, "role1", "role2", "role3", "role4", "role5", "role6", "role7", "role8", "role9")).queue( + success -> ctx.reply("Successfully set roles"), + error -> ctx.error("Failed to set roles") ), - error -> ia.error("Emote not found in this guild") + error -> ctx.error("Emote not found in this guild") ); } @@ -81,21 +81,21 @@ public ResetCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ - if(!ia.getSelfMember().hasPermission(Permission.MANAGE_EMOTES)){ - ia.error("I can't manage emotes due to lack of permissions. Please give me the `MANAGE_EMOTES` permission to use this command."); + public void run(Options options, GuildCommandContext ctx){ + if(!ctx.getSelfMember().hasPermission(Permission.MANAGE_EMOTES)){ + ctx.error("I can't manage emotes due to lack of permissions. Please give me the `MANAGE_EMOTES` permission to use this command."); return; } - var emoteAction = options.getEmote(ia.getGuild(), "emote"); + var emoteAction = options.getEmote(ctx.getGuild(), "emote"); if(emoteAction == null){ - ia.error("Failed to parse emote: `" + options.getString("emote") + "`"); + ctx.error("Failed to parse emote: `" + options.getString("emote") + "`"); return; } emoteAction.queue(emote -> emote.getManager().setRoles(new HashSet<>()).queue( - success -> ia.reply("Successfully reset emote"), - error -> ia.error("Failed to reset emote") + success -> ctx.reply("Successfully reset emote"), + error -> ctx.error("Failed to reset emote") ), - error -> ia.error("Emote not found in this guild") + error -> ctx.error("Emote not found in this guild") ); } diff --git a/src/main/java/de/kittybot/kittybot/commands/admin/ban/AddCommand.java b/src/main/java/de/kittybot/kittybot/commands/admin/ban/AddCommand.java index df0fd089d..b1496763b 100644 --- a/src/main/java/de/kittybot/kittybot/commands/admin/ban/AddCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/admin/ban/AddCommand.java @@ -1,11 +1,11 @@ package de.kittybot.kittybot.commands.admin.ban; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionInteger; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionString; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionUser; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.utils.MarkdownSanitizer; @@ -21,27 +21,27 @@ public AddCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ - if(!ia.getSelfMember().hasPermission(Permission.BAN_MEMBERS)){ - ia.error("I don't have the required permission to ban members"); + public void run(Options options, GuildCommandContext ctx){ + if(!ctx.getSelfMember().hasPermission(Permission.BAN_MEMBERS)){ + ctx.error("I don't have the required permission to ban members"); return; } var user = options.getUser("user"); - if(user.getIdLong() == ia.getUserId()){ - ia.error("You can't ban yourself"); + if(user.getIdLong() == ctx.getUserId()){ + ctx.error("You can't ban yourself"); } var member = options.getMember("user"); if(member != null){ - if(!ia.getSelfMember().canInteract(member)){ - ia.error("I can't interact with this member"); + if(!ctx.getSelfMember().canInteract(member)){ + ctx.error("I can't interact with this member"); return; } } - var reason = options.has("reason") ? options.getString("reason") : "Banned by " + ia.getMember().getAsMention(); + var reason = options.has("reason") ? options.getString("reason") : "Banned by " + ctx.getMember().getAsMention(); var delDays = options.has("del-days") ? options.getInt("del-days") : 0; - ia.getGuild().ban(user, delDays, reason).reason(reason).queue(success -> - ia.reply("Banned `" + MarkdownSanitizer.escape(user.getAsTag()) + "`(`" + user.getId() + "`)\nReason: " + reason + "\nDeleted messages of last " + delDays + " days"), - error -> ia.error("Failed to ban " + user.getAsMention() + ".\nReason: `" + error.getMessage() + "`") + ctx.getGuild().ban(user, delDays, reason).reason(reason).queue(success -> + ctx.reply("Banned `" + MarkdownSanitizer.escape(user.getAsTag()) + "`(`" + user.getId() + "`)\nReason: " + reason + "\nDeleted messages of last " + delDays + " days"), + error -> ctx.error("Failed to ban " + user.getAsMention() + ".\nReason: `" + error.getMessage() + "`") ); } diff --git a/src/main/java/de/kittybot/kittybot/commands/admin/ban/ListCommand.java b/src/main/java/de/kittybot/kittybot/commands/admin/ban/ListCommand.java index 40797f9e2..4d43a94a1 100644 --- a/src/main/java/de/kittybot/kittybot/commands/admin/ban/ListCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/admin/ban/ListCommand.java @@ -1,8 +1,8 @@ package de.kittybot.kittybot.commands.admin.ban; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import net.dv8tion.jda.api.utils.MarkdownSanitizer; import java.util.stream.Collectors; @@ -14,14 +14,14 @@ public ListCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ - ia.getGuild().retrieveBanList().queue(bans -> { + public void run(Options options, GuildCommandContext ctx){ + ctx.getGuild().retrieveBanList().queue(bans -> { if(bans.isEmpty()){ - ia.reply("There are no banned users yet"); + ctx.reply("There are no banned users yet"); return; } - ia.reply("**Banned Users:**\n" + bans.stream().map(ban -> MarkdownSanitizer.escape(ban.getUser().getAsTag()) + "(`" + ban.getUser().getId() + "`)" + " - " + ban.getReason()).collect(Collectors.joining("\n"))); - }, error -> ia.error("I was not able to retrieve the bans. Please give me the `ban members` permission") + ctx.reply("**Banned Users:**\n" + bans.stream().map(ban -> MarkdownSanitizer.escape(ban.getUser().getAsTag()) + "(`" + ban.getUser().getId() + "`)" + " - " + ban.getReason()).collect(Collectors.joining("\n"))); + }, error -> ctx.error("I was not able to retrieve the bans. Please give me the `ban members` permission") ); } diff --git a/src/main/java/de/kittybot/kittybot/commands/admin/ban/RemoveCommand.java b/src/main/java/de/kittybot/kittybot/commands/admin/ban/RemoveCommand.java index 245359764..d31a93999 100644 --- a/src/main/java/de/kittybot/kittybot/commands/admin/ban/RemoveCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/admin/ban/RemoveCommand.java @@ -3,8 +3,8 @@ import de.kittybot.kittybot.slashcommands.application.options.CommandOptionString; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionUser; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; public class RemoveCommand extends GuildSubCommand{ @@ -17,16 +17,16 @@ public RemoveCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ + public void run(Options options, GuildCommandContext ctx){ var user = options.getUser("user"); if(user == null){ - ia.error("Please provide a valid user id"); + ctx.error("Please provide a valid user id"); return; } - var reason = options.has("reason") ? options.getString("reason") : "Unbanned by " + ia.getMember().getAsMention(); - ia.getGuild().unban(user).reason(reason).queue(success -> - ia.reply("Unbanned " + user.getAsMention() + " with reason: " + reason), - error -> ia.error("Failed to unban " + user.getAsMention() + " for reason: `" + error.getMessage() + "`") + var reason = options.has("reason") ? options.getString("reason") : "Unbanned by " + ctx.getMember().getAsMention(); + ctx.getGuild().unban(user).reason(reason).queue(success -> + ctx.reply("Unbanned " + user.getAsMention() + " with reason: " + reason), + error -> ctx.error("Failed to unban " + user.getAsMention() + " for reason: `" + error.getMessage() + "`") ); } diff --git a/src/main/java/de/kittybot/kittybot/commands/admin/ignore/channel/AddCommand.java b/src/main/java/de/kittybot/kittybot/commands/admin/ignore/channel/AddCommand.java index 1375f5c06..0007cedca 100644 --- a/src/main/java/de/kittybot/kittybot/commands/admin/ignore/channel/AddCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/admin/ignore/channel/AddCommand.java @@ -1,25 +1,25 @@ package de.kittybot.kittybot.commands.admin.ignore.channel; import de.kittybot.kittybot.modules.SettingsModule; -import de.kittybot.kittybot.slashcommands.application.options.CommandOptionChannel; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; +import de.kittybot.kittybot.slashcommands.application.options.CommandOptionGuildChannel; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; public class AddCommand extends GuildSubCommand{ public AddCommand(){ super("add", "Used to disable a channel"); addOptions( - new CommandOptionChannel("channel", "Channel to disable").required() + new CommandOptionGuildChannel("channel", "Channel to disable").required() ); } @Override - public void run(Options options, GuildInteraction ia){ + public void run(Options options, GuildCommandContext ctx){ var channel = options.getTextChannel("channel"); - ia.get(SettingsModule.class).setBotDisabledInChannel(ia.getGuildId(), channel.getIdLong(), true); - ia.reply("Disabled commands in: " + channel.getAsMention()); + ctx.get(SettingsModule.class).setBotDisabledInChannel(ctx.getGuildId(), channel.getIdLong(), true); + ctx.reply("Disabled commands in: " + channel.getAsMention()); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/admin/ignore/channel/ListCommand.java b/src/main/java/de/kittybot/kittybot/commands/admin/ignore/channel/ListCommand.java index 156055c18..1f0ba0298 100644 --- a/src/main/java/de/kittybot/kittybot/commands/admin/ignore/channel/ListCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/admin/ignore/channel/ListCommand.java @@ -2,8 +2,8 @@ import de.kittybot.kittybot.modules.SettingsModule; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.utils.MessageUtils; import java.util.stream.Collectors; @@ -15,12 +15,12 @@ public ListCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ - var channels = ia.get(SettingsModule.class).getBotDisabledChannels(ia.getGuildId()); + public void run(Options options, GuildCommandContext ctx){ + var channels = ctx.get(SettingsModule.class).getBotDisabledChannels(ctx.getGuildId()); if(channels.isEmpty()){ - ia.reply("No disabled channels configured yet"); + ctx.reply("No disabled channels configured yet"); } - ia.reply("**Disabled following channels:**\n" + channels.stream().map(MessageUtils::getChannelMention).collect(Collectors.joining(", "))); + ctx.reply("**Disabled following channels:**\n" + channels.stream().map(MessageUtils::getChannelMention).collect(Collectors.joining(", "))); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/admin/ignore/channel/RemoveCommand.java b/src/main/java/de/kittybot/kittybot/commands/admin/ignore/channel/RemoveCommand.java index 20d43ff11..4ad7ca10d 100644 --- a/src/main/java/de/kittybot/kittybot/commands/admin/ignore/channel/RemoveCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/admin/ignore/channel/RemoveCommand.java @@ -1,25 +1,25 @@ package de.kittybot.kittybot.commands.admin.ignore.channel; import de.kittybot.kittybot.modules.SettingsModule; -import de.kittybot.kittybot.slashcommands.application.options.CommandOptionChannel; +import de.kittybot.kittybot.slashcommands.application.options.CommandOptionGuildChannel; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; public class RemoveCommand extends GuildSubCommand{ public RemoveCommand(){ super("remove", "Used to enable a channel"); addOptions( - new CommandOptionChannel("channel", "Channel to enable").required() + new CommandOptionGuildChannel("channel", "Channel to enable").required() ); } @Override - public void run(Options options, GuildInteraction ia){ + public void run(Options options, GuildCommandContext ctx){ var channel = options.getTextChannel("channel"); - ia.get(SettingsModule.class).setBotDisabledInChannel(ia.getGuildId(), channel.getIdLong(), false); - ia.reply("Enabled commands in: " + channel.getAsMention()); + ctx.get(SettingsModule.class).setBotDisabledInChannel(ctx.getGuildId(), channel.getIdLong(), false); + ctx.reply("Enabled commands in: " + channel.getAsMention()); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/admin/ignore/user/AddCommand.java b/src/main/java/de/kittybot/kittybot/commands/admin/ignore/user/AddCommand.java index 59413c5a0..9f21e6848 100644 --- a/src/main/java/de/kittybot/kittybot/commands/admin/ignore/user/AddCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/admin/ignore/user/AddCommand.java @@ -1,10 +1,10 @@ package de.kittybot.kittybot.commands.admin.ignore.user; import de.kittybot.kittybot.modules.SettingsModule; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionUser; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; import java.util.Collections; @@ -18,10 +18,10 @@ public AddCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ + public void run(Options options, GuildCommandContext ctx){ var user = options.getUser("user"); - ia.get(SettingsModule.class).addBotIgnoredUsers(ia.getGuildId(), Collections.singleton(user.getIdLong())); - ia.reply("Disabled commands for: " + user.getAsMention()); + ctx.get(SettingsModule.class).addBotIgnoredUsers(ctx.getGuildId(), Collections.singleton(user.getIdLong())); + ctx.reply("Disabled commands for: " + user.getAsMention()); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/admin/ignore/user/ListCommand.java b/src/main/java/de/kittybot/kittybot/commands/admin/ignore/user/ListCommand.java index 7b20e9a2e..2ce675de2 100644 --- a/src/main/java/de/kittybot/kittybot/commands/admin/ignore/user/ListCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/admin/ignore/user/ListCommand.java @@ -2,8 +2,8 @@ import de.kittybot.kittybot.modules.SettingsModule; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.utils.MessageUtils; import java.util.stream.Collectors; @@ -15,12 +15,12 @@ public ListCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ - var users = ia.get(SettingsModule.class).getBotIgnoredUsers(ia.getGuildId()); + public void run(Options options, GuildCommandContext ctx){ + var users = ctx.get(SettingsModule.class).getBotIgnoredUsers(ctx.getGuildId()); if(users.isEmpty()){ - ia.reply("No disabled users configured yet"); + ctx.reply("No disabled users configured yet"); } - ia.reply("**Disabled following users:**\n" + users.stream().map(MessageUtils::getUserMention).collect(Collectors.joining(", "))); + ctx.reply("**Disabled following users:**\n" + users.stream().map(MessageUtils::getUserMention).collect(Collectors.joining(", "))); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/admin/ignore/user/RemoveCommand.java b/src/main/java/de/kittybot/kittybot/commands/admin/ignore/user/RemoveCommand.java index e14d43cb2..a19d14e12 100644 --- a/src/main/java/de/kittybot/kittybot/commands/admin/ignore/user/RemoveCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/admin/ignore/user/RemoveCommand.java @@ -3,8 +3,8 @@ import de.kittybot.kittybot.modules.SettingsModule; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionUser; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import java.util.Collections; @@ -18,10 +18,10 @@ public RemoveCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ + public void run(Options options, GuildCommandContext ctx){ var user = options.getUser("user"); - ia.get(SettingsModule.class).removeBotIgnoredUsers(ia.getGuildId(), Collections.singleton(user.getIdLong())); - ia.reply("Enabled commands for: " + user.getAsMention()); + ctx.get(SettingsModule.class).removeBotIgnoredUsers(ctx.getGuildId(), Collections.singleton(user.getIdLong())); + ctx.reply("Enabled commands for: " + user.getAsMention()); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/admin/settings/AnnouncementChannelCommand.java b/src/main/java/de/kittybot/kittybot/commands/admin/settings/AnnouncementChannelCommand.java index 5389000a0..be894f0a0 100644 --- a/src/main/java/de/kittybot/kittybot/commands/admin/settings/AnnouncementChannelCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/admin/settings/AnnouncementChannelCommand.java @@ -1,25 +1,25 @@ package de.kittybot.kittybot.commands.admin.settings; import de.kittybot.kittybot.modules.SettingsModule; -import de.kittybot.kittybot.slashcommands.application.options.CommandOptionChannel; +import de.kittybot.kittybot.slashcommands.application.options.CommandOptionGuildChannel; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; public class AnnouncementChannelCommand extends GuildSubCommand{ public AnnouncementChannelCommand(){ super("announcementchannel", "Sets the announcement channel"); addOptions( - new CommandOptionChannel("channel", "The new announcement channel").required() + new CommandOptionGuildChannel("channel", "The new announcement channel").required() ); } @Override - public void run(Options options, GuildInteraction ia){ + public void run(Options options, GuildCommandContext ctx){ var channel = options.getTextChannel("channel"); - ia.get(SettingsModule.class).setAnnouncementChannelId(ia.getGuildId(), channel.getIdLong()); - ia.reply("Announcement channel set to: " + channel.getAsMention()); + ctx.get(SettingsModule.class).setAnnouncementChannelId(ctx.getGuildId(), channel.getIdLong()); + ctx.reply("Announcement channel set to: " + channel.getAsMention()); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/admin/settings/DJRoleCommand.java b/src/main/java/de/kittybot/kittybot/commands/admin/settings/DJRoleCommand.java index 1a8ccb782..20b3fe477 100644 --- a/src/main/java/de/kittybot/kittybot/commands/admin/settings/DJRoleCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/admin/settings/DJRoleCommand.java @@ -3,8 +3,8 @@ import de.kittybot.kittybot.modules.SettingsModule; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionRole; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; public class DJRoleCommand extends GuildSubCommand{ @@ -16,10 +16,10 @@ public DJRoleCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ + public void run(Options options, GuildCommandContext ctx){ var role = options.getRole("role"); - ia.get(SettingsModule.class).setDjRoleId(ia.getGuildId(), role.getIdLong()); - ia.reply("DJ Role set to: " + role.getAsMention()); + ctx.get(SettingsModule.class).setDjRoleId(ctx.getGuildId(), role.getIdLong()); + ctx.reply("DJ Role set to: " + role.getAsMention()); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/admin/settings/JoinMessageCommand.java b/src/main/java/de/kittybot/kittybot/commands/admin/settings/JoinMessageCommand.java index 49c44c830..0c897792c 100644 --- a/src/main/java/de/kittybot/kittybot/commands/admin/settings/JoinMessageCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/admin/settings/JoinMessageCommand.java @@ -4,8 +4,8 @@ import de.kittybot.kittybot.slashcommands.application.options.CommandOptionBoolean; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionString; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; public class JoinMessageCommand extends GuildSubCommand{ @@ -18,26 +18,26 @@ public JoinMessageCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ - var settings = ia.get(SettingsModule.class); + public void run(Options options, GuildCommandContext ctx){ + var settings = ctx.get(SettingsModule.class); var returnMessage = ""; if(options.has("enabled")){ var enabled = options.getBoolean("enabled"); - settings.setJoinMessagesEnabled(ia.getGuildId(), enabled); + settings.setJoinMessagesEnabled(ctx.getGuildId(), enabled); returnMessage += "Join messages `" + (enabled ? "enabled" : "disabled") + "`\n"; } if(options.has("message")){ var message = options.getString("message"); - settings.setJoinMessage(ia.getGuildId(), message); + settings.setJoinMessage(ctx.getGuildId(), message); returnMessage += "Join message to:\n" + message + "\n"; } if(returnMessage.isBlank()){ - ia.reply("Join message `" + (settings.areJoinMessagesEnabled(ia.getGuildId()) ? "enabled" : "disabled") + "` and set to:\n" + settings.getJoinMessage(ia.getGuildId())); + ctx.reply("Join message `" + (settings.areJoinMessagesEnabled(ctx.getGuildId()) ? "enabled" : "disabled") + "` and set to:\n" + settings.getJoinMessage(ctx.getGuildId())); return; } - ia.reply(returnMessage); + ctx.reply(returnMessage); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/admin/settings/LeaveMessageCommand.java b/src/main/java/de/kittybot/kittybot/commands/admin/settings/LeaveMessageCommand.java index 7bec10fc7..82ed33a00 100644 --- a/src/main/java/de/kittybot/kittybot/commands/admin/settings/LeaveMessageCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/admin/settings/LeaveMessageCommand.java @@ -4,8 +4,8 @@ import de.kittybot.kittybot.slashcommands.application.options.CommandOptionBoolean; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionString; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; public class LeaveMessageCommand extends GuildSubCommand{ @@ -18,26 +18,26 @@ public LeaveMessageCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ - var settings = ia.get(SettingsModule.class); + public void run(Options options, GuildCommandContext ctx){ + var settings = ctx.get(SettingsModule.class); var returnMessage = ""; if(options.has("enabled")){ var enabled = options.getBoolean("enabled"); - settings.setLeaveMessagesEnabled(ia.getGuildId(), enabled); + settings.setLeaveMessagesEnabled(ctx.getGuildId(), enabled); returnMessage += "Leave messages `" + (enabled ? "enabled" : "disabled") + "`\n"; } if(options.has("message")){ var message = options.getString("message"); - settings.setLeaveMessage(ia.getGuildId(), message); + settings.setLeaveMessage(ctx.getGuildId(), message); returnMessage += "Leave message to:\n" + message + "\n"; } if(returnMessage.isBlank()){ - ia.reply("Leave message `" + (settings.areLeaveMessagesEnabled(ia.getGuildId()) ? "enabled" : "disabled") + "` and set to:\n" + settings.getLeaveMessage(ia.getGuildId())); + ctx.reply("Leave message `" + (settings.areLeaveMessagesEnabled(ctx.getGuildId()) ? "enabled" : "disabled") + "` and set to:\n" + settings.getLeaveMessage(ctx.getGuildId())); return; } - ia.reply(returnMessage); + ctx.reply(returnMessage); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/admin/settings/ListCommand.java b/src/main/java/de/kittybot/kittybot/commands/admin/settings/ListCommand.java index 0dcfd6fe3..595b84bc8 100644 --- a/src/main/java/de/kittybot/kittybot/commands/admin/settings/ListCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/admin/settings/ListCommand.java @@ -3,8 +3,8 @@ import de.kittybot.kittybot.modules.SettingsModule; import de.kittybot.kittybot.objects.enums.Emoji; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.utils.Config; import de.kittybot.kittybot.utils.MessageUtils; @@ -15,10 +15,10 @@ public ListCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ - var guildId = ia.getGuildId(); - var settings = ia.get(SettingsModule.class).getSettings(guildId); - ia.reply(builder -> builder + public void run(Options options, GuildCommandContext ctx){ + var guildId = ctx.getGuildId(); + var settings = ctx.get(SettingsModule.class).getSettings(guildId); + ctx.reply(builder -> builder .setAuthor("Guild settings:", Config.ORIGIN_URL + "/guilds/" + guildId + "/dashboard", Emoji.SETTINGS.getUrl()) .addField("Announcement Channel: ", settings.getAnnouncementChannel(), false) .addField("Join Messages: " + MessageUtils.getBoolEmote(settings.areJoinMessagesEnabled()), settings.getJoinMessage(), false) diff --git a/src/main/java/de/kittybot/kittybot/commands/admin/settings/LogMessagesCommand.java b/src/main/java/de/kittybot/kittybot/commands/admin/settings/LogMessagesCommand.java index 3eb4400e3..1144925be 100644 --- a/src/main/java/de/kittybot/kittybot/commands/admin/settings/LogMessagesCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/admin/settings/LogMessagesCommand.java @@ -2,11 +2,10 @@ import de.kittybot.kittybot.modules.SettingsModule; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionBoolean; -import de.kittybot.kittybot.slashcommands.application.options.CommandOptionChannel; +import de.kittybot.kittybot.slashcommands.application.options.CommandOptionGuildChannel; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; -import de.kittybot.kittybot.slashcommands.interaction.response.InteractionResponse; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.utils.MessageUtils; public class LogMessagesCommand extends GuildSubCommand{ @@ -15,32 +14,32 @@ public LogMessagesCommand(){ super("logmessages", "Sets the logging channel or enable/disables log messages"); addOptions( new CommandOptionBoolean("enabled", "Whether log messages are enabled"), - new CommandOptionChannel("channel", "The log message channel") + new CommandOptionGuildChannel("channel", "The log message channel") ); } @Override - public void run(Options options, GuildInteraction ia){ - var settings = ia.get(SettingsModule.class); + public void run(Options options, GuildCommandContext ctx){ + var settings = ctx.get(SettingsModule.class); var returnMessage = ""; if(options.has("enabled")){ var enabled = options.getBoolean("enabled"); - settings.setLogMessagesEnabled(ia.getGuildId(), enabled); + settings.setLogMessagesEnabled(ctx.getGuildId(), enabled); returnMessage += "Log messages `" + (enabled ? "enabled" : "disabled") + "`\n"; } if(options.has("channel")){ var channel = options.getTextChannel("channel"); - settings.setLogChannelId(ia.getGuildId(), channel.getIdLong()); + settings.setLogChannelId(ctx.getGuildId(), channel.getIdLong()); returnMessage += "Log channel to:\n" + channel.getAsMention() + "\n"; } if(returnMessage.isBlank()){ - ia.reply("Log message `" + (settings.areLogMessagesEnabled(ia.getGuildId()) ? "enabled" : "disabled") + "` and send to channel " + - MessageUtils.getChannelMention(settings.getLogChannelId(ia.getGuildId()))); + ctx.reply("Log message `" + (settings.areLogMessagesEnabled(ctx.getGuildId()) ? "enabled" : "disabled") + "` and send to channel " + + MessageUtils.getChannelMention(settings.getLogChannelId(ctx.getGuildId()))); return; } - ia.reply(returnMessage); + ctx.reply(returnMessage); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/admin/settings/NsfwCommand.java b/src/main/java/de/kittybot/kittybot/commands/admin/settings/NsfwCommand.java index 08043badf..35e59a7b6 100644 --- a/src/main/java/de/kittybot/kittybot/commands/admin/settings/NsfwCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/admin/settings/NsfwCommand.java @@ -3,8 +3,8 @@ import de.kittybot.kittybot.modules.SettingsModule; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionBoolean; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; public class NsfwCommand extends GuildSubCommand{ @@ -16,10 +16,10 @@ public NsfwCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ + public void run(Options options, GuildCommandContext ctx){ var enabled = options.getBoolean("enabled"); - ia.get(SettingsModule.class).setNsfwEnabled(ia.getGuildId(), enabled); - ia.reply((enabled ? "Enabled" : "Disabled") + "nsfw commands"); + ctx.get(SettingsModule.class).setNsfwEnabled(ctx.getGuildId(), enabled); + ctx.reply((enabled ? "Enabled" : "Disabled") + "nsfw commands"); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/admin/settings/RoleSaverCommand.java b/src/main/java/de/kittybot/kittybot/commands/admin/settings/RoleSaverCommand.java index 2595011ce..dc09fe3a6 100644 --- a/src/main/java/de/kittybot/kittybot/commands/admin/settings/RoleSaverCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/admin/settings/RoleSaverCommand.java @@ -3,8 +3,8 @@ import de.kittybot.kittybot.modules.SettingsModule; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionBoolean; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; public class RoleSaverCommand extends GuildSubCommand{ @@ -16,10 +16,10 @@ public RoleSaverCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ + public void run(Options options, GuildCommandContext ctx){ var enabled = options.getBoolean("enabled"); - ia.get(SettingsModule.class).setRoleSaverEnabled(ia.getGuildId(), enabled); - ia.reply((enabled ? "Enabled" : "Disabled") + " role saving"); + ctx.get(SettingsModule.class).setRoleSaverEnabled(ctx.getGuildId(), enabled); + ctx.reply((enabled ? "Enabled" : "Disabled") + " role saving"); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/admin/settings/SnipesCommand.java b/src/main/java/de/kittybot/kittybot/commands/admin/settings/SnipesCommand.java index be37c9f47..8f956be1e 100644 --- a/src/main/java/de/kittybot/kittybot/commands/admin/settings/SnipesCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/admin/settings/SnipesCommand.java @@ -1,12 +1,6 @@ package de.kittybot.kittybot.commands.admin.settings; -import de.kittybot.kittybot.modules.SettingsModule; -import de.kittybot.kittybot.slashcommands.application.options.CommandOptionBoolean; -import de.kittybot.kittybot.slashcommands.application.options.CommandOptionChannel; -import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; import de.kittybot.kittybot.slashcommands.application.options.SubCommandGroup; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; public class SnipesCommand extends SubCommandGroup{ diff --git a/src/main/java/de/kittybot/kittybot/commands/admin/settings/snipes/ChannelCommand.java b/src/main/java/de/kittybot/kittybot/commands/admin/settings/snipes/ChannelCommand.java index 708f5c96c..b485dc471 100644 --- a/src/main/java/de/kittybot/kittybot/commands/admin/settings/snipes/ChannelCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/admin/settings/snipes/ChannelCommand.java @@ -2,27 +2,27 @@ import de.kittybot.kittybot.modules.SettingsModule; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionBoolean; -import de.kittybot.kittybot.slashcommands.application.options.CommandOptionChannel; +import de.kittybot.kittybot.slashcommands.application.options.CommandOptionGuildChannel; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; public class ChannelCommand extends GuildSubCommand{ public ChannelCommand(){ super("channel", "Used to enable/disable snipes in a specific channel"); addOptions( - new CommandOptionChannel("channel", "The channel to enable/disable snipes").required(), + new CommandOptionGuildChannel("channel", "The channel to enable/disable snipes").required(), new CommandOptionBoolean("enabled", "Whether to enable/disable snipes").required() ); } @Override - public void run(Options options, GuildInteraction ia){ + public void run(Options options, GuildCommandContext ctx){ var channel = options.getTextChannel("channel"); var enabled = options.getBoolean("enabled"); - ia.get(SettingsModule.class).setSnipesDisabledInChannel(ia.getGuildId(), channel.getIdLong(), !enabled); - ia.reply("Snipes `" + (enabled ? "enabled" : "disabled") + "` in " + channel.getAsMention()); + ctx.get(SettingsModule.class).setSnipesDisabledInChannel(ctx.getGuildId(), channel.getIdLong(), !enabled); + ctx.reply("Snipes `" + (enabled ? "enabled" : "disabled") + "` in " + channel.getAsMention()); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/admin/settings/snipes/EnableCommand.java b/src/main/java/de/kittybot/kittybot/commands/admin/settings/snipes/EnableCommand.java index 395386762..264d4be68 100644 --- a/src/main/java/de/kittybot/kittybot/commands/admin/settings/snipes/EnableCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/admin/settings/snipes/EnableCommand.java @@ -3,8 +3,8 @@ import de.kittybot.kittybot.modules.SettingsModule; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionBoolean; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; public class EnableCommand extends GuildSubCommand{ @@ -16,10 +16,10 @@ public EnableCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ + public void run(Options options, GuildCommandContext ctx){ var enabled = options.getBoolean("enabled"); - ia.get(SettingsModule.class).setSnipesEnabled(ia.getGuildId(), enabled); - ia.reply("Snipes globally `" + (enabled ? "enabled" : "disabled") + "`"); + ctx.get(SettingsModule.class).setSnipesEnabled(ctx.getGuildId(), enabled); + ctx.reply("Snipes globally `" + (enabled ? "enabled" : "disabled") + "`"); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/dev/EvalCommand.java b/src/main/java/de/kittybot/kittybot/commands/dev/EvalCommand.java index aef98ed18..4bbdecaab 100644 --- a/src/main/java/de/kittybot/kittybot/commands/dev/EvalCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/dev/EvalCommand.java @@ -2,13 +2,10 @@ import de.kittybot.kittybot.slashcommands.application.Category; import de.kittybot.kittybot.slashcommands.application.RunCommand; +import de.kittybot.kittybot.slashcommands.CommandContext; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionString; -import de.kittybot.kittybot.slashcommands.application.options.SubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Interaction; -import de.kittybot.kittybot.slashcommands.interaction.Options; -import de.kittybot.kittybot.slashcommands.interaction.response.InteractionResponse; -import net.dv8tion.jda.api.EmbedBuilder; import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; @@ -35,21 +32,21 @@ public EvalCommand(){ } @Override - public void run(Options options, Interaction ia){ + public void run(Options options, CommandContext ctx){ var code = options.getString("code"); Object out; var color = Color.GREEN; var status = "Success"; - this.scriptEngine.put("ia", ia); + this.scriptEngine.put("ctx", ctx); this.scriptEngine.put("options", options); - this.scriptEngine.put("jda", ia.getJDA()); + this.scriptEngine.put("jda", ctx.getJDA()); - this.scriptEngine.put("channel", ia.getChannel()); - this.scriptEngine.put("user", ia.getUser()); - if(ia instanceof GuildInteraction){ - var guildIa = (GuildInteraction) ia; - this.scriptEngine.put("guild", guildIa.getGuild()); - this.scriptEngine.put("member", guildIa.getMember()); + this.scriptEngine.put("channel", ctx.getChannel()); + this.scriptEngine.put("user", ctx.getUser()); + if(ctx instanceof GuildCommandContext){ + var guildCtx = (GuildCommandContext) ctx; + this.scriptEngine.put("guild", guildCtx.getGuild()); + this.scriptEngine.put("member", guildCtx.getMember()); } var imports = new StringBuilder(); @@ -63,17 +60,16 @@ public void run(Options options, Interaction ia){ color = Color.RED; status = "Failed"; } - ia.reply(new InteractionResponse.Builder() - .addEmbeds(new EmbedBuilder() - .setTitle("Eval") - .setColor(color) - .addField("Status:", status, true) - .addField("Duration:", (System.currentTimeMillis() - start) + "ms", true) - .addField("Code:", "```java\n" + code + "\n```", false) - .addField("Result:", out == null ? "" : out.toString(), false) - .build() - ).build() - ); + ctx.acknowledge(true).queue(); + ctx.getHook().sendMessage("").addEmbeds(ctx.getEmbed() + .setTitle("Eval") + .setColor(color) + .addField("Status:", status, true) + .addField("Duration:", (System.currentTimeMillis() - start) + "ms", true) + .addField("Code:", "```java\n" + code + "\n```", false) + .addField("Result:", out == null ? "" : out.toString(), false) + .build() + ).queue(); } -} \ No newline at end of file +} diff --git a/src/main/java/de/kittybot/kittybot/commands/dev/dev/DeployCommand.java b/src/main/java/de/kittybot/kittybot/commands/dev/dev/DeployCommand.java index 3ea36d8d9..5e56bd7df 100644 --- a/src/main/java/de/kittybot/kittybot/commands/dev/dev/DeployCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/dev/dev/DeployCommand.java @@ -1,19 +1,13 @@ package de.kittybot.kittybot.commands.dev.dev; import de.kittybot.kittybot.modules.CommandsModule; -import de.kittybot.kittybot.slashcommands.application.CommandOptionChoice; +import de.kittybot.kittybot.slashcommands.CommandContext; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; +import de.kittybot.kittybot.slashcommands.application.OptionChoice; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionInteger; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionLong; import de.kittybot.kittybot.slashcommands.application.options.SubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Interaction; -import de.kittybot.kittybot.slashcommands.interaction.Options; -import de.kittybot.kittybot.slashcommands.interaction.response.FollowupMessage; -import de.kittybot.kittybot.slashcommands.interaction.response.InteractionResponse; -import de.kittybot.kittybot.utils.Colors; -import net.dv8tion.jda.api.EmbedBuilder; - -import java.util.concurrent.TimeUnit; public class DeployCommand extends SubCommand{ @@ -22,8 +16,8 @@ public DeployCommand(){ addOptions( new CommandOptionInteger("environment", "In which environment should the commands get deployed").required() .addChoices( - new CommandOptionChoice<>("global", 0), - new CommandOptionChoice<>("guild", 1) + new OptionChoice("global", 0), + new OptionChoice("guild", 1) ), new CommandOptionLong("guild", "In which guild commands should get deployed") ); @@ -31,26 +25,20 @@ public DeployCommand(){ } @Override - public void run(Options options, Interaction ia){ + public void run(Options options, CommandContext ctx){ var environment = options.getInt("environment"); if(environment == 0){ - ia.reply(new InteractionResponse.Builder().ephemeral().setContent("processing...").build()); - ia.getModules().schedule(() -> { - ia.get(CommandsModule.class).deployAllCommands(-1L); - ia.followup(new FollowupMessage.Builder().setEmbeds(new EmbedBuilder().setColor(Colors.KITTYBOT_BLUE).setDescription("Deployed slash commands globally").build()).build()); - }, 0, TimeUnit.SECONDS); + ctx.get(CommandsModule.class).deployAllCommands(-1L); + ctx.reply(embed -> embed.setDescription("Deployed slash commands globally")); return; } - var guildId = options.has("guild") ? options.getLong("guild") : ia instanceof GuildInteraction ? ((GuildInteraction) ia).getGuildId() : -1L; + var guildId = options.has("guild") ? options.getLong("guild") : ctx instanceof GuildCommandContext ? ((GuildCommandContext) ctx).getGuildId() : -1L; if(guildId == -1L){ - ia.error("Please provide a valid guild id"); + ctx.error("Please provide a valid guild id"); return; } - ia.reply(new InteractionResponse.Builder().ephemeral().setContent("processing...").build()); - ia.getModules().schedule(() -> { - ia.get(CommandsModule.class).deployAllCommands(guildId); - ia.followup(new FollowupMessage.Builder().setEmbeds(new EmbedBuilder().setColor(Colors.KITTYBOT_BLUE).setDescription("Deployed slash commands for guild `" + guildId + "`").build()).build()); - }, 0, TimeUnit.SECONDS); + ctx.get(CommandsModule.class).deployAllCommands(guildId); + ctx.reply(embed -> embed.setDescription("Deployed slash commands for guild `" + guildId + "`")); } } \ No newline at end of file diff --git a/src/main/java/de/kittybot/kittybot/commands/dev/dev/PresenceCommand.java b/src/main/java/de/kittybot/kittybot/commands/dev/dev/PresenceCommand.java index 8fd4c364f..7bdb208c1 100644 --- a/src/main/java/de/kittybot/kittybot/commands/dev/dev/PresenceCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/dev/dev/PresenceCommand.java @@ -1,10 +1,10 @@ package de.kittybot.kittybot.commands.dev.dev; -import de.kittybot.kittybot.slashcommands.application.CommandOptionChoice; +import de.kittybot.kittybot.slashcommands.CommandContext; +import de.kittybot.kittybot.slashcommands.Options; +import de.kittybot.kittybot.slashcommands.application.OptionChoice; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionString; import de.kittybot.kittybot.slashcommands.application.options.SubCommand; -import de.kittybot.kittybot.slashcommands.interaction.Interaction; -import de.kittybot.kittybot.slashcommands.interaction.Options; import net.dv8tion.jda.api.OnlineStatus; import net.dv8tion.jda.api.entities.Activity; @@ -14,18 +14,18 @@ public PresenceCommand(){ super("presence", "Set the presence & activity"); addOptions( new CommandOptionString("status", "The online status").addChoices( - new CommandOptionChoice<>(OnlineStatus.ONLINE), - new CommandOptionChoice<>(OnlineStatus.DO_NOT_DISTURB), - new CommandOptionChoice<>(OnlineStatus.IDLE), - new CommandOptionChoice<>(OnlineStatus.OFFLINE), - new CommandOptionChoice<>(OnlineStatus.INVISIBLE) + new OptionChoice(OnlineStatus.ONLINE), + new OptionChoice(OnlineStatus.DO_NOT_DISTURB), + new OptionChoice(OnlineStatus.IDLE), + new OptionChoice(OnlineStatus.OFFLINE), + new OptionChoice(OnlineStatus.INVISIBLE) ), new CommandOptionString("activity", "The online status").addChoices( - new CommandOptionChoice<>(Activity.ActivityType.COMPETING), - new CommandOptionChoice<>(Activity.ActivityType.LISTENING), - new CommandOptionChoice<>(Activity.ActivityType.WATCHING), - new CommandOptionChoice<>(Activity.ActivityType.STREAMING), - new CommandOptionChoice<>(Activity.ActivityType.DEFAULT) + new OptionChoice(Activity.ActivityType.COMPETING), + new OptionChoice(Activity.ActivityType.LISTENING), + new OptionChoice(Activity.ActivityType.WATCHING), + new OptionChoice(Activity.ActivityType.STREAMING), + new OptionChoice(Activity.ActivityType.DEFAULT) ), new CommandOptionString("message", "The activity message"), new CommandOptionString("streaming-url", "The streaming url if you chose streaming as activity") @@ -35,18 +35,18 @@ public PresenceCommand(){ @Override - public void run(Options options, Interaction ia){ + public void run(Options options, CommandContext ctx){ var status = options.has("status") ? OnlineStatus.valueOf(options.getString("status")) : null; var activity = options.has("activity") ? Activity.ActivityType.valueOf(options.getString("activity")) : null; var message = options.has("message") ? options.getString("message") : null; var streamingURL = options.has("streaming-url") ? options.getString("streaming-url") : null; if(activity == Activity.ActivityType.STREAMING && message == null){ - ia.error("The message may not be empty for streaming"); + ctx.error("The message may not be empty for streaming"); return; } - ia.getJDA().getPresence().setPresence(status, activity == null ? null : Activity.of(activity, message == null ? "" : message, streamingURL)); - ia.reply("Successfully set presence"); + ctx.getJDA().getPresence().setPresence(status, activity == null ? null : Activity.of(activity, message == null ? "" : message, streamingURL)); + ctx.reply("Successfully set presence"); } } \ No newline at end of file diff --git a/src/main/java/de/kittybot/kittybot/commands/dev/dev/RemoveCommand.java b/src/main/java/de/kittybot/kittybot/commands/dev/dev/RemoveCommand.java index 2a450c43d..da8032593 100644 --- a/src/main/java/de/kittybot/kittybot/commands/dev/dev/RemoveCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/dev/dev/RemoveCommand.java @@ -2,19 +2,13 @@ import de.kittybot.kittybot.modules.CommandsModule; import de.kittybot.kittybot.objects.enums.Environment; -import de.kittybot.kittybot.slashcommands.application.CommandOptionChoice; +import de.kittybot.kittybot.slashcommands.CommandContext; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; +import de.kittybot.kittybot.slashcommands.application.OptionChoice; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionInteger; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionLong; import de.kittybot.kittybot.slashcommands.application.options.SubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Interaction; -import de.kittybot.kittybot.slashcommands.interaction.Options; -import de.kittybot.kittybot.slashcommands.interaction.response.FollowupMessage; -import de.kittybot.kittybot.slashcommands.interaction.response.InteractionResponse; -import de.kittybot.kittybot.utils.Colors; -import net.dv8tion.jda.api.EmbedBuilder; - -import java.util.concurrent.TimeUnit; public class RemoveCommand extends SubCommand{ @@ -23,8 +17,8 @@ public RemoveCommand(){ addOptions( new CommandOptionInteger("environment", "In which environment should the commands get removed").required() .addChoices( - new CommandOptionChoice<>("global", 0), - new CommandOptionChoice<>("guild", 1) + new OptionChoice("global", 0), + new OptionChoice("guild", 1) ), new CommandOptionLong("guild", "In which guild commands should get removed") ); @@ -32,32 +26,25 @@ public RemoveCommand(){ } @Override - public void run(Options options, Interaction ia){ + public void run(Options options, CommandContext ctx){ var environment = options.getInt("environment"); if(environment == 0){ if(Environment.getCurrent() == Environment.PRODUCTION){ - ia.reply(new InteractionResponse.Builder().ephemeral().setContent("Removing commands globally in production is not allowed sorry :3").build()); + ctx.error("Removing commands globally in production is not allowed sorry :3"); return; } - ia.reply(new InteractionResponse.Builder().ephemeral().setContent("processing...").build()); - ia.getModules().schedule(() -> { - var commandsModule = ia.get(CommandsModule.class); - commandsModule.deleteAllCommands(-1L); - ia.followup(new FollowupMessage.Builder().setEmbeds(new EmbedBuilder().setColor(Colors.KITTYBOT_BLUE).setDescription("Removed slash commands globally").build()).build()); - }, 0, TimeUnit.SECONDS); + ctx.get(CommandsModule.class).deleteAllCommands(-1L); + ctx.reply(embed -> embed.setDescription("Removed slash commands globally").build()); return; } - var guildId = options.has("guild") ? options.getLong("guild") : ia instanceof GuildInteraction ? ((GuildInteraction) ia).getGuildId() : -1L; + var guildId = options.has("guild") ? options.getLong("guild") : ctx instanceof GuildCommandContext ? ((GuildCommandContext) ctx).getGuildId() : -1L; if(guildId == -1){ - ia.error("Please provide a valid guild id"); + ctx.error("Please provide a valid guild id"); return; } - ia.reply(new InteractionResponse.Builder().ephemeral().setContent("processing...").build()); - ia.getModules().schedule(() -> { - var commandsModule = ia.get(CommandsModule.class); - commandsModule.deleteAllCommands(guildId); - ia.followup(new FollowupMessage.Builder().setEmbeds(new EmbedBuilder().setColor(Colors.KITTYBOT_BLUE).setDescription("Removed slash commands for guild `" + guildId + "`").build()).build()); - }, 0, TimeUnit.SECONDS); + ctx.get(CommandsModule.class).deleteAllCommands(guildId); + ctx.reply(embed -> embed.setDescription("Removed slash commands for guild `" + guildId + "`")); + } } \ No newline at end of file diff --git a/src/main/java/de/kittybot/kittybot/commands/dev/dev/TestCommand.java b/src/main/java/de/kittybot/kittybot/commands/dev/dev/TestCommand.java index ab897012e..ac448d940 100644 --- a/src/main/java/de/kittybot/kittybot/commands/dev/dev/TestCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/dev/dev/TestCommand.java @@ -12,4 +12,4 @@ public TestCommand(){ ); } -} \ No newline at end of file +} diff --git a/src/main/java/de/kittybot/kittybot/commands/dev/dev/test/ResponseCommand.java b/src/main/java/de/kittybot/kittybot/commands/dev/dev/test/ResponseCommand.java index 91433cb25..423e621d6 100644 --- a/src/main/java/de/kittybot/kittybot/commands/dev/dev/test/ResponseCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/dev/dev/test/ResponseCommand.java @@ -1,15 +1,13 @@ package de.kittybot.kittybot.commands.dev.dev.test; -import de.kittybot.kittybot.slashcommands.application.CommandOptionChoice; +import de.kittybot.kittybot.slashcommands.CommandContext; +import de.kittybot.kittybot.slashcommands.application.OptionChoice; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionBoolean; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionString; import de.kittybot.kittybot.slashcommands.application.options.SubCommand; -import de.kittybot.kittybot.slashcommands.interaction.Interaction; -import de.kittybot.kittybot.slashcommands.interaction.InteractionDataOption; -import de.kittybot.kittybot.slashcommands.interaction.Options; -import de.kittybot.kittybot.slashcommands.interaction.response.InteractionResponse; -import de.kittybot.kittybot.slashcommands.interaction.response.InteractionResponseType; -import net.dv8tion.jda.api.EmbedBuilder; +import de.kittybot.kittybot.slashcommands.Options; +import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; +import net.dv8tion.jda.api.requests.restaction.CommandReplyAction; import java.util.stream.Collectors; @@ -19,34 +17,17 @@ public ResponseCommand(){ super("response", "Let's you choose the response type"); addOptions( new CommandOptionString("type", "The response type you want").required().addChoices( - new CommandOptionChoice<>(InteractionResponseType.ACKNOWLEDGE), - new CommandOptionChoice<>(InteractionResponseType.ACKNOWLEDGE_WITH_SOURCE), - new CommandOptionChoice<>(InteractionResponseType.CHANNEL_MESSAGE), - new CommandOptionChoice<>(InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE) + new OptionChoice(CommandReplyAction.ResponseType.CHANNEL_MESSAGE_WITH_SOURCE), + new OptionChoice(CommandReplyAction.ResponseType.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE) ), new CommandOptionBoolean("ephemeral", "Weather the response should be a ephemeral message") ); } @Override - public void run(Options options, Interaction ia){ - var content = options.stream().map(InteractionDataOption::getValue).map(Object::toString).collect(Collectors.joining(", ")); - var response = new InteractionResponse.Builder() - .setType(InteractionResponseType.valueOf(options.getString("type"))); - if(options.has("ephemeral")){ - response.setEphemeral(options.getBoolean("ephemeral")); - } - if(response.isEphemeral()){ - response.setContent(content); - } - else{ - response.addEmbeds(ia.applyDefaultStyle(new EmbedBuilder() - .setTitle("Response") - .setDescription(content) - ).build() - ); - } - ia.reply(response.build()); + public void run(Options options, CommandContext ctx){ + var content = options.stream().map(SlashCommandEvent.OptionData::getAsString).collect(Collectors.joining(", ")); + ctx.getEvent().reply(content).setEphemeral(options.getBoolean("ephemeral", false)).queue(); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/info/AvatarCommand.java b/src/main/java/de/kittybot/kittybot/commands/info/AvatarCommand.java index 31248e863..59de6099a 100644 --- a/src/main/java/de/kittybot/kittybot/commands/info/AvatarCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/info/AvatarCommand.java @@ -1,13 +1,12 @@ package de.kittybot.kittybot.commands.info; import de.kittybot.kittybot.slashcommands.application.Category; -import de.kittybot.kittybot.slashcommands.application.CommandOptionChoice; +import de.kittybot.kittybot.slashcommands.CommandContext; +import de.kittybot.kittybot.slashcommands.Options; +import de.kittybot.kittybot.slashcommands.application.OptionChoice; import de.kittybot.kittybot.slashcommands.application.RunCommand; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionInteger; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionUser; -import de.kittybot.kittybot.slashcommands.application.options.SubCommand; -import de.kittybot.kittybot.slashcommands.interaction.Interaction; -import de.kittybot.kittybot.slashcommands.interaction.Options; import de.kittybot.kittybot.utils.MessageUtils; @SuppressWarnings("unused") @@ -19,24 +18,24 @@ public AvatarCommand(){ new CommandOptionUser("user", "The user to get the avatar from"), new CommandOptionInteger("size", "The image size") .addChoices( - new CommandOptionChoice<>("16px", 16), - new CommandOptionChoice<>("32px", 32), - new CommandOptionChoice<>("64px", 64), - new CommandOptionChoice<>("128px", 128), - new CommandOptionChoice<>("256px", 256), - new CommandOptionChoice<>("512px", 512), - new CommandOptionChoice<>("1024px", 1024), - new CommandOptionChoice<>("2048px", 2048) + new OptionChoice("16px", 16), + new OptionChoice("32px", 32), + new OptionChoice("64px", 64), + new OptionChoice("128px", 128), + new OptionChoice("256px", 256), + new OptionChoice("512px", 512), + new OptionChoice("1024px", 1024), + new OptionChoice("2048px", 2048) ) ); } @Override - public void run(Options options, Interaction ia){ - var user = options.has("user") ? options.getUser("user") : ia.getUser(); - var size = options.has("size") ? options.getInt("size") : 1024; + public void run(Options options, CommandContext ctx){ + var user = options.getUser("user", ctx.getUser()); + var size = options.getInt("size", 1024); - ia.reply(builder -> builder + ctx.reply(builder -> builder .setTitle(user.getAsTag() + " Avatar") .setThumbnail(user.getEffectiveAvatarUrl()) .setDescription(MessageUtils.maskLink(size + "px", user.getEffectiveAvatarUrl() + "?size=" + size)) diff --git a/src/main/java/de/kittybot/kittybot/commands/info/CommandsCommand.java b/src/main/java/de/kittybot/kittybot/commands/info/CommandsCommand.java index b45c5c576..ce81b0571 100644 --- a/src/main/java/de/kittybot/kittybot/commands/info/CommandsCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/info/CommandsCommand.java @@ -2,13 +2,13 @@ import de.kittybot.kittybot.modules.CommandsModule; import de.kittybot.kittybot.modules.PaginatorModule; +import de.kittybot.kittybot.slashcommands.CommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.Category; import de.kittybot.kittybot.slashcommands.application.Command; import de.kittybot.kittybot.slashcommands.application.RunCommand; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionString; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.Interaction; -import de.kittybot.kittybot.slashcommands.interaction.Options; import de.kittybot.kittybot.utils.Colors; import de.kittybot.kittybot.utils.Config; import de.kittybot.kittybot.utils.MessageUtils; @@ -28,18 +28,18 @@ public CommandsCommand(){ } @Override - public void run(Options options, Interaction ia){ - var commands = ia.get(CommandsModule.class).getCommands().values(); + public void run(Options options, CommandContext ctx){ + var commands = ctx.get(CommandsModule.class).getCommands().values(); if(options.has("command")){ var cmdName = options.getString("command"); var optCmd = commands.stream().filter(cmd -> cmd.getName().equalsIgnoreCase(cmdName)).findFirst(); if(optCmd.isEmpty()){ - ia.error("Command `" + cmdName + "` not found"); + ctx.error("Command `" + cmdName + "` not found"); return; } var cmd = optCmd.get(); - ia.reply(builder -> builder - .setAuthor("Commands", Config.ORIGIN_URL + "/commands#" + cmd.getName(), ia.getSelfUser().getEffectiveAvatarUrl()) + ctx.reply(builder -> builder + .setAuthor("Commands", Config.ORIGIN_URL + "/commands#" + cmd.getName(), ctx.getSelfUser().getEffectiveAvatarUrl()) .setDescription("`/" + cmd.getName() + "` - *" + cmd.getDescription() + "*\n\n" + cmd.getOptions().stream() .filter(GuildSubCommand.class::isInstance) .map(c -> "`/" + cmd.getName() + " " + c.getName() + "` - *" + c.getDescription() + "*") @@ -61,11 +61,11 @@ public void run(Options options, Interaction ia){ pages.add(page.toString()); }); - ia.get(PaginatorModule.class).create( - ia, + ctx.get(PaginatorModule.class).create( + ctx, pages.size(), (page, embedBuilder) -> embedBuilder.setColor(Colors.KITTYBOT_BLUE) - .setAuthor("Commands", Config.ORIGIN_URL + "/commands", ia.getJDA().getSelfUser().getEffectiveAvatarUrl()) + .setAuthor("Commands", Config.ORIGIN_URL + "/commands", ctx.getJDA().getSelfUser().getEffectiveAvatarUrl()) .setDescription(pages.get(page)) .appendDescription("\n\n*Commands can also be found " + MessageUtils.maskLink("here", Config.ORIGIN_URL + "/commands") + "*") .setTimestamp(Instant.now()) diff --git a/src/main/java/de/kittybot/kittybot/commands/info/DashboardCommand.java b/src/main/java/de/kittybot/kittybot/commands/info/DashboardCommand.java index 74d730837..3ae749031 100644 --- a/src/main/java/de/kittybot/kittybot/commands/info/DashboardCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/info/DashboardCommand.java @@ -2,9 +2,9 @@ import de.kittybot.kittybot.slashcommands.application.Category; import de.kittybot.kittybot.slashcommands.application.RunCommand; +import de.kittybot.kittybot.slashcommands.CommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.options.SubCommand; -import de.kittybot.kittybot.slashcommands.interaction.Interaction; -import de.kittybot.kittybot.slashcommands.interaction.Options; import de.kittybot.kittybot.utils.Config; import de.kittybot.kittybot.utils.MessageUtils; @@ -16,8 +16,8 @@ public DashboardCommand(){ } @Override - public void run(Options options, Interaction ia){ - ia.reply("You can find our dashboard " + MessageUtils.maskLink("here", Config.ORIGIN_URL)); + public void run(Options options, CommandContext ctx){ + ctx.reply("You can find our dashboard " + MessageUtils.maskLink("here", Config.ORIGIN_URL)); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/info/HelpCommand.java b/src/main/java/de/kittybot/kittybot/commands/info/HelpCommand.java index b6f93cc60..865e4a494 100644 --- a/src/main/java/de/kittybot/kittybot/commands/info/HelpCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/info/HelpCommand.java @@ -1,10 +1,10 @@ package de.kittybot.kittybot.commands.info; import de.kittybot.kittybot.objects.enums.Emoji; +import de.kittybot.kittybot.slashcommands.CommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.Category; import de.kittybot.kittybot.slashcommands.application.RunCommand; -import de.kittybot.kittybot.slashcommands.interaction.Interaction; -import de.kittybot.kittybot.slashcommands.interaction.Options; import de.kittybot.kittybot.utils.Config; import de.kittybot.kittybot.utils.MessageUtils; @@ -16,12 +16,12 @@ public HelpCommand(){ } @Override - public void run(Options options, Interaction ia){ - ia.reply(builder -> builder - .setAuthor("Help", Config.ORIGIN_URL, ia.getSelfUser().getEffectiveAvatarUrl()) - .setThumbnail(ia.getSelfUser().getEffectiveAvatarUrl()) + public void run(Options options, CommandContext ctx){ + ctx.reply(builder -> builder + .setAuthor("Help", Config.ORIGIN_URL, ctx.getSelfUser().getEffectiveAvatarUrl()) + .setThumbnail(ctx.getSelfUser().getEffectiveAvatarUrl()) .setDescription( - "Hello " + ia.getUser().getAsMention() + "\n" + + "Hello " + ctx.getUser().getAsMention() + "\n" + "KittyBot uses the new " + Emoji.SLASH.get() + " Slash Commands by Discord!\n" + "To see all available commands just type `/` or use `/commands`\n\n" + MessageUtils.maskLink("Website", Config.ORIGIN_URL) + " | " + diff --git a/src/main/java/de/kittybot/kittybot/commands/info/InfoCommand.java b/src/main/java/de/kittybot/kittybot/commands/info/InfoCommand.java index 687e34d95..7b200beaf 100644 --- a/src/main/java/de/kittybot/kittybot/commands/info/InfoCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/info/InfoCommand.java @@ -1,10 +1,9 @@ package de.kittybot.kittybot.commands.info; +import de.kittybot.kittybot.slashcommands.CommandContext; import de.kittybot.kittybot.slashcommands.application.Category; import de.kittybot.kittybot.slashcommands.application.RunCommand; -import de.kittybot.kittybot.slashcommands.application.options.SubCommand; -import de.kittybot.kittybot.slashcommands.interaction.Interaction; -import de.kittybot.kittybot.slashcommands.interaction.Options; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.utils.Config; import de.kittybot.kittybot.utils.Utils; import net.dv8tion.jda.api.JDAInfo; @@ -19,10 +18,10 @@ public InfoCommand(){ } @Override - public void run(Options options, Interaction ia){ - var shardManager = ia.getModules().getShardManager(); + public void run(Options options, CommandContext ctx){ + var shardManager = ctx.getModules().getShardManager(); var runtime = Runtime.getRuntime(); - ia.reply(builder -> builder + ctx.reply(builder -> builder .setAuthor("KittyBot Information", Config.ORIGIN_URL, Category.INFORMATION.getEmoteUrl()) .addField("JVM Version:", System.getProperty("java.version"), true) @@ -30,7 +29,7 @@ public void run(Options options, Interaction ia){ .addBlankField(true) .addField("Total Shards:", String.valueOf(shardManager.getShardsTotal()), true) - .addField("Current Shard:", String.valueOf(ia.getJDA().getShardInfo().getShardId()), true) + .addField("Current Shard:", String.valueOf(ctx.getJDA().getShardInfo().getShardId()), true) .addBlankField(true) .addField("Total Guilds:", String.valueOf(shardManager.getGuildCache().size()), true) diff --git a/src/main/java/de/kittybot/kittybot/commands/info/PingCommand.java b/src/main/java/de/kittybot/kittybot/commands/info/PingCommand.java index 71809303c..bff97a669 100644 --- a/src/main/java/de/kittybot/kittybot/commands/info/PingCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/info/PingCommand.java @@ -2,9 +2,9 @@ import de.kittybot.kittybot.slashcommands.application.Category; import de.kittybot.kittybot.slashcommands.application.RunCommand; +import de.kittybot.kittybot.slashcommands.CommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.options.SubCommand; -import de.kittybot.kittybot.slashcommands.interaction.Interaction; -import de.kittybot.kittybot.slashcommands.interaction.Options; import de.kittybot.kittybot.utils.Config; @SuppressWarnings("unused") @@ -15,10 +15,10 @@ public PingCommand(){ } @Override - public void run(Options options, Interaction ia){ - var jda = ia.getJDA(); + public void run(Options options, CommandContext ctx){ + var jda = ctx.getJDA(); jda.getRestPing().queue(ping -> - ia.reply(builder -> builder + ctx.reply(builder -> builder .setAuthor("KittyBot Ping", Config.ORIGIN_URL, jda.getSelfUser().getEffectiveAvatarUrl()) .addField("Gateway Ping:", jda.getGatewayPing() + "ms", false) diff --git a/src/main/java/de/kittybot/kittybot/commands/info/PrivacyCommand.java b/src/main/java/de/kittybot/kittybot/commands/info/PrivacyCommand.java index 1bfd09686..c007804f5 100644 --- a/src/main/java/de/kittybot/kittybot/commands/info/PrivacyCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/info/PrivacyCommand.java @@ -2,9 +2,9 @@ import de.kittybot.kittybot.slashcommands.application.Category; import de.kittybot.kittybot.slashcommands.application.RunCommand; +import de.kittybot.kittybot.slashcommands.CommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.options.SubCommand; -import de.kittybot.kittybot.slashcommands.interaction.Interaction; -import de.kittybot.kittybot.slashcommands.interaction.Options; import de.kittybot.kittybot.utils.Config; import de.kittybot.kittybot.utils.MessageUtils; @@ -16,8 +16,8 @@ public PrivacyCommand(){ } @Override - public void run(Options options, Interaction ia){ - ia.reply("You can find our privacy policy " + MessageUtils.maskLink("here", Config.ORIGIN_URL + "/privacy")); + public void run(Options options, CommandContext ctx){ + ctx.reply("You can find our privacy policy " + MessageUtils.maskLink("here", Config.ORIGIN_URL + "/privacy")); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/info/ServerBannerCommand.java b/src/main/java/de/kittybot/kittybot/commands/info/ServerBannerCommand.java index ab42a1d30..98920acf7 100644 --- a/src/main/java/de/kittybot/kittybot/commands/info/ServerBannerCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/info/ServerBannerCommand.java @@ -1,14 +1,13 @@ package de.kittybot.kittybot.commands.info; +import de.kittybot.kittybot.slashcommands.CommandContext; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.Category; -import de.kittybot.kittybot.slashcommands.application.CommandOptionChoice; +import de.kittybot.kittybot.slashcommands.application.OptionChoice; import de.kittybot.kittybot.slashcommands.application.RunCommand; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionInteger; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionLong; -import de.kittybot.kittybot.slashcommands.application.options.SubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Interaction; -import de.kittybot.kittybot.slashcommands.interaction.Options; import de.kittybot.kittybot.utils.MessageUtils; @SuppressWarnings("unused") @@ -20,38 +19,38 @@ public ServerBannerCommand(){ new CommandOptionLong("server-id", "The server id to get the banner from"), new CommandOptionInteger("size", "The image size") .addChoices( - new CommandOptionChoice<>("16", 16), - new CommandOptionChoice<>("32", 32), - new CommandOptionChoice<>("64", 64), - new CommandOptionChoice<>("128", 128), - new CommandOptionChoice<>("256", 256), - new CommandOptionChoice<>("512", 512), - new CommandOptionChoice<>("1024", 1024), - new CommandOptionChoice<>("2048", 2048) + new OptionChoice("16", 16), + new OptionChoice("32", 32), + new OptionChoice("64", 64), + new OptionChoice("128", 128), + new OptionChoice("256", 256), + new OptionChoice("512", 512), + new OptionChoice("1024", 1024), + new OptionChoice("2048", 2048) ) ); } @Override - public void run(Options options, Interaction ia){ - var guildId = options.getOrDefault("server-id", ia instanceof GuildInteraction ? ((GuildInteraction) ia).getGuildId() : -1L); + public void run(Options options, CommandContext ctx){ + var guildId = options.getLong("server-id", ctx instanceof GuildCommandContext ? ((GuildCommandContext) ctx).getGuildId() : -1L); if(guildId == -1L){ - ia.error("Please provide a server id"); + ctx.error("Please provide a server id"); return; } var size = options.has("size") ? options.getInt("size") : 1024; - var guild = ia.getJDA().getGuildById(guildId); + var guild = ctx.getJDA().getGuildById(guildId); if(guild == null){ - ia.error("Server not found in my cache"); + ctx.error("Server not found in my cache"); return; } var banner = guild.getBannerUrl(); if(banner == null){ - ia.error("Server has no banner set"); + ctx.error("Server has no banner set"); return; } - ia.reply(builder -> builder + ctx.reply(builder -> builder .setTitle(guild.getName() + " Banner") .setThumbnail(banner) .setDescription(MessageUtils.maskLink(size + "px", banner + "?size=" + size))); diff --git a/src/main/java/de/kittybot/kittybot/commands/info/ServerIconCommand.java b/src/main/java/de/kittybot/kittybot/commands/info/ServerIconCommand.java index 9820bffb3..77e73e238 100644 --- a/src/main/java/de/kittybot/kittybot/commands/info/ServerIconCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/info/ServerIconCommand.java @@ -1,14 +1,13 @@ package de.kittybot.kittybot.commands.info; +import de.kittybot.kittybot.slashcommands.CommandContext; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.Category; -import de.kittybot.kittybot.slashcommands.application.CommandOptionChoice; +import de.kittybot.kittybot.slashcommands.application.OptionChoice; import de.kittybot.kittybot.slashcommands.application.RunCommand; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionInteger; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionLong; -import de.kittybot.kittybot.slashcommands.application.options.SubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Interaction; -import de.kittybot.kittybot.slashcommands.interaction.Options; import de.kittybot.kittybot.utils.MessageUtils; @SuppressWarnings("unused") @@ -20,38 +19,38 @@ public ServerIconCommand(){ new CommandOptionLong("server-id", "The server id to get the icon from").required(), new CommandOptionInteger("size", "The image size") .addChoices( - new CommandOptionChoice<>("16", 16), - new CommandOptionChoice<>("32", 32), - new CommandOptionChoice<>("64", 64), - new CommandOptionChoice<>("128", 128), - new CommandOptionChoice<>("256", 256), - new CommandOptionChoice<>("512", 512), - new CommandOptionChoice<>("1024", 1024), - new CommandOptionChoice<>("2048", 2048) + new OptionChoice("16", 16), + new OptionChoice("32", 32), + new OptionChoice("64", 64), + new OptionChoice("128", 128), + new OptionChoice("256", 256), + new OptionChoice("512", 512), + new OptionChoice("1024", 1024), + new OptionChoice("2048", 2048) ) ); } @Override - public void run(Options options, Interaction ia){ - var guildId = options.getOrDefault("server-id", ia instanceof GuildInteraction ? ((GuildInteraction) ia).getGuildId() : -1L); + public void run(Options options, CommandContext ctx){ + var guildId = options.getLong("guild-id", ctx instanceof GuildCommandContext ? ((GuildCommandContext) ctx).getGuildId() : -1L); if(guildId == -1L){ - ia.error("Please provide a server id"); + ctx.error("Please provide a server id"); return; } var size = options.has("size") ? options.getInt("size") : 1024; - var guild = ia.getJDA().getGuildById(guildId); + var guild = ctx.getJDA().getGuildById(guildId); if(guild == null){ - ia.error("Server not found"); + ctx.error("Server not found"); return; } var icon = guild.getIconUrl(); if(icon == null){ - ia.error("Server has no icon set"); + ctx.error("Server has no icon set"); return; } - ia.reply(builder -> builder + ctx.reply(builder -> builder .setTitle(guild.getName() + " Icon") .setThumbnail(icon) .setDescription(MessageUtils.maskLink(size + "px", icon + "?size=" + size))); diff --git a/src/main/java/de/kittybot/kittybot/commands/info/UptimeCommand.java b/src/main/java/de/kittybot/kittybot/commands/info/UptimeCommand.java index 91552169d..cff04bab5 100644 --- a/src/main/java/de/kittybot/kittybot/commands/info/UptimeCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/info/UptimeCommand.java @@ -1,10 +1,10 @@ package de.kittybot.kittybot.commands.info; +import de.kittybot.kittybot.slashcommands.CommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.Category; import de.kittybot.kittybot.slashcommands.application.RunCommand; import de.kittybot.kittybot.slashcommands.application.options.SubCommand; -import de.kittybot.kittybot.slashcommands.interaction.Interaction; -import de.kittybot.kittybot.slashcommands.interaction.Options; import de.kittybot.kittybot.utils.Config; import de.kittybot.kittybot.utils.TimeUtils; @@ -18,9 +18,9 @@ public UptimeCommand(){ } @Override - public void run(Options options, Interaction ia){ - ia.reply(builder -> builder - .setAuthor("KittyBot Uptime", Config.ORIGIN_URL, ia.getSelfUser().getEffectiveAvatarUrl()) + public void run(Options options, CommandContext ctx){ + ctx.reply(builder -> builder + .setAuthor("KittyBot Uptime", Config.ORIGIN_URL, ctx.getSelfUser().getEffectiveAvatarUrl()) .addField("Uptime:", TimeUtils.formatDurationDHMS(ManagementFactory.getRuntimeMXBean().getUptime()), false) ); } diff --git a/src/main/java/de/kittybot/kittybot/commands/info/VoteCommand.java b/src/main/java/de/kittybot/kittybot/commands/info/VoteCommand.java index 851a3f6d9..aa30ad289 100644 --- a/src/main/java/de/kittybot/kittybot/commands/info/VoteCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/info/VoteCommand.java @@ -1,12 +1,11 @@ package de.kittybot.kittybot.commands.info; import de.kittybot.kittybot.objects.enums.BotList; +import de.kittybot.kittybot.slashcommands.CommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.Category; -import de.kittybot.kittybot.slashcommands.application.Command; import de.kittybot.kittybot.slashcommands.application.RunCommand; import de.kittybot.kittybot.slashcommands.application.options.SubCommand; -import de.kittybot.kittybot.slashcommands.interaction.Interaction; -import de.kittybot.kittybot.slashcommands.interaction.Options; import de.kittybot.kittybot.utils.MessageUtils; import java.util.Arrays; @@ -20,8 +19,8 @@ public VoteCommand(){ } @Override - public void run(Options options, Interaction ia){ - ia.reply("You can vote on following sites for KittyBot:\n" + Arrays.stream(BotList.values()). + public void run(Options options, CommandContext ctx){ + ctx.reply("You can vote on following sites for KittyBot:\n" + Arrays.stream(BotList.values()). filter(BotList::canVote) .map(botList -> MessageUtils.maskLink(botList.getName(), botList.getBotUrl())) .collect(Collectors.joining(", ")) diff --git a/src/main/java/de/kittybot/kittybot/commands/music/FilterCommand.java b/src/main/java/de/kittybot/kittybot/commands/music/FilterCommand.java index 30d370235..652901b77 100644 --- a/src/main/java/de/kittybot/kittybot/commands/music/FilterCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/music/FilterCommand.java @@ -1,13 +1,13 @@ package de.kittybot.kittybot.commands.music; import de.kittybot.kittybot.modules.MusicModule; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.Category; import de.kittybot.kittybot.slashcommands.application.Command; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionFloat; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionInteger; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; import de.kittybot.kittybot.utils.MusicUtils; import lavalink.client.io.filters.*; @@ -39,15 +39,15 @@ public EqualizerCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ - var scheduler = ia.get(MusicModule.class).getScheduler(ia.getGuildId()); - if(!MusicUtils.checkCommandRequirements(ia, scheduler) || !MusicUtils.checkMusicPermissions(ia, scheduler)){ + public void run(Options options, GuildCommandContext ctx){ + var scheduler = ctx.get(MusicModule.class).getScheduler(ctx.getGuildId()); + if(!MusicUtils.checkCommandRequirements(ctx, scheduler) || !MusicUtils.checkMusicPermissions(ctx, scheduler)){ return; } var band = options.getInt("band"); var multiplier = options.getFloat("multiplier"); scheduler.getFilters().setBand(band, multiplier).commit(); - ia.reply("Set band " + band + " to " + multiplier); + ctx.reply("Set band " + band + " to " + multiplier); } } @@ -65,9 +65,9 @@ public KaraokeCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ - var scheduler = ia.get(MusicModule.class).getScheduler(ia.getGuildId()); - if(!MusicUtils.checkCommandRequirements(ia, scheduler) || !MusicUtils.checkMusicPermissions(ia, scheduler)){ + public void run(Options options, GuildCommandContext ctx){ + var scheduler = ctx.get(MusicModule.class).getScheduler(ctx.getGuildId()); + if(!MusicUtils.checkCommandRequirements(ctx, scheduler) || !MusicUtils.checkMusicPermissions(ctx, scheduler)){ return; } var karaoke = new Karaoke(); @@ -84,7 +84,7 @@ public void run(Options options, GuildInteraction ia){ karaoke = karaoke.setFilterWidth(options.getFloat("filterWidth")); } scheduler.getFilters().setKaraoke(karaoke).commit(); - ia.reply("Set karaoke filter"); + ctx.reply("Set karaoke filter"); } } @@ -101,9 +101,9 @@ public TimescaleCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ - var scheduler = ia.get(MusicModule.class).getScheduler(ia.getGuildId()); - if(!MusicUtils.checkCommandRequirements(ia, scheduler) || !MusicUtils.checkMusicPermissions(ia, scheduler)){ + public void run(Options options, GuildCommandContext ctx){ + var scheduler = ctx.get(MusicModule.class).getScheduler(ctx.getGuildId()); + if(!MusicUtils.checkCommandRequirements(ctx, scheduler) || !MusicUtils.checkMusicPermissions(ctx, scheduler)){ return; } var timescale = new Timescale(); @@ -117,7 +117,7 @@ public void run(Options options, GuildInteraction ia){ timescale = timescale.setRate(options.getFloat("rate")); } scheduler.getFilters().setTimescale(timescale).commit(); - ia.reply("Set timescale filter"); + ctx.reply("Set timescale filter"); } } @@ -133,9 +133,9 @@ public TremoloCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ - var scheduler = ia.get(MusicModule.class).getScheduler(ia.getGuildId()); - if(!MusicUtils.checkCommandRequirements(ia, scheduler) || !MusicUtils.checkMusicPermissions(ia, scheduler)){ + public void run(Options options, GuildCommandContext ctx){ + var scheduler = ctx.get(MusicModule.class).getScheduler(ctx.getGuildId()); + if(!MusicUtils.checkCommandRequirements(ctx, scheduler) || !MusicUtils.checkMusicPermissions(ctx, scheduler)){ return; } var tremolo = new Tremolo(); @@ -148,7 +148,7 @@ public void run(Options options, GuildInteraction ia){ tremolo = tremolo.setDepth(depth); } scheduler.getFilters().setTremolo(tremolo).commit(); - ia.reply("Set tremolo filter"); + ctx.reply("Set tremolo filter"); } } @@ -164,9 +164,9 @@ public VibratoCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ - var scheduler = ia.get(MusicModule.class).getScheduler(ia.getGuildId()); - if(!MusicUtils.checkCommandRequirements(ia, scheduler) || !MusicUtils.checkMusicPermissions(ia, scheduler)){ + public void run(Options options, GuildCommandContext ctx){ + var scheduler = ctx.get(MusicModule.class).getScheduler(ctx.getGuildId()); + if(!MusicUtils.checkCommandRequirements(ctx, scheduler) || !MusicUtils.checkMusicPermissions(ctx, scheduler)){ return; } var vibrato = new Vibrato(); @@ -179,7 +179,7 @@ public void run(Options options, GuildInteraction ia){ vibrato = vibrato.setDepth(depth); } scheduler.getFilters().setVibrato(vibrato).commit(); - ia.reply("Set vibrato filter"); + ctx.reply("Set vibrato filter"); } } @@ -194,14 +194,14 @@ public RotationCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ - var scheduler = ia.get(MusicModule.class).getScheduler(ia.getGuildId()); - if(!MusicUtils.checkCommandRequirements(ia, scheduler) || !MusicUtils.checkMusicPermissions(ia, scheduler)){ + public void run(Options options, GuildCommandContext ctx){ + var scheduler = ctx.get(MusicModule.class).getScheduler(ctx.getGuildId()); + if(!MusicUtils.checkCommandRequirements(ctx, scheduler) || !MusicUtils.checkMusicPermissions(ctx, scheduler)){ return; } var frequency = options.getFloat("frequency"); scheduler.getFilters().setRotation(new Rotation().setFrequency(frequency)).commit(); - ia.reply("Set rotation filter"); + ctx.reply("Set rotation filter"); } } @@ -224,9 +224,9 @@ public DistortionCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ - var scheduler = ia.get(MusicModule.class).getScheduler(ia.getGuildId()); - if(!MusicUtils.checkCommandRequirements(ia, scheduler) || !MusicUtils.checkMusicPermissions(ia, scheduler)){ + public void run(Options options, GuildCommandContext ctx){ + var scheduler = ctx.get(MusicModule.class).getScheduler(ctx.getGuildId()); + if(!MusicUtils.checkCommandRequirements(ctx, scheduler) || !MusicUtils.checkMusicPermissions(ctx, scheduler)){ return; } var distortion = new Distortion(); @@ -257,7 +257,7 @@ public void run(Options options, GuildInteraction ia){ } scheduler.getFilters().setDistortion(distortion).commit(); - ia.reply("Set distortion filter"); + ctx.reply("Set distortion filter"); } } @@ -269,13 +269,13 @@ public ClearCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ - var scheduler = ia.get(MusicModule.class).getScheduler(ia.getGuildId()); - if(!MusicUtils.checkCommandRequirements(ia, scheduler) || !MusicUtils.checkMusicPermissions(ia, scheduler)){ + public void run(Options options, GuildCommandContext ctx){ + var scheduler = ctx.get(MusicModule.class).getScheduler(ctx.getGuildId()); + if(!MusicUtils.checkCommandRequirements(ctx, scheduler) || !MusicUtils.checkMusicPermissions(ctx, scheduler)){ return; } scheduler.getFilters().clear().commit(); - ia.reply("Cleared all filters!"); + ctx.reply("Cleared all filters!"); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/music/ForwardCommand.java b/src/main/java/de/kittybot/kittybot/commands/music/ForwardCommand.java index 6aea7c8b2..b36856761 100644 --- a/src/main/java/de/kittybot/kittybot/commands/music/ForwardCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/music/ForwardCommand.java @@ -1,11 +1,11 @@ package de.kittybot.kittybot.commands.music; import de.kittybot.kittybot.modules.MusicModule; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.Category; import de.kittybot.kittybot.slashcommands.application.RunGuildCommand; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionInteger; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; import de.kittybot.kittybot.utils.MusicUtils; import de.kittybot.kittybot.utils.TimeUtils; @@ -20,12 +20,12 @@ public ForwardCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ - var scheduler = ia.get(MusicModule.class).getScheduler(ia.getGuildId()); - if(!MusicUtils.checkCommandRequirements(ia, scheduler)){ + public void run(Options options, GuildCommandContext ctx){ + var scheduler = ctx.get(MusicModule.class).getScheduler(ctx.getGuildId()); + if(!MusicUtils.checkCommandRequirements(ctx, scheduler)){ return; } - if(!MusicUtils.checkMusicPermissions(ia, scheduler)){ + if(!MusicUtils.checkMusicPermissions(ctx, scheduler)){ return; } var forward = options.getInt("seconds") * 1000; @@ -34,11 +34,11 @@ public void run(Options options, GuildInteraction ia){ var newPos = position + forward; if(newPos > scheduler.getPlayingTrack().getDuration()){ scheduler.next(true); - ia.reply("Skipped to next track"); + ctx.reply("Skipped to next track"); return; } lavalinkPlayer.seekTo(newPos); - ia.reply("Forwarded track to `" + TimeUtils.formatDuration(newPos) + "`"); + ctx.reply("Forwarded track to `" + TimeUtils.formatDuration(newPos) + "`"); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/music/HistoryCommand.java b/src/main/java/de/kittybot/kittybot/commands/music/HistoryCommand.java index 8865d74a2..5704e2951 100644 --- a/src/main/java/de/kittybot/kittybot/commands/music/HistoryCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/music/HistoryCommand.java @@ -1,10 +1,10 @@ package de.kittybot.kittybot.commands.music; import de.kittybot.kittybot.modules.MusicModule; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.Category; import de.kittybot.kittybot.slashcommands.application.RunGuildCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; import de.kittybot.kittybot.utils.MessageUtils; import de.kittybot.kittybot.utils.MusicUtils; @@ -16,17 +16,17 @@ public HistoryCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ - var scheduler = ia.get(MusicModule.class).getScheduler(ia.getGuildId()); - if(!MusicUtils.checkCommandRequirements(ia, scheduler)){ + public void run(Options options, GuildCommandContext ctx){ + var scheduler = ctx.get(MusicModule.class).getScheduler(ctx.getGuildId()); + if(!MusicUtils.checkCommandRequirements(ctx, scheduler)){ return; } var tracks = scheduler.getHistory(); if(tracks.isEmpty()){ - ia.reply("The history is empty. Play some tracks to fill it"); + ctx.reply("The history is empty. Play some tracks to fill it"); return; } - MusicUtils.sendTracks(tracks, ia.getModules(), ia.getChannel(), ia.getUserId(), "Currently " + tracks.size() + " " + MessageUtils.pluralize("track", tracks) + " are in the history"); + MusicUtils.sendTracks(tracks, ctx.getModules(), ctx.getChannel(), ctx.getUserId(), "Currently " + tracks.size() + " " + MessageUtils.pluralize("track", tracks) + " are in the history"); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/music/PauseCommand.java b/src/main/java/de/kittybot/kittybot/commands/music/PauseCommand.java index 9f1c2ae54..4a8ccb83c 100644 --- a/src/main/java/de/kittybot/kittybot/commands/music/PauseCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/music/PauseCommand.java @@ -1,11 +1,11 @@ package de.kittybot.kittybot.commands.music; import de.kittybot.kittybot.modules.MusicModule; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.Category; import de.kittybot.kittybot.slashcommands.application.RunGuildCommand; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionBoolean; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; import de.kittybot.kittybot.utils.MusicUtils; @SuppressWarnings("unused") @@ -19,12 +19,12 @@ public PauseCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ - var scheduler = ia.get(MusicModule.class).getScheduler(ia.getGuildId()); - if(!MusicUtils.checkCommandRequirements(ia, scheduler)){ + public void run(Options options, GuildCommandContext ctx){ + var scheduler = ctx.get(MusicModule.class).getScheduler(ctx.getGuildId()); + if(!MusicUtils.checkCommandRequirements(ctx, scheduler)){ return; } - if(!MusicUtils.checkMusicPermissions(ia, scheduler)){ + if(!MusicUtils.checkMusicPermissions(ctx, scheduler)){ return; } boolean pause; @@ -35,7 +35,7 @@ public void run(Options options, GuildInteraction ia){ pause = !scheduler.isPaused(); } scheduler.setPaused(pause); - ia.reply("Toggled pause"); + ctx.reply("Toggled pause"); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/music/PlayCommand.java b/src/main/java/de/kittybot/kittybot/commands/music/PlayCommand.java index 6eee71fa0..3f1b93b1d 100644 --- a/src/main/java/de/kittybot/kittybot/commands/music/PlayCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/music/PlayCommand.java @@ -2,12 +2,12 @@ import de.kittybot.kittybot.modules.MusicModule; import de.kittybot.kittybot.objects.music.SearchProvider; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.Category; -import de.kittybot.kittybot.slashcommands.application.CommandOptionChoice; +import de.kittybot.kittybot.slashcommands.application.OptionChoice; import de.kittybot.kittybot.slashcommands.application.RunGuildCommand; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionString; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; import de.kittybot.kittybot.utils.MusicUtils; import net.dv8tion.jda.api.Permission; @@ -20,28 +20,28 @@ public PlayCommand(){ new CommandOptionString("query", "A link or search query to play from").required(), new CommandOptionString("search-provider", "Which search provider use") .addChoices( - new CommandOptionChoice<>("youtube", "yt"), - new CommandOptionChoice<>("soundcloud", "sc")/*, + new OptionChoice("youtube", "yt"), + new OptionChoice("soundcloud", "sc")/*, new CommandOptionChoice<>("spotify", "sp")*/ ) ); } @Override - public void run(Options options, GuildInteraction ia){ - if(!ia.getGuild().getSelfMember().hasPermission(ia.getChannel(), Permission.MESSAGE_WRITE, Permission.MESSAGE_ADD_REACTION, Permission.MESSAGE_EXT_EMOJI, Permission.MESSAGE_HISTORY, Permission.VIEW_CHANNEL)){ - ia.error("Please make sure I have following permissions in this channel: `Send Messages`, `Add Reactions`, `Use External Emoji`, `Read Message History`, `View Channel`"); + public void run(Options options, GuildCommandContext ctx){ + if(!ctx.getGuild().getSelfMember().hasPermission(ctx.getChannel(), Permission.MESSAGE_WRITE, Permission.MESSAGE_ADD_REACTION, Permission.MESSAGE_EXT_EMOJI, Permission.MESSAGE_HISTORY, Permission.VIEW_CHANNEL)){ + ctx.error("Please make sure I have following permissions in this channel: `Send Messages`, `Add Reactions`, `Use External Emoji`, `Read Message History`, `View Channel`"); return; } - if(!MusicUtils.checkMusicRequirements(ia)){ + if(!MusicUtils.checkMusicRequirements(ctx)){ return; } - var musicModule = ia.get(MusicModule.class); + var musicModule = ctx.get(MusicModule.class); var searchProvider = SearchProvider.YOUTUBE; if(options.has("search-provider")){ searchProvider = SearchProvider.getByShortname(options.getString("search-provider")); } - musicModule.play(ia, options.getString("query"), searchProvider); + musicModule.play(ctx, options.getString("query"), searchProvider); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/music/PreviousCommand.java b/src/main/java/de/kittybot/kittybot/commands/music/PreviousCommand.java index a0e782340..0414731b0 100644 --- a/src/main/java/de/kittybot/kittybot/commands/music/PreviousCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/music/PreviousCommand.java @@ -1,10 +1,10 @@ package de.kittybot.kittybot.commands.music; import de.kittybot.kittybot.modules.MusicModule; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.Category; import de.kittybot.kittybot.slashcommands.application.RunGuildCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; import de.kittybot.kittybot.utils.MusicUtils; @SuppressWarnings("unused") @@ -15,19 +15,19 @@ public PreviousCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ - var scheduler = ia.get(MusicModule.class).getScheduler(ia.getGuildId()); - if(!MusicUtils.checkCommandRequirements(ia, scheduler)){ + public void run(Options options, GuildCommandContext ctx){ + var scheduler = ctx.get(MusicModule.class).getScheduler(ctx.getGuildId()); + if(!MusicUtils.checkCommandRequirements(ctx, scheduler)){ return; } - if(!MusicUtils.checkMusicPermissions(ia, scheduler)){ + if(!MusicUtils.checkMusicPermissions(ctx, scheduler)){ return; } if(scheduler.getHistory().isEmpty()){ - ia.error("Can't go back because the history is empty"); + ctx.error("Can't go back because the history is empty"); return; } - ia.reply("Went back to the previous song"); + ctx.reply("Went back to the previous song"); scheduler.previous(); scheduler.setPaused(false); } diff --git a/src/main/java/de/kittybot/kittybot/commands/music/QueueCommand.java b/src/main/java/de/kittybot/kittybot/commands/music/QueueCommand.java index c011d21ee..4da750228 100644 --- a/src/main/java/de/kittybot/kittybot/commands/music/QueueCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/music/QueueCommand.java @@ -2,12 +2,12 @@ import de.kittybot.kittybot.modules.MusicModule; import de.kittybot.kittybot.objects.music.SearchProvider; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.Category; -import de.kittybot.kittybot.slashcommands.application.CommandOptionChoice; +import de.kittybot.kittybot.slashcommands.application.OptionChoice; import de.kittybot.kittybot.slashcommands.application.RunGuildCommand; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionString; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; import de.kittybot.kittybot.utils.MessageUtils; import de.kittybot.kittybot.utils.MusicUtils; import net.dv8tion.jda.api.Permission; @@ -21,41 +21,41 @@ public QueueCommand(){ new CommandOptionString("query", "A link or search query to play from"), new CommandOptionString("search-provider", "Which search provider use") .addChoices( - new CommandOptionChoice<>(SearchProvider.YOUTUBE), - new CommandOptionChoice<>(SearchProvider.SOUNDCLOUD)/*, + new OptionChoice(SearchProvider.YOUTUBE), + new OptionChoice(SearchProvider.SOUNDCLOUD)/*, new CommandOptionChoice<>("spotify", "sp")*/ ) ); } @Override - public void run(Options options, GuildInteraction ia){ - if(!ia.getGuild().getSelfMember().hasPermission(ia.getChannel(), Permission.MESSAGE_WRITE, Permission.MESSAGE_ADD_REACTION, Permission.MESSAGE_EXT_EMOJI, Permission.MESSAGE_HISTORY, Permission.VIEW_CHANNEL)){ - ia.error("Please make sure I have following permissions in this channel: `Send Messages`, `Add Reactions`, `Use External Emoji`, `Read Message History`, `View Channel`"); + public void run(Options options, GuildCommandContext ctx){ + if(!ctx.getGuild().getSelfMember().hasPermission(ctx.getChannel(), Permission.MESSAGE_WRITE, Permission.MESSAGE_ADD_REACTION, Permission.MESSAGE_EXT_EMOJI, Permission.MESSAGE_HISTORY, Permission.VIEW_CHANNEL)){ + ctx.error("Please make sure I have following permissions in this channel: `Send Messages`, `Add Reactions`, `Use External Emoji`, `Read Message History`, `View Channel`"); return; } - if(!MusicUtils.checkMusicRequirements(ia)){ + if(!MusicUtils.checkMusicRequirements(ctx)){ return; } - var musicModule = ia.get(MusicModule.class); + var musicModule = ctx.get(MusicModule.class); if(options.has("query")){ var searchProvider = SearchProvider.YOUTUBE; if(options.has("search-provider")){ searchProvider = SearchProvider.getByShortname(options.getString("search-provider")); } - musicModule.play(ia, options.getString("query"), searchProvider); + musicModule.play(ctx, options.getString("query"), searchProvider); return; } - var manager = musicModule.get(ia.getGuildId()); + var manager = musicModule.get(ctx.getGuildId()); var scheduler = manager.getScheduler(); var tracks = scheduler.getQueue(); if(tracks.isEmpty()){ - ia.reply("The queue is empty. You can queue new tracks with `/play ` or `/queue `"); + ctx.reply("The queue is empty. You can queue new tracks with `/play ` or `/queue `"); return; } - ia.acknowledge(true).queue(success -> - MusicUtils.sendTracks(tracks, ia.getModules(), ia.getChannel(), ia.getUserId(), "Currently " + tracks.size() + " " + MessageUtils.pluralize("track", tracks) + " are queued") + ctx.acknowledge(true).queue(success -> + MusicUtils.sendTracks(tracks, ctx.getModules(), ctx.getChannel(), ctx.getUserId(), "Currently " + tracks.size() + " " + MessageUtils.pluralize("track", tracks) + " are queued") ); } diff --git a/src/main/java/de/kittybot/kittybot/commands/music/RemoveCommand.java b/src/main/java/de/kittybot/kittybot/commands/music/RemoveCommand.java index 3f4465305..906c5aa31 100644 --- a/src/main/java/de/kittybot/kittybot/commands/music/RemoveCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/music/RemoveCommand.java @@ -2,12 +2,12 @@ import de.kittybot.kittybot.modules.MusicModule; import de.kittybot.kittybot.modules.SettingsModule; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.Category; import de.kittybot.kittybot.slashcommands.application.RunGuildCommand; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionBoolean; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionInteger; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; import de.kittybot.kittybot.utils.MusicUtils; import net.dv8tion.jda.api.Permission; @@ -24,35 +24,35 @@ public RemoveCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ - var scheduler = ia.get(MusicModule.class).getScheduler(ia.getGuildId()); + public void run(Options options, GuildCommandContext ctx){ + var scheduler = ctx.get(MusicModule.class).getScheduler(ctx.getGuildId()); var queue = scheduler.getQueue(); if(queue.isEmpty()){ - ia.error("The queue is empty. Nothing to remove"); + ctx.error("The queue is empty. Nothing to remove"); return; } - if(!MusicUtils.checkCommandRequirements(ia, scheduler)){ + if(!MusicUtils.checkCommandRequirements(ctx, scheduler)){ return; } if(options.has("all") && options.getBoolean("all")){ - var member = ia.getMember(); - if(!member.hasPermission(Permission.ADMINISTRATOR) && !ia.get(SettingsModule.class).hasDJRole(member)){ - ia.error("You need to be the dj"); + var member = ctx.getMember(); + if(!member.hasPermission(Permission.ADMINISTRATOR) && !ctx.get(SettingsModule.class).hasDJRole(member)){ + ctx.error("You need to be the dj"); return; } scheduler.getQueue().clear(); - ia.reply("Removed all queued songs"); + ctx.reply("Removed all queued songs"); return; } if(!options.has("from")){ - ia.error("Please specify from"); + ctx.error("Please specify from"); return; } var from = options.getInt("from"); var to = options.has("to") ? options.getInt("to") : from; - var removed = scheduler.removeQueue(from, to, ia.getMember()); - ia.reply("Removed " + removed + " " + (removed > 1 ? "entries" : "entry")); + var removed = scheduler.removeQueue(from, to, ctx.getMember()); + ctx.reply("Removed " + removed + " " + (removed > 1 ? "entries" : "entry")); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/music/RepeatCommand.java b/src/main/java/de/kittybot/kittybot/commands/music/RepeatCommand.java index 54f09f26b..d66187efe 100644 --- a/src/main/java/de/kittybot/kittybot/commands/music/RepeatCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/music/RepeatCommand.java @@ -2,12 +2,12 @@ import de.kittybot.kittybot.modules.MusicModule; import de.kittybot.kittybot.objects.music.RepeatMode; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.Category; -import de.kittybot.kittybot.slashcommands.application.CommandOptionChoice; +import de.kittybot.kittybot.slashcommands.application.OptionChoice; import de.kittybot.kittybot.slashcommands.application.RunGuildCommand; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionString; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; @SuppressWarnings("unused") public class RepeatCommand extends RunGuildCommand{ @@ -17,20 +17,20 @@ public RepeatCommand(){ addOptions( new CommandOptionString("type", "The repeat mode").required() .addChoices( - new CommandOptionChoice<>("off", "OFF"), - new CommandOptionChoice<>("song", "SONG"), - new CommandOptionChoice<>("queue", "QUEUE") + new OptionChoice("off", "OFF"), + new OptionChoice("song", "SONG"), + new OptionChoice("queue", "QUEUE") ) ); } @Override - public void run(Options options, GuildInteraction ia){ - var scheduler = ia.get(MusicModule.class).getScheduler(ia.getGuildId()); + public void run(Options options, GuildCommandContext ctx){ + var scheduler = ctx.get(MusicModule.class).getScheduler(ctx.getGuildId()); var repeatMode = RepeatMode.valueOf(options.getString("type")); scheduler.setRepeatMode(repeatMode); - ia.reply("Set repeat mode to `" + repeatMode.getName() + "`"); + ctx.reply("Set repeat mode to `" + repeatMode.getName() + "`"); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/music/RewindCommand.java b/src/main/java/de/kittybot/kittybot/commands/music/RewindCommand.java index 71c9ba43a..2bc2a8c36 100644 --- a/src/main/java/de/kittybot/kittybot/commands/music/RewindCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/music/RewindCommand.java @@ -1,11 +1,11 @@ package de.kittybot.kittybot.commands.music; import de.kittybot.kittybot.modules.MusicModule; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.Category; import de.kittybot.kittybot.slashcommands.application.RunGuildCommand; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionInteger; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; import de.kittybot.kittybot.utils.MusicUtils; import de.kittybot.kittybot.utils.TimeUtils; @@ -20,12 +20,12 @@ public RewindCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ - var scheduler = ia.get(MusicModule.class).getScheduler(ia.getGuildId()); - if(!MusicUtils.checkCommandRequirements(ia, scheduler)){ + public void run(Options options, GuildCommandContext ctx){ + var scheduler = ctx.get(MusicModule.class).getScheduler(ctx.getGuildId()); + if(!MusicUtils.checkCommandRequirements(ctx, scheduler)){ return; } - if(!MusicUtils.checkMusicPermissions(ia, scheduler)){ + if(!MusicUtils.checkMusicPermissions(ctx, scheduler)){ return; } var rewind = options.getInt("seconds") * 1000; @@ -36,7 +36,7 @@ public void run(Options options, GuildInteraction ia){ newPos = 0; } lavalinkPlayer.seekTo(newPos); - ia.reply("Rewinded track to `" + TimeUtils.formatDuration(newPos) + "`"); + ctx.reply("Rewinded track to `" + TimeUtils.formatDuration(newPos) + "`"); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/music/SearchCommand.java b/src/main/java/de/kittybot/kittybot/commands/music/SearchCommand.java index 025f22541..ef745e320 100644 --- a/src/main/java/de/kittybot/kittybot/commands/music/SearchCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/music/SearchCommand.java @@ -1,11 +1,11 @@ package de.kittybot.kittybot.commands.music; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.Category; -import de.kittybot.kittybot.slashcommands.application.CommandOptionChoice; +import de.kittybot.kittybot.slashcommands.application.OptionChoice; import de.kittybot.kittybot.slashcommands.application.RunGuildCommand; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionString; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; import de.kittybot.kittybot.utils.annotations.Ignore; @SuppressWarnings("unused") @@ -18,16 +18,16 @@ public SearchCommand(){ new CommandOptionString("search-term", "A search-term to search for").required(), new CommandOptionString("search-provider", "Which search provider use") .addChoices( - new CommandOptionChoice<>("youtube", "yt"), - new CommandOptionChoice<>("soundcloud", "sc") + new OptionChoice("youtube", "yt"), + new OptionChoice("soundcloud", "sc") ) ); } @Override - public void run(Options options, GuildInteraction ia){ + public void run(Options options, GuildCommandContext ctx){ // TODO implement - ia.error("not implemented yet"); + ctx.error("not implemented yet"); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/music/SeekCommand.java b/src/main/java/de/kittybot/kittybot/commands/music/SeekCommand.java index b0da4127c..84df40764 100644 --- a/src/main/java/de/kittybot/kittybot/commands/music/SeekCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/music/SeekCommand.java @@ -1,11 +1,11 @@ package de.kittybot.kittybot.commands.music; import de.kittybot.kittybot.modules.MusicModule; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.Category; import de.kittybot.kittybot.slashcommands.application.RunGuildCommand; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionInteger; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; import de.kittybot.kittybot.utils.MusicUtils; import de.kittybot.kittybot.utils.TimeUtils; @@ -20,23 +20,23 @@ public SeekCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ - var scheduler = ia.get(MusicModule.class).getScheduler(ia.getGuildId()); - if(!MusicUtils.checkCommandRequirements(ia, scheduler)){ + public void run(Options options, GuildCommandContext ctx){ + var scheduler = ctx.get(MusicModule.class).getScheduler(ctx.getGuildId()); + if(!MusicUtils.checkCommandRequirements(ctx, scheduler)){ return; } - if(!MusicUtils.checkMusicPermissions(ia, scheduler)){ + if(!MusicUtils.checkMusicPermissions(ctx, scheduler)){ return; } var newPos = options.getLong("seconds") * 1000; var lavalinkPlayer = scheduler.getPlayer(); if(newPos > scheduler.getPlayingTrack().getDuration()){ scheduler.next(true); - ia.reply("Skipped to next track"); + ctx.reply("Skipped to next track"); return; } lavalinkPlayer.seekTo(newPos); - ia.reply("Sought to `" + TimeUtils.formatDuration(newPos) + "`"); + ctx.reply("Sought to `" + TimeUtils.formatDuration(newPos) + "`"); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/music/ShuffleCommand.java b/src/main/java/de/kittybot/kittybot/commands/music/ShuffleCommand.java index 0c4502e6b..d1e68f91e 100644 --- a/src/main/java/de/kittybot/kittybot/commands/music/ShuffleCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/music/ShuffleCommand.java @@ -2,10 +2,10 @@ import de.kittybot.kittybot.modules.MusicModule; import de.kittybot.kittybot.modules.SettingsModule; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.Category; import de.kittybot.kittybot.slashcommands.application.RunGuildCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; import de.kittybot.kittybot.utils.MusicUtils; @SuppressWarnings("unused") @@ -16,20 +16,20 @@ public ShuffleCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ - var scheduler = ia.get(MusicModule.class).getScheduler(ia.getGuildId()); - if(!MusicUtils.checkCommandRequirements(ia, scheduler)){ + public void run(Options options, GuildCommandContext ctx){ + var scheduler = ctx.get(MusicModule.class).getScheduler(ctx.getGuildId()); + if(!MusicUtils.checkCommandRequirements(ctx, scheduler)){ return; } - if(!ia.get(SettingsModule.class).hasDJRole(ia.getMember())){ - ia.error("Only DJs are allowed shuffle"); + if(!ctx.get(SettingsModule.class).hasDJRole(ctx.getMember())){ + ctx.error("Only DJs are allowed shuffle"); return; } if(scheduler.shuffle()){ - ia.reply("Queue shuffled"); + ctx.reply("Queue shuffled"); return; } - ia.error("Queue is empty. Nothing to shuffle"); + ctx.error("Queue is empty. Nothing to shuffle"); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/music/SkipCommand.java b/src/main/java/de/kittybot/kittybot/commands/music/SkipCommand.java index b7414c19e..e3e17bfc4 100644 --- a/src/main/java/de/kittybot/kittybot/commands/music/SkipCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/music/SkipCommand.java @@ -1,10 +1,10 @@ package de.kittybot.kittybot.commands.music; import de.kittybot.kittybot.modules.MusicModule; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.Category; import de.kittybot.kittybot.slashcommands.application.RunGuildCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; import de.kittybot.kittybot.utils.MusicUtils; @SuppressWarnings("unused") @@ -15,15 +15,15 @@ public SkipCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ - var scheduler = ia.get(MusicModule.class).getScheduler(ia.getGuildId()); - if(!MusicUtils.checkCommandRequirements(ia, scheduler)){ + public void run(Options options, GuildCommandContext ctx){ + var scheduler = ctx.get(MusicModule.class).getScheduler(ctx.getGuildId()); + if(!MusicUtils.checkCommandRequirements(ctx, scheduler)){ return; } - if(!MusicUtils.checkMusicPermissions(ia, scheduler)){ + if(!MusicUtils.checkMusicPermissions(ctx, scheduler)){ return; } - ia.reply("Skipped to the next song"); + ctx.reply("Skipped to the next song"); scheduler.next(true); scheduler.setPaused(false); } diff --git a/src/main/java/de/kittybot/kittybot/commands/music/StopCommand.java b/src/main/java/de/kittybot/kittybot/commands/music/StopCommand.java index 1a493d214..af600c109 100644 --- a/src/main/java/de/kittybot/kittybot/commands/music/StopCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/music/StopCommand.java @@ -1,10 +1,10 @@ package de.kittybot.kittybot.commands.music; import de.kittybot.kittybot.modules.MusicModule; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.Category; import de.kittybot.kittybot.slashcommands.application.RunGuildCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; import de.kittybot.kittybot.utils.MusicUtils; @SuppressWarnings("unused") @@ -15,15 +15,15 @@ public StopCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ - var scheduler = ia.get(MusicModule.class).getScheduler(ia.getGuildId()); - if(!MusicUtils.checkCommandRequirements(ia, scheduler)){ + public void run(Options options, GuildCommandContext ctx){ + var scheduler = ctx.get(MusicModule.class).getScheduler(ctx.getGuildId()); + if(!MusicUtils.checkCommandRequirements(ctx, scheduler)){ return; } - if(!MusicUtils.checkMusicPermissions(ia, scheduler)){ + if(!MusicUtils.checkMusicPermissions(ctx, scheduler)){ return; } - ia.acknowledge(true).queue(success -> ia.get(MusicModule.class).destroy(ia.getGuildId(), ia.getUserId())); + ctx.acknowledge(true).queue(success -> ctx.get(MusicModule.class).destroy(ctx.getGuildId(), ctx.getUserId())); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/music/VolumeCommand.java b/src/main/java/de/kittybot/kittybot/commands/music/VolumeCommand.java index 4a1837e04..e8ae05851 100644 --- a/src/main/java/de/kittybot/kittybot/commands/music/VolumeCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/music/VolumeCommand.java @@ -1,11 +1,11 @@ package de.kittybot.kittybot.commands.music; import de.kittybot.kittybot.modules.MusicModule; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.Category; import de.kittybot.kittybot.slashcommands.application.RunGuildCommand; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionInteger; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; import de.kittybot.kittybot.utils.MusicUtils; @SuppressWarnings("unused") @@ -19,18 +19,18 @@ public VolumeCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ - var scheduler = ia.get(MusicModule.class).getScheduler(ia.getGuildId()); - if(!MusicUtils.checkCommandRequirements(ia, scheduler)){ + public void run(Options options, GuildCommandContext ctx){ + var scheduler = ctx.get(MusicModule.class).getScheduler(ctx.getGuildId()); + if(!MusicUtils.checkCommandRequirements(ctx, scheduler)){ return; } int volume = options.getInt("volume"); if(volume < 0 || volume > 150){ - ia.error("Volume needs to between 0 and 150"); + ctx.error("Volume needs to between 0 and 150"); return; } scheduler.setVolume(volume); - ia.reply("Volume set to: `" + volume + "`"); + ctx.reply("Volume set to: `" + volume + "`"); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/neko/NekoCommand.java b/src/main/java/de/kittybot/kittybot/commands/neko/NekoCommand.java index dc2fcb493..1c4e6f8e5 100644 --- a/src/main/java/de/kittybot/kittybot/commands/neko/NekoCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/neko/NekoCommand.java @@ -3,13 +3,13 @@ import de.kittybot.kittybot.modules.RequestModule; import de.kittybot.kittybot.modules.SettingsModule; import de.kittybot.kittybot.objects.enums.Neko; +import de.kittybot.kittybot.slashcommands.CommandContext; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.Category; -import de.kittybot.kittybot.slashcommands.application.CommandOptionChoice; +import de.kittybot.kittybot.slashcommands.application.OptionChoice; import de.kittybot.kittybot.slashcommands.application.RunCommand; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionString; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Interaction; -import de.kittybot.kittybot.slashcommands.interaction.Options; @SuppressWarnings("unused") public class NekoCommand extends RunCommand{ @@ -20,49 +20,49 @@ public NekoCommand(){ new CommandOptionString("type", "The image type") .required() .addChoices( - new CommandOptionChoice<>(Neko.ANAL), - new CommandOptionChoice<>(Neko.BLOWJOB), - new CommandOptionChoice<>(Neko.CUM), - new CommandOptionChoice<>(Neko.FUCK), - new CommandOptionChoice<>(Neko.NEKO_NSFW), - new CommandOptionChoice<>(Neko.NEKO_NSFW_GIF), - new CommandOptionChoice<>(Neko.PUSSY_LICK), - new CommandOptionChoice<>(Neko.SOLO), - new CommandOptionChoice<>(Neko.THREESOME_FFF), - new CommandOptionChoice<>(Neko.THREESOME_FFM), - new CommandOptionChoice<>(Neko.THREESOME_MMF), - new CommandOptionChoice<>(Neko.YAOI), - new CommandOptionChoice<>(Neko.YURI), - new CommandOptionChoice<>(Neko.KITSUNE), - new CommandOptionChoice<>(Neko.SENKO), - new CommandOptionChoice<>(Neko.TAIL), - new CommandOptionChoice<>(Neko.FLUFF), - new CommandOptionChoice<>(Neko.EEVEE), - new CommandOptionChoice<>(Neko.EEVEE_GIF), - new CommandOptionChoice<>(Neko.NEKO_SFW), - new CommandOptionChoice<>(Neko.NEKO_SFW_GIF) + new OptionChoice(Neko.ANAL), + new OptionChoice(Neko.BLOWJOB), + new OptionChoice(Neko.CUM), + new OptionChoice(Neko.FUCK), + new OptionChoice(Neko.NEKO_NSFW), + new OptionChoice(Neko.NEKO_NSFW_GIF), + new OptionChoice(Neko.PUSSY_LICK), + new OptionChoice(Neko.SOLO), + new OptionChoice(Neko.THREESOME_FFF), + new OptionChoice(Neko.THREESOME_FFM), + new OptionChoice(Neko.THREESOME_MMF), + new OptionChoice(Neko.YAOI), + new OptionChoice(Neko.YURI), + new OptionChoice(Neko.KITSUNE), + new OptionChoice(Neko.SENKO), + new OptionChoice(Neko.TAIL), + new OptionChoice(Neko.FLUFF), + new OptionChoice(Neko.EEVEE), + new OptionChoice(Neko.EEVEE_GIF), + new OptionChoice(Neko.NEKO_SFW), + new OptionChoice(Neko.NEKO_SFW_GIF) ) ); } @Override - public void run(Options options, Interaction ia){ + public void run(Options options, CommandContext ctx){ var neko = Neko.valueOf(options.getString("type")); if(neko.isNsfw()){ - if(ia.isFromGuild()){ - var guildIa = (GuildInteraction) ia; - if(!ia.get(SettingsModule.class).isNsfwEnabled(guildIa.getGuildId())){ - ia.error("NSFW commands are disabled in this guild"); + if(ctx.isFromGuild()){ + var guildCtx = (GuildCommandContext) ctx; + if(!ctx.get(SettingsModule.class).isNsfwEnabled(guildCtx.getGuildId())){ + ctx.error("NSFW commands are disabled in this guild"); return; } - if(!guildIa.getChannel().isNSFW()){ - ia.error("This command is nsfw channel only"); + if(!guildCtx.getChannel().isNSFW()){ + ctx.error("This command is nsfw channel only"); return; } } } - ia.reply(builder -> builder - .setImage(ia.get(RequestModule.class).getNeko(neko)) + ctx.reply(builder -> builder + .setImage(ctx.get(RequestModule.class).getNeko(neko)) ); } diff --git a/src/main/java/de/kittybot/kittybot/commands/neko/ReactionCommand.java b/src/main/java/de/kittybot/kittybot/commands/neko/ReactionCommand.java index fc8ffc1ce..eb04feb90 100644 --- a/src/main/java/de/kittybot/kittybot/commands/neko/ReactionCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/neko/ReactionCommand.java @@ -2,11 +2,11 @@ import de.kittybot.kittybot.modules.RequestModule; import de.kittybot.kittybot.objects.enums.Neko; +import de.kittybot.kittybot.slashcommands.CommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.Category; import de.kittybot.kittybot.slashcommands.application.RunCommand; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionUser; -import de.kittybot.kittybot.slashcommands.interaction.Interaction; -import de.kittybot.kittybot.slashcommands.interaction.Options; import de.kittybot.kittybot.utils.annotations.Ignore; @Ignore @@ -25,29 +25,29 @@ protected ReactionCommand(Neko neko, String description, String text){ } @Override - public void run(Options options, Interaction ia){ + public void run(Options options, CommandContext ctx){ var user = options.getUser("user"); var message = new StringBuilder(); - if(user.getIdLong() == ia.getUserId()){ + if(user.getIdLong() == ctx.getUserId()){ message .append("You are not allowed to ") .append(getName()) .append(" yourself so I ") .append(getName()) .append(" you ") - .append(ia.getUser().getAsMention()); + .append(ctx.getUser().getAsMention()); } else{ message - .append(ia.getUser().getAsMention()) + .append(ctx.getUser().getAsMention()) .append(" ") .append(this.text) .append(" ") .append(user.getAsMention()); } - ia.reply(builder -> builder + ctx.reply(builder -> builder .setDescription(message) - .setImage(ia.get(RequestModule.class).getNeko(this.neko)) + .setImage(ctx.get(RequestModule.class).getNeko(this.neko)) ); } diff --git a/src/main/java/de/kittybot/kittybot/commands/notification/notification/CreateCommand.java b/src/main/java/de/kittybot/kittybot/commands/notification/notification/CreateCommand.java index 8a2babdc1..3b2f12209 100644 --- a/src/main/java/de/kittybot/kittybot/commands/notification/notification/CreateCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/notification/notification/CreateCommand.java @@ -4,8 +4,8 @@ import de.kittybot.kittybot.slashcommands.application.options.CommandOptionString; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionTime; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.utils.TimeUtils; import java.time.LocalDateTime; @@ -23,26 +23,26 @@ public CreateCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ + public void run(Options options, GuildCommandContext ctx){ var time = options.getTime("time"); if(time.isBefore(LocalDateTime.now())){ - ia.error("Please provide a valid time or duration in this format: "); + ctx.error("Please provide a valid time or duration in this format: "); return; } var message = options.getString("message"); - var notif = ia.get(NotificationModule.class).create( - ia.getGuildId(), - ia.getChannelId(), + var notif = ctx.get(NotificationModule.class).create( + ctx.getGuildId(), + ctx.getChannelId(), -1, - ia.getUser().getIdLong(), + ctx.getUser().getIdLong(), message, time ); if(notif == null){ - ia.error("There was an unexpected error while creating your notification"); + ctx.error("There was an unexpected error while creating your notification"); return; } - ia.reply("Notification at `" + TimeUtils.formatDuration(notif.getCreatedAt().until(notif.getNotificationTime(), ChronoUnit.MILLIS)) + "` created with id: `" + notif.getId() + "`"); + ctx.reply("Notification at `" + TimeUtils.formatDuration(notif.getCreatedAt().until(notif.getNotificationTime(), ChronoUnit.MILLIS)) + "` created with id: `" + notif.getId() + "`"); } diff --git a/src/main/java/de/kittybot/kittybot/commands/notification/notification/DeleteCommand.java b/src/main/java/de/kittybot/kittybot/commands/notification/notification/DeleteCommand.java index 3f04d89fe..90e8dcce8 100644 --- a/src/main/java/de/kittybot/kittybot/commands/notification/notification/DeleteCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/notification/notification/DeleteCommand.java @@ -3,8 +3,8 @@ import de.kittybot.kittybot.modules.NotificationModule; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionInteger; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; public class DeleteCommand extends GuildSubCommand{ @@ -16,13 +16,13 @@ public DeleteCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ + public void run(Options options, GuildCommandContext ctx){ var notificationId = options.getLong("notification-id"); - if(ia.get(NotificationModule.class).delete(notificationId, ia.getUserId())){ - ia.reply("Deleted your notification with id `" + notificationId + "`"); + if(ctx.get(NotificationModule.class).delete(notificationId, ctx.getUserId())){ + ctx.reply("Deleted your notification with id `" + notificationId + "`"); return; } - ia.error("Notification either does not exist or does not belong to you"); + ctx.error("Notification either does not exist or does not belong to you"); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/notification/notification/ListCommand.java b/src/main/java/de/kittybot/kittybot/commands/notification/notification/ListCommand.java index e1c5c4053..6f0eb9ef9 100644 --- a/src/main/java/de/kittybot/kittybot/commands/notification/notification/ListCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/notification/notification/ListCommand.java @@ -4,8 +4,8 @@ import de.kittybot.kittybot.modules.PaginatorModule; import de.kittybot.kittybot.slashcommands.application.Category; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.utils.Colors; import de.kittybot.kittybot.utils.Config; import de.kittybot.kittybot.utils.TimeUtils; @@ -20,11 +20,11 @@ public ListCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ - var notifs = ia.get(NotificationModule.class).get(ia.getUserId()); + public void run(Options options, GuildCommandContext ctx){ + var notifs = ctx.get(NotificationModule.class).get(ctx.getUserId()); if(notifs.isEmpty()){ - ia.reply("You have no notifications"); + ctx.reply("You have no notifications"); return; } @@ -41,9 +41,9 @@ public void run(Options options, GuildInteraction ia){ } pages.add(notifMessage.toString()); - ia.acknowledge(true).queue(success -> ia.get(PaginatorModule.class).create( - ia.getChannel(), - ia.getUserId(), + ctx.acknowledge(true).queue(success -> ctx.get(PaginatorModule.class).create( + ctx.getChannel(), + ctx.getUserId(), pages.size(), (page, embedBuilder) -> embedBuilder .setColor(Colors.KITTYBOT_BLUE) diff --git a/src/main/java/de/kittybot/kittybot/commands/roles/AssignCommand.java b/src/main/java/de/kittybot/kittybot/commands/roles/AssignCommand.java index 242c28af2..d02b276b7 100644 --- a/src/main/java/de/kittybot/kittybot/commands/roles/AssignCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/roles/AssignCommand.java @@ -1,11 +1,11 @@ package de.kittybot.kittybot.commands.roles; import de.kittybot.kittybot.modules.SettingsModule; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.Category; import de.kittybot.kittybot.slashcommands.application.RunGuildCommand; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionRole; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; @SuppressWarnings("unused") public class AssignCommand extends RunGuildCommand{ @@ -18,42 +18,42 @@ public AssignCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ + public void run(Options options, GuildCommandContext ctx){ var role = options.getRole("role"); if(role == null){ - ia.error("Unknown role provided"); + ctx.error("Unknown role provided"); return; } - var settings = ia.get(SettingsModule.class).getSettings(ia.getGuildId()); + var settings = ctx.get(SettingsModule.class).getSettings(ctx.getGuildId()); var selfAssignableRoles = settings.getSelfAssignableRoles(); if(selfAssignableRoles == null || selfAssignableRoles.isEmpty()){ - ia.error("No self assignable roles configured"); + ctx.error("No self assignable roles configured"); return; } var selfAssignableRole = selfAssignableRoles.stream().filter(r -> role.getIdLong() == r.getRoleId()).findFirst().orElse(null); if(selfAssignableRole == null){ - ia.error("This role is not self assignable"); + ctx.error("This role is not self assignable"); return; } - if(!ia.getSelfMember().canInteract(role)){ - ia.error("I don't have the permissions to assign you this role"); + if(!ctx.getSelfMember().canInteract(role)){ + ctx.error("I don't have the permissions to assign you this role"); return; } var group = settings.getSelfAssignableRoleGroups().stream().filter(g -> g.getId() == selfAssignableRole.getGroupId()).findFirst().orElse(null); if(group == null){ - ia.error("This role somehow misses a self assignable role group"); + ctx.error("This role somehow misses a self assignable role group"); return; } - if(group.getMaxRoles() != -1 && selfAssignableRoles.stream().filter(r -> r.getGroupId() == group.getId() && ia.getMember().getRoles().stream().anyMatch(mr -> mr.getIdLong() == r.getRoleId())).count() >= group.getMaxRoles()){ - ia.error("Can't assign you " + role.getAsMention() + ". You already have the max roles of this group"); + if(group.getMaxRoles() != -1 && selfAssignableRoles.stream().filter(r -> r.getGroupId() == group.getId() && ctx.getMember().getRoles().stream().anyMatch(mr -> mr.getIdLong() == r.getRoleId())).count() >= group.getMaxRoles()){ + ctx.error("Can't assign you " + role.getAsMention() + ". You already have the max roles of this group"); return; } - ia.getGuild().addRoleToMember(ia.getMember(), role) + ctx.getGuild().addRoleToMember(ctx.getMember(), role) .reason("self assigned with kittybot") - .queue(unused -> ia.reply("Assigned " + role.getAsMention())); + .queue(unused -> ctx.reply("Assigned " + role.getAsMention())); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/roles/InviteRolesCommand.java b/src/main/java/de/kittybot/kittybot/commands/roles/InviteRolesCommand.java index 7aa10e7b6..b1e2a5064 100644 --- a/src/main/java/de/kittybot/kittybot/commands/roles/InviteRolesCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/roles/InviteRolesCommand.java @@ -2,13 +2,13 @@ import de.kittybot.kittybot.modules.InviteModule; import de.kittybot.kittybot.modules.SettingsModule; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.Category; import de.kittybot.kittybot.slashcommands.application.Command; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionRole; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionString; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; import de.kittybot.kittybot.utils.MessageUtils; import net.dv8tion.jda.api.Permission; @@ -40,20 +40,20 @@ public AddCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ + public void run(Options options, GuildCommandContext ctx){ var code = options.getString("code"); var role = options.getRole("role"); - var invites = ia.get(InviteModule.class).getGuildInvites(ia.getGuildId()); + var invites = ctx.get(InviteModule.class).getGuildInvites(ctx.getGuildId()); if(invites == null || invites.isEmpty()){ - ia.error("No invites found for this guild"); + ctx.error("No invites found for this guild"); return; } if(!invites.containsKey(code)){ - ia.error("No invite with code '" + code + "' found"); + ctx.error("No invite with code '" + code + "' found"); return; } - ia.get(SettingsModule.class).addInviteRoles(ia.getGuildId(), code, Collections.singleton(role.getIdLong())); - ia.reply("Added role " + role.getAsMention() + " to invite `" + code + "`"); + ctx.get(SettingsModule.class).addInviteRoles(ctx.getGuildId(), code, Collections.singleton(role.getIdLong())); + ctx.reply("Added role " + role.getAsMention() + " to invite `" + code + "`"); } } @@ -69,20 +69,20 @@ public RemoveCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ + public void run(Options options, GuildCommandContext ctx){ var code = options.getString("code"); var role = options.getRole("role"); - var invites = ia.get(InviteModule.class).getGuildInvites(ia.getGuildId()); + var invites = ctx.get(InviteModule.class).getGuildInvites(ctx.getGuildId()); if(invites == null || invites.isEmpty()){ - ia.error("No invites found for this guild"); + ctx.error("No invites found for this guild"); return; } if(!invites.containsKey(code)){ - ia.error("No invite with code '" + code + "' found"); + ctx.error("No invite with code '" + code + "' found"); return; } - ia.get(SettingsModule.class).removeInviteRoles(ia.getGuildId(), code, Collections.singleton(role.getIdLong())); - ia.reply("Removed role " + role.getAsMention() + " from invite `" + code + "`"); + ctx.get(SettingsModule.class).removeInviteRoles(ctx.getGuildId(), code, Collections.singleton(role.getIdLong())); + ctx.reply("Removed role " + role.getAsMention() + " from invite `" + code + "`"); } } @@ -97,19 +97,19 @@ public ResetCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ + public void run(Options options, GuildCommandContext ctx){ var code = options.getString("code"); - var invites = ia.get(InviteModule.class).getGuildInvites(ia.getGuildId()); + var invites = ctx.get(InviteModule.class).getGuildInvites(ctx.getGuildId()); if(invites == null || invites.isEmpty()){ - ia.error("No invites found for this guild"); + ctx.error("No invites found for this guild"); return; } if(!invites.containsKey(code)){ - ia.error("No invite with code '" + code + "' found"); + ctx.error("No invite with code '" + code + "' found"); return; } - ia.get(SettingsModule.class).removeInviteRoles(ia.getGuildId(), code); - ia.reply("Roles reset from invite `" + code + "`"); + ctx.get(SettingsModule.class).removeInviteRoles(ctx.getGuildId(), code); + ctx.reply("Roles reset from invite `" + code + "`"); } } @@ -124,14 +124,14 @@ public ListCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ - var inviteRoles = ia.get(SettingsModule.class).getInviteRoles(ia.getGuildId()); + public void run(Options options, GuildCommandContext ctx){ + var inviteRoles = ctx.get(SettingsModule.class).getInviteRoles(ctx.getGuildId()); if(inviteRoles.isEmpty()){ - ia.error("No invite roles found"); + ctx.error("No invite roles found"); return; } - ia.reply("**Invite Roles:**\n\n" + inviteRoles.entrySet().stream().map(entry -> + ctx.reply("**Invite Roles:**\n\n" + inviteRoles.entrySet().stream().map(entry -> "**" + entry.getKey() + "**" + entry.getValue().stream().map(MessageUtils::getRoleMention).collect(Collectors.joining("\n")) ).collect(Collectors.joining("\n"))); } diff --git a/src/main/java/de/kittybot/kittybot/commands/roles/RolesCommand.java b/src/main/java/de/kittybot/kittybot/commands/roles/RolesCommand.java index bea819c11..d381ee13f 100644 --- a/src/main/java/de/kittybot/kittybot/commands/roles/RolesCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/roles/RolesCommand.java @@ -20,7 +20,7 @@ public RolesCommand(){ new GroupsCommand(), new GenericHelpCommand("To configure self assignable roles you need first need to create a group with `/roles groups add `.\n" + "Then you can add a role to this group by doing `/roles add <@role> `.\n" + - "You can add as much as you like but only 20 of them are assignable by reactions via the specific emote.\n" + + "You can add as much as you like but only 20 of them are assignable by reactions vctx the specific emote.\n" + "Use `/roles list` to view all roles with groups in a nice message" ) ); diff --git a/src/main/java/de/kittybot/kittybot/commands/roles/UnassignCommand.java b/src/main/java/de/kittybot/kittybot/commands/roles/UnassignCommand.java index 25ef24e6d..03a22cadb 100644 --- a/src/main/java/de/kittybot/kittybot/commands/roles/UnassignCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/roles/UnassignCommand.java @@ -1,11 +1,11 @@ package de.kittybot.kittybot.commands.roles; import de.kittybot.kittybot.modules.SettingsModule; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.Category; import de.kittybot.kittybot.slashcommands.application.RunGuildCommand; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionRole; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; @SuppressWarnings("unused") public class UnassignCommand extends RunGuildCommand{ @@ -18,32 +18,32 @@ public UnassignCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ + public void run(Options options, GuildCommandContext ctx){ var role = options.getRole("role"); if(role == null){ - ia.error("Unknown role provided"); + ctx.error("Unknown role provided"); return; } - var settings = ia.get(SettingsModule.class).getSettings(ia.getGuildId()); + var settings = ctx.get(SettingsModule.class).getSettings(ctx.getGuildId()); var selfAssignableRoles = settings.getSelfAssignableRoles(); if(selfAssignableRoles == null || selfAssignableRoles.isEmpty()){ - ia.error("No self assignable roles configured"); + ctx.error("No self assignable roles configured"); return; } var selfAssignableRole = selfAssignableRoles.stream().filter(r -> role.getIdLong() == r.getRoleId()).findFirst().orElse(null); if(selfAssignableRole == null){ - ia.error("This role is not self assignable"); + ctx.error("This role is not self assignable"); return; } - if(!ia.getSelfMember().canInteract(role)){ - ia.error("I don't have the permissions to unassign you this role"); + if(!ctx.getSelfMember().canInteract(role)){ + ctx.error("I don't have the permissions to unassign you this role"); return; } - ia.getGuild().removeRoleFromMember(ia.getMember(), role) + ctx.getGuild().removeRoleFromMember(ctx.getMember(), role) .reason("self unassigned with kittybot") - .queue(unused -> ia.reply("Unassigned " + role.getAsMention())); + .queue(unused -> ctx.reply("Unassigned " + role.getAsMention())); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/roles/roles/AddCommand.java b/src/main/java/de/kittybot/kittybot/commands/roles/roles/AddCommand.java index 7e35d557d..fabb1dd54 100644 --- a/src/main/java/de/kittybot/kittybot/commands/roles/roles/AddCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/roles/roles/AddCommand.java @@ -6,8 +6,8 @@ import de.kittybot.kittybot.slashcommands.application.options.CommandOptionRole; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionString; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import net.dv8tion.jda.api.Permission; import java.util.Collections; @@ -25,21 +25,21 @@ public AddCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ + public void run(Options options, GuildCommandContext ctx){ var role = options.getRole("role"); - var emoteAction = options.getEmote(ia.getGuild(), "emote"); + var emoteAction = options.getEmote(ctx.getGuild(), "emote"); var groupName = options.getString("group"); emoteAction.queue(emote -> { - var group = ia.get(SettingsModule.class).getSelfAssignableRoleGroups(ia.getGuildId()).stream().filter(g -> g.getName().equalsIgnoreCase(groupName)).findFirst(); + var group = ctx.get(SettingsModule.class).getSelfAssignableRoleGroups(ctx.getGuildId()).stream().filter(g -> g.getName().equalsIgnoreCase(groupName)).findFirst(); if(group.isEmpty()){ - ia.error("Please provide a valid group"); + ctx.error("Please provide a valid group"); return; } - ia.get(SettingsModule.class).addSelfAssignableRoles(ia.getGuildId(), Collections.singleton(new SelfAssignableRole(role.getIdLong(), emote.getIdLong(), ia.getGuildId(), group.get().getId()))); - ia.reply("Added self assignable role"); - }, error -> ia.error("Please provide a valid emote from this server") + ctx.get(SettingsModule.class).addSelfAssignableRoles(ctx.getGuildId(), Collections.singleton(new SelfAssignableRole(role.getIdLong(), emote.getIdLong(), ctx.getGuildId(), group.get().getId()))); + ctx.reply("Added self assignable role"); + }, error -> ctx.error("Please provide a valid emote from this server") ); } diff --git a/src/main/java/de/kittybot/kittybot/commands/roles/roles/ListCommand.java b/src/main/java/de/kittybot/kittybot/commands/roles/roles/ListCommand.java index 80f11af07..edf6b531a 100644 --- a/src/main/java/de/kittybot/kittybot/commands/roles/roles/ListCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/roles/roles/ListCommand.java @@ -6,8 +6,8 @@ import de.kittybot.kittybot.objects.settings.SelfAssignableRole; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionString; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.utils.Colors; import de.kittybot.kittybot.utils.MessageUtils; import net.dv8tion.jda.api.EmbedBuilder; @@ -26,12 +26,12 @@ public ListCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ - var settings = ia.get(SettingsModule.class).getSettings(ia.getGuildId()); + public void run(Options options, GuildCommandContext ctx){ + var settings = ctx.get(SettingsModule.class).getSettings(ctx.getGuildId()); var roles = settings.getSelfAssignableRoles(); var groups = settings.getSelfAssignableRoleGroups(); if(roles == null || roles.isEmpty()){ - ia.error("No self assignable roles configured"); + ctx.error("No self assignable roles configured"); return; } var sortedRoles = new LinkedHashSet<>(roles); @@ -48,13 +48,13 @@ public void run(Options options, GuildInteraction ia){ }).collect(Collectors.joining("\n")) ).build(); - if(!ia.getSelfMember().hasPermission(ia.getChannel(), Permission.MESSAGE_WRITE, Permission.MESSAGE_ADD_REACTION)){ - ia.error("To list roles make sure I have the following permissions: `MESSAGE_WRITE` & `MESSAGE_ADD_REACTION`"); + if(!ctx.getSelfMember().hasPermission(ctx.getChannel(), Permission.MESSAGE_WRITE, Permission.MESSAGE_ADD_REACTION)){ + ctx.error("To list roles make sure I have the following permissions: `MESSAGE_WRITE` & `MESSAGE_ADD_REACTION`"); return; } - ia.acknowledge(true).queue(success -> - ia.getChannel().sendMessage(embed).queue(message -> { - ia.get(ReactionRoleModule.class).add(message.getGuild().getIdLong(), message.getIdLong()); + ctx.acknowledge(true).queue(success -> + ctx.getChannel().sendMessage(embed).queue(message -> { + ctx.get(ReactionRoleModule.class).add(message.getGuild().getIdLong(), message.getIdLong()); sortedRoles.forEach(role -> message.addReaction("test:" + role.getEmoteId()).queue()); }) ); diff --git a/src/main/java/de/kittybot/kittybot/commands/roles/roles/RemoveCommand.java b/src/main/java/de/kittybot/kittybot/commands/roles/roles/RemoveCommand.java index d765b34e5..f220eb6a9 100644 --- a/src/main/java/de/kittybot/kittybot/commands/roles/roles/RemoveCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/roles/roles/RemoveCommand.java @@ -3,8 +3,8 @@ import de.kittybot.kittybot.modules.SettingsModule; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionRole; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import net.dv8tion.jda.api.Permission; import java.util.Collections; @@ -20,15 +20,15 @@ public RemoveCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ + public void run(Options options, GuildCommandContext ctx){ var role = options.getRole("role"); - var settings = ia.get(SettingsModule.class); - if(settings.getSelfAssignableRoles(ia.getGuildId()).stream().noneMatch(r -> r.getRoleId() == role.getIdLong())){ - ia.error("This role is not self assignable"); + var settings = ctx.get(SettingsModule.class); + if(settings.getSelfAssignableRoles(ctx.getGuildId()).stream().noneMatch(r -> r.getRoleId() == role.getIdLong())){ + ctx.error("This role is not self assignable"); return; } - settings.removeSelfAssignableRoles(ia.getGuildId(), Collections.singleton(role.getIdLong())); - ia.reply("Removed self assignable role"); + settings.removeSelfAssignableRoles(ctx.getGuildId(), Collections.singleton(role.getIdLong())); + ctx.reply("Removed self assignable role"); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/roles/roles/groups/AddCommand.java b/src/main/java/de/kittybot/kittybot/commands/roles/roles/groups/AddCommand.java index e737d1725..8e555eb71 100644 --- a/src/main/java/de/kittybot/kittybot/commands/roles/roles/groups/AddCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/roles/roles/groups/AddCommand.java @@ -5,8 +5,8 @@ import de.kittybot.kittybot.slashcommands.application.options.CommandOptionInteger; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionString; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import net.dv8tion.jda.api.Permission; import java.util.Collections; @@ -23,11 +23,11 @@ public AddCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ + public void run(Options options, GuildCommandContext ctx){ var name = options.getString("name"); var maxRoles = options.has("max-roles") ? options.getInt("max-roles") : -1; - ia.get(SettingsModule.class).addSelfAssignableRoleGroups(ia.getGuildId(), Collections.singleton(new SelfAssignableRoleGroup(-1, ia.getGuildId(), name, maxRoles))); - ia.reply("New group added"); + ctx.get(SettingsModule.class).addSelfAssignableRoleGroups(ctx.getGuildId(), Collections.singleton(new SelfAssignableRoleGroup(-1, ctx.getGuildId(), name, maxRoles))); + ctx.reply("New group added"); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/roles/roles/groups/ListCommand.java b/src/main/java/de/kittybot/kittybot/commands/roles/roles/groups/ListCommand.java index a11c64ae8..751c6ceb5 100644 --- a/src/main/java/de/kittybot/kittybot/commands/roles/roles/groups/ListCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/roles/roles/groups/ListCommand.java @@ -2,8 +2,8 @@ import de.kittybot.kittybot.modules.SettingsModule; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import java.util.stream.Collectors; @@ -14,14 +14,14 @@ public ListCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ - var settings = ia.get(SettingsModule.class).getSettings(ia.getGuildId()); + public void run(Options options, GuildCommandContext ctx){ + var settings = ctx.get(SettingsModule.class).getSettings(ctx.getGuildId()); var groups = settings.getSelfAssignableRoleGroups(); if(groups.isEmpty()){ - ia.error("There are not groups defined.\nYou can add them with `/groups add `"); + ctx.error("There are not groups defined.\nYou can add them with `/groups add `"); return; } - ia.reply("**Self assignable role groups:**\n\n" + groups.stream().map(group -> "**Name:** `" + group.getName() + "` **Max Roles:** `" + group.getFormattedMaxRoles() + "`").collect(Collectors.joining("\n"))); + ctx.reply("**Self assignable role groups:**\n\n" + groups.stream().map(group -> "**Name:** `" + group.getName() + "` **Max Roles:** `" + group.getFormattedMaxRoles() + "`").collect(Collectors.joining("\n"))); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/roles/roles/groups/RemoveCommand.java b/src/main/java/de/kittybot/kittybot/commands/roles/roles/groups/RemoveCommand.java index 07772b4ed..36d36925f 100644 --- a/src/main/java/de/kittybot/kittybot/commands/roles/roles/groups/RemoveCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/roles/roles/groups/RemoveCommand.java @@ -3,8 +3,8 @@ import de.kittybot.kittybot.modules.SettingsModule; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionString; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import net.dv8tion.jda.api.Permission; import java.util.Collections; @@ -20,16 +20,16 @@ public RemoveCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ + public void run(Options options, GuildCommandContext ctx){ var name = options.getString("name"); - var settings = ia.get(SettingsModule.class); - var group = settings.getSelfAssignableRoleGroups(ia.getGuildId()).stream().filter(g -> g.getName().equalsIgnoreCase(name)).findFirst(); + var settings = ctx.get(SettingsModule.class); + var group = settings.getSelfAssignableRoleGroups(ctx.getGuildId()).stream().filter(g -> g.getName().equalsIgnoreCase(name)).findFirst(); if(group.isEmpty()){ - ia.error("Group with name `" + name + "` not found"); + ctx.error("Group with name `" + name + "` not found"); return; } - settings.removeSelfAssignableRoleGroups(ia.getGuildId(), Collections.singleton(group.get().getId())); - ia.reply("Removed group with name `" + name + "`"); + settings.removeSelfAssignableRoleGroups(ctx.getGuildId(), Collections.singleton(group.get().getId())); + ctx.reply("Removed group with name `" + name + "`"); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/snipe/EditSnipeCommand.java b/src/main/java/de/kittybot/kittybot/commands/snipe/EditSnipeCommand.java index 9f1b69f65..631c4f5f0 100644 --- a/src/main/java/de/kittybot/kittybot/commands/snipe/EditSnipeCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/snipe/EditSnipeCommand.java @@ -2,10 +2,10 @@ import de.kittybot.kittybot.modules.MessageModule; import de.kittybot.kittybot.modules.SettingsModule; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.Category; import de.kittybot.kittybot.slashcommands.application.RunGuildCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; import java.awt.Color; @@ -17,21 +17,21 @@ public EditSnipeCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ - var settings = ia.get(SettingsModule.class).getSettings(ia.getGuildId()); + public void run(Options options, GuildCommandContext ctx){ + var settings = ctx.get(SettingsModule.class).getSettings(ctx.getGuildId()); if(!settings.areSnipesEnabled()){ - ia.error("Snipes are disabled for this guild"); + ctx.error("Snipes are disabled for this guild"); } - if(settings.areSnipesDisabledInChannel(ia.getChannelId())){ - ia.error("Snipes are disabled for this channel"); + if(settings.areSnipesDisabledInChannel(ctx.getChannelId())){ + ctx.error("Snipes are disabled for this channel"); } - var lastEditedMessage = ia.get(MessageModule.class).getLastEditedMessage(ia.getChannelId()); + var lastEditedMessage = ctx.get(MessageModule.class).getLastEditedMessage(ctx.getChannelId()); if(lastEditedMessage == null){ - ia.reply(builder -> builder.setColor(Color.RED).setDescription("There are no edited messages to snipe")); + ctx.reply(builder -> builder.setColor(Color.RED).setDescription("There are no edited messages to snipe")); return; } - ia.getJDA().retrieveUserById(lastEditedMessage.getAuthorId()).queue(user -> - ia.reply(builder -> { + ctx.getJDA().retrieveUserById(lastEditedMessage.getAuthorId()).queue(user -> + ctx.reply(builder -> { builder .setAuthor("Edit Sniped " + user.getName(), lastEditedMessage.getJumpUrl()) .setDescription(lastEditedMessage.getContent()) diff --git a/src/main/java/de/kittybot/kittybot/commands/snipe/SnipeCommand.java b/src/main/java/de/kittybot/kittybot/commands/snipe/SnipeCommand.java index 5d905598a..9d08e8544 100644 --- a/src/main/java/de/kittybot/kittybot/commands/snipe/SnipeCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/snipe/SnipeCommand.java @@ -2,10 +2,10 @@ import de.kittybot.kittybot.modules.MessageModule; import de.kittybot.kittybot.modules.SettingsModule; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.Category; import de.kittybot.kittybot.slashcommands.application.RunGuildCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; import java.awt.Color; @@ -17,21 +17,22 @@ public SnipeCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ - if(!ia.get(SettingsModule.class).areSnipesEnabled(ia.getGuildId())){ - ia.error("Snipes are disabled for this guild"); + public void run(Options options, GuildCommandContext ctx){ + if(!ctx.get(SettingsModule.class).areSnipesEnabled(ctx.getGuildId())){ + ctx.error("Snipes are disabled for this guild"); } - if(ia.get(SettingsModule.class).areSnipesDisabledInChannel(ia.getGuildId(), ia.getChannelId())){ - ia.error("Snipes are disabled for this channel"); + if(ctx.get(SettingsModule.class).areSnipesDisabledInChannel(ctx.getGuildId(), ctx.getChannelId())){ + ctx.error("Snipes are disabled for this channel"); } - var lastDeletedMessage = ia.get(MessageModule.class).getLastDeletedMessage(ia.getChannelId()); + var lastDeletedMessage = ctx.get(MessageModule.class).getLastDeletedMessage(ctx.getChannelId()); if(lastDeletedMessage == null){ - ia.reply(builder -> builder.setColor(Color.RED).setDescription("There are no deleted messages to snipe")); + ctx.reply(builder -> builder.setColor(Color.RED).setDescription("There are no deleted messages to snipe")); return; } - ia.getJDA().retrieveUserById(lastDeletedMessage.getAuthorId()).queue(user -> - ia.reply(builder -> { - builder.setAuthor("Sniped " + user.getName(), lastDeletedMessage.getJumpUrl()) + ctx.getJDA().retrieveUserById(lastDeletedMessage.getAuthorId()).queue(user -> + ctx.reply(builder -> { + builder + .setAuthor("Sniped " + user.getName(), lastDeletedMessage.getJumpUrl()) .setDescription(lastDeletedMessage.getContent()) .setFooter("from " + user.getName(), user.getEffectiveAvatarUrl()) .setTimestamp(lastDeletedMessage.getTimeCreated()); diff --git a/src/main/java/de/kittybot/kittybot/commands/streams/streams/AddCommand.java b/src/main/java/de/kittybot/kittybot/commands/streams/streams/AddCommand.java index 614443478..53a65cbae 100644 --- a/src/main/java/de/kittybot/kittybot/commands/streams/streams/AddCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/streams/streams/AddCommand.java @@ -4,8 +4,8 @@ import de.kittybot.kittybot.objects.streams.StreamType; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionString; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; public class AddCommand extends GuildSubCommand{ @@ -17,15 +17,15 @@ public AddCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ + public void run(Options options, GuildCommandContext ctx){ var type = StreamType.TWITCH;//StreamType.byId(options.getInt("service")); var username = options.getString("username"); - var user = ia.get(StreamModule.class).add(username, ia.getGuildId(), type); + var user = ctx.get(StreamModule.class).add(username, ctx.getGuildId(), type); if(user == null){ - ia.error("No user found with username " + username + "for " + type.getName()); + ctx.error("No user found with username " + username + "for " + type.getName()); return; } - ia.reply("Stream announcement for " + type.getName() + " with username: " + user.getDisplayName() + " added"); + ctx.reply("Stream announcement for " + type.getName() + " with username: " + user.getDisplayName() + " added"); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/streams/streams/ChannelCommand.java b/src/main/java/de/kittybot/kittybot/commands/streams/streams/ChannelCommand.java index ce1da2706..2386f2aac 100644 --- a/src/main/java/de/kittybot/kittybot/commands/streams/streams/ChannelCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/streams/streams/ChannelCommand.java @@ -1,25 +1,25 @@ package de.kittybot.kittybot.commands.streams.streams; import de.kittybot.kittybot.modules.SettingsModule; -import de.kittybot.kittybot.slashcommands.application.options.CommandOptionChannel; +import de.kittybot.kittybot.slashcommands.application.options.CommandOptionGuildChannel; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; public class ChannelCommand extends GuildSubCommand{ public ChannelCommand(){ super("channel", "Sets the stream announcement channel"); addOptions( - new CommandOptionChannel("channel", "The channel which stream announcements should get send to").required() + new CommandOptionGuildChannel("channel", "The channel which stream announcements should get send to").required() ); } @Override - public void run(Options options, GuildInteraction ia){ + public void run(Options options, GuildCommandContext ctx){ var channel = options.getTextChannel("channel"); - ia.get(SettingsModule.class).setStreamAnnouncementChannelId(ia.getGuildId(), channel.getIdLong()); - ia.reply("Stream announcements now get send to " + channel.getAsMention()); + ctx.get(SettingsModule.class).setStreamAnnouncementChannelId(ctx.getGuildId(), channel.getIdLong()); + ctx.reply("Stream announcements now get send to " + channel.getAsMention()); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/streams/streams/ListCommand.java b/src/main/java/de/kittybot/kittybot/commands/streams/streams/ListCommand.java index 5bb012411..8ce0f0714 100644 --- a/src/main/java/de/kittybot/kittybot/commands/streams/streams/ListCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/streams/streams/ListCommand.java @@ -3,8 +3,8 @@ import de.kittybot.kittybot.modules.StreamModule; import de.kittybot.kittybot.objects.streams.StreamType; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.utils.MessageUtils; import java.util.stream.Collectors; @@ -16,13 +16,13 @@ public ListCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ - var streamAnnouncements = ia.get(StreamModule.class).get(ia.getGuildId()); + public void run(Options options, GuildCommandContext ctx){ + var streamAnnouncements = ctx.get(StreamModule.class).get(ctx.getGuildId()); if(streamAnnouncements.isEmpty()){ - ia.error("No stream announcements found. Create them with `/settings streamannouncements add `"); + ctx.error("No stream announcements found. Create them with `/settings streamannouncements add `"); return; } - ia.reply("**Stream Announcements:**\n" + streamAnnouncements.stream().map(sa -> MessageUtils.maskLink(sa.getUserName(), "https://twitch.tv/" + sa.getUserName()) + " on " + StreamType.byId(sa.getStreamType()).getName()).collect(Collectors.joining("\n"))); + ctx.reply("**Stream Announcements:**\n" + streamAnnouncements.stream().map(sa -> MessageUtils.maskLink(sa.getUserName(), "https://twitch.tv/" + sa.getUserName()) + " on " + StreamType.byId(sa.getStreamType()).getName()).collect(Collectors.joining("\n"))); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/streams/streams/MessageCommand.java b/src/main/java/de/kittybot/kittybot/commands/streams/streams/MessageCommand.java index 37cd7e326..5ec6a68bb 100644 --- a/src/main/java/de/kittybot/kittybot/commands/streams/streams/MessageCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/streams/streams/MessageCommand.java @@ -3,8 +3,8 @@ import de.kittybot.kittybot.modules.SettingsModule; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionString; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; public class MessageCommand extends GuildSubCommand{ @@ -16,10 +16,10 @@ public MessageCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ + public void run(Options options, GuildCommandContext ctx){ var message = options.getString("message"); - ia.get(SettingsModule.class).setStreamAnnouncementMessage(ia.getGuildId(), message); - ia.reply("Set stream announcements template to:\n" + message); + ctx.get(SettingsModule.class).setStreamAnnouncementMessage(ctx.getGuildId(), message); + ctx.reply("Set stream announcements template to:\n" + message); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/streams/streams/RemoveCommand.java b/src/main/java/de/kittybot/kittybot/commands/streams/streams/RemoveCommand.java index acd6f5320..c120856cc 100644 --- a/src/main/java/de/kittybot/kittybot/commands/streams/streams/RemoveCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/streams/streams/RemoveCommand.java @@ -4,8 +4,8 @@ import de.kittybot.kittybot.objects.streams.StreamType; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionString; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; public class RemoveCommand extends GuildSubCommand{ @@ -17,15 +17,15 @@ public RemoveCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ + public void run(Options options, GuildCommandContext ctx){ var type = StreamType.TWITCH;//StreamType.byId(options.getInt("service")); var username = options.getString("username"); - var success = ia.get(StreamModule.class).remove(username, ia.getGuildId(), type); + var success = ctx.get(StreamModule.class).remove(username, ctx.getGuildId(), type); if(!success){ - ia.error("Could not find stream announcement for " + type.getName() + " with username: " + username + ". Check your spelling"); + ctx.error("Could not find stream announcement for " + type.getName() + " with username: " + username + ". Check your spelling"); return; } - ia.reply("Stream announcement for " + type.getName() + " with username: " + username + " removed"); + ctx.reply("Stream announcement for " + type.getName() + " with username: " + username + " removed"); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/tags/TagCommand.java b/src/main/java/de/kittybot/kittybot/commands/tags/TagCommand.java index c826eaa36..2e2067673 100644 --- a/src/main/java/de/kittybot/kittybot/commands/tags/TagCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/tags/TagCommand.java @@ -1,14 +1,15 @@ package de.kittybot.kittybot.commands.tags; import de.kittybot.kittybot.modules.TagsModule; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.Category; import de.kittybot.kittybot.slashcommands.application.RunGuildCommand; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionString; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; -import de.kittybot.kittybot.slashcommands.interaction.response.InteractionResponse; import net.dv8tion.jda.api.entities.Message; +import java.util.Set; + @SuppressWarnings("unused") public class TagCommand extends RunGuildCommand{ @@ -20,18 +21,15 @@ public TagCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ + public void run(Options options, GuildCommandContext ctx){ var tagName = options.getString("name"); - var tag = ia.get(TagsModule.class).get(tagName, ia.getGuildId()); + var tag = ctx.get(TagsModule.class).get(tagName, ctx.getGuildId()); if(tag == null){ - ia.error("Tag with name `" + tagName + "` not found"); + ctx.error("Tag with name `" + tagName + "` not found"); return; } - ia.reply(new InteractionResponse.Builder().setContent(tag.getContent()) - .setAllowedMentions(Message.MentionType.EMOTE, Message.MentionType.CHANNEL) - .build() - ); + ctx.getEvent().reply(tag.getContent()).allowedMentions(Set.of(Message.MentionType.EMOTE, Message.MentionType.CHANNEL)).queue(); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/tags/TagsCommand.java b/src/main/java/de/kittybot/kittybot/commands/tags/TagsCommand.java index 7096313bb..7500d1e41 100644 --- a/src/main/java/de/kittybot/kittybot/commands/tags/TagsCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/tags/TagsCommand.java @@ -20,9 +20,9 @@ public TagsCommand(){ new PublishCommand(), new RemoveCommand(), new GenericHelpCommand("Tags lets anyone create shortcuts to certain information.\n" + - "You can create them via `/tags create ` or `/tags create ` to mirror the content of an already sent message.\n" + + "You can create them vctx `/tags create ` or `/tags create ` to mirror the content of an already sent message.\n" + "Members with the `MANAGE_SERVER` permission can also add up to 50 tags as server commands with `/tags publish `\n" + - "You can remove them again via `/tags remove `" + "You can remove them again vctx `/tags remove `" ) ); } diff --git a/src/main/java/de/kittybot/kittybot/commands/tags/tags/CreateCommand.java b/src/main/java/de/kittybot/kittybot/commands/tags/tags/CreateCommand.java index b86083aac..9941c9e36 100644 --- a/src/main/java/de/kittybot/kittybot/commands/tags/tags/CreateCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/tags/tags/CreateCommand.java @@ -1,11 +1,11 @@ package de.kittybot.kittybot.commands.tags.tags; import de.kittybot.kittybot.modules.TagsModule; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionLong; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionString; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; public class CreateCommand extends GuildSubCommand{ @@ -19,14 +19,14 @@ public CreateCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ + public void run(Options options, GuildCommandContext ctx){ var tagName = options.getString("name"); if(tagName.length() > 64){ - ia.error("Tag names must be 64 or less characters"); + ctx.error("Tag names must be 64 or less characters"); return; } if(!options.has("content") && !options.has("message-id")){ - ia.reply("Please provide either content or message-id"); + ctx.reply("Please provide either content or message-id"); return; } var content = ""; @@ -34,21 +34,21 @@ public void run(Options options, GuildInteraction ia){ content = options.getString("content"); } else{ - var message = ia.getChannel().retrieveMessageById(options.getLong("message-id")).complete(); + var message = ctx.getChannel().retrieveMessageById(options.getLong("message-id")).complete(); if(message == null){ - ia.error("Please provide a recent message id"); + ctx.error("Please provide a recent message id"); return; } content = message.getContentRaw(); } - var created = ia.get(TagsModule.class).create(tagName, content, ia.getGuildId(), ia.getUserId()); + var created = ctx.get(TagsModule.class).create(tagName, content, ctx.getGuildId(), ctx.getUserId()); if(created){ - ia.reply("Created tag with name `" + tagName + "`"); + ctx.reply("Created tag with name `" + tagName + "`"); return; } - ia.error("A tag with the name `" + tagName + "` already exists"); + ctx.error("A tag with the name `" + tagName + "` already exists"); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/tags/tags/DeleteCommand.java b/src/main/java/de/kittybot/kittybot/commands/tags/tags/DeleteCommand.java index 9f8da9fb1..b8c9f887f 100644 --- a/src/main/java/de/kittybot/kittybot/commands/tags/tags/DeleteCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/tags/tags/DeleteCommand.java @@ -1,10 +1,10 @@ package de.kittybot.kittybot.commands.tags.tags; import de.kittybot.kittybot.modules.TagsModule; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionString; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; import net.dv8tion.jda.api.Permission; public class DeleteCommand extends GuildSubCommand{ @@ -17,21 +17,21 @@ public DeleteCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ + public void run(Options options, GuildCommandContext ctx){ var tagName = options.getString("name"); var deleted = false; - if(ia.getMember().hasPermission(Permission.ADMINISTRATOR)){ - deleted = ia.get(TagsModule.class).delete(tagName, ia.getGuildId()); + if(ctx.getMember().hasPermission(Permission.ADMINISTRATOR)){ + deleted = ctx.get(TagsModule.class).delete(tagName, ctx.getGuildId()); } else{ - deleted = ia.get(TagsModule.class).delete(tagName, ia.getGuildId(), ia.getUserId()); + deleted = ctx.get(TagsModule.class).delete(tagName, ctx.getGuildId(), ctx.getUserId()); } if(deleted){ - ia.reply("Deleted tag with name `" + tagName + "`"); + ctx.reply("Deleted tag with name `" + tagName + "`"); return; } - ia.error("Tag `" + tagName + "` does not exist or is not owned by you"); + ctx.error("Tag `" + tagName + "` does not exist or is not owned by you"); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/tags/tags/EditCommand.java b/src/main/java/de/kittybot/kittybot/commands/tags/tags/EditCommand.java index 193b0a912..d02b28086 100644 --- a/src/main/java/de/kittybot/kittybot/commands/tags/tags/EditCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/tags/tags/EditCommand.java @@ -2,11 +2,11 @@ import de.kittybot.kittybot.modules.MessageModule; import de.kittybot.kittybot.modules.TagsModule; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionLong; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionString; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; public class EditCommand extends GuildSubCommand{ @@ -21,10 +21,10 @@ public EditCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ + public void run(Options options, GuildCommandContext ctx){ var tagName = options.getString("name"); if(!options.has("content") && !options.has("message-id") && !options.has("new-name")){ - ia.error("Please provide either content, message-id or new-name"); + ctx.error("Please provide either content, message-id or new-name"); return; } String content; @@ -32,9 +32,9 @@ public void run(Options options, GuildInteraction ia){ content = options.getString("content"); } else if(options.has("message-id")){ - var message = ia.get(MessageModule.class).getMessageById(options.getLong("message-id")); + var message = ctx.get(MessageModule.class).getMessageById(options.getLong("message-id")); if(message == null){ - ia.error("Please provide a recent message id"); + ctx.error("Please provide a recent message id"); return; } content = message.getContent(); @@ -43,12 +43,12 @@ else if(options.has("message-id")){ content = null; } - var edited = ia.get(TagsModule.class).edit(tagName, content, ia.getGuildId(), ia.getUserId(), options.has("new-name") ? options.getString("new-name") : null); + var edited = ctx.get(TagsModule.class).edit(tagName, content, ctx.getGuildId(), ctx.getUserId(), options.has("new-name") ? options.getString("new-name") : null); if(edited){ - ia.reply("Edited tag with name `" + tagName + "`"); + ctx.reply("Edited tag with name `" + tagName + "`"); return; } - ia.error("Tag `" + tagName + "` does not exist or is not owned by you"); + ctx.error("Tag `" + tagName + "` does not exist or is not owned by you"); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/tags/tags/InfoCommand.java b/src/main/java/de/kittybot/kittybot/commands/tags/tags/InfoCommand.java index c0e5a22fc..8a3dbd4a7 100644 --- a/src/main/java/de/kittybot/kittybot/commands/tags/tags/InfoCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/tags/tags/InfoCommand.java @@ -1,10 +1,10 @@ package de.kittybot.kittybot.commands.tags.tags; import de.kittybot.kittybot.modules.TagsModule; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionString; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; import de.kittybot.kittybot.utils.MessageUtils; import de.kittybot.kittybot.utils.TimeUtils; @@ -18,15 +18,15 @@ public InfoCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ + public void run(Options options, GuildCommandContext ctx){ var tagName = options.getString("name"); - var tag = ia.get(TagsModule.class).get(tagName, ia.getGuildId()); + var tag = ctx.get(TagsModule.class).get(tagName, ctx.getGuildId()); if(tag == null){ - ia.error("Tag with name `" + tagName + "` not found"); + ctx.error("Tag with name `" + tagName + "` not found"); return; } - ia.reply(builder -> builder + ctx.reply(builder -> builder .setTitle("Tag `" + tagName + "`") .addField("Owner", MessageUtils.getUserMention(tag.getUserId()), false) .addField("ID", Long.toString(tag.getId()), false) diff --git a/src/main/java/de/kittybot/kittybot/commands/tags/tags/ListCommand.java b/src/main/java/de/kittybot/kittybot/commands/tags/tags/ListCommand.java index 4bd4ccaf4..0be4bda41 100644 --- a/src/main/java/de/kittybot/kittybot/commands/tags/tags/ListCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/tags/tags/ListCommand.java @@ -2,10 +2,10 @@ import de.kittybot.kittybot.modules.TagsModule; import de.kittybot.kittybot.objects.settings.Tag; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionUser; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; import de.kittybot.kittybot.utils.MessageUtils; import java.util.List; @@ -21,21 +21,21 @@ public ListCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ + public void run(Options options, GuildCommandContext ctx){ List tags; if(options.has("user")){ - tags = ia.get(TagsModule.class).get(ia.getGuildId(), options.getLong("user")); + tags = ctx.get(TagsModule.class).get(ctx.getGuildId(), options.getLong("user")); } else{ - tags = ia.get(TagsModule.class).get(ia.getGuildId()); + tags = ctx.get(TagsModule.class).get(ctx.getGuildId()); } if(tags.isEmpty()){ - ia.reply("No tags created yet"); + ctx.reply("No tags created yet"); return; } // TODO add paginator - ia.reply("**Following tags exist:**\n" + tags.stream().map(tag -> "• `" + tag.getName() + "` (" + MessageUtils.getUserMention(tag.getUserId()) + ")").collect(Collectors.joining("\n"))); + ctx.reply("**Following tags exist:**\n" + tags.stream().map(tag -> "• `" + tag.getName() + "` (" + MessageUtils.getUserMention(tag.getUserId()) + ")").collect(Collectors.joining("\n"))); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/tags/tags/PublishCommand.java b/src/main/java/de/kittybot/kittybot/commands/tags/tags/PublishCommand.java index e31ee85c7..2d272d12a 100644 --- a/src/main/java/de/kittybot/kittybot/commands/tags/tags/PublishCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/tags/tags/PublishCommand.java @@ -1,10 +1,10 @@ package de.kittybot.kittybot.commands.tags.tags; import de.kittybot.kittybot.modules.TagsModule; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionString; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.utils.MarkdownSanitizer; @@ -24,29 +24,29 @@ public PublishCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ + public void run(Options options, GuildCommandContext ctx){ var name = options.getString("name"); - var tagsModule = ia.get(TagsModule.class); - var tag = tagsModule.get(name, ia.getGuildId()); + var tagsModule = ctx.get(TagsModule.class); + var tag = tagsModule.get(name, ctx.getGuildId()); if(tag == null){ - ia.error("Tag with name `" + MarkdownSanitizer.escape(name) + "` not found"); + ctx.error("Tag with name `" + MarkdownSanitizer.escape(name) + "` not found"); return; } if(!COMMAND_NAME_PATTERN.matcher(name).matches()){ - ia.error("Please make sure your tag name only contains letters, numbers & -"); + ctx.error("Please make sure your tag name only contains letters, numbers & -"); return; } - if(!tagsModule.canPublishTag(ia.getGuildId())){ - ia.error("You reached the maximum of 50 guild commands due to discords limitations"); + if(!tagsModule.canPublishTag(ctx.getGuildId())){ + ctx.error("You reached the maximum of 50 guild commands due to discords limitations"); return; } - var res = tagsModule.publishTag(name, options.getString("description"), ia.getGuildId()); + var res = tagsModule.publishTag(name, options.getString("description"), ctx.getGuildId()); if(!res){ - ia.error("Something went wrong while publishing your tag to slash commands"); + ctx.error("Something went wrong while publishing your tag to slash commands"); return; } - ia.reply("Successfully published your tag to slash commands"); + ctx.reply("Successfully published your tag to slash commands"); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/tags/tags/RemoveCommand.java b/src/main/java/de/kittybot/kittybot/commands/tags/tags/RemoveCommand.java index 218ed4920..e58233ab2 100644 --- a/src/main/java/de/kittybot/kittybot/commands/tags/tags/RemoveCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/tags/tags/RemoveCommand.java @@ -1,10 +1,10 @@ package de.kittybot.kittybot.commands.tags.tags; import de.kittybot.kittybot.modules.TagsModule; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionString; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.utils.MarkdownSanitizer; @@ -19,24 +19,24 @@ public RemoveCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ + public void run(Options options, GuildCommandContext ctx){ var name = options.getString("name"); - var tagsModule = ia.get(TagsModule.class); - var tag = tagsModule.get(name, ia.getGuildId()); + var tagsModule = ctx.get(TagsModule.class); + var tag = tagsModule.get(name, ctx.getGuildId()); if(tag == null){ - ia.error("Tag with name `" + MarkdownSanitizer.escape(name) + "` not found"); + ctx.error("Tag with name `" + MarkdownSanitizer.escape(name) + "` not found"); return; } if(tag.getCommandId() == -1L){ - ia.error("Tag with name `" + MarkdownSanitizer.escape(name) + "` is not published"); + ctx.error("Tag with name `" + MarkdownSanitizer.escape(name) + "` is not published"); return; } - var res = tagsModule.removePublishedTag(ia.getGuildId(), tag.getCommandId()); + var res = tagsModule.removePublishedTag(ctx.getGuildId(), tag.getCommandId()); if(!res){ - ia.error("Something went wrong while removing your tag from slash commands"); + ctx.error("Something went wrong while removing your tag from slash commands"); return; } - ia.reply("Successfully removed tag from slash commands"); + ctx.reply("Successfully removed tag from slash commands"); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/tags/tags/SearchCommand.java b/src/main/java/de/kittybot/kittybot/commands/tags/tags/SearchCommand.java index 35b40ba1a..0b87b6303 100644 --- a/src/main/java/de/kittybot/kittybot/commands/tags/tags/SearchCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/tags/tags/SearchCommand.java @@ -1,10 +1,10 @@ package de.kittybot.kittybot.commands.tags.tags; import de.kittybot.kittybot.modules.TagsModule; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionString; import de.kittybot.kittybot.slashcommands.application.options.GuildSubCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; import de.kittybot.kittybot.utils.MessageUtils; import java.util.stream.Collectors; @@ -19,16 +19,16 @@ public SearchCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ + public void run(Options options, GuildCommandContext ctx){ var tagName = options.getString("name"); - var tags = ia.get(TagsModule.class).search(tagName, ia.getGuildId(), ia.getUserId()); + var tags = ctx.get(TagsModule.class).search(tagName, ctx.getGuildId(), ctx.getUserId()); if(tags.isEmpty()){ - ia.reply("No tags found for `" + tagName + "`"); + ctx.reply("No tags found for `" + tagName + "`"); return; } // TODO add paginator - ia.reply("**Following tags were found for `" + tagName + "`:**\n" + + ctx.reply("**Following tags were found for `" + tagName + "`:**\n" + tags.stream().map(tag -> "• `" + tag.getName() + "` (" + MessageUtils.getUserMention(tag.getUserId()) + ")").collect(Collectors.joining("\n")) ); } diff --git a/src/main/java/de/kittybot/kittybot/commands/utility/HastebinCommand.java b/src/main/java/de/kittybot/kittybot/commands/utility/HastebinCommand.java index bb651aed4..a665d5344 100644 --- a/src/main/java/de/kittybot/kittybot/commands/utility/HastebinCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/utility/HastebinCommand.java @@ -1,12 +1,12 @@ package de.kittybot.kittybot.commands.utility; import de.kittybot.kittybot.modules.RequestModule; +import de.kittybot.kittybot.slashcommands.CommandContext; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.Category; import de.kittybot.kittybot.slashcommands.application.RunCommand; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionUrl; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Interaction; -import de.kittybot.kittybot.slashcommands.interaction.Options; import de.kittybot.kittybot.utils.Config; import net.dv8tion.jda.api.Permission; import org.apache.commons.io.IOUtils; @@ -27,59 +27,59 @@ public HastebinCommand(){ } @Override - public void run(Options options, Interaction ia){ - if(ia instanceof GuildInteraction && !((GuildInteraction) ia).getSelfMember().hasPermission(((GuildInteraction) ia).getChannel(), Permission.VIEW_CHANNEL, Permission.MESSAGE_HISTORY)){ - ia.error("Please make sure I have following permissions: `VIEW_CHANNEL`, `MESSAGE_HISTORY`"); + public void run(Options options, CommandContext ctx){ + if(ctx instanceof GuildCommandContext && !((GuildCommandContext) ctx).getSelfMember().hasPermission(((GuildCommandContext) ctx).getChannel(), Permission.VIEW_CHANNEL, Permission.MESSAGE_HISTORY)){ + ctx.error("Please make sure I have following permissions: `VIEW_CHANNEL`, `MESSAGE_HISTORY`"); return; } if(Config.HASTEBIN_URL.isBlank()){ - ia.error("No hastebin url configured"); + ctx.error("No hastebin url configured"); return; } if(options.has("url")){ - ia.get(RequestModule.class).retrieveUrlContent(options.getString("url"), + ctx.get(RequestModule.class).retrieveUrlContent(options.getString("url"), (call, response) -> { var body = response.body(); if(body == null){ - ia.error("Provided link has no content"); + ctx.error("Provided link has no content"); return; } try{ - ia.get(RequestModule.class).postToHastebin(body.string(), key -> { + ctx.get(RequestModule.class).postToHastebin(body.string(), key -> { if(key == null){ - ia.error("Unexpected error while creating hastebin"); + ctx.error("Unexpected error while creating hastebin"); return; } - ia.reply(maskLink("here is a hastebin", Config.HASTEBIN_URL + "/" + key)); + ctx.reply(maskLink("here is a hastebin", Config.HASTEBIN_URL + "/" + key)); }); } catch(IOException e){ - ia.error("Error while getting body data from link"); + ctx.error("Error while getting body data from link"); } } - , (call, response) -> ia.error("Error while retrieving data from link")); + , (call, response) -> ctx.error("Error while retrieving data from link")); return; } - ia.getChannel().getIterableHistory().takeAsync(25).thenAcceptAsync(messages -> { + ctx.getChannel().getIterableHistory().takeAsync(25).thenAcceptAsync(messages -> { var message = messages.stream().filter(msg -> !msg.getAttachments().isEmpty() && msg.getAttachments().stream().anyMatch(attachment -> !attachment.isImage() && !attachment.isVideo())).findFirst(); if(message.isEmpty()){ - ia.error("No file found to in recent 25 messages"); + ctx.error("No file found to in recent 25 messages"); return; } message.get().getAttachments().forEach(attachment -> attachment.retrieveInputStream().thenAcceptAsync(inputStream -> { try(inputStream){ var text = IOUtils.toString(inputStream, StandardCharsets.UTF_8); - ia.get(RequestModule.class).postToHastebin(text, key -> { + ctx.get(RequestModule.class).postToHastebin(text, key -> { if(key == null){ - ia.error("Unexpected error while creating hastebin"); + ctx.error("Unexpected error while creating hastebin"); return; } - ia.reply(maskLink("here is a hastebin", Config.HASTEBIN_URL + "/" + key)); + ctx.reply(maskLink("here is a hastebin", Config.HASTEBIN_URL + "/" + key)); }); } catch(IOException e){ - ia.error("Error while creating hastebin\nError: " + e.getMessage()); + ctx.error("Error while creating hastebin\nError: " + e.getMessage()); } }) ); diff --git a/src/main/java/de/kittybot/kittybot/commands/utility/StealEmoteCommand.java b/src/main/java/de/kittybot/kittybot/commands/utility/StealEmoteCommand.java index 9217cdb5f..3da7e3aaf 100644 --- a/src/main/java/de/kittybot/kittybot/commands/utility/StealEmoteCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/utility/StealEmoteCommand.java @@ -1,10 +1,10 @@ package de.kittybot.kittybot.commands.utility; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.Category; import de.kittybot.kittybot.slashcommands.application.Command; import de.kittybot.kittybot.slashcommands.application.options.*; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; import de.kittybot.kittybot.utils.EmoteHelper; import net.dv8tion.jda.api.Permission; @@ -35,13 +35,13 @@ public EmoteCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ - if(!ia.getSelfMember().hasPermission(Permission.MANAGE_EMOTES)){ - ia.error("To steal emotes I need the `" + Permission.MANAGE_EMOTES.getName() + "` permission"); + public void run(Options options, GuildCommandContext ctx){ + if(!ctx.getSelfMember().hasPermission(Permission.MANAGE_EMOTES)){ + ctx.error("To steal emotes I need the `" + Permission.MANAGE_EMOTES.getName() + "` permission"); return; } var name = options.has("new-name") ? options.getString("new-name") : options.getEmoteName("emote"); - EmoteHelper.createEmote(ia, name, options.getEmoteId("emote"), options.getEmoteAnimated("emote")); + EmoteHelper.createEmote(ctx, name, options.getEmoteId("emote"), options.getEmoteAnimated("emote")); } } @@ -58,14 +58,14 @@ public EmoteIdCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ - if(!ia.getSelfMember().hasPermission(Permission.MANAGE_EMOTES)){ - ia.error("To steal emotes I need the `" + Permission.MANAGE_EMOTES.getName() + "` permission"); + public void run(Options options, GuildCommandContext ctx){ + if(!ctx.getSelfMember().hasPermission(Permission.MANAGE_EMOTES)){ + ctx.error("To steal emotes I need the `" + Permission.MANAGE_EMOTES.getName() + "` permission"); return; } var emoteId = options.getLong("emote-id"); var name = options.has("new-name") ? options.getString("new-name") : Long.toString(emoteId); - EmoteHelper.createEmote(ia, name, emoteId, options.has("animated") && options.getBoolean("animated")); + EmoteHelper.createEmote(ctx, name, emoteId, options.has("animated") && options.getBoolean("animated")); } } @@ -81,12 +81,12 @@ public URLCommand(){ } @Override - public void run(Options options, GuildInteraction ia){ - if(!ia.getSelfMember().hasPermission(Permission.MANAGE_EMOTES)){ - ia.error("To steal emotes I need the `" + Permission.MANAGE_EMOTES.getName() + "` permission"); + public void run(Options options, GuildCommandContext ctx){ + if(!ctx.getSelfMember().hasPermission(Permission.MANAGE_EMOTES)){ + ctx.error("To steal emotes I need the `" + Permission.MANAGE_EMOTES.getName() + "` permission"); return; } - EmoteHelper.createEmote(ia, options.getString("new-name"), options.getString("url")); + EmoteHelper.createEmote(ctx, options.getString("new-name"), options.getString("url")); } } diff --git a/src/main/java/de/kittybot/kittybot/commands/utility/TranslateCommand.java b/src/main/java/de/kittybot/kittybot/commands/utility/TranslateCommand.java index 3e4eef088..935143df5 100644 --- a/src/main/java/de/kittybot/kittybot/commands/utility/TranslateCommand.java +++ b/src/main/java/de/kittybot/kittybot/commands/utility/TranslateCommand.java @@ -2,11 +2,11 @@ import de.kittybot.kittybot.modules.RequestModule; import de.kittybot.kittybot.objects.enums.Language; +import de.kittybot.kittybot.slashcommands.CommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.Category; import de.kittybot.kittybot.slashcommands.application.RunCommand; import de.kittybot.kittybot.slashcommands.application.options.CommandOptionString; -import de.kittybot.kittybot.slashcommands.interaction.Interaction; -import de.kittybot.kittybot.slashcommands.interaction.Options; import net.dv8tion.jda.api.utils.MarkdownSanitizer; @SuppressWarnings("unused") @@ -22,28 +22,28 @@ public TranslateCommand(){ } @Override - public void run(Options options, Interaction ia){ + public void run(Options options, CommandContext ctx){ var toLang = Language.getFromName(options.getString("to-language")); var fromLang = options.has("from-language") ? Language.getFromName(options.getString("from-language")) : Language.AUTO; if(toLang == Language.UNKNOWN || fromLang == Language.UNKNOWN){ - ia.error("Invalid language entered"); + ctx.error("Invalid language entered"); return; } if(toLang == fromLang){ - ia.error("From lang can not be same as to lang"); + ctx.error("From lang can not be same as to lang"); return; } var text = options.getString("text"); if(text.isBlank()){ - ia.error("Please provide text to translate"); + ctx.error("Please provide text to translate"); return; } - ia.get(RequestModule.class).translateText(text, fromLang, toLang, translatedText -> { + ctx.get(RequestModule.class).translateText(text, fromLang, toLang, translatedText -> { if(translatedText == null){ - ia.error("Error while trying to translate text"); + ctx.error("Error while trying to translate text"); return; } - ia.reply("Translated text to `" + toLang.getName() + "`:\n```\n" + MarkdownSanitizer.escape(translatedText) + "\n```"); + ctx.reply("Translated text to `" + toLang.getName() + "`:\n```\n" + MarkdownSanitizer.escape(translatedText) + "\n```"); }); } diff --git a/src/main/java/de/kittybot/kittybot/modules/CommandsModule.java b/src/main/java/de/kittybot/kittybot/modules/CommandsModule.java index fee258717..0fe9b4fed 100644 --- a/src/main/java/de/kittybot/kittybot/modules/CommandsModule.java +++ b/src/main/java/de/kittybot/kittybot/modules/CommandsModule.java @@ -7,8 +7,13 @@ import de.kittybot.kittybot.utils.annotations.Ignore; import io.github.classgraph.ClassGraph; import io.github.classgraph.ClassInfo; +import net.dv8tion.jda.api.entities.Guild; +import net.dv8tion.jda.api.events.ReadyEvent; +import net.dv8tion.jda.api.events.guild.GuildReadyEvent; +import net.dv8tion.jda.api.requests.restaction.CommandUpdateAction; import net.dv8tion.jda.api.utils.data.DataArray; import net.dv8tion.jda.api.utils.data.DataObject; +import net.dv8tion.jda.internal.entities.GuildImpl; import net.dv8tion.jda.internal.requests.Method; import net.dv8tion.jda.internal.requests.Requester; import net.dv8tion.jda.internal.requests.Route; @@ -16,6 +21,7 @@ import okhttp3.MediaType; import okhttp3.Request; import okhttp3.RequestBody; +import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -28,35 +34,27 @@ public class CommandsModule extends Module{ - public static final Route COMMANDS_CREATE = Route.custom(Method.PUT, "applications/{application.id}/commands"); - public static final Route GUILD_COMMANDS_CREATE = Route.custom(Method.PUT, "applications/{application.id}/guilds/{guild.id}/commands"); - public static final Route GUILD_COMMANDS = Route.custom(Method.GET, "applications/{application.id}/guilds/{guild.id}/commands"); - public static final Route GUILD_COMMAND_CREATE = Route.custom(Method.POST, "applications/{application.id}/guilds/{guild.id}/commands"); - public static final Route GUILD_COMMAND_EDIT = Route.custom(Method.PATCH, "applications/{application.id}/guilds/{guild.id}/commands/{command.id}"); - public static final Route GUILD_COMMAND_DELETE = Route.custom(Method.DELETE, "applications/{application.id}/guilds/{guild.id}/commands/{command.id}"); - private static final Logger LOG = LoggerFactory.getLogger(CommandsModule.class); private static final String COMMANDS_PACKAGE = "de.kittybot.kittybot.commands"; - private static final Set> DEPENDENCIES = Set.of(RequestModule.class); private Map commands; @Override - public Set> getDependencies(){ - return DEPENDENCIES; + public void onEnable(){ + scanCommands(); } @Override - public void onEnable(){ - scanCommands(); - var env = Environment.getCurrent(); - if(env == Environment.PRODUCTION){ + public void onReady(@NotNull ReadyEvent event){ + if(Environment.getCurrent() == Environment.PRODUCTION){ deployAllCommands(-1L); } - else if(env == Environment.DEVELOPMENT){ - if(Config.SUPPORT_GUILD_ID != -1){ - deployAllCommands(Config.SUPPORT_GUILD_ID); - } + } + + @Override + public void onGuildReady(@NotNull GuildReadyEvent event){ + if(Environment.getCurrent() == Environment.DEVELOPMENT && Config.SUPPORT_GUILD_ID == event.getGuild().getIdLong()){ + deployAllCommands(Config.SUPPORT_GUILD_ID); } } @@ -83,131 +81,33 @@ public void scanCommands(){ } public void deployAllCommands(long guildId){ - LOG.info("Registering commands {}...", guildId == -1 ? "global" : "for guild " + guildId); - - var commands = DataArray.fromCollection(this.commands.values().stream().map(Command::toJSON).collect(Collectors.toList())); - var rqBody = RequestBody.create(commands.toJson(), MediaType.parse("application/json")); - - var route = guildId == -1L ? COMMANDS_CREATE.compile(String.valueOf(Config.BOT_ID)) : GUILD_COMMANDS_CREATE.compile(String.valueOf(Config.BOT_ID), String.valueOf(guildId)); - try(var resp = newCall(route, rqBody).execute()){ - if(!resp.isSuccessful()){ - var body = resp.body(); - LOG.error("Registering commands failed. Request Body: {}, Response Body: {}", commands.toString(), body == null ? "null" : body.string()); - return; - } - } - catch(IOException e){ - LOG.error("Error while processing registerCommands", e); - } - if(guildId == -1L && !Config.DISCORD_SERVICES_TOKEN.isBlank()){ - this.modules.get(RequestModule.class).uploadCommands(this.commands); + CommandUpdateAction action; + if(guildId == -1L){ + action = this.modules.getJDA().updateCommands(); } - LOG.info("Registered " + this.commands.size() + " commands..."); - } - - private Call newCall(Route.CompiledRoute route, RequestBody body){ - return this.modules.getHttpClient().newCall(newBuilder(route).method(route.getMethod().name(), body).build()); - } - - private Request.Builder newBuilder(Route.CompiledRoute route){ - return new Request.Builder() - .url(Requester.DISCORD_API_PREFIX + route.getCompiledRoute()) - .addHeader("Authorization", "Bot " + Config.BOT_TOKEN); - } - - public long registerGuildCommand(long guildId, DataObject command){ - var rqBody = RequestBody.create(command.toJson(), MediaType.parse("application/json")); - - var route = GUILD_COMMAND_CREATE.compile(String.valueOf(Config.BOT_ID), String.valueOf(guildId)); - try(var resp = newCall(route, rqBody).execute()){ - if(!resp.isSuccessful()){ - var body = resp.body(); - LOG.error("Registering command failed. Request Body: {}, Response Body: {}", command.toString(), body == null ? "null" : body.string()); - return -1L; - } - var body = resp.body(); - if(body == null){ - LOG.error("empty body received"); - return -1L; - } - LOG.info("Registered command"); - return DataObject.fromJson(body.byteStream()).getLong("id"); - } - catch(IOException e){ - LOG.error("Error while processing registerGuildCommand", e); - } - return -1L; - } - - public boolean deleteGuildCommand(long guildId, long commandId){ - var route = GUILD_COMMAND_DELETE.compile(String.valueOf(Config.BOT_ID), String.valueOf(guildId), String.valueOf(commandId)); - try(var resp = newCall(route, null).execute()){ - if(resp.code() == 204){ - LOG.info("Deleted command"); - return true; - } - var body = resp.body(); - LOG.error("Deleting command failed. Command ID: {}, Response Body: {}", commandId, body == null ? "null" : body.string()); - } - catch(IOException e){ - LOG.error("Error while processing deleteGuildCommand", e); - } - return false; - } - - public boolean editGuildCommand(long guildId, long commandId, DataObject command){ - var rqBody = RequestBody.create(command.toJson(), MediaType.parse("application/json")); - - var route = GUILD_COMMAND_EDIT.compile(String.valueOf(Config.BOT_ID), String.valueOf(guildId), String.valueOf(commandId)); - try(var resp = newCall(route, rqBody).execute()){ - if(resp.code() == 200){ - LOG.info("Edited command"); - return true; - } - var body = resp.body(); - LOG.error("Editing command failed. Command ID: {}, Response Body: {}", commandId, body == null ? "null" : body.string()); - } - catch(IOException e){ - LOG.error("Error while processing editGuildCommand", e); - } - return false; - } - - public DataArray getGuildCommands(long guildId){ - var route = GUILD_COMMANDS.compile(String.valueOf(Config.BOT_ID), String.valueOf(guildId)); - try(var resp = newCall(route, null).execute()){ - var body = resp.body(); - if(!resp.isSuccessful()){ - LOG.error("Registering command failed. Guild ID: {}, Response Body: {}", guildId, body == null ? "null" : body.string()); - return null; - } - if(body == null){ - return null; + else{ + var guild = this.modules.getGuildById(guildId); + if(guild == null){ + return; } - return DataArray.fromJson(body.byteStream()); - } - catch(IOException e){ - LOG.error("Error while processing deleteGuildCommand", e); + action = guild.updateCommands(); } - return null; + action.addCommands(this.commands.values().stream().map(Command::toData).collect(Collectors.toList())).queue(); } public void deleteAllCommands(long guildId){ - LOG.info("Deleting commands {}...", guildId == -1 ? "global" : "for guild " + guildId); - var rqBody = RequestBody.create(DataArray.empty().toString(), MediaType.parse("application/json")); - - var route = guildId == -1L ? COMMANDS_CREATE.compile(String.valueOf(Config.BOT_ID)) : GUILD_COMMANDS_CREATE.compile(String.valueOf(Config.BOT_ID), String.valueOf(guildId)); - try(var resp = newCall(route, rqBody).execute()){ - if(!resp.isSuccessful()){ - var body = resp.body(); - LOG.error("Deleting commands failed. Body: {}", body == null ? "null" : body.string()); + CommandUpdateAction action; + if(guildId == -1L){ + action = this.modules.getJDA().updateCommands(); + } + else{ + var guild = this.modules.getGuildById(guildId); + if(guild == null){ return; } + action = guild.updateCommands(); } - catch(IOException e){ - LOG.error("Error while processing deleteAllCommands", e); - } - LOG.info("Deleted all commands..."); + action.queue(); } public Map getCommands(){ diff --git a/src/main/java/de/kittybot/kittybot/modules/InteractionsModule.java b/src/main/java/de/kittybot/kittybot/modules/InteractionsModule.java index 761dd585a..8b6270a28 100644 --- a/src/main/java/de/kittybot/kittybot/modules/InteractionsModule.java +++ b/src/main/java/de/kittybot/kittybot/modules/InteractionsModule.java @@ -1,106 +1,87 @@ package de.kittybot.kittybot.modules; -import club.minnced.discord.webhook.receive.ReadonlyMessage; +import de.kittybot.kittybot.objects.exceptions.OptionParseException; import de.kittybot.kittybot.objects.module.Module; +import de.kittybot.kittybot.slashcommands.CommandContext; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.CommandOptionsHolder; import de.kittybot.kittybot.slashcommands.application.PermissionHolder; import de.kittybot.kittybot.slashcommands.application.RunnableCommand; import de.kittybot.kittybot.slashcommands.application.RunnableGuildCommand; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Interaction; -import de.kittybot.kittybot.slashcommands.interaction.InteractionOptionsHolder; -import de.kittybot.kittybot.slashcommands.interaction.Options; -import de.kittybot.kittybot.slashcommands.interaction.response.FollowupMessage; -import de.kittybot.kittybot.slashcommands.interaction.response.InteractionRespondAction; -import de.kittybot.kittybot.slashcommands.interaction.response.InteractionResponseType; import de.kittybot.kittybot.utils.Config; import de.kittybot.kittybot.utils.MessageUtils; import de.kittybot.kittybot.utils.exporters.Metrics; import net.dv8tion.jda.api.Permission; -import net.dv8tion.jda.api.events.RawGatewayEvent; -import net.dv8tion.jda.api.requests.RestAction; +import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; import net.dv8tion.jda.internal.requests.Method; -import net.dv8tion.jda.internal.requests.RestActionImpl; import net.dv8tion.jda.internal.requests.Route; -import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.List; import java.util.Set; import java.util.stream.Collectors; @SuppressWarnings("unused") public class InteractionsModule extends Module{ - public static final Route INTERACTION_RESPONSE = Route.custom(Method.POST, "interactions/{interaction.id}/{interaction.token}/callback"); - public static final Route INTERACTION_FOLLOW_UP = Route.custom(Method.POST, "webhooks/{application.id}/{interaction.token}"); private static final Logger LOG = LoggerFactory.getLogger(InteractionsModule.class); - private static final Set> DEPENDENCIES = Set.of(CommandsModule.class); - private static final String INTERACTION_CREATE = "INTERACTION_CREATE"; @Override public Set> getDependencies(){ - return DEPENDENCIES; + return Set.of(CommandsModule.class); } @Override - public void onRawGateway(@NotNull RawGatewayEvent event){ - if(!event.getType().equals(INTERACTION_CREATE)){ - return; - } + public void onSlashCommand(SlashCommandEvent event) { var start = System.currentTimeMillis(); - var interaction = Interaction.fromJSON(this.modules, event.getPayload(), event.getJDA()); + var guild = event.getGuild(); + if(guild != null && event.getMember() != null){ + var settings = this.modules.get(SettingsModule.class).getSettings(guild.getIdLong()); - if(interaction instanceof GuildInteraction){ - var guildInteraction = (GuildInteraction) interaction; - var settings = this.modules.get(SettingsModule.class).getSettings(guildInteraction.getGuild().getIdLong()); - - if(settings.isBotIgnoredUser(guildInteraction.getMember().getIdLong())){ - interaction.error("I ignore u baka"); + if(settings.isBotIgnoredUser(event.getMember().getIdLong())){ + event.reply("I ignore u baka").setEphemeral(true).queue(); return; } - if(settings.isBotDisabledInChannel(interaction.getChannelId())){ - interaction.error("I'm disabled in this channel"); + if(settings.isBotDisabledInChannel(event.getChannel().getIdLong())){ + event.reply("I'm disabled in this channel").setEphemeral(true).queue(); return; } } - - var data = interaction.getData(); - var cmd = this.modules.get(CommandsModule.class).getCommands().get(data.getName()); + var cmd = this.modules.get(CommandsModule.class).getCommands().get(event.getName()); if(cmd != null){ - process(cmd, interaction, data); - Metrics.COMMAND_LATENCY.labels(cmd.getName()).observe(System.currentTimeMillis() - start); - Metrics.COMMAND_COUNTER.labels(cmd.getName()).inc(); + process(cmd, event, event.getOptions()); + Metrics.COMMAND_LATENCY.labels(event.getName()).observe(System.currentTimeMillis() - start); + Metrics.COMMAND_COUNTER.labels(event.getName()).inc(); return; } - var tag = this.modules.get(TagsModule.class).getPublishedTagById(data.getId()); + var tag = this.modules.get(TagsModule.class).getPublishedTagById(event.getCommandIdLong()); if(tag != null){ - if(!(interaction instanceof GuildInteraction)){ + if(!(event.getGuild() == null)){ LOG.error("Guild Tag command received from dms???? guild: {} command: {}", tag.getGuildId(), tag.getCommandId()); return; } - tag.process((GuildInteraction) interaction); + tag.process(event); return; } - LOG.error("Could not process interaction: {}", event.getPayload()); - interaction.error("Nani u discovered a secret don't tell anyone(This command does not exist anymore)"); + event.reply("Nani u discovered a secret don't tell anyone(This command does not exist anymore)").setEphemeral(true).queue(); } - public void process(CommandOptionsHolder applicationHolder, Interaction interaction, InteractionOptionsHolder holder){ + public void process(CommandOptionsHolder applicationHolder, SlashCommandEvent event, List options){ if(applicationHolder instanceof PermissionHolder){ var permHolder = ((PermissionHolder) applicationHolder); - var user = interaction.getUser(); + var user = event.getUser(); if(permHolder.isDevOnly() && !Config.DEV_IDS.contains(user.getIdLong())){ - reply(interaction).ephemeral().content("This command is developer only").type(InteractionResponseType.ACKNOWLEDGE).queue(); + event.reply("This command is developer only").setEphemeral(true).queue(); return; } - if(!Config.DEV_IDS.contains(interaction.getUserId())){ - if(interaction instanceof GuildInteraction){ - var guildInteraction = (GuildInteraction) interaction; - var missingPerms = permHolder.getPermissions().stream().dropWhile(guildInteraction.getMember().getPermissions()::contains).collect(Collectors.toSet()); + if(!Config.DEV_IDS.contains(event.getUser().getIdLong())){ + if(event.getGuild() != null && event.getMember() != null){ + var missingPerms = permHolder.getPermissions().stream().dropWhile(event.getMember().getPermissions()::contains).collect(Collectors.toSet()); if(!missingPerms.isEmpty()){ - interaction.error("You are missing following permissions to use this command:\n" + missingPerms.stream().map(Permission::getName).collect(Collectors.joining(", "))); + event.reply("You are missing following permissions to use this command:\n" + missingPerms.stream().map(Permission::getName).collect(Collectors.joining(", "))).setEphemeral(true).queue(); return; } } @@ -109,52 +90,37 @@ public void process(CommandOptionsHolder applicationHolder, Interaction interact if(applicationHolder instanceof RunnableCommand || applicationHolder instanceof RunnableGuildCommand){ try{ - var options = new Options(applicationHolder.getOptions(), holder.getOptions(), interaction.getData().getResolvedMentions()); + var commandOptions = new Options(event.getOptions(), event.getJDA()); if(applicationHolder instanceof RunnableCommand){ - ((RunnableCommand) applicationHolder).run(options, interaction); + ((RunnableCommand) applicationHolder).run(commandOptions, new CommandContext(this.modules, commandOptions, event)); } - else if(interaction instanceof GuildInteraction){ - ((RunnableGuildCommand) applicationHolder).run(options, (GuildInteraction) interaction); + else if(event.getGuild() != null){ + ((RunnableGuildCommand) applicationHolder).run(commandOptions, new GuildCommandContext(this.modules, commandOptions, event)); } - else if(interaction.isFromGuild()){ + /*else if(interaction.isFromGuild()){ interaction.reply("This slash command is not available without inviting Kitty. You can do this " + MessageUtils.maskLink("here", Config.BOT_INVITE_URL)); - } + }*/ else{ - interaction.reply("This slash command is not available in dms. Surruwu"); + event.reply("This slash command is not available in dms. Surruwu").queue(); } } + catch(OptionParseException e){ + event.reply(e.getMessage()).setEphemeral(true).queue(); + } catch(Exception e){ - interaction.error(e.getMessage()); + LOG.error("Unexpected error while handling command", e); + event.reply("Error while handling event please redirect to following to my dev " + MessageUtils.maskLink("here", Config.SUPPORT_GUILD_INVITE_URL) + "\nError: `" + e.getMessage() + "`").queue(); } return; } for(var option : applicationHolder.getOptions()){ - var opt = holder.getOptions().get(0); + var opt = options.get(0); if(opt.getName().equalsIgnoreCase(option.getName())){ - process(option, interaction, opt); + process(option, event, opt.get()); return; } } } - public InteractionRespondAction acknowledge(Interaction interaction, boolean withSource){ - return new InteractionRespondAction(interaction.getJDA(), INTERACTION_RESPONSE.compile(String.valueOf(interaction.getId()), interaction.getToken()), interaction, withSource).channelMessage(false); - } - - public InteractionRespondAction reply(Interaction interaction){ - return reply(interaction, true); - } - - public InteractionRespondAction reply(Interaction interaction, boolean withSource){ - return new InteractionRespondAction(interaction.getJDA(), INTERACTION_RESPONSE.compile(String.valueOf(interaction.getId()), interaction.getToken()), interaction, withSource); - } - - public RestAction followup(Interaction interaction, FollowupMessage message){ - - Route.CompiledRoute route = INTERACTION_FOLLOW_UP.compile(interaction.getJDA().getSelfUser().getId(), interaction.getToken()); - - return new RestActionImpl<>(interaction.getJDA(), route, message.toJSON()); - } - } diff --git a/src/main/java/de/kittybot/kittybot/modules/MusicModule.java b/src/main/java/de/kittybot/kittybot/modules/MusicModule.java index 0ae38b835..2204a0a88 100644 --- a/src/main/java/de/kittybot/kittybot/modules/MusicModule.java +++ b/src/main/java/de/kittybot/kittybot/modules/MusicModule.java @@ -5,7 +5,7 @@ import de.kittybot.kittybot.objects.music.MusicManager; import de.kittybot.kittybot.objects.music.SearchProvider; import de.kittybot.kittybot.objects.music.TrackScheduler; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; import de.kittybot.kittybot.utils.Config; import de.kittybot.kittybot.utils.MessageUtils; import lavalink.client.io.Link; @@ -198,12 +198,12 @@ public void destroy(MusicManager musicManager, String reason){ } } - public void play(GuildInteraction ia, String query, SearchProvider searchProvider){ - var manager = this.musicPlayers.computeIfAbsent(ia.getGuildId(), guildId -> new MusicManager(this.modules, guildId, ia.getChannelId())); + public void play(GuildCommandContext ctx, String query, SearchProvider searchProvider){ + var manager = this.musicPlayers.computeIfAbsent(ctx.getGuildId(), guildId -> new MusicManager(this.modules, guildId, ctx.getChannelId())); var matcher = SPOTIFY_URL_PATTERN.matcher(query); if(matcher.matches()){ - this.modules.get(SpotifyModule.class).load(ia, manager, matcher); + this.modules.get(SpotifyModule.class).load(ctx, manager, matcher); return; } @@ -217,7 +217,7 @@ public void play(GuildInteraction ia, String query, SearchProvider searchProvide break; } } - manager.getScheduler().getLink().getRestClient().loadItem(query, new AudioLoader(ia, manager)); + manager.getScheduler().getLink().getRestClient().loadItem(query, new AudioLoader(ctx, manager)); } public TrackScheduler getScheduler(long guildId){ diff --git a/src/main/java/de/kittybot/kittybot/modules/PaginatorModule.java b/src/main/java/de/kittybot/kittybot/modules/PaginatorModule.java index 607d2d533..f5636ca04 100644 --- a/src/main/java/de/kittybot/kittybot/modules/PaginatorModule.java +++ b/src/main/java/de/kittybot/kittybot/modules/PaginatorModule.java @@ -5,7 +5,7 @@ import de.kittybot.kittybot.objects.data.Paginator; import de.kittybot.kittybot.objects.enums.Emoji; import de.kittybot.kittybot.objects.module.Module; -import de.kittybot.kittybot.slashcommands.interaction.Interaction; +import de.kittybot.kittybot.slashcommands.CommandContext; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.GuildChannel; @@ -98,11 +98,11 @@ public void create(int maxPages, BiFunction }); } - public void create(Interaction ia, int maxPages, BiFunction embedFunction){ - ia.acknowledge(true).queue(success -> { + public void create(CommandContext ctx, int maxPages, BiFunction embedFunction){ + ctx.acknowledge(true).queue(success -> { var embedBuilder = embedFunction.apply(0, new EmbedBuilder().setFooter("Page: 1/" + maxPages)).build(); - var channel = ia.getChannel(); - create(maxPages, embedFunction, embedBuilder, channel, ia.getUserId()); + var channel = ctx.getChannel(); + create(maxPages, embedFunction, embedBuilder, channel, ctx.getUserId()); }); } diff --git a/src/main/java/de/kittybot/kittybot/modules/ReactiveMessageModule.java b/src/main/java/de/kittybot/kittybot/modules/ReactiveMessageModule.java index ec8d7485c..0857b3a5a 100644 --- a/src/main/java/de/kittybot/kittybot/modules/ReactiveMessageModule.java +++ b/src/main/java/de/kittybot/kittybot/modules/ReactiveMessageModule.java @@ -5,7 +5,7 @@ import com.github.benmanes.caffeine.cache.stats.CacheStats; import de.kittybot.kittybot.objects.data.ReactiveMessage; import de.kittybot.kittybot.objects.module.Module; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; import java.util.concurrent.TimeUnit; @@ -22,10 +22,10 @@ public void remove(long responseId){ reactiveMessages.invalidate(responseId); } - public void add(GuildInteraction ia, long responseId, long allowed){ + public void add(GuildCommandContext ctx, long responseId, long allowed){ reactiveMessages.put( responseId, - new ReactiveMessage(ia.getGuildId(), ia.getChannelId(), -1, responseId, ia.getUser().getIdLong(), ia.getData().getName(), + new ReactiveMessage(ctx.getGuildId(), ctx.getChannelId(), -1, responseId, ctx.getUser().getIdLong(), ctx.getEvent().getName(), allowed ) ); diff --git a/src/main/java/de/kittybot/kittybot/modules/SpotifyModule.java b/src/main/java/de/kittybot/kittybot/modules/SpotifyModule.java index f3dc4e146..54e31f0c8 100644 --- a/src/main/java/de/kittybot/kittybot/modules/SpotifyModule.java +++ b/src/main/java/de/kittybot/kittybot/modules/SpotifyModule.java @@ -6,13 +6,13 @@ import de.kittybot.kittybot.objects.module.Module; import de.kittybot.kittybot.objects.music.MusicManager; import de.kittybot.kittybot.objects.music.SearchProvider; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.response.FollowupMessage; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; import de.kittybot.kittybot.utils.Config; import de.kittybot.kittybot.utils.Utils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.awt.Color; import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -54,44 +54,44 @@ private void refreshAccessToken(){ } } - public void load(GuildInteraction ia, MusicManager manager, Matcher matcher){ + public void load(GuildCommandContext ctx, MusicManager manager, Matcher matcher){ switch(matcher.group(3)){ case "album": - loadAlbum(matcher.group(4), ia, manager); + loadAlbum(matcher.group(4), ctx, manager); break; case "track": - loadTrack(matcher.group(4), ia, manager); + loadTrack(matcher.group(4), ctx, manager); break; case "playlist": - loadPlaylist(matcher.group(4), ia, manager); + loadPlaylist(matcher.group(4), ctx, manager); break; } } - private void loadAlbum(String id, GuildInteraction ia, MusicManager manager){ + private void loadAlbum(String id, GuildCommandContext ctx, MusicManager manager){ this.spotify.getAlbumsTracks(id).build().executeAsync().thenAcceptAsync(tracks -> { var items = tracks.getItems(); var toLoad = new ArrayList(); for(var track : items){ toLoad.add("ytsearch:" + track.getArtists()[0].getName() + " " + track.getName()); } - loadTracks(id, ia, manager, toLoad); + loadTracks(id, ctx, manager, toLoad); }).exceptionally(throwable -> { - ia.error(throwable.getMessage().contains("invalid id") ? "Album not found" : "There was an error while loading the album"); + ctx.error(throwable.getMessage().contains("invalid id") ? "Album not found" : "There was an error while loading the album"); return null; }); } - private void loadTrack(String id, GuildInteraction ia, MusicManager manager){ + private void loadTrack(String id, GuildCommandContext ctx, MusicManager manager){ this.spotify.getTrack(id).build().executeAsync().thenAcceptAsync(track -> - this.modules.get(MusicModule.class).play(ia, track.getArtists()[0].getName() + " " + track.getName(), SearchProvider.YOUTUBE) + this.modules.get(MusicModule.class).play(ctx, track.getArtists()[0].getName() + " " + track.getName(), SearchProvider.YOUTUBE) ).exceptionally(throwable -> { - ia.error(throwable.getMessage().contains("invalid id") ? "Track not found" : "There was an error while loading the track"); + ctx.error(throwable.getMessage().contains("invalid id") ? "Track not found" : "There was an error while loading the track"); return null; }); } - private void loadPlaylist(String id, GuildInteraction ia, MusicManager manager){ + private void loadPlaylist(String id, GuildCommandContext ctx, MusicManager manager){ this.spotify.getPlaylistsItems(id).build().executeAsync().thenAcceptAsync(tracks -> { var items = tracks.getItems(); var toLoad = new ArrayList(); @@ -99,15 +99,15 @@ private void loadPlaylist(String id, GuildInteraction ia, MusicManager manager){ var track = (Track) item.getTrack(); toLoad.add("ytsearch:" + track.getArtists()[0].getName() + " " + track.getName()); } - loadTracks(id, ia, manager, toLoad); + loadTracks(id, ctx, manager, toLoad); }).exceptionally(throwable -> { - ia.error(throwable.getMessage().contains("Invalid playlist Id") ? "Playlist not found" : "There was an error while loading the playlist"); + ctx.error(throwable.getMessage().contains("Invalid playlist Id") ? "Playlist not found" : "There was an error while loading the playlist"); return null; }); } - private void loadTracks(String id, GuildInteraction ia, MusicManager manager, List toLoad){ - ia.acknowledge(true).content("Loading...\nThis may take a while").ephemeral().queue(); + private void loadTracks(String id, GuildCommandContext ctx, MusicManager manager, List toLoad){ + ctx.reply("Loading tracks...\nThis may take a while"); var restClient = manager.getScheduler().getLink().getRestClient(); Utils.all(toLoad.stream().map(restClient::getYoutubeSearchResult).collect(Collectors.toList())) .thenAcceptAsync(results -> { @@ -116,24 +116,25 @@ private void loadTracks(String id, GuildInteraction ia, MusicManager manager, Li return null; } var track = result.get(0); - track.setUserData(ia.getUserId()); + track.setUserData(ctx.getUserId()); return track; }).filter(Objects::nonNull).collect(Collectors.toList()); if(tracks.isEmpty()){ - ia.followupError("No tracks on youtube found"); + ctx.getHook().sendMessage("No tracks on youtube found").queue(); return; } - manager.connectToChannel(ia); + manager.connectToChannel(ctx); var toPlay = tracks.remove(0); var embed = manager.getScheduler().queue(toPlay, tracks); if(embed == null){ return; } - ia.followupMessage(new FollowupMessage.Builder().setEmbeds(embed).build()) + ctx.getHook().editOriginal("").addEmbeds(embed) .queue(success -> manager.getScheduler().tryPlay(toPlay), error -> manager.getScheduler().tryPlay(toPlay)); }) .exceptionally(error -> { - ia.followupError("Something went wrong while fetching your tracks: \n" + error.getMessage()); + ctx.getHook().editOriginal("") + .addEmbeds(ctx.getEmbed().setColor(Color.RED).setDescription("Something went wrong while fetching your tracks: \n" + error.getMessage()).build()).queue(); return null; }); } diff --git a/src/main/java/de/kittybot/kittybot/objects/exceptions/MissingOptionException.java b/src/main/java/de/kittybot/kittybot/objects/exceptions/MissingOptionException.java deleted file mode 100644 index 6a3f2cab1..000000000 --- a/src/main/java/de/kittybot/kittybot/objects/exceptions/MissingOptionException.java +++ /dev/null @@ -1,9 +0,0 @@ -package de.kittybot.kittybot.objects.exceptions; - -public class MissingOptionException extends RuntimeException{ - - public MissingOptionException(String name, Class clazz){ - super("Option `" + name + "` of type `" + clazz.getSimpleName() + "` is missing"); - } - -} diff --git a/src/main/java/de/kittybot/kittybot/objects/exceptions/OptionParseException.java b/src/main/java/de/kittybot/kittybot/objects/exceptions/OptionParseException.java index b4d66722f..08e3add83 100644 --- a/src/main/java/de/kittybot/kittybot/objects/exceptions/OptionParseException.java +++ b/src/main/java/de/kittybot/kittybot/objects/exceptions/OptionParseException.java @@ -1,9 +1,16 @@ package de.kittybot.kittybot.objects.exceptions; +import de.kittybot.kittybot.slashcommands.application.CommandOption; +import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; + public class OptionParseException extends RuntimeException{ public OptionParseException(String message){ super(message, null, false, false); } + public OptionParseException(SlashCommandEvent.OptionData optionData, String parseExample){ + super("Failed to parse " + (optionData == null ? "null" : optionData.getAsString()) + " as " + parseExample, null, false, false); + } + } diff --git a/src/main/java/de/kittybot/kittybot/objects/music/AudioLoader.java b/src/main/java/de/kittybot/kittybot/objects/music/AudioLoader.java index 810a97f1c..187dd91b1 100644 --- a/src/main/java/de/kittybot/kittybot/objects/music/AudioLoader.java +++ b/src/main/java/de/kittybot/kittybot/objects/music/AudioLoader.java @@ -4,7 +4,7 @@ import com.sedmelluq.discord.lavaplayer.tools.FriendlyException; import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist; import com.sedmelluq.discord.lavaplayer.track.AudioTrack; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; import java.util.Collections; import java.util.stream.Collectors; @@ -12,45 +12,45 @@ public class AudioLoader implements AudioLoadResultHandler{ - private final GuildInteraction ia; + private final GuildCommandContext ctx; private final MusicManager manager; - public AudioLoader(GuildInteraction ia, MusicManager manager){ - this.ia = ia; + public AudioLoader(GuildCommandContext ctx, MusicManager manager){ + this.ctx = ctx; this.manager = manager; } @Override public void trackLoaded(AudioTrack track){ - this.manager.connectToChannel(ia); - track.setUserData(ia.getUserId()); - this.manager.getScheduler().queue(ia, track, Collections.emptyList()); + this.manager.connectToChannel(ctx); + track.setUserData(ctx.getUserId()); + this.manager.getScheduler().queue(ctx, track, Collections.emptyList()); } @Override public void playlistLoaded(AudioPlaylist playlist){ - this.manager.connectToChannel(this.ia); + this.manager.connectToChannel(this.ctx); for(var track : playlist.getTracks()){ - track.setUserData(this.ia.getUserId()); + track.setUserData(this.ctx.getUserId()); } var firstTrack = playlist.getTracks().get(0); if(playlist.isSearchResult()){ - this.manager.getScheduler().queue(this.ia, firstTrack, Collections.emptyList()); + this.manager.getScheduler().queue(this.ctx, firstTrack, Collections.emptyList()); return; } var toPlay = playlist.getSelectedTrack() == null ? firstTrack : playlist.getSelectedTrack(); - this.manager.getScheduler().queue(this.ia, toPlay, playlist.getTracks().stream().filter(track -> !track.equals(toPlay)).collect(Collectors.toList())); + this.manager.getScheduler().queue(this.ctx, toPlay, playlist.getTracks().stream().filter(track -> !track.equals(toPlay)).collect(Collectors.toList())); } @Override public void noMatches(){ - this.ia.reply("No track found"); + this.ctx.reply("No track found"); } @Override public void loadFailed(FriendlyException e){ - this.ia.reply("Failed to load track:\n" + e.getMessage()); + this.ctx.reply("Failed to load track:\n" + e.getMessage()); } } diff --git a/src/main/java/de/kittybot/kittybot/objects/music/MusicManager.java b/src/main/java/de/kittybot/kittybot/objects/music/MusicManager.java index 37d35f06e..e4c1ae11e 100644 --- a/src/main/java/de/kittybot/kittybot/objects/music/MusicManager.java +++ b/src/main/java/de/kittybot/kittybot/objects/music/MusicManager.java @@ -6,7 +6,7 @@ import de.kittybot.kittybot.modules.MusicModule; import de.kittybot.kittybot.objects.enums.Emoji; import de.kittybot.kittybot.objects.module.Modules; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; import de.kittybot.kittybot.utils.MessageUtils; import de.kittybot.kittybot.utils.MusicUtils; import de.kittybot.kittybot.utils.TimeUtils; @@ -57,8 +57,8 @@ public void cancelDestroy(){ this.future = null; } - public void connectToChannel(GuildInteraction ia){ - var voiceState = ia.getMember().getVoiceState(); + public void connectToChannel(GuildCommandContext ctx){ + var voiceState = ctx.getMember().getVoiceState(); if(voiceState != null && voiceState.getChannel() != null && this.scheduler.getLink().getChannelId() != voiceState.getChannel().getIdLong()){ ((JdaLink) this.scheduler.getLink()).connect(voiceState.getChannel()); } diff --git a/src/main/java/de/kittybot/kittybot/objects/music/TrackScheduler.java b/src/main/java/de/kittybot/kittybot/objects/music/TrackScheduler.java index 2ebb1a8ea..e1deff7da 100644 --- a/src/main/java/de/kittybot/kittybot/objects/music/TrackScheduler.java +++ b/src/main/java/de/kittybot/kittybot/objects/music/TrackScheduler.java @@ -4,7 +4,7 @@ import com.sedmelluq.discord.lavaplayer.track.AudioTrackEndReason; import de.kittybot.kittybot.modules.SettingsModule; import de.kittybot.kittybot.objects.module.Modules; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; import de.kittybot.kittybot.utils.Colors; import de.kittybot.kittybot.utils.MessageUtils; import de.kittybot.kittybot.utils.MusicUtils; @@ -96,11 +96,11 @@ public void next(boolean force, AudioTrack track){ } } - public void queue(GuildInteraction ia, AudioTrack toPlay, List tracks){ + public void queue(GuildCommandContext ctx, AudioTrack toPlay, List tracks){ var embed = queue(toPlay, tracks); - var action = ia.acknowledge(true); + var action = ctx.acknowledge(true); if(embed != null){ - action.embeds(embed); + action = action.addEmbeds(embed); } action.queue(success -> tryPlay(toPlay), error -> tryPlay(toPlay)); } diff --git a/src/main/java/de/kittybot/kittybot/objects/settings/Tag.java b/src/main/java/de/kittybot/kittybot/objects/settings/Tag.java index 87a27bc02..cca5fcd84 100644 --- a/src/main/java/de/kittybot/kittybot/objects/settings/Tag.java +++ b/src/main/java/de/kittybot/kittybot/objects/settings/Tag.java @@ -1,9 +1,7 @@ package de.kittybot.kittybot.objects.settings; import de.kittybot.kittybot.jooq.tables.records.GuildTagsRecord; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.response.InteractionResponse; -import de.kittybot.kittybot.slashcommands.interaction.response.InteractionResponseType; +import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; import java.time.LocalDateTime; @@ -56,8 +54,8 @@ public long getCommandId(){ return this.commandId; } - public void process(GuildInteraction ia){ - ia.reply(new InteractionResponse.Builder().setType(InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE).setContent(this.content).build()); + public void process(SlashCommandEvent event){ + event.reply(this.content).queue(); } } diff --git a/src/main/java/de/kittybot/kittybot/slashcommands/CommandContext.java b/src/main/java/de/kittybot/kittybot/slashcommands/CommandContext.java new file mode 100644 index 000000000..c6abf7dc6 --- /dev/null +++ b/src/main/java/de/kittybot/kittybot/slashcommands/CommandContext.java @@ -0,0 +1,119 @@ +package de.kittybot.kittybot.slashcommands; + +import de.kittybot.kittybot.objects.enums.Emoji; +import de.kittybot.kittybot.objects.module.Module; +import de.kittybot.kittybot.objects.module.Modules; +import de.kittybot.kittybot.utils.Colors; +import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.JDA; +import net.dv8tion.jda.api.commands.CommandHook; +import net.dv8tion.jda.api.entities.MessageChannel; +import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; +import net.dv8tion.jda.api.requests.restaction.CommandReplyAction; + +import java.time.Instant; +import java.util.function.Consumer; + +public class CommandContext{ + + protected final Modules modules; + protected final Options options; + protected final SlashCommandEvent event; + + public CommandContext(Modules modules, Options options, SlashCommandEvent event){ + this.event = event; + this.options = options; + this.modules = modules; + } + + public SlashCommandEvent getEvent(){ + return this.event; + } + + public CommandHook getHook() { + return this.event.getHook(); + } + + public Options getOptions(){ + return this.options; + } + + public long getChannelId(){ + return getChannel().getIdLong(); + } + + public User getUser(){ + return this.event.getUser(); + } + + public long getUserId(){ + return getUser().getIdLong(); + } + + public User getSelfUser(){ + return this.event.getJDA().getSelfUser(); + } + + public MessageChannel getChannel(){ + return this.event.getChannel(); + } + + public boolean isFromGuild(){ + return this.event.getGuild() != null && this.event.getMember() != null; + } + + public Modules getModules(){ + return this.modules; + } + + public T get(Class clazz){ + return this.modules.get(clazz); + } + + public JDA getJDA(){ + return this.event.getJDA(); + } + + public CommandReplyAction acknowledge(){ + return this.event.acknowledge(); + } + + public CommandReplyAction acknowledge(boolean ephemeral){ + return this.event.acknowledge(ephemeral); + } + + public void reply(String message){ + this.event.reply(getEmbed().setDescription(message).build()).queue(); + } + + public void replyEphemeral(String message){ + this.event.reply(message).setEphemeral(true).queue(); + } + + public EmbedBuilder getEmbed(){ + return applyDefaultStyle(new EmbedBuilder()); + } + + public EmbedBuilder applyDefaultStyle(EmbedBuilder embedBuilder){ + String name; + if(this instanceof GuildCommandContext){ + name = ((GuildCommandContext) this).getMember().getEffectiveName(); + } + else{ + name = getUser().getName(); + } + return embedBuilder.setColor(Colors.KITTYBOT_BLUE).setFooter(name, getUser().getEffectiveAvatarUrl()).setTimestamp(Instant.now()); + } + + public void reply(Consumer consumer){ + var embedBuilder = applyDefaultStyle(new EmbedBuilder()); + consumer.accept(embedBuilder); + this.event.reply(embedBuilder.build()).queue(); + } + + public void error(String error){ + this.event.reply(Emoji.X.get() + " " + error).setEphemeral(true).queue(); + } + +} diff --git a/src/main/java/de/kittybot/kittybot/slashcommands/GuildCommandContext.java b/src/main/java/de/kittybot/kittybot/slashcommands/GuildCommandContext.java new file mode 100644 index 000000000..9b670812b --- /dev/null +++ b/src/main/java/de/kittybot/kittybot/slashcommands/GuildCommandContext.java @@ -0,0 +1,36 @@ +package de.kittybot.kittybot.slashcommands; + +import de.kittybot.kittybot.objects.module.Modules; +import net.dv8tion.jda.api.entities.Guild; +import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.TextChannel; +import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; + +public class GuildCommandContext extends CommandContext{ + + public GuildCommandContext(Modules modules, Options options, SlashCommandEvent event){ + super(modules, options, event); + } + + public Guild getGuild(){ + return this.event.getGuild(); + } + + public long getGuildId(){ + return getGuild().getIdLong(); + } + + public Member getMember(){ + return this.event.getMember(); + } + + public Member getSelfMember(){ + return getGuild().getSelfMember(); + } + + @Override + public TextChannel getChannel(){ + return (TextChannel) super.getChannel(); + } + +} diff --git a/src/main/java/de/kittybot/kittybot/slashcommands/Options.java b/src/main/java/de/kittybot/kittybot/slashcommands/Options.java new file mode 100644 index 000000000..0233eca09 --- /dev/null +++ b/src/main/java/de/kittybot/kittybot/slashcommands/Options.java @@ -0,0 +1,220 @@ +package de.kittybot.kittybot.slashcommands; + +import dataflow.analysis.Store; +import de.kittybot.kittybot.utils.TimeUtils; +import net.dv8tion.jda.api.JDA; +import net.dv8tion.jda.api.entities.*; +import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; +import net.dv8tion.jda.api.utils.MiscUtil; +import net.dv8tion.jda.internal.JDAImpl; +import net.dv8tion.jda.internal.entities.EmoteImpl; +import org.w3c.dom.Text; + +import javax.annotation.CheckReturnValue; +import java.time.LocalDateTime; +import java.util.List; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class Options{ + + private final Map options; + private final JDA jda; + + public Options(List options, JDA jda){ + this.options = options.stream().collect(Collectors.toMap(SlashCommandEvent.OptionData::getName, Function.identity())); + this.jda = jda; + } + + public Map getMap(){ + return this.options; + } + + public Stream stream(){ + return this.options.values().stream(); + } + + public boolean has(String name){ + return this.options.containsKey(name); + } + + public SlashCommandEvent.OptionData get(String name){ + return this.options.get(name); + } + + private T getOrDefault(String name, Function mapper, T defaultValue){ + if(!has(name)){ + return defaultValue; + } + var value = mapper.apply(name); + return value == null ? value : defaultValue; + } + + @CheckReturnValue + public String getString(String name){ + return get(name).getAsString(); + } + public String getString(String name, String defaultString){ + return getOrDefault(name, this::getString, defaultString); + } + + @CheckReturnValue + public Long getLong(String name){ + return get(name).getAsLong(); + } + public long getLong(String name, long defaultLong){ + return getOrDefault(name, this::getLong, defaultLong); + } + + @CheckReturnValue + public int getInt(String name){ + return (int) get(name).getAsLong(); + } + public int getInt(String name, int defaultInt){ + return getOrDefault(name, this::getInt, defaultInt); + } + + @CheckReturnValue + public float getFloat(String name){ + return Float.parseFloat(get(name).getAsString()); + } + public float getFloat(String name, float defaultFloat){ + return getOrDefault(name, this::getFloat, defaultFloat); + } + + @CheckReturnValue + public boolean getBoolean(String name){ + return get(name).getAsBoolean(); + } + public boolean getBoolean(String name, boolean defaultBoolean){ + return getOrDefault(name, this::getBoolean, defaultBoolean); + } + + @CheckReturnValue + public Member getMember(String name){ + return this.options.get(name).getAsMember(); + } + public Member getMember(String name, Member defaultMember){ + return getOrDefault(name, this::getMember, defaultMember); + } + + @CheckReturnValue + public User getUser(String name){ + return get(name).getAsUser(); + } + public User getUser(String name, User defaultUser){ + return getOrDefault(name, this::getUser, defaultUser); + } + + @CheckReturnValue + public PrivateChannel getPrivateChannel(String name){ + return get(name).getAsPrivateChannel(); + } + public PrivateChannel getPrivateChannel(String name, PrivateChannel defaultPrivateChannel){ + return getOrDefault(name, this::getPrivateChannel, defaultPrivateChannel); + } + + @CheckReturnValue + public MessageChannel getMessageChannel(String name){ + return get(name).getAsMessageChannel(); + } + public MessageChannel getMessageChannel(String name, MessageChannel defaultMessageChannel){ + return getOrDefault(name, this::getMessageChannel, defaultMessageChannel); + } + + @CheckReturnValue + public GuildChannel getGuildChannel(String name){ + return get(name).getAsGuildChannel(); + } + public GuildChannel getGuildChannel(String name, GuildChannel defaultGuildChannel){ + return getOrDefault(name, this::getGuildChannel, defaultGuildChannel); + } + + @CheckReturnValue + public TextChannel getTextChannel(String name){ + var channel = get(name).getAsGuildChannel(); + if(channel == null){ + return null; + } + return channel instanceof TextChannel ? (TextChannel) channel : null; + } + public TextChannel getTextChannel(String name, TextChannel defaultTextChannel){ + return getOrDefault(name, this::getTextChannel, defaultTextChannel); + } + + @CheckReturnValue + public VoiceChannel getVoiceChannel(String name){ + var channel = get(name).getAsGuildChannel(); + if(channel == null){ + return null; + } + return channel instanceof VoiceChannel ? (VoiceChannel) channel : null; + } + public VoiceChannel getVoiceChannel(String name, VoiceChannel defaultVoiceChannel){ + return getOrDefault(name, this::getVoiceChannel, defaultVoiceChannel); + } + + @CheckReturnValue + public StoreChannel getStoreChannel(String name){ + var channel = get(name).getAsGuildChannel(); + if(channel == null){ + return null; + } + return channel instanceof StoreChannel ? (StoreChannel) channel : null; + } + public StoreChannel getStoreChannel(String name, StoreChannel defaultStoreChannel){ + return getOrDefault(name, this::getStoreChannel, defaultStoreChannel); + } + + @CheckReturnValue + public Category getCategory(String name){ + var channel = get(name).getAsGuildChannel(); + if(channel == null){ + return null; + } + return channel instanceof Category ? (Category) channel : null; + } + public Category getCategory(String name, Category defaultCategory){ + return getOrDefault(name, this::getCategory, defaultCategory); + } + + public Role getRole(String name){ + return get(name).getAsRole(); + } + public Role getRole(String name, Role defaultRole){ + return getOrDefault(name, this::getRole, defaultRole); + } + + public LocalDateTime getTime(String name){ + return TimeUtils.parse(getString(name)); + } + public LocalDateTime getTime(String name, LocalDateTime defaultLocalDateTime){ + return getOrDefault(name, this::getTime, defaultLocalDateTime); + } + + public Emote getEmote(String name){ + try{ + var rawEmote = getString(name); + var matcher = Message.MentionType.EMOTE.getPattern().matcher(rawEmote); + if(matcher.matches()){ + long emoteId = MiscUtil.parseSnowflake(matcher.group(2)); + var emote = this.jda.getEmoteById(emoteId); + if(emote == null){ + emote = new EmoteImpl(emoteId, (JDAImpl) jda).setName(matcher.group(1)).setAnimated(matcher.group(0).startsWith(" permissions; private final List> options; + private boolean guildOnly; private boolean devOnly; public Command(String name, String description, Category category){ this.name = name; this.description = description; this.category = category; + this.guildOnly = false; this.devOnly = false; this.permissions = new HashSet<>(); this.options = new ArrayList<>(); } + public void guildOnly(){ + this.guildOnly = true; + } + + public boolean isGuildOnly(){ + return this.guildOnly; + } + public void devOnly(){ this.devOnly = true; } @@ -60,34 +71,26 @@ public List> getOptions(){ return this.options; } - public DataObject toJSON(){ - var json = DataObject.empty() - .put("name", this.name) - .put("description", this.description); - if(!this.options.isEmpty()){ - json.put("options", CommandOption.toJSON(this.options)); + public CommandUpdateAction.CommandData toData(){ + var data = new CommandUpdateAction.CommandData(this.name, this.description); + for(var option : this.options){ + data.addOption(option.toData()); } - return json; + return data; } - public DataObject toDetailedJSON(){ + public DataObject toJSON(){ var json = DataObject.empty() .put("name", this.name) .put("description", this.description) .put("category", this.category.getName()) - .put("permissions", getPermissionArray()); + .put("permissions", DataArray.fromCollection(this.permissions.stream().map(Permission::getName).collect(Collectors.toList()))); if(!this.options.isEmpty()){ - json.put("options", CommandOption.toDetailedJSON(this.options)); + json.put("options", this.options.stream().map(CommandOption::toData).collect(Collectors.toList())); } return json; } - private DataArray getPermissionArray(){ - return DataArray.fromCollection( - this.permissions.stream().map(Permission::getName).collect(Collectors.toList()) - ); - } - public DataObject toDiscordServicesJSON(){ return DataObject.empty() .put("command", "/" + this.name) diff --git a/src/main/java/de/kittybot/kittybot/slashcommands/application/CommandOption.java b/src/main/java/de/kittybot/kittybot/slashcommands/application/CommandOption.java index 670b08b49..0d1df4d0b 100644 --- a/src/main/java/de/kittybot/kittybot/slashcommands/application/CommandOption.java +++ b/src/main/java/de/kittybot/kittybot/slashcommands/application/CommandOption.java @@ -1,46 +1,35 @@ package de.kittybot.kittybot.slashcommands.application; +import net.dv8tion.jda.api.entities.Command; +import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; +import net.dv8tion.jda.api.requests.restaction.CommandUpdateAction; import net.dv8tion.jda.api.utils.data.DataArray; import net.dv8tion.jda.api.utils.data.DataObject; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import java.util.stream.Collectors; public abstract class CommandOption implements CommandOptionsHolder{ - private final CommandOptionType type; + private final Command.OptionType type; private final String name, description; - private final List> choices; + private final List choices; private final List> options; - private boolean isDefault, isRequired; + private boolean isRequired; - protected CommandOption(CommandOptionType type, String name, String description){ + protected CommandOption(Command.OptionType type, String name, String description){ this.type = type; this.name = name.toLowerCase(); this.description = description; - this.isDefault = false; this.isRequired = false; this.choices = new ArrayList<>(); this.options = new ArrayList<>(); } - public static DataArray toJSON(Collection> options){ - return DataArray.fromCollection( - options.stream().map(CommandOption::toJSON).collect(Collectors.toList()) - ); - } - - public static DataArray toDetailedJSON(Collection> options){ - return DataArray.fromCollection( - options.stream().map(CommandOption::toDetailedJSON).collect(Collectors.toList()) - ); - } - - public abstract T parseValue(Object value); + public abstract T parseValue(SlashCommandEvent.OptionData optionData); - public CommandOption addChoices(CommandOptionChoice... choices){ + public CommandOption addChoices(OptionChoice... choices){ if(this.choices.size() + choices.length > 25){ throw new IllegalArgumentException("Options can have up to 25 choices"); } @@ -53,17 +42,12 @@ public CommandOption addOptions(CommandOption... options){ return this; } - public CommandOption setDefault(){ - this.isDefault = true; - return this; - } - public CommandOption required(){ this.isRequired = true; return this; } - public CommandOptionType getType(){ + public Command.OptionType getType(){ return this.type; } @@ -75,15 +59,11 @@ public String getDescription(){ return this.description; } - public boolean isDefault(){ - return this.isDefault; - } - public boolean isRequired(){ return this.isRequired; } - public List> getChoices(){ + public List getChoices(){ return this.choices; } @@ -92,28 +72,36 @@ public List> getOptions(){ return options; } + public CommandUpdateAction.OptionData toData(){ + var data = new CommandUpdateAction.OptionData(this.type, this.name, this.description); + data.setRequired(this.isRequired); + for(var choice : this.choices){ + var value = choice.getValue(); + if(value instanceof Integer){ + data.addChoice(choice.getName(), (Integer) choice.getValue()); + } + else if(value instanceof String){ + data.addChoice(choice.getName(), (String) choice.getValue()); + } + } + return data; + } + public DataObject toJSON(){ var json = DataObject.empty() - .put("type", this.type.getType()) + .put("type", this.type.getKey()) .put("name", this.name) .put("description", this.description); - if(this.isDefault){ - json.put("default", true); - } if(this.isRequired){ json.put("required", true); } if(!this.choices.isEmpty()){ - json.put("choices", CommandOptionChoice.toJSON(this.choices)); + json.put("choices", DataArray.fromCollection(choices.stream().map(OptionChoice::toJSON).collect(Collectors.toList()))); } if(!this.options.isEmpty()){ - json.put("options", CommandOption.toJSON(this.options)); + json.put("options", DataArray.fromCollection(options.stream().map(CommandOption::toJSON).collect(Collectors.toList()))); } return json; } - public DataObject toDetailedJSON(){ - return toJSON(); - } - } diff --git a/src/main/java/de/kittybot/kittybot/slashcommands/application/CommandOptionChoice.java b/src/main/java/de/kittybot/kittybot/slashcommands/application/CommandOptionChoice.java deleted file mode 100644 index 7d0ee3378..000000000 --- a/src/main/java/de/kittybot/kittybot/slashcommands/application/CommandOptionChoice.java +++ /dev/null @@ -1,34 +0,0 @@ -package de.kittybot.kittybot.slashcommands.application; - -import net.dv8tion.jda.api.utils.data.DataArray; -import net.dv8tion.jda.api.utils.data.DataObject; - -import java.util.Collection; -import java.util.stream.Collectors; - -public class CommandOptionChoice{ - - private final String name; - private final T value; - - public CommandOptionChoice(String name, T value){ - this.name = name; - this.value = value; - } - - public CommandOptionChoice(T tEnum){ - this.name = tEnum.toString(); - this.value = tEnum; - } - - public static DataArray toJSON(Collection> choices){ - return DataArray.fromCollection( - choices.stream().map(CommandOptionChoice::toJSON).collect(Collectors.toList()) - ); - } - - public DataObject toJSON(){ - return DataObject.empty().put("name", this.name).put("value", this.value); - } - -} diff --git a/src/main/java/de/kittybot/kittybot/slashcommands/application/GenericHelpCommand.java b/src/main/java/de/kittybot/kittybot/slashcommands/application/GenericHelpCommand.java index 03985662f..0c7128ab6 100644 --- a/src/main/java/de/kittybot/kittybot/slashcommands/application/GenericHelpCommand.java +++ b/src/main/java/de/kittybot/kittybot/slashcommands/application/GenericHelpCommand.java @@ -1,8 +1,8 @@ package de.kittybot.kittybot.slashcommands.application; +import de.kittybot.kittybot.slashcommands.CommandContext; +import de.kittybot.kittybot.slashcommands.Options; import de.kittybot.kittybot.slashcommands.application.options.SubCommand; -import de.kittybot.kittybot.slashcommands.interaction.Interaction; -import de.kittybot.kittybot.slashcommands.interaction.Options; public class GenericHelpCommand extends SubCommand{ @@ -14,8 +14,8 @@ public GenericHelpCommand(String help){ } @Override - public void run(Options options, Interaction ia){ - ia.reply(this.help); + public void run(Options options, CommandContext ctx){ + ctx.reply(this.help); } } diff --git a/src/main/java/de/kittybot/kittybot/slashcommands/application/OptionChoice.java b/src/main/java/de/kittybot/kittybot/slashcommands/application/OptionChoice.java new file mode 100644 index 000000000..5209c3ed8 --- /dev/null +++ b/src/main/java/de/kittybot/kittybot/slashcommands/application/OptionChoice.java @@ -0,0 +1,37 @@ +package de.kittybot.kittybot.slashcommands.application; + +import net.dv8tion.jda.api.utils.data.DataObject; + +public class OptionChoice{ + + private final String name; + private final Object value; + + public OptionChoice(String name, String value){ + this.name = name; + this.value = value; + } + + public OptionChoice(String name, int value){ + this.name = name; + this.value = value; + } + + public OptionChoice(Enum tEnum){ + this.name = tEnum.toString(); + this.value = tEnum; + } + + public String getName(){ + return this.name; + } + + public Object getValue(){ + return this.value; + } + + public DataObject toJSON(){ + return DataObject.empty().put("name", this.name).put("value", this.value); + } + +} diff --git a/src/main/java/de/kittybot/kittybot/slashcommands/application/PermissionHolder.java b/src/main/java/de/kittybot/kittybot/slashcommands/application/PermissionHolder.java index 70e596594..5200e4804 100644 --- a/src/main/java/de/kittybot/kittybot/slashcommands/application/PermissionHolder.java +++ b/src/main/java/de/kittybot/kittybot/slashcommands/application/PermissionHolder.java @@ -6,6 +6,10 @@ public interface PermissionHolder{ + boolean isGuildOnly(); + + void guildOnly(); + void devOnly(); boolean isDevOnly(); diff --git a/src/main/java/de/kittybot/kittybot/slashcommands/application/RunnableCommand.java b/src/main/java/de/kittybot/kittybot/slashcommands/application/RunnableCommand.java index b7304c71d..3c9f4e626 100644 --- a/src/main/java/de/kittybot/kittybot/slashcommands/application/RunnableCommand.java +++ b/src/main/java/de/kittybot/kittybot/slashcommands/application/RunnableCommand.java @@ -1,10 +1,10 @@ package de.kittybot.kittybot.slashcommands.application; -import de.kittybot.kittybot.slashcommands.interaction.Interaction; -import de.kittybot.kittybot.slashcommands.interaction.Options; +import de.kittybot.kittybot.slashcommands.CommandContext; +import de.kittybot.kittybot.slashcommands.Options; public interface RunnableCommand{ - void run(Options options, Interaction ia); + void run(Options options, CommandContext ctx); } diff --git a/src/main/java/de/kittybot/kittybot/slashcommands/application/RunnableGuildCommand.java b/src/main/java/de/kittybot/kittybot/slashcommands/application/RunnableGuildCommand.java index 8749ac782..befd5474a 100644 --- a/src/main/java/de/kittybot/kittybot/slashcommands/application/RunnableGuildCommand.java +++ b/src/main/java/de/kittybot/kittybot/slashcommands/application/RunnableGuildCommand.java @@ -1,10 +1,10 @@ package de.kittybot.kittybot.slashcommands.application; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.Options; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; +import de.kittybot.kittybot.slashcommands.Options; public interface RunnableGuildCommand{ - void run(Options options, GuildInteraction ia); + void run(Options options, GuildCommandContext ctx); } diff --git a/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionBoolean.java b/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionBoolean.java index 28566fa05..4e42ffda1 100644 --- a/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionBoolean.java +++ b/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionBoolean.java @@ -3,19 +3,22 @@ import de.kittybot.kittybot.objects.exceptions.OptionParseException; import de.kittybot.kittybot.slashcommands.application.CommandOption; import de.kittybot.kittybot.slashcommands.application.CommandOptionType; +import net.dv8tion.jda.api.entities.Command; +import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; +import net.dv8tion.jda.api.exceptions.ParsingException; public class CommandOptionBoolean extends CommandOption{ public CommandOptionBoolean(String name, String description){ - super(CommandOptionType.BOOLEAN, name, description); + super(Command.OptionType.BOOLEAN, name, description); } - public Boolean parseValue(Object value){ + public Boolean parseValue(SlashCommandEvent.OptionData optionData){ try{ - return (boolean) value; + return optionData.getAsBoolean(); } - catch(ClassCastException e){ - throw new OptionParseException("Failed to parse " + value + " as true/false"); + catch(ParsingException e){ + throw new OptionParseException(optionData, "true/false"); } } diff --git a/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionChannel.java b/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionChannel.java deleted file mode 100644 index 255e242b1..000000000 --- a/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionChannel.java +++ /dev/null @@ -1,23 +0,0 @@ -package de.kittybot.kittybot.slashcommands.application.options; - -import de.kittybot.kittybot.objects.exceptions.OptionParseException; -import de.kittybot.kittybot.slashcommands.application.CommandOption; -import de.kittybot.kittybot.slashcommands.application.CommandOptionType; - -public class CommandOptionChannel extends CommandOption{ - - public CommandOptionChannel(String name, String description){ - super(CommandOptionType.CHANNEL, name, description); - } - - @Override - public Long parseValue(Object value){ - try{ - return value instanceof Long ? (Long) value : Long.parseLong((String) value); - } - catch(ClassCastException | NumberFormatException e){ - throw new OptionParseException("Failed to parse " + value + " as channel"); - } - } - -} diff --git a/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionEmote.java b/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionEmote.java index 16d1b9302..d3e80086c 100644 --- a/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionEmote.java +++ b/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionEmote.java @@ -3,26 +3,29 @@ import de.kittybot.kittybot.objects.exceptions.OptionParseException; import de.kittybot.kittybot.slashcommands.application.CommandOption; import de.kittybot.kittybot.slashcommands.application.CommandOptionType; +import net.dv8tion.jda.api.entities.Command; import net.dv8tion.jda.api.entities.Message; +import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; +import net.dv8tion.jda.api.exceptions.ParsingException; public class CommandOptionEmote extends CommandOption{ public CommandOptionEmote(String name, String description){ - super(CommandOptionType.STRING, name, description); + super(Command.OptionType.STRING, name, description); } @Override - public String parseValue(Object value){ + public String parseValue(SlashCommandEvent.OptionData optionData){ try{ - var emote = (String) value; + var emote = optionData.getAsString(); var matcher = Message.MentionType.EMOTE.getPattern().matcher(emote); if(matcher.matches()){ return emote; } } - catch(ClassCastException | NumberFormatException ignored){ + catch(ParsingException ignored){ } - throw new OptionParseException("Failed to parse " + value + " as emote"); + throw new OptionParseException(optionData, "emote"); } } diff --git a/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionFloat.java b/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionFloat.java index ebd08b86c..37bc1beb8 100644 --- a/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionFloat.java +++ b/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionFloat.java @@ -3,20 +3,23 @@ import de.kittybot.kittybot.objects.exceptions.OptionParseException; import de.kittybot.kittybot.slashcommands.application.CommandOption; import de.kittybot.kittybot.slashcommands.application.CommandOptionType; +import net.dv8tion.jda.api.entities.Command; +import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; +import net.dv8tion.jda.api.exceptions.ParsingException; public class CommandOptionFloat extends CommandOption{ public CommandOptionFloat(String name, String description){ - super(CommandOptionType.STRING, name, description); + super(Command.OptionType.STRING, name, description); } @Override - public Float parseValue(Object value){ + public Float parseValue(SlashCommandEvent.OptionData optionData){ try{ - return Float.parseFloat((String) value); + return Float.parseFloat(optionData.getAsString()); } - catch(ClassCastException | NumberFormatException e){ - throw new OptionParseException("Failed to parse " + value + " as float"); + catch(ParsingException | NumberFormatException e){ + throw new OptionParseException(optionData, "float"); } } diff --git a/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionGuildChannel.java b/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionGuildChannel.java new file mode 100644 index 000000000..1473856a9 --- /dev/null +++ b/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionGuildChannel.java @@ -0,0 +1,27 @@ +package de.kittybot.kittybot.slashcommands.application.options; + +import de.kittybot.kittybot.objects.exceptions.OptionParseException; +import de.kittybot.kittybot.slashcommands.application.CommandOption; +import de.kittybot.kittybot.slashcommands.application.CommandOptionType; +import net.dv8tion.jda.api.entities.Command; +import net.dv8tion.jda.api.entities.GuildChannel; +import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; +import net.dv8tion.jda.api.exceptions.ParsingException; + +public class CommandOptionGuildChannel extends CommandOption{ + + public CommandOptionGuildChannel(String name, String description){ + super(Command.OptionType.CHANNEL, name, description); + } + + @Override + public GuildChannel parseValue(SlashCommandEvent.OptionData optionData){ + try{ + return optionData.getAsGuildChannel(); + } + catch(ParsingException e){ + throw new OptionParseException(optionData, "server channel"); + } + } + +} diff --git a/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionInteger.java b/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionInteger.java index 0ba3a1d87..f80185348 100644 --- a/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionInteger.java +++ b/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionInteger.java @@ -3,20 +3,23 @@ import de.kittybot.kittybot.objects.exceptions.OptionParseException; import de.kittybot.kittybot.slashcommands.application.CommandOption; import de.kittybot.kittybot.slashcommands.application.CommandOptionType; +import net.dv8tion.jda.api.entities.Command; +import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; +import net.dv8tion.jda.api.exceptions.ParsingException; public class CommandOptionInteger extends CommandOption{ public CommandOptionInteger(String name, String description){ - super(CommandOptionType.INTEGER, name, description); + super(Command.OptionType.INTEGER, name, description); } @Override - public Integer parseValue(Object value){ + public Integer parseValue(SlashCommandEvent.OptionData optionData){ try{ - return (int) value; + return (int) optionData.getAsLong(); } - catch(ClassCastException e){ - throw new OptionParseException("Failed to parse " + value + " as integer"); + catch(ParsingException | ClassCastException e){ + throw new OptionParseException(optionData, "number"); } } diff --git a/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionLong.java b/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionLong.java index 01dc9e775..d5505ea9b 100644 --- a/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionLong.java +++ b/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionLong.java @@ -3,20 +3,23 @@ import de.kittybot.kittybot.objects.exceptions.OptionParseException; import de.kittybot.kittybot.slashcommands.application.CommandOption; import de.kittybot.kittybot.slashcommands.application.CommandOptionType; +import net.dv8tion.jda.api.entities.Command; +import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; +import net.dv8tion.jda.api.exceptions.ParsingException; public class CommandOptionLong extends CommandOption{ public CommandOptionLong(String name, String description){ - super(CommandOptionType.STRING, name, description); + super(Command.OptionType.STRING, name, description); } @Override - public Long parseValue(Object value){ + public Long parseValue(SlashCommandEvent.OptionData optionData){ try{ - return Long.parseLong((String) value); + return optionData.getAsLong(); } - catch(ClassCastException | NumberFormatException e){ - throw new OptionParseException("Failed to parse " + value + " as long"); + catch(ParsingException | ClassCastException e){ + throw new OptionParseException(optionData, "long number"); } } diff --git a/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionMember.java b/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionMember.java new file mode 100644 index 000000000..75de9f49e --- /dev/null +++ b/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionMember.java @@ -0,0 +1,27 @@ +package de.kittybot.kittybot.slashcommands.application.options; + +import de.kittybot.kittybot.objects.exceptions.OptionParseException; +import de.kittybot.kittybot.slashcommands.application.CommandOption; +import net.dv8tion.jda.api.entities.Command; +import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; +import net.dv8tion.jda.api.exceptions.ParsingException; + +public class CommandOptionMember extends CommandOption{ + + public CommandOptionMember(String name, String description){ + super(Command.OptionType.USER, name, description); + } + + @Override + public Member parseValue(SlashCommandEvent.OptionData optionData){ + try{ + return optionData.getAsMember(); + } + catch(ParsingException e){ + throw new OptionParseException(optionData, "member"); + } + } + +} diff --git a/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionMessageChannel.java b/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionMessageChannel.java new file mode 100644 index 000000000..b415dd405 --- /dev/null +++ b/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionMessageChannel.java @@ -0,0 +1,27 @@ +package de.kittybot.kittybot.slashcommands.application.options; + +import de.kittybot.kittybot.objects.exceptions.OptionParseException; +import de.kittybot.kittybot.slashcommands.application.CommandOption; +import net.dv8tion.jda.api.entities.Command; +import net.dv8tion.jda.api.entities.GuildChannel; +import net.dv8tion.jda.api.entities.MessageChannel; +import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; +import net.dv8tion.jda.api.exceptions.ParsingException; + +public class CommandOptionMessageChannel extends CommandOption{ + + public CommandOptionMessageChannel(String name, String description){ + super(Command.OptionType.CHANNEL, name, description); + } + + @Override + public MessageChannel parseValue(SlashCommandEvent.OptionData optionData){ + try{ + return optionData.getAsMessageChannel(); + } + catch(ParsingException e){ + throw new OptionParseException(optionData, "message channel"); + } + } + +} diff --git a/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionRawEmote.java b/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionRawEmote.java index 2504d3ad4..cbb97902d 100644 --- a/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionRawEmote.java +++ b/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionRawEmote.java @@ -3,26 +3,29 @@ import de.kittybot.kittybot.objects.exceptions.OptionParseException; import de.kittybot.kittybot.slashcommands.application.CommandOption; import de.kittybot.kittybot.slashcommands.application.CommandOptionType; +import net.dv8tion.jda.api.entities.Command; import net.dv8tion.jda.api.entities.Message; +import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; +import net.dv8tion.jda.api.exceptions.ParsingException; public class CommandOptionRawEmote extends CommandOption{ public CommandOptionRawEmote(String name, String description){ - super(CommandOptionType.STRING, name, description); + super(Command.OptionType.STRING, name, description); } @Override - public String parseValue(Object value){ + public String parseValue(SlashCommandEvent.OptionData optionData){ try{ - var rawEmote = (String) value; + var rawEmote = optionData.getAsString(); var matcher = Message.MentionType.EMOTE.getPattern().matcher(rawEmote); if(matcher.matches()){ return rawEmote; } } - catch(ClassCastException ignored){ + catch(ParsingException ignored){ } - throw new OptionParseException("Failed to parse " + value + " as emote"); + throw new OptionParseException(optionData, "emote"); } } diff --git a/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionRole.java b/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionRole.java index cc4760e38..3c8d3b9e9 100644 --- a/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionRole.java +++ b/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionRole.java @@ -3,20 +3,24 @@ import de.kittybot.kittybot.objects.exceptions.OptionParseException; import de.kittybot.kittybot.slashcommands.application.CommandOption; import de.kittybot.kittybot.slashcommands.application.CommandOptionType; +import net.dv8tion.jda.api.entities.Command; +import net.dv8tion.jda.api.entities.Role; +import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; +import net.dv8tion.jda.api.exceptions.ParsingException; -public class CommandOptionRole extends CommandOption{ +public class CommandOptionRole extends CommandOption{ public CommandOptionRole(String name, String description){ - super(CommandOptionType.ROLE, name, description); + super(Command.OptionType.ROLE, name, description); } @Override - public Long parseValue(Object value){ + public Role parseValue(SlashCommandEvent.OptionData optionData){ try{ - return value instanceof Long ? (Long) value : Long.parseLong((String) value); + return optionData.getAsRole(); } - catch(ClassCastException | NumberFormatException e){ - throw new OptionParseException("Failed to parse " + value + " as role"); + catch(ParsingException e){ + throw new OptionParseException(optionData, "role"); } } diff --git a/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionString.java b/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionString.java index 0ee63931e..8dbb8ffe2 100644 --- a/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionString.java +++ b/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionString.java @@ -3,20 +3,23 @@ import de.kittybot.kittybot.objects.exceptions.OptionParseException; import de.kittybot.kittybot.slashcommands.application.CommandOption; import de.kittybot.kittybot.slashcommands.application.CommandOptionType; +import net.dv8tion.jda.api.entities.Command; +import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; +import net.dv8tion.jda.api.exceptions.ParsingException; public class CommandOptionString extends CommandOption{ public CommandOptionString(String name, String description){ - super(CommandOptionType.STRING, name, description); + super(Command.OptionType.STRING, name, description); } @Override - public String parseValue(Object value){ + public String parseValue(SlashCommandEvent.OptionData optionData){ try{ - return (String) value; + return optionData.getAsString(); } - catch(ClassCastException e){ - throw new OptionParseException("Failed to parse " + value + " as string"); + catch(ParsingException e){ + throw new OptionParseException(optionData, "string"); } } diff --git a/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionTime.java b/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionTime.java index a50f0744c..cc6388490 100644 --- a/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionTime.java +++ b/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionTime.java @@ -4,23 +4,26 @@ import de.kittybot.kittybot.slashcommands.application.CommandOption; import de.kittybot.kittybot.slashcommands.application.CommandOptionType; import de.kittybot.kittybot.utils.TimeUtils; +import net.dv8tion.jda.api.entities.Command; +import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; +import net.dv8tion.jda.api.exceptions.ParsingException; import java.time.LocalDateTime; public class CommandOptionTime extends CommandOption{ public CommandOptionTime(String name, String description){ - super(CommandOptionType.STRING, name, description); + super(Command.OptionType.STRING, name, description); } @Override - public LocalDateTime parseValue(Object value){ + public LocalDateTime parseValue(SlashCommandEvent.OptionData optionData){ try{ - return TimeUtils.parse((String) value); + return TimeUtils.parse(optionData.getAsString()); } - catch(ClassCastException ignored){ + catch(ParsingException e){ + throw new OptionParseException(optionData, "true/false"); } - throw new OptionParseException("Failed to parse " + value + " as time"); } } diff --git a/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionUrl.java b/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionUrl.java index c89e1debd..fff89ee71 100644 --- a/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionUrl.java +++ b/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionUrl.java @@ -3,6 +3,9 @@ import de.kittybot.kittybot.objects.exceptions.OptionParseException; import de.kittybot.kittybot.slashcommands.application.CommandOption; import de.kittybot.kittybot.slashcommands.application.CommandOptionType; +import net.dv8tion.jda.api.entities.Command; +import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; +import net.dv8tion.jda.api.exceptions.ParsingException; import java.net.MalformedURLException; import java.net.URL; @@ -10,18 +13,18 @@ public class CommandOptionUrl extends CommandOption{ public CommandOptionUrl(String name, String description){ - super(CommandOptionType.STRING, name, description); + super(Command.OptionType.STRING, name, description); } @Override - public String parseValue(Object value){ + public String parseValue(SlashCommandEvent.OptionData optionData){ try{ - var url = (String) value; + var url = optionData.getAsString(); new URL(url); return url; } - catch(ClassCastException | MalformedURLException e){ - throw new OptionParseException("Failed to parse " + value + " as url"); + catch(ParsingException | MalformedURLException e){ + throw new OptionParseException(optionData, "url"); } } diff --git a/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionUser.java b/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionUser.java index 42f13648f..5a30cb5eb 100644 --- a/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionUser.java +++ b/src/main/java/de/kittybot/kittybot/slashcommands/application/options/CommandOptionUser.java @@ -3,20 +3,26 @@ import de.kittybot.kittybot.objects.exceptions.OptionParseException; import de.kittybot.kittybot.slashcommands.application.CommandOption; import de.kittybot.kittybot.slashcommands.application.CommandOptionType; +import net.dv8tion.jda.api.entities.Command; +import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; +import net.dv8tion.jda.api.exceptions.ParsingException; -public class CommandOptionUser extends CommandOption{ +import java.net.MalformedURLException; + +public class CommandOptionUser extends CommandOption{ public CommandOptionUser(String name, String description){ - super(CommandOptionType.USER, name, description); + super(Command.OptionType.USER, name, description); } @Override - public Long parseValue(Object value){ + public User parseValue(SlashCommandEvent.OptionData optionData){ try{ - return value instanceof Long ? (Long) value : Long.parseLong((String) value); + return optionData.getAsUser(); } - catch(ClassCastException | NumberFormatException e){ - throw new OptionParseException("Failed to parse " + value + " as user"); + catch(ParsingException e){ + throw new OptionParseException(optionData, "user"); } } diff --git a/src/main/java/de/kittybot/kittybot/slashcommands/application/options/GuildSubCommand.java b/src/main/java/de/kittybot/kittybot/slashcommands/application/options/GuildSubCommand.java index 15e44a8ad..83fd69e5d 100644 --- a/src/main/java/de/kittybot/kittybot/slashcommands/application/options/GuildSubCommand.java +++ b/src/main/java/de/kittybot/kittybot/slashcommands/application/options/GuildSubCommand.java @@ -1,11 +1,12 @@ package de.kittybot.kittybot.slashcommands.application.options; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; import de.kittybot.kittybot.slashcommands.application.RunnableGuildCommand; public abstract class GuildSubCommand extends SubBaseCommand implements RunnableGuildCommand{ public GuildSubCommand(String name, String description){ - super(name, description); + super(name, description, true); } } diff --git a/src/main/java/de/kittybot/kittybot/slashcommands/application/options/SubBaseCommand.java b/src/main/java/de/kittybot/kittybot/slashcommands/application/options/SubBaseCommand.java index 00cd4c75d..709f590a8 100644 --- a/src/main/java/de/kittybot/kittybot/slashcommands/application/options/SubBaseCommand.java +++ b/src/main/java/de/kittybot/kittybot/slashcommands/application/options/SubBaseCommand.java @@ -1,9 +1,10 @@ package de.kittybot.kittybot.slashcommands.application.options; import de.kittybot.kittybot.slashcommands.application.CommandOption; -import de.kittybot.kittybot.slashcommands.application.CommandOptionType; import de.kittybot.kittybot.slashcommands.application.PermissionHolder; import net.dv8tion.jda.api.Permission; +import net.dv8tion.jda.api.entities.Command; +import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; import net.dv8tion.jda.api.utils.data.DataObject; import java.util.Arrays; @@ -14,14 +15,24 @@ public abstract class SubBaseCommand extends CommandOption implements PermissionHolder{ private final Set permissions; + private boolean guildOnly; private boolean devOnly; - public SubBaseCommand(String name, String description){ - super(CommandOptionType.SUB_COMMAND, name, description); + public SubBaseCommand(String name, String description, boolean guildOnly){ + super(Command.OptionType.SUB_COMMAND, name, description); + this.guildOnly = guildOnly; this.devOnly = false; this.permissions = new HashSet<>(); } + public void guildOnly() { + this.guildOnly = true; + } + + public boolean isGuildOnly(){ + return this.guildOnly; + } + public void devOnly(){ this.devOnly = true; } @@ -39,13 +50,13 @@ public Set getPermissions(){ } @Override - public Void parseValue(Object value){ + public Void parseValue(SlashCommandEvent.OptionData optionData){ throw new UnsupportedOperationException("This is SubCommand"); } @Override - public DataObject toDetailedJSON(){ - return super.toDetailedJSON() + public DataObject toJSON(){ + return super.toJSON() .put("permissions", this.permissions.stream().map(Permission::getName).collect(Collectors.toList())) .put("dev_only", this.devOnly); } diff --git a/src/main/java/de/kittybot/kittybot/slashcommands/application/options/SubCommand.java b/src/main/java/de/kittybot/kittybot/slashcommands/application/options/SubCommand.java index 962f9d4f7..b3937fac1 100644 --- a/src/main/java/de/kittybot/kittybot/slashcommands/application/options/SubCommand.java +++ b/src/main/java/de/kittybot/kittybot/slashcommands/application/options/SubCommand.java @@ -5,7 +5,7 @@ public abstract class SubCommand extends SubBaseCommand implements RunnableCommand{ public SubCommand(String name, String description){ - super(name, description); + super(name, description, false); } } diff --git a/src/main/java/de/kittybot/kittybot/slashcommands/application/options/SubCommandGroup.java b/src/main/java/de/kittybot/kittybot/slashcommands/application/options/SubCommandGroup.java index db2ed1ec6..cd65b1658 100644 --- a/src/main/java/de/kittybot/kittybot/slashcommands/application/options/SubCommandGroup.java +++ b/src/main/java/de/kittybot/kittybot/slashcommands/application/options/SubCommandGroup.java @@ -1,9 +1,10 @@ package de.kittybot.kittybot.slashcommands.application.options; import de.kittybot.kittybot.slashcommands.application.CommandOption; -import de.kittybot.kittybot.slashcommands.application.CommandOptionType; import de.kittybot.kittybot.slashcommands.application.PermissionHolder; import net.dv8tion.jda.api.Permission; +import net.dv8tion.jda.api.entities.Command; +import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; import net.dv8tion.jda.api.utils.data.DataObject; import java.util.Arrays; @@ -14,38 +15,54 @@ public class SubCommandGroup extends CommandOption implements PermissionHolder{ private final Set permissions; + private boolean guildOnly; private boolean devOnly; public SubCommandGroup(String name, String description){ - super(CommandOptionType.SUB_COMMAND_GROUP, name, description); + super(Command.OptionType.SUB_COMMAND_GROUP, name, description); + this.guildOnly = false; this.devOnly = false; this.permissions = new HashSet<>(); } + @Override + public boolean isGuildOnly(){ + return this.guildOnly; + } + + @Override + public void guildOnly(){ + this.guildOnly = true; + } + + @Override public void devOnly(){ this.devOnly = true; } + @Override public boolean isDevOnly(){ return this.devOnly; } + @Override public void addPermissions(Permission... permissions){ this.permissions.addAll(Arrays.asList(permissions)); } + @Override public Set getPermissions(){ return this.permissions; } @Override - public Void parseValue(Object value){ + public Void parseValue(SlashCommandEvent.OptionData optionData){ throw new UnsupportedOperationException("This is SubCommand group"); } @Override - public DataObject toDetailedJSON(){ - return super.toDetailedJSON() + public DataObject toJSON(){ + return super.toJSON() .put("permissions", this.permissions.stream().map(Permission::getName).collect(Collectors.toList())) .put("dev_only", this.devOnly); } diff --git a/src/main/java/de/kittybot/kittybot/slashcommands/interaction/GuildInteraction.java b/src/main/java/de/kittybot/kittybot/slashcommands/interaction/GuildInteraction.java deleted file mode 100644 index ada63f542..000000000 --- a/src/main/java/de/kittybot/kittybot/slashcommands/interaction/GuildInteraction.java +++ /dev/null @@ -1,42 +0,0 @@ -package de.kittybot.kittybot.slashcommands.interaction; - -import de.kittybot.kittybot.objects.module.Modules; -import net.dv8tion.jda.api.JDA; -import net.dv8tion.jda.api.entities.Guild; -import net.dv8tion.jda.api.entities.Member; -import net.dv8tion.jda.api.entities.TextChannel; -import net.dv8tion.jda.api.utils.data.DataObject; - -public class GuildInteraction extends Interaction{ - - private final Guild guild; - private final Member member; - - public GuildInteraction(DataObject json, InteractionData data, Guild guild, Member member, TextChannel channel, Modules modules, JDA jda){ - super(json, data, member.getUser(), channel, true, modules, jda); - this.guild = guild; - this.member = member; - } - - public Guild getGuild(){ - return this.guild; - } - - public long getGuildId(){ - return this.guild.getIdLong(); - } - - public Member getMember(){ - return this.member; - } - - public Member getSelfMember(){ - return this.guild.getSelfMember(); - } - - @Override - public TextChannel getChannel(){ - return (TextChannel) this.channel; - } - -} diff --git a/src/main/java/de/kittybot/kittybot/slashcommands/interaction/Interaction.java b/src/main/java/de/kittybot/kittybot/slashcommands/interaction/Interaction.java deleted file mode 100644 index c9e29b0fe..000000000 --- a/src/main/java/de/kittybot/kittybot/slashcommands/interaction/Interaction.java +++ /dev/null @@ -1,193 +0,0 @@ -package de.kittybot.kittybot.slashcommands.interaction; - -import club.minnced.discord.webhook.receive.ReadonlyMessage; -import de.kittybot.kittybot.modules.InteractionsModule; -import de.kittybot.kittybot.objects.enums.Emoji; -import de.kittybot.kittybot.objects.module.Module; -import de.kittybot.kittybot.objects.module.Modules; -import de.kittybot.kittybot.slashcommands.interaction.response.FollowupMessage; -import de.kittybot.kittybot.slashcommands.interaction.response.InteractionRespondAction; -import de.kittybot.kittybot.slashcommands.interaction.response.InteractionResponse; -import de.kittybot.kittybot.slashcommands.interaction.response.InteractionResponseType; -import de.kittybot.kittybot.utils.Colors; -import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.JDA; -import net.dv8tion.jda.api.entities.MessageChannel; -import net.dv8tion.jda.api.entities.User; -import net.dv8tion.jda.api.requests.RestAction; -import net.dv8tion.jda.api.utils.data.DataObject; -import net.dv8tion.jda.internal.JDAImpl; -import net.dv8tion.jda.internal.entities.GuildImpl; - -import java.awt.Color; -import java.time.Instant; -import java.util.function.Consumer; - -public class Interaction{ - - protected final long id, channelId; - protected final InteractionType type; - protected final InteractionData data; - protected final String token; - protected final int version; - protected final User user; - protected final MessageChannel channel; - protected final boolean isFromGuild; - protected final Modules modules; - protected final JDA jda; - - protected Interaction(DataObject json, InteractionData data, User user, MessageChannel channel, boolean isFromGuild, Modules modules, JDA jda){ - this.id = json.getLong("id"); - this.type = InteractionType.get(json.getInt("type")); - this.channelId = json.getLong("channel_id"); - this.token = json.getString("token"); - this.version = json.getInt("version"); - this.data = data; - this.user = user; - this.isFromGuild = isFromGuild; - this.channel = channel; - this.modules = modules; - this.jda = jda; - } - - public static Interaction fromJSON(Modules modules, DataObject json, JDA jda){ - var entityBuilder = ((JDAImpl) jda).getEntityBuilder(); - - var guild = (GuildImpl) jda.getGuildById(json.getLong("guild_id", -1L)); - if(guild == null){ - return new Interaction( - json, - InteractionData.fromJSON(json.getObject("data"), entityBuilder, null), - entityBuilder.createUser(json.optObject("user").orElseGet(() -> json.getObject("member").getObject("user"))), - jda.getPrivateChannelById(json.getLong("channel_id")), - json.hasKey("guild_id"), - modules, - jda - ); - } - - return new GuildInteraction( - json, - InteractionData.fromJSON(json.getObject("data"), entityBuilder, guild), - guild, - entityBuilder.createMember(guild, json.getObject("member")), - guild.getTextChannelById(json.getLong("channel_id")), - modules, - jda - ); - } - - public long getId(){ - return this.id; - } - - public long getChannelId(){ - return this.channelId; - } - - public InteractionType getType(){ - return this.type; - } - - public InteractionData getData(){ - return this.data; - } - - public String getToken(){ - return this.token; - } - - public int getVersion(){ - return this.version; - } - - public User getUser(){ - return this.user; - } - - public long getUserId(){ - return this.user.getIdLong(); - } - - public User getSelfUser(){ - return this.jda.getSelfUser(); - } - - public MessageChannel getChannel(){ - return this.channel; - } - - public boolean isFromGuild(){ - return this.isFromGuild; - } - - public Modules getModules(){ - return this.modules; - } - - public T get(Class clazz){ - return this.modules.get(clazz); - } - - public JDA getJDA(){ - return this.jda; - } - - public void reply(String message){ - this.modules.get(InteractionsModule.class).reply(this).embeds(getEmbed().setDescription(message).build()).queue(); - } - - public EmbedBuilder getEmbed(){ - return applyDefaultStyle(new EmbedBuilder()); - } - - public EmbedBuilder applyDefaultStyle(EmbedBuilder embedBuilder){ - String name; - if(this instanceof GuildInteraction){ - name = ((GuildInteraction) this).getMember().getEffectiveName(); - } - else{ - name = user.getName(); - } - return embedBuilder.setColor(Colors.KITTYBOT_BLUE).setFooter(name, user.getEffectiveAvatarUrl()).setTimestamp(Instant.now()); - } - - public void reply(Consumer consumer){ - var embedBuilder = applyDefaultStyle(new EmbedBuilder()); - consumer.accept(embedBuilder); - this.modules.get(InteractionsModule.class).reply(this).embeds(embedBuilder.build()).queue(); - } - - public void reply(InteractionResponse response){ - this.modules.get(InteractionsModule.class).reply(this).fromData(response).queue(); - } - - public void error(String error){ - this.modules.get(InteractionsModule.class).reply(this).type(InteractionResponseType.ACKNOWLEDGE).content(Emoji.X.get() + " " + error).ephemeral().queue(); - } - - public void followup(String message){ - followup(new FollowupMessage.Builder().setEmbeds(getEmbed().setDescription(message).build()).build()); - } - - public void followup(FollowupMessage message){ - followupMessage(message).queue(); - } - - public RestAction followupMessage(FollowupMessage message){ - return this.modules.get(InteractionsModule.class).followup(this, message); - } - - public void followupError(String error){ - followup(new FollowupMessage.Builder().setEmbeds(getErrorEmbed().setDescription(error).build()).build()); - } - - public EmbedBuilder getErrorEmbed(){ - return getEmbed().setColor(Color.RED); - } - - public InteractionRespondAction acknowledge(boolean withSource){ - return this.modules.get(InteractionsModule.class).acknowledge(this, withSource); - } - -} diff --git a/src/main/java/de/kittybot/kittybot/slashcommands/interaction/InteractionData.java b/src/main/java/de/kittybot/kittybot/slashcommands/interaction/InteractionData.java deleted file mode 100644 index 537608a73..000000000 --- a/src/main/java/de/kittybot/kittybot/slashcommands/interaction/InteractionData.java +++ /dev/null @@ -1,48 +0,0 @@ -package de.kittybot.kittybot.slashcommands.interaction; - -import net.dv8tion.jda.api.utils.data.DataObject; -import net.dv8tion.jda.internal.entities.EntityBuilder; -import net.dv8tion.jda.internal.entities.GuildImpl; - -import java.util.List; - -public class InteractionData implements InteractionOptionsHolder{ - - private final long id; - private final String name; - private final List options; - private final ResolvedMentions resolvedMentions; - - public InteractionData(long id, String name, List options, ResolvedMentions resolvedMentions){ - this.id = id; - this.name = name; - this.options = options; - this.resolvedMentions = resolvedMentions; - } - - public static InteractionData fromJSON(DataObject json, EntityBuilder entityBuilder, GuildImpl guild){ - return new InteractionData( - json.getLong("id"), - json.getString("name"), - InteractionDataOption.fromJSON(json.optArray("options").orElse(null)), - new ResolvedMentions(json.optObject("resolved").orElse(DataObject.empty()), entityBuilder, guild) - ); - } - - public long getId(){ - return this.id; - } - - public String getName(){ - return this.name; - } - - public List getOptions(){ - return this.options; - } - - public ResolvedMentions getResolvedMentions(){ - return this.resolvedMentions; - } - -} diff --git a/src/main/java/de/kittybot/kittybot/slashcommands/interaction/InteractionDataOption.java b/src/main/java/de/kittybot/kittybot/slashcommands/interaction/InteractionDataOption.java deleted file mode 100644 index a48a7afb8..000000000 --- a/src/main/java/de/kittybot/kittybot/slashcommands/interaction/InteractionDataOption.java +++ /dev/null @@ -1,75 +0,0 @@ -package de.kittybot.kittybot.slashcommands.interaction; - -import de.kittybot.kittybot.slashcommands.application.CommandOptionType; -import net.dv8tion.jda.api.utils.data.DataArray; -import net.dv8tion.jda.api.utils.data.DataObject; - -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -public class InteractionDataOption implements InteractionOptionsHolder{ - - private final String name; - private final CommandOptionType type; - private final Object value; - private final List options; - - public InteractionDataOption(String name, CommandOptionType type, Object value, List options){ - this.name = name.toLowerCase(); - this.type = type; - this.value = value; - this.options = options; - } - - public static InteractionDataOption fromJSON(DataObject json){ - return new InteractionDataOption( - json.getString("name"), - CommandOptionType.get(json.getInt("type", 0)), - json.opt("value").orElse(null), - InteractionDataOption.fromJSON(json.optArray("options").orElse(null)) - ); - } - - public static List fromJSON(DataArray json){ - if(json == null){ - return new ArrayList<>(); - } - return json.stream((array, index) -> fromJSON(array.getObject(index))).collect(Collectors.toList()); - } - - public String getName(){ - return this.name; - } - - public CommandOptionType getType(){ - return this.type; - } - - public Object getValue(){ - return this.value; - } - - /* - public String getEmoteName(){ - var matcher = Message.MentionType.EMOTE.getPattern().matcher(getString()); - if(!matcher.matches()){ - return null; - } - return matcher.group(1); - }*/ - - public List getOptions(){ - return this.options; - } - - @Override - public String toString(){ - return "InteractionDataOption{" + - "name='" + this.name + '\'' + - ", value='" + this.value + '\'' + - ", options=" + this.options + - '}'; - } - -} diff --git a/src/main/java/de/kittybot/kittybot/slashcommands/interaction/InteractionOptionsHolder.java b/src/main/java/de/kittybot/kittybot/slashcommands/interaction/InteractionOptionsHolder.java deleted file mode 100644 index 9ec0d9cd4..000000000 --- a/src/main/java/de/kittybot/kittybot/slashcommands/interaction/InteractionOptionsHolder.java +++ /dev/null @@ -1,9 +0,0 @@ -package de.kittybot.kittybot.slashcommands.interaction; - -import java.util.List; - -public interface InteractionOptionsHolder{ - - List getOptions(); - -} diff --git a/src/main/java/de/kittybot/kittybot/slashcommands/interaction/InteractionType.java b/src/main/java/de/kittybot/kittybot/slashcommands/interaction/InteractionType.java deleted file mode 100644 index fe76a0c69..000000000 --- a/src/main/java/de/kittybot/kittybot/slashcommands/interaction/InteractionType.java +++ /dev/null @@ -1,28 +0,0 @@ -package de.kittybot.kittybot.slashcommands.interaction; - -public enum InteractionType{ - - PING(1), - APPLICATION_COMMAND(2); - - private final int type; - - InteractionType(int type){ - this.type = type; - } - - public static InteractionType get(int type){ - if(type == 1){ - return PING; - } - else if(type == 2){ - return APPLICATION_COMMAND; - } - throw new IllegalArgumentException("Unknown InteractionType: " + type + " provided"); - } - - public int getType(){ - return this.type; - } - -} diff --git a/src/main/java/de/kittybot/kittybot/slashcommands/interaction/Options.java b/src/main/java/de/kittybot/kittybot/slashcommands/interaction/Options.java deleted file mode 100644 index 5bd3ab77f..000000000 --- a/src/main/java/de/kittybot/kittybot/slashcommands/interaction/Options.java +++ /dev/null @@ -1,146 +0,0 @@ -package de.kittybot.kittybot.slashcommands.interaction; - -import de.kittybot.kittybot.objects.exceptions.MissingOptionException; -import de.kittybot.kittybot.objects.exceptions.OptionParseException; -import de.kittybot.kittybot.slashcommands.application.CommandOption; -import net.dv8tion.jda.api.entities.*; -import net.dv8tion.jda.api.requests.RestAction; -import net.dv8tion.jda.api.utils.MiscUtil; - -import java.time.LocalDateTime; -import java.util.List; -import java.util.Map; -import java.util.function.Function; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -public class Options{ - - private final Map> definedOptions; - private final Map options; - private final ResolvedMentions resolvedMentions; - - public Options(List> definedOptions, List options, ResolvedMentions resolvedMentions){ - this.definedOptions = definedOptions.stream().collect(Collectors.toMap(CommandOption::getName, Function.identity())); - this.options = options.stream().collect(Collectors.toMap(InteractionDataOption::getName, Function.identity())); - this.resolvedMentions = resolvedMentions; - } - - public int size(){ - return this.options.size(); - } - - public boolean isEmpty(){ - return this.options.isEmpty(); - } - - public String getString(String name){ - return getValue(name, String.class); - } - - @SuppressWarnings("unchecked") - private T getValue(String name, Class clazz){ - var value = this.options.get(name).getValue(); - if(value == null){ - throw new MissingOptionException(name, clazz); - } - return (T) this.definedOptions.get(name).parseValue(value); - } - - public int getInt(String name){ - return getValue(name, Integer.class); - } - - public float getFloat(String name){ - return getValue(name, Float.class); - } - - public boolean getBoolean(String name){ - return getValue(name, Boolean.class); - } - - public Member getMember(String name){ - return this.resolvedMentions.getMentionedMembers().get(getLong(name)); - } - - public long getLong(String name){ - return getValue(name, Long.class); - } - - public User getUser(String name){ - return this.resolvedMentions.getMentionedUsers().get(getLong(name)); - } - - public GuildChannel getChannel(String name){ - return this.resolvedMentions.getMentionedChannels().get(getLong(name)); - } - - public TextChannel getTextChannel(String name){ - var channel = this.resolvedMentions.getMentionedChannels().get(getLong(name)); - if(channel instanceof TextChannel){ - return (TextChannel) channel; - } - throw new OptionParseException("Please provide a valid text channel"); - } - - public Role getRole(String name){ - return this.resolvedMentions.getMentionedRoles().get(getLong(name)); - } - - public LocalDateTime getTime(String name){ - return getValue(name, LocalDateTime.class); - } - - public RestAction getEmote(Guild guild, String name){ - return guild.retrieveEmoteById(getEmoteId(name)); - } - - public long getEmoteId(String name){ - var emote = getValue(name, String.class); - var matcher = Message.MentionType.EMOTE.getPattern().matcher(emote); - if(matcher.matches()){ - return MiscUtil.parseSnowflake(matcher.group(2)); - } - throw new OptionParseException("Failed to parse emote id"); - } - - public String getEmoteName(String name){ - var emote = getValue(name, String.class); - var matcher = Message.MentionType.EMOTE.getPattern().matcher(emote); - if(matcher.matches()){ - return matcher.group(1); - } - throw new OptionParseException("Failed to parse emote name"); - } - - public boolean getEmoteAnimated(String name){ - return getValue(name, String.class).startsWith(" T getOrDefault(String name, T defaultValue){ - try{ - return (T) getValue(name, defaultValue.getClass()); - } - catch(NullPointerException e){ - return defaultValue; - } - } - - public InteractionDataOption get(String name){ - return this.options.get(name); - } - - public Map getMap(){ - return this.options; - } - - public Stream stream(){ - return this.options.values().stream(); - } - -} diff --git a/src/main/java/de/kittybot/kittybot/slashcommands/interaction/ResolvedMentions.java b/src/main/java/de/kittybot/kittybot/slashcommands/interaction/ResolvedMentions.java deleted file mode 100644 index 62f2e9997..000000000 --- a/src/main/java/de/kittybot/kittybot/slashcommands/interaction/ResolvedMentions.java +++ /dev/null @@ -1,135 +0,0 @@ -package de.kittybot.kittybot.slashcommands.interaction; - -import net.dv8tion.jda.api.entities.*; -import net.dv8tion.jda.api.utils.data.DataObject; -import net.dv8tion.jda.internal.entities.EntityBuilder; -import net.dv8tion.jda.internal.entities.GuildImpl; - -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.function.Function; -import java.util.stream.Collectors; - -public class ResolvedMentions{ - - private final EntityBuilder entityBuilder; - private final GuildImpl guild; - private final DataObject rawChannels; - private final DataObject rawMembers; - private final DataObject rawRoles; - private final DataObject rawUsers; - private Map channels; - private Map members; - private Map roles; - private Map users; - - public ResolvedMentions(DataObject json, EntityBuilder entityBuilder, GuildImpl guild){ - this.entityBuilder = entityBuilder; - this.guild = guild; - this.channels = null; - this.rawChannels = json.optObject("channels").orElse(null); - this.members = null; - this.rawMembers = json.optObject("members").orElse(null); - this.roles = null; - this.rawRoles = json.optObject("roles").orElse(null); - this.users = null; - this.rawUsers = json.optObject("users").orElse(null); - } - - public Map getMentionedChannels(){ - if(this.channels == null){ - if(this.rawChannels == null){ - this.channels = new HashMap<>(); - } - else{ - this.channels = this.rawChannels.keys().stream() - .map(this::createChannel) - .filter(Objects::nonNull) - .collect(Collectors.toMap(ISnowflake::getIdLong, Function.identity())); - } - } - return this.channels; - } - - private GuildChannel createChannel(String key){ - //GuildChannel channel; - var json = this.rawChannels.getObject(key); - return guild.getGuildChannelById(json.getLong("id")); - /*switch(ChannelType.fromId(json.getInt("type"))){ - case CATEGORY: - channel = this.entityBuilder.createCategory(guild, json, guild.getIdLong()); - break; - case TEXT: - channel = this.entityBuilder.createTextChannel(guild, json, guild.getIdLong()); - break; - case STORE: - channel = this.entityBuilder.createStoreChannel(guild, json, guild.getIdLong()); - break; - case VOICE: - channel = this.entityBuilder.createVoiceChannel(guild, json, guild.getIdLong()); - break; - default: - channel = null; - break; - } - return channel;*/ - } - - public Map getMentionedMembers(){ - if(this.members == null){ - if(this.rawMembers == null){ - this.members = new HashMap<>(); - } - else{ - this.members = this.rawMembers.keys().stream() - .map(this::createMember) - .collect(Collectors.toMap(ISnowflake::getIdLong, Function.identity())); - } - } - return this.members; - } - - private Member createMember(String key){ - return this.entityBuilder.createMember(this.guild, this.rawMembers.getObject(key).put("user", this.rawUsers.getObject(key))); - } - - public Map getMentionedUsers(){ - if(this.users == null){ - if(this.rawUsers == null){ - this.users = new HashMap<>(); - } - else{ - this.users = this.rawUsers.keys().stream() - .map(this::createUser) - .collect(Collectors.toMap(ISnowflake::getIdLong, Function.identity())); - } - } - return this.users; - } - - private User createUser(String key){ - return this.entityBuilder.createUser(this.rawUsers.getObject(key)); - } - - public Map getMentionedRoles(){ - if(this.roles == null){ - if(this.rawRoles == null){ - this.roles = new HashMap<>(); - } - else{ - this.roles = this.rawRoles.keys().stream() - .map(this::createRole) - .collect(Collectors.toMap(ISnowflake::getIdLong, Function.identity())); - } - } - return this.roles; - } - - private Role createRole(String key){ - var role = this.rawRoles.getObject(key); - role.put("permissions_new", role.getLong("permissions")); - return this.entityBuilder.createRole(this.guild, role, this.guild.getIdLong()); - } - -} diff --git a/src/main/java/de/kittybot/kittybot/slashcommands/interaction/response/FollowupMessage.java b/src/main/java/de/kittybot/kittybot/slashcommands/interaction/response/FollowupMessage.java deleted file mode 100644 index 467176b86..000000000 --- a/src/main/java/de/kittybot/kittybot/slashcommands/interaction/response/FollowupMessage.java +++ /dev/null @@ -1,140 +0,0 @@ -package de.kittybot.kittybot.slashcommands.interaction.response; - -import net.dv8tion.jda.api.entities.Message; -import net.dv8tion.jda.api.entities.MessageEmbed; -import net.dv8tion.jda.api.utils.data.DataArray; -import net.dv8tion.jda.api.utils.data.DataObject; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Collections; -import java.util.EnumSet; -import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; - -public class FollowupMessage{ - - private final String username, avatarUrl, content; - private final List embeds; - private final boolean isTTS; - private final EnumSet allowedMentions; - - private FollowupMessage(String username, String avatarUrl, String content, List embeds, boolean isTTS, EnumSet allowedMentions){ - this.username = username; - this.avatarUrl = avatarUrl; - this.content = content; - this.embeds = embeds; - this.isTTS = isTTS; - this.allowedMentions = allowedMentions; - } - - @Nullable - public String getUsername(){ - return username; - } - - @Nullable - public String getAvatarUrl(){ - return avatarUrl; - } - - @Nullable - public String getContent(){ - return content; - } - - @NotNull - public List getEmbeds(){ - return embeds == null ? Collections.emptyList() : embeds; - } - - public boolean isTTS(){ - return isTTS; - } - - @NotNull - public DataObject toJSON(){ - final DataObject payload = DataObject.empty(); - payload.put("content", this.content); - if(this.embeds != null && !this.embeds.isEmpty()){ - payload.put("embeds", DataArray.fromCollection(this.embeds.stream().map(MessageEmbed::toData).collect(Collectors.toSet()))); - } - if(this.avatarUrl != null){ - payload.put("avatar_url", this.avatarUrl); - } - if(this.username != null){ - payload.put("username", this.username); - } - payload.put("tts", isTTS); - payload.put("allowed_mentions", getAllowedMentionsObj()); - return payload; - } - - protected DataObject getAllowedMentionsObj(){ - DataObject allowedMentionsObj = DataObject.empty(); - DataArray parsable = DataArray.empty(); - if(allowedMentions != null){ - // Add parsing options - allowedMentions.stream() - .map(Message.MentionType::getParseKey) - .filter(Objects::nonNull) - .distinct() - .forEach(parsable::add); - } - return allowedMentionsObj.put("parse", parsable); - } - - public static class Builder{ - - private String username, avatarUrl, content; - private List embeds; - private boolean isTTS; - private EnumSet allowedMentions; - - public Builder(){ - this.username = null; - this.avatarUrl = null; - this.content = ""; - this.embeds = null; - this.isTTS = false; - this.allowedMentions = null; - } - - public Builder setUsername(String username){ - this.username = username; - return this; - } - - public Builder setAvatarUrl(String avatarUrl){ - this.avatarUrl = avatarUrl; - return this; - } - - public Builder setContent(String content){ - this.content = content; - return this; - } - - public Builder setEmbeds(MessageEmbed... embeds){ - this.embeds = List.of(embeds); - return this; - } - - public Builder setTTS(boolean TTS){ - isTTS = TTS; - return this; - } - - public Builder setAllowedMentions(EnumSet allowedMentions){ - this.allowedMentions = allowedMentions; - return this; - } - - public FollowupMessage build(){ - return new FollowupMessage(this.username, this.avatarUrl, this.content, this.embeds, this.isTTS, this.allowedMentions); - } - - } - -} diff --git a/src/main/java/de/kittybot/kittybot/slashcommands/interaction/response/InteractionRespondAction.java b/src/main/java/de/kittybot/kittybot/slashcommands/interaction/response/InteractionRespondAction.java deleted file mode 100644 index c60940fd3..000000000 --- a/src/main/java/de/kittybot/kittybot/slashcommands/interaction/response/InteractionRespondAction.java +++ /dev/null @@ -1,272 +0,0 @@ -package de.kittybot.kittybot.slashcommands.interaction.response; - -import de.kittybot.kittybot.slashcommands.interaction.Interaction; -import net.dv8tion.jda.api.JDA; -import net.dv8tion.jda.api.Permission; -import net.dv8tion.jda.api.entities.*; -import net.dv8tion.jda.api.requests.Request; -import net.dv8tion.jda.api.requests.Response; -import net.dv8tion.jda.api.utils.data.DataArray; -import net.dv8tion.jda.api.utils.data.DataObject; -import net.dv8tion.jda.internal.requests.Requester; -import net.dv8tion.jda.internal.requests.RestActionImpl; -import net.dv8tion.jda.internal.requests.Route; -import net.dv8tion.jda.internal.utils.Checks; -import net.dv8tion.jda.internal.utils.Helpers; -import okhttp3.RequestBody; - -import javax.annotation.CheckReturnValue; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import java.util.*; -import java.util.concurrent.TimeUnit; -import java.util.function.BooleanSupplier; -import java.util.stream.Collectors; - -public class InteractionRespondAction extends RestActionImpl{ - - private static final String CONTENT_TOO_BIG = String.format("A message may not exceed %d characters. Please limit your input!", Message.MAX_CONTENT_LENGTH); - private static EnumSet defaultMentions = EnumSet.allOf(Message.MentionType.class); - private final Interaction interaction; - protected EnumSet allowedMentions; - protected Set mentionableUsers = new HashSet<>(); - protected Set mentionableRoles = new HashSet<>(); - private InteractionResponseType type = InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE; - private StringBuilder content = new StringBuilder(); - private boolean tts = false; - private int flags = 0; - private List embeds = new ArrayList<>(); - - public InteractionRespondAction(JDA api, Route.CompiledRoute route, Interaction interaction){ - super(api, route); - this.interaction = interaction; - } - - public InteractionRespondAction(JDA api, Route.CompiledRoute route, Interaction interaction, boolean withSource){ - super(api, route); - this.interaction = interaction; - this.type = withSource ? InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE : InteractionResponseType.CHANNEL_MESSAGE; - } - - @Nonnull - public static EnumSet getDefaultMentions(){ - return defaultMentions.clone(); - } - - public static void setDefaultMentions(@Nullable Collection allowedMentions){ - InteractionRespondAction.defaultMentions = allowedMentions == null - ? EnumSet.allOf(Message.MentionType.class) // Default to all mentions enabled - : Helpers.copyEnumSet(Message.MentionType.class, allowedMentions); - } - - @Nonnull - @Override - public InteractionRespondAction setCheck(BooleanSupplier checks){ - return (InteractionRespondAction) super.setCheck(checks); - } - - @Nonnull - @Override - public InteractionRespondAction deadline(long timestamp){ - return (InteractionRespondAction) super.deadline(timestamp); - } - - @Override - public RequestBody finalizeData(){ - return asJSON(); - } - - protected RequestBody asJSON(){ - return RequestBody.create(getJSON().toJson(), Requester.MEDIA_TYPE_JSON); - } - - protected DataObject getJSON(){ - var json = DataObject.empty(); - - json.put("type", this.type.getType()); - - if(!embeds.isEmpty() || content.length() > 0){ - var obj = DataObject.empty(); - if(!embeds.isEmpty()){ - obj.put("embeds", DataArray.fromCollection(this.embeds.stream().map(MessageEmbed::toData).collect(Collectors.toSet()))); - } - if(content.length() > 0){ - obj.put("content", content.toString()); - } - if(flags != 0){ - obj.put("flags", flags); - } - - obj.put("tts", tts); - if(allowedMentions != null || !mentionableUsers.isEmpty() || !mentionableRoles.isEmpty()){ - obj.put("allowed_mentions", getAllowedMentionsObj()); - } - json.put("data", obj); - } - return json; - } - - protected DataObject getAllowedMentionsObj(){ - DataObject allowedMentionsObj = DataObject.empty(); - DataArray parsable = DataArray.empty(); - if(allowedMentions != null){ - // Add parsing options - allowedMentions.stream() - .map(Message.MentionType::getParseKey) - .filter(Objects::nonNull) - .distinct() - .forEach(parsable::add); - } - if(!mentionableUsers.isEmpty()){ - // Whitelist certain users - parsable.remove(Message.MentionType.USER.getParseKey()); - allowedMentionsObj.put("users", DataArray.fromCollection(mentionableUsers)); - } - if(!mentionableRoles.isEmpty()){ - // Whitelist certain roles - parsable.remove(Message.MentionType.ROLE.getParseKey()); - allowedMentionsObj.put("roles", DataArray.fromCollection(mentionableRoles)); - } - return allowedMentionsObj.put("parse", parsable); - } - - @Override - protected void handleSuccess(Response response, Request request){ - request.onSuccess(this.interaction); - } - - public boolean hasPermission(Permission perm){ - var channel = getChannel(); - if(channel.getType() != ChannelType.TEXT){ - return true; - } - TextChannel text = (TextChannel) channel; - Member self = text.getGuild().getSelfMember(); - return self.hasPermission(text, perm); - } - - @Nonnull - public MessageChannel getChannel(){ - return this.interaction.getChannel(); - } - - @Nonnull - @Override - public InteractionRespondAction timeout(long timeout, @Nonnull TimeUnit unit){ - return (InteractionRespondAction) super.timeout(timeout, unit); - } - - public InteractionRespondAction withSource(boolean withSource){ - if(this.type == InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE || this.type == InteractionResponseType.CHANNEL_MESSAGE){ - this.type = withSource ? InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE : InteractionResponseType.CHANNEL_MESSAGE; - } - else{ - this.type = withSource ? InteractionResponseType.ACKNOWLEDGE_WITH_SOURCE : InteractionResponseType.ACKNOWLEDGE; - } - return this; - } - - public InteractionRespondAction channelMessage(boolean channelMessage){ - if(this.type == InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE || this.type == InteractionResponseType.ACKNOWLEDGE_WITH_SOURCE){ - this.type = channelMessage ? InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE : InteractionResponseType.ACKNOWLEDGE_WITH_SOURCE; - } - else{ - this.type = channelMessage ? InteractionResponseType.CHANNEL_MESSAGE : InteractionResponseType.ACKNOWLEDGE; - } - return this; - } - - public InteractionRespondAction type(InteractionResponseType type){ - this.type = type; - return this; - } - - public InteractionRespondAction ephemeral(){ - this.flags = 1 << 6; - return this; - } - - public InteractionRespondAction embeds(MessageEmbed... embeds){ - if(embeds.length > 0){ - Checks.check(Arrays.stream(embeds).anyMatch(MessageEmbed::isSendable), - "Provided Message contains an empty embed or an embed with a length greater than %d characters, which is the max for bot accounts!", - MessageEmbed.EMBED_MAX_LENGTH_BOT); - } - this.embeds = List.of(embeds); - return this; - } - - @Nonnull - public InteractionRespondAction allowedMentions(@Nullable Collection allowedMentions){ - this.allowedMentions = allowedMentions == null - ? EnumSet.allOf(Message.MentionType.class) - : Helpers.copyEnumSet(Message.MentionType.class, allowedMentions); - return this; - } - - @Nonnull - public InteractionRespondAction mention(@Nonnull IMentionable... mentions){ - Checks.noneNull(mentions, "Mentionables"); - for(IMentionable mentionable : mentions){ - if(mentionable instanceof User || mentionable instanceof Member){ - mentionableUsers.add(mentionable.getId()); - } - else if(mentionable instanceof Role){ - mentionableRoles.add(mentionable.getId()); - } - } - return this; - } - - @Nonnull - public InteractionRespondAction mentionUsers(@Nonnull String... userIds){ - Checks.noneNull(userIds, "User Id"); - Collections.addAll(mentionableUsers, userIds); - return this; - } - - @Nonnull - public InteractionRespondAction mentionRoles(@Nonnull String... roleIds){ - Checks.noneNull(roleIds, "Role Id"); - Collections.addAll(mentionableRoles, roleIds); - return this; - } - - @Nonnull - @CheckReturnValue - public InteractionRespondAction tts(boolean isTTS){ - this.tts = isTTS; - return this; - } - - public InteractionRespondAction fromData(InteractionResponse response){ - this.type = response.getType(); - var data = response.getData(); - this.content = new StringBuilder(data.getContent()); - this.tts = data.isTts(); - this.allowedMentions = data.getAllowedMentions(); - this.embeds = data.getEmbeds(); - this.flags = data.getFlags(); - return this; - } - - @Nonnull - @CheckReturnValue - public InteractionRespondAction content(final String content){ - if(content == null || content.isEmpty()){ - this.content.setLength(0); - } - else if(content.length() <= Message.MAX_CONTENT_LENGTH){ - this.content.replace(0, this.content.length(), content); - } - else{ - throw new IllegalArgumentException(CONTENT_TOO_BIG); - } - return this; - } - - public Interaction getInteraction(){ - return this.interaction; - } - -} diff --git a/src/main/java/de/kittybot/kittybot/slashcommands/interaction/response/InteractionResponse.java b/src/main/java/de/kittybot/kittybot/slashcommands/interaction/response/InteractionResponse.java deleted file mode 100644 index d725b100c..000000000 --- a/src/main/java/de/kittybot/kittybot/slashcommands/interaction/response/InteractionResponse.java +++ /dev/null @@ -1,112 +0,0 @@ -package de.kittybot.kittybot.slashcommands.interaction.response; - -import net.dv8tion.jda.api.entities.Message; -import net.dv8tion.jda.api.entities.MessageEmbed; -import net.dv8tion.jda.internal.utils.Helpers; - -import javax.annotation.Nullable; -import java.util.ArrayList; -import java.util.Collection; -import java.util.EnumSet; -import java.util.List; - -public class InteractionResponse{ - - private static final int EPHEMERAL_FLAG = 1 << 6; - - private final InteractionResponseType type; - private final InteractionResponseData data; - - public InteractionResponse(InteractionResponseType type, InteractionResponseData data){ - this.type = type; - this.data = data; - } - - public InteractionResponseType getType(){ - return this.type; - } - - public InteractionResponseData getData(){ - return this.data; - } - - public static class Builder{ - - private final List embeds; - private InteractionResponseType type; - private boolean tts; - private String content; - private int flags; - private EnumSet allowedMentions; - - public Builder(){ - this.type = InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE; - this.tts = false; - this.content = ""; - this.embeds = new ArrayList<>(); - this.flags = 0; - this.allowedMentions = EnumSet.allOf(Message.MentionType.class); - } - - public Builder setType(InteractionResponseType type){ - this.type = type; - return this; - } - - public Builder setTTS(boolean tts){ - this.tts = tts; - return this; - } - - public Builder setContent(String content){ - this.content = content; - return this; - } - - public Builder ephemeral(){ - this.flags = EPHEMERAL_FLAG; - return this; - } - - public boolean isEphemeral(){ - return this.flags == EPHEMERAL_FLAG; - } - - public Builder setEphemeral(boolean ephemeral){ - if(ephemeral){ - this.flags = EPHEMERAL_FLAG; - } - else{ - this.flags = 0; - } - return this; - } - - public Builder addEmbeds(MessageEmbed... embeds){ - var newEmbeds = List.of(embeds); - if(this.embeds.size() + newEmbeds.size() > 10){ - throw new IllegalArgumentException("Max of 10 embeds are supported"); - } - this.embeds.addAll(newEmbeds); - return this; - } - - public Builder setAllowedMentions(@Nullable Message.MentionType... allowedMentions){ - return setAllowedMentions(List.of(allowedMentions)); - } - - public Builder setAllowedMentions(@Nullable Collection allowedMentions){ - this.allowedMentions = allowedMentions == null ? EnumSet.allOf(Message.MentionType.class) : Helpers.copyEnumSet(Message.MentionType.class, allowedMentions); - return this; - } - - public InteractionResponse build(){ - if(this.flags == EPHEMERAL_FLAG && !this.embeds.isEmpty()){ - throw new IllegalArgumentException("Ephemeral messages do not support embeds"); - } - return new InteractionResponse(this.type, new InteractionResponseData(this.tts, this.content, this.embeds, this.flags, this.allowedMentions)); - } - - } - -} diff --git a/src/main/java/de/kittybot/kittybot/slashcommands/interaction/response/InteractionResponseData.java b/src/main/java/de/kittybot/kittybot/slashcommands/interaction/response/InteractionResponseData.java deleted file mode 100644 index 54dc73109..000000000 --- a/src/main/java/de/kittybot/kittybot/slashcommands/interaction/response/InteractionResponseData.java +++ /dev/null @@ -1,45 +0,0 @@ -package de.kittybot.kittybot.slashcommands.interaction.response; - -import net.dv8tion.jda.api.entities.Message; -import net.dv8tion.jda.api.entities.MessageEmbed; - -import java.util.EnumSet; -import java.util.List; - -public class InteractionResponseData{ - - private final boolean tts; - private final String content; - private final List embeds; - private final int flags; - private final EnumSet allowedMentions; - - protected InteractionResponseData(boolean tts, String content, List embeds, int flags, EnumSet allowedMentions){ - this.tts = tts; - this.content = content; - this.embeds = embeds; - this.flags = flags; - this.allowedMentions = allowedMentions; - } - - public boolean isTts(){ - return this.tts; - } - - public String getContent(){ - return this.content; - } - - public List getEmbeds(){ - return this.embeds; - } - - public int getFlags(){ - return this.flags; - } - - public EnumSet getAllowedMentions(){ - return this.allowedMentions; - } - -} diff --git a/src/main/java/de/kittybot/kittybot/slashcommands/interaction/response/InteractionResponseType.java b/src/main/java/de/kittybot/kittybot/slashcommands/interaction/response/InteractionResponseType.java deleted file mode 100644 index f20f15217..000000000 --- a/src/main/java/de/kittybot/kittybot/slashcommands/interaction/response/InteractionResponseType.java +++ /dev/null @@ -1,21 +0,0 @@ -package de.kittybot.kittybot.slashcommands.interaction.response; - -public enum InteractionResponseType{ - - PONG(1), - ACKNOWLEDGE(2), - ACKNOWLEDGE_WITH_SOURCE(5), - CHANNEL_MESSAGE(3), - CHANNEL_MESSAGE_WITH_SOURCE(4); - - private final int type; - - InteractionResponseType(int type){ - this.type = type; - } - - public int getType(){ - return this.type; - } - -} diff --git a/src/main/java/de/kittybot/kittybot/utils/EmoteHelper.java b/src/main/java/de/kittybot/kittybot/utils/EmoteHelper.java index 2c74e470d..18551fcd5 100644 --- a/src/main/java/de/kittybot/kittybot/utils/EmoteHelper.java +++ b/src/main/java/de/kittybot/kittybot/utils/EmoteHelper.java @@ -1,9 +1,9 @@ package de.kittybot.kittybot.utils; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; -import de.kittybot.kittybot.slashcommands.interaction.response.InteractionResponse; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; import net.dv8tion.jda.api.entities.Icon; +import java.awt.Color; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; @@ -15,33 +15,33 @@ public class EmoteHelper{ private EmoteHelper(){} - public static void createEmote(GuildInteraction ia, String name, long emoteId, boolean animated){ - createEmote(ia, name, "https://cdn.discordapp.com/emojis/" + emoteId + "." + (animated ? "gif" : "png")); + public static void createEmote(GuildCommandContext ctx, String name, long emoteId, boolean animated){ + createEmote(ctx, name, "https://cdn.discordapp.com/emojis/" + emoteId + "." + (animated ? "gif" : "png")); } - public static void createEmote(GuildInteraction ia, String name, String url){ + public static void createEmote(GuildCommandContext ctx, String name, String url){ try{ - createEmote(ia, name, new URL(url).openStream()); + createEmote(ctx, name, new URL(url).openStream()); } catch(MalformedURLException e){ - ia.error("Please provide a valid url or emote id"); + ctx.error("Please provide a valid url or emote id"); } catch(IOException e){ - ia.error("Error creating emote please try again\nError: " + e.getMessage()); + ctx.error("Error creating emote please try again\nError: " + e.getMessage()); } } - public static void createEmote(GuildInteraction ia, String name, InputStream inputStream){ - ia.reply(new InteractionResponse.Builder().ephemeral().setContent("processing...").build()); + public static void createEmote(GuildCommandContext ctx, String name, InputStream inputStream){ + ctx.replyEphemeral("processing..."); try{ if(inputStream.available() > MAX_EMOTE_SIZE){ - ia.followup("The image provided is bigger than 256kb"); + ctx.getHook().sendMessage("").addEmbeds(ctx.getEmbed().setColor(Color.RED).setDescription("The image provided is bigger than 256kb").build()).queue(); return; } - ia.getGuild().createEmote(name, Icon.from(inputStream)).queue(success -> ia.followup("Stole emote: " + success.getAsMention()), failure -> ia.followup("Error creating emote: " + failure.getMessage())); + ctx.getGuild().createEmote(name, Icon.from(inputStream)).queue(success -> ctx.getHook().sendMessage("").addEmbeds(ctx.getEmbed().setColor(Color.RED).setDescription("Stole emote: " + success.getAsMention()).build()).queue(), failure -> ctx.getHook().sendMessage("").addEmbeds(ctx.getEmbed().setColor(Color.RED).setDescription("Error creating emote: " + failure.getMessage()).build()).queue()); } catch(IOException e){ - ia.followup("Error creating emote please try again\nError: " + e.getMessage()); + ctx.getHook().sendMessage("").addEmbeds(ctx.getEmbed().setColor(Color.RED).setDescription("Error creating emote please try again\nError: " + e.getMessage()).build()).queue(); } } diff --git a/src/main/java/de/kittybot/kittybot/utils/MusicUtils.java b/src/main/java/de/kittybot/kittybot/utils/MusicUtils.java index 0764e31ac..946aa5f84 100644 --- a/src/main/java/de/kittybot/kittybot/utils/MusicUtils.java +++ b/src/main/java/de/kittybot/kittybot/utils/MusicUtils.java @@ -5,7 +5,7 @@ import de.kittybot.kittybot.modules.SettingsModule; import de.kittybot.kittybot.objects.module.Modules; import de.kittybot.kittybot.objects.music.TrackScheduler; -import de.kittybot.kittybot.slashcommands.interaction.GuildInteraction; +import de.kittybot.kittybot.slashcommands.GuildCommandContext; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.TextChannel; @@ -39,31 +39,31 @@ public static String formatTrack(AudioTrack track){ return MessageUtils.maskLink("`" + info.title + "`", info.uri); } - public static boolean checkCommandRequirements(GuildInteraction ia, TrackScheduler scheduler){ + public static boolean checkCommandRequirements(GuildCommandContext ctx, TrackScheduler scheduler){ if(scheduler == null){ - ia.error("No active player found"); + ctx.error("No active player found"); return false; } - return checkMusicRequirements(ia); + return checkMusicRequirements(ctx); } - public static boolean checkMusicRequirements(GuildInteraction ia){ - var voiceState = ia.getMember().getVoiceState(); + public static boolean checkMusicRequirements(GuildCommandContext ctx){ + var voiceState = ctx.getMember().getVoiceState(); if(voiceState == null || voiceState.getChannel() == null){ - ia.error("Please connect to a voice channel to use music commands"); + ctx.error("Please connect to a voice channel to use music commands"); return false; } - var myVoiceState = ia.getSelfMember().getVoiceState(); + var myVoiceState = ctx.getSelfMember().getVoiceState(); if(myVoiceState != null && myVoiceState.getChannel() != null && voiceState.getChannel().getIdLong() != myVoiceState.getChannel().getIdLong()){ - ia.error("Please connect to the same voice channel as me to use music commands"); + ctx.error("Please connect to the same voice channel as me to use music commands"); return false; } return true; } - public static boolean checkMusicPermissions(GuildInteraction ia, TrackScheduler scheduler){ - var member = ia.getMember(); - if(member.hasPermission(Permission.ADMINISTRATOR) || ia.get(SettingsModule.class).hasDJRole(member)){ + public static boolean checkMusicPermissions(GuildCommandContext ctx, TrackScheduler scheduler){ + var member = ctx.getMember(); + if(member.hasPermission(Permission.ADMINISTRATOR) || ctx.get(SettingsModule.class).hasDJRole(member)){ return true; } var track = scheduler.getPlayingTrack(); @@ -71,7 +71,7 @@ public static boolean checkMusicPermissions(GuildInteraction ia, TrackScheduler return false; } if(track.getUserData(Long.class) != member.getIdLong()){ - ia.error("You are not the song requester or the DJ"); + ctx.error("You are not the song requester or the DJ"); return false; } return true; diff --git a/src/main/java/de/kittybot/kittybot/web/commands/GetCommandsRoute.java b/src/main/java/de/kittybot/kittybot/web/commands/GetCommandsRoute.java index a1564cc60..075d433d7 100644 --- a/src/main/java/de/kittybot/kittybot/web/commands/GetCommandsRoute.java +++ b/src/main/java/de/kittybot/kittybot/web/commands/GetCommandsRoute.java @@ -26,7 +26,7 @@ public GetCommandsRoute(Modules modules){ public void handle(@NotNull Context ctx){ var categories = DataArray.fromCollection(Arrays.stream(Category.values()).map(Category::toJSON).collect(Collectors.toList())); - var commands = DataArray.fromCollection(this.modules.get(CommandsModule.class).getCommands().values().stream().map(Command::toDetailedJSON).collect(Collectors.toList())); + var commands = DataArray.fromCollection(this.modules.get(CommandsModule.class).getCommands().values().stream().map(Command::toJSON).collect(Collectors.toList())); WebModule.ok(ctx, DataObject.empty().put("categories", categories).put("commands", commands)); }