Skip to content

Commit 150d3d8

Browse files
Add the /join-dm command
1 parent a197715 commit 150d3d8

3 files changed

Lines changed: 53 additions & 1 deletion

File tree

src/main/java/technobot/commands/CommandRegistry.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import technobot.commands.greetings.FarewellCommand;
1414
import technobot.commands.greetings.GreetCommand;
1515
import technobot.commands.greetings.GreetingsCommand;
16+
import technobot.commands.greetings.JoinDMCommand;
1617
import technobot.commands.levels.*;
1718
import technobot.commands.music.*;
1819
import technobot.commands.staff.*;
@@ -49,6 +50,7 @@ public CommandRegistry(TechnoBot bot) {
4950
//Greeting commands
5051
new GreetCommand(bot),
5152
new FarewellCommand(bot),
53+
new JoinDMCommand(bot),
5254
new GreetingsCommand(bot),
5355

5456
//Fun commands

src/main/java/technobot/commands/greetings/FarewellCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import technobot.util.embeds.EmbedUtils;
1414

1515
/**
16-
* Command that configures auto greetings.
16+
* Command that configures auto farewells.
1717
*
1818
* @author TechnoVision
1919
*/
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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

Comments
 (0)