From 0be43894481cecb2af22ca6b394c16b48fe897a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beatrice=20Dellac=C3=A0?= Date: Wed, 21 Dec 2022 03:50:16 +0100 Subject: [PATCH] Disable trivia in dms --- .../hidekobot/commands/message/TriviaCommand.java | 12 ++++++++++-- .../wtf/beatrice/hidekobot/runnables/TriviaTask.java | 10 ++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 src/main/java/wtf/beatrice/hidekobot/runnables/TriviaTask.java diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/message/TriviaCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/message/TriviaCommand.java index a5dfceb..eea50ae 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/message/TriviaCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/message/TriviaCommand.java @@ -3,6 +3,8 @@ package wtf.beatrice.hidekobot.commands.message; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Message; +import net.dv8tion.jda.api.entities.channel.Channel; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.interactions.components.buttons.Button; import org.jetbrains.annotations.NotNull; @@ -14,7 +16,6 @@ import wtf.beatrice.hidekobot.objects.commands.CommandCategory; import wtf.beatrice.hidekobot.objects.commands.MessageCommand; import wtf.beatrice.hidekobot.util.TriviaUtil; -import java.nio.channels.ScatteringByteChannel; import java.util.ArrayList; import java.util.Collections; import java.util.LinkedList; @@ -61,8 +62,15 @@ public class TriviaCommand implements MessageCommand @Override public void runCommand(MessageReceivedEvent event, String label, String[] args) { + Channel channel = event.getChannel(); - if(TriviaUtil.channelsRunningTrivia.contains(event.getChannel().getId())) + if(!(channel instanceof TextChannel)) + { + event.getMessage().reply("\uD83D\uDE22 Sorry! Trivia doesn't work in DMs.").queue(); + return; + } + + if(TriviaUtil.channelsRunningTrivia.contains(channel.getId())) { // todo nicer looking // todo: also what if the bot stops (database...?) diff --git a/src/main/java/wtf/beatrice/hidekobot/runnables/TriviaTask.java b/src/main/java/wtf/beatrice/hidekobot/runnables/TriviaTask.java new file mode 100644 index 0000000..3372c88 --- /dev/null +++ b/src/main/java/wtf/beatrice/hidekobot/runnables/TriviaTask.java @@ -0,0 +1,10 @@ +package wtf.beatrice.hidekobot.runnables; + +public class TriviaTask implements Runnable +{ + + @Override + public void run() { + + } +}