1
0
mirror of https://github.com/sciwhiz12/Janitor.git synced 2024-11-10 03:21:26 +00:00

Add shutdown command

This commit is contained in:
Arnold Alejo Nunag 2020-09-01 16:57:22 +08:00
parent 079d1d37e7
commit 1f2668458a
Signed by: sciwhiz12
GPG Key ID: 622CF446534317E1
2 changed files with 27 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import net.dv8tion.jda.api.requests.GatewayIntent;
import sciwhiz12.janitor.commands.CommandRegistry;
import sciwhiz12.janitor.commands.OKCommand;
import sciwhiz12.janitor.commands.PingCommand;
import sciwhiz12.janitor.commands.ShutdownCommand;
import javax.security.auth.login.LoginException;
@ -40,6 +41,9 @@ public class JanitorBot {
.accepts("token", "The Discord token for the bot user").withRequiredArg().required();
ArgumentAcceptingOptionSpec<String> prefix = parser
.accepts("prefix", "The prefix for commands").withRequiredArg().defaultsTo("!");
ArgumentAcceptingOptionSpec<Long> owner = parser.accepts("owner",
"The snowflake ID of the bot owner; Used for shutdowns and other bot management commands")
.withRequiredArg().ofType(Long.class);
OptionSet options = parser.parse(args);
@ -55,6 +59,9 @@ public class JanitorBot {
INSTANCE.getCommandRegistry().addCommand("ping", new PingCommand());
INSTANCE.getCommandRegistry().addCommand("ok", new OKCommand());
if (options.has(owner)) {
INSTANCE.getCommandRegistry().addCommand("shutdown", new ShutdownCommand(owner.value(options)));
}
System.out.println("Ready! Invite URL: " + inviteURL);
}

View File

@ -0,0 +1,20 @@
package sciwhiz12.janitor.commands;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import sciwhiz12.janitor.JanitorBot;
public class ShutdownCommand implements ICommand {
private final long ownerID;
public ShutdownCommand(long ownerID) {
this.ownerID = ownerID;
}
@Override
public void onCommand(JanitorBot bot, MessageReceivedEvent event) {
if (event.getAuthor().getIdLong() == ownerID) {
event.getMessage().getChannel().sendMessage("Shutting down. Goodbye!").queue();
event.getJDA().shutdown();
}
}
}