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:
parent
079d1d37e7
commit
1f2668458a
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user