Skip to content

Commit a197715

Browse files
Add the /farewell command
1 parent fb4a86a commit a197715

5 files changed

Lines changed: 57 additions & 7 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.jetbrains.annotations.NotNull;
1111
import technobot.TechnoBot;
1212
import technobot.commands.fun.*;
13+
import technobot.commands.greetings.FarewellCommand;
1314
import technobot.commands.greetings.GreetCommand;
1415
import technobot.commands.greetings.GreetingsCommand;
1516
import technobot.commands.levels.*;
@@ -47,6 +48,7 @@ public CommandRegistry(TechnoBot bot) {
4748
mapCommand(
4849
//Greeting commands
4950
new GreetCommand(bot),
51+
new FarewellCommand(bot),
5052
new GreetingsCommand(bot),
5153

5254
//Fun commands
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 greetings.
17+
*
18+
* @author TechnoVision
19+
*/
20+
public class FarewellCommand extends Command {
21+
22+
public FarewellCommand(TechnoBot bot) {
23+
super(bot);
24+
this.name = "farewell";
25+
this.description = "Sets a farewell to be sent to the welcome channel when a member leaves.";
26+
this.category = Category.GREETINGS;
27+
this.args.add(new OptionData(OptionType.STRING, "message", "The message to send as a farewell"));
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.removeFarewell();
40+
String text = EmbedUtils.BLUE_X + " Farewell message successfully removed!";
41+
event.getHook().sendMessageEmbeds(EmbedUtils.createDefault(text)).queue();
42+
return;
43+
}
44+
45+
// Set greeting message
46+
greetingHandler.setFarewell(farewellOption.getAsString());
47+
String text = EmbedUtils.BLUE_TICK + " Farewell message successfully updated!";
48+
event.getHook().sendMessageEmbeds(EmbedUtils.createDefault(text)).queue();
49+
}
50+
}

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package technobot.commands.greetings;
22

33
import net.dv8tion.jda.api.Permission;
4-
import net.dv8tion.jda.api.entities.Guild;
54
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
65
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
76
import net.dv8tion.jda.api.interactions.commands.OptionType;
@@ -25,16 +24,15 @@ public GreetCommand(TechnoBot bot) {
2524
this.name = "greet";
2625
this.description = "Sets a message to be sent to the welcome channel when a member joins.";
2726
this.category = Category.GREETINGS;
28-
this.args.add(new OptionData(OptionType.STRING, "greeting", "The message to send as a greeting"));
27+
this.args.add(new OptionData(OptionType.STRING, "message", "The message to send as a greeting"));
2928
this.permission = Permission.MANAGE_SERVER;
3029
}
3130

3231
@Override
3332
public void execute(SlashCommandInteractionEvent event) {
3433
event.deferReply().queue();
35-
Guild guild = event.getGuild();
36-
GreetingHandler greetingHandler = GuildData.get(guild).greetingHandler;
37-
OptionMapping greetingOption = event.getOption("greeting");
34+
GreetingHandler greetingHandler = GuildData.get(event.getGuild()).greetingHandler;
35+
OptionMapping greetingOption = event.getOption("message");
3836

3937
// Remove greeting message
4038
if (greetingOption == null) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ private String configToString(Greetings greetings) {
7979
if (greetings.getGreeting() == null) {
8080
text += "**Greeting:** none\n";
8181
} else {
82-
text += "**Greeting:** '" + greetings.getGreeting() + "'\n";
82+
text += "**Greeting:** " + greetings.getGreeting() + "\n";
8383
}
8484
if (greetings.getFarewell() == null) {
8585
text += "**Farewell:** none\n";

src/main/java/technobot/handlers/GreetingHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void setFarewell(String msg) {
7373
* Remove farewell message from this server.
7474
*/
7575
public void removeFarewell() {
76-
greetings.setGreeting(null);
76+
greetings.setFarewell(null);
7777
bot.database.greetings.updateOne(filter, Updates.unset("farewell"));
7878
}
7979

0 commit comments

Comments
 (0)