|
| 1 | +package technobot.commands.greetings; |
| 2 | + |
| 3 | +import net.dv8tion.jda.api.Permission; |
| 4 | +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; |
| 5 | +import net.dv8tion.jda.api.interactions.commands.OptionMapping; |
| 6 | +import net.dv8tion.jda.api.interactions.commands.OptionType; |
| 7 | +import net.dv8tion.jda.api.interactions.commands.build.OptionData; |
| 8 | +import technobot.TechnoBot; |
| 9 | +import technobot.commands.Category; |
| 10 | +import technobot.commands.Command; |
| 11 | +import technobot.data.GuildData; |
| 12 | +import technobot.handlers.GreetingHandler; |
| 13 | +import technobot.util.embeds.EmbedUtils; |
| 14 | + |
| 15 | +/** |
| 16 | + * Command that configures auto join DMs. |
| 17 | + * |
| 18 | + * @author TechnoVision |
| 19 | + */ |
| 20 | +public class JoinDMCommand extends Command { |
| 21 | + |
| 22 | + public JoinDMCommand(TechnoBot bot) { |
| 23 | + super(bot); |
| 24 | + this.name = "join-dm"; |
| 25 | + this.description = "Sets a message to be private messaged when a member joins."; |
| 26 | + this.category = Category.GREETINGS; |
| 27 | + this.args.add(new OptionData(OptionType.STRING, "message", "The message to send as a DM")); |
| 28 | + this.permission = Permission.MANAGE_SERVER; |
| 29 | + } |
| 30 | + |
| 31 | + @Override |
| 32 | + public void execute(SlashCommandInteractionEvent event) { |
| 33 | + event.deferReply().queue(); |
| 34 | + GreetingHandler greetingHandler = GuildData.get(event.getGuild()).greetingHandler; |
| 35 | + OptionMapping farewellOption = event.getOption("message"); |
| 36 | + |
| 37 | + // Remove farewell message |
| 38 | + if (farewellOption == null) { |
| 39 | + greetingHandler.removeJoinDM(); |
| 40 | + String text = EmbedUtils.BLUE_X + " Join DM message successfully removed!"; |
| 41 | + event.getHook().sendMessageEmbeds(EmbedUtils.createDefault(text)).queue(); |
| 42 | + return; |
| 43 | + } |
| 44 | + |
| 45 | + // Set greeting message |
| 46 | + greetingHandler.setJoinDM(farewellOption.getAsString()); |
| 47 | + String text = EmbedUtils.BLUE_TICK + " Join DM message successfully updated!"; |
| 48 | + event.getHook().sendMessageEmbeds(EmbedUtils.createDefault(text)).queue(); |
| 49 | + } |
| 50 | +} |
0 commit comments