From 016f14c75aeae04532486307dac100b398b06014 Mon Sep 17 00:00:00 2001
From: beanbeanjuice
Date: Tue, 26 Jul 2022 19:07:12 -0400
Subject: [PATCH 1/9] Updated FUNDING.yml and Created Small README
---
.github/FUNDING.yml | 2 +-
README-small.md | 204 ++++++++++++++++++++++++++++++++++++++++++++
README.md | 5 ++
3 files changed, 210 insertions(+), 1 deletion(-)
create mode 100644 README-small.md
diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml
index 5d017fac..154de1de 100644
--- a/.github/FUNDING.yml
+++ b/.github/FUNDING.yml
@@ -9,4 +9,4 @@
# liberapay: # Replace with a single Liberapay username
# issuehunt: # Replace with a single IssueHunt username
# otechie: # Replace with a single Otechie username
-custom: ['https://streamelements.com/beanbeanjuice/tip']
\ No newline at end of file
+custom: ['https://www.buymeacoffee.com/beanbeanjuice']
\ No newline at end of file
diff --git a/README-small.md b/README-small.md
new file mode 100644
index 00000000..a6868402
--- /dev/null
+++ b/README-small.md
@@ -0,0 +1,204 @@
+
+[![Contributors][contributors-shield]][contributors-url]
+[![Forks][forks-shield]][forks-url]
+[![Stargazers][stars-shield]][stars-url]
+[![CodeFactor][codefactor-shield]][codefactor-url]
+![GitHub release (latest by date)](https://img.shields.io/github/v/release/beanbeanjuice/cafebot?style=for-the-badge)
+
+
+
+
+
+
+
+
+
cafeBot
+
+
+ A cafe bot for your discord server!
+
+ Explore the Docs »
+
+
+ View Demo
+ ·
+ Report Bug
+ ·
+ Request Feature
+
+
+
+
+
+
+
+
+
+
+ Table of Contents
+
+ -
+ About The Project
+
+
+ -
+ Getting Started
+
+
+ - Usage
+ - Roadmap
+ - Contributing
+ - License
+ - What data does this bot store?
+ - Contact
+ - Acknowledgements
+
+
+
+
+# About The Project
+
+[![Product Name Screen Shot][product-title]](https://www.beanbeanjuice.com/cafeBot.html)
+
+### About the Bot
+`cafeBot`, formerly `beanBot` is a general purpose bot that has many features. Many features work across Discord servers. Some features include;
+* Global Birthday Checker
+* Global Currency
+* Global Counting Leaderboard (Only Tells You What Place Number You Are In)
+* Interaction Commands
+* Moderation Commands
+* Poll/Raffle Commands
+* Bind Roles to Voice Channels
+* AI Responses to Certain Words/Phrases
+* And more to come...
+
+
+# Usage
+
+#### **The Help Command**
+* `/help` - Shows a list of command section.
+* `/help (command section name)` - Shows a list of commands in that section.
+* `/help (command name/alias)` - Shows how to use the command.
+* `/get-prefix` - Gets the current prefix for the server if you forget it!
+
+
+
+
+
+As you can see, this was shown using the command `/help order`. It shows each parameter you can run. For example, the first `` is the `CATEGORY NUMBER` for the menu, needs to be a number, and is required. The `help` command also provides an example on how to actually use the command if you are stuck!
+
+#### **Command Section**
+*There are many command sections, with more coming soon. To show the commands in a specific section, do `!!help (command section)` or for example, `!!help moderation`!* Doing `!!help (command)` will also show you an example of how to use the command.
+
+##### 1. **GENERIC**
+* `bot-donate` - Donate for the bot!
+* `bot-invite` - A command to get an invite link for the bot!
+* `bot-upvote` - Upvote the bot!
+* `bot-version` - Gets a specific/the latest release notes for the bot!
+* `bug-report` - Report a bug with the bot.
+* `define` - Define a word!
+* `feature-request` - Request a bot feature.
+* `generate-code` - Generate a random 32-digit long code!
+* `help` - Shows the list of command sections and command list for those sections.
+* `info` - Show information about the bot!
+* `ping` - Show technical information about the bot!
+* `remove-my-data` - Request to remove your data from the bot!
+* `stats` - Show statistics such as commands run, current servers, and users!
+* `support` - Get support for the bot!
+* `user-info` - Get user information about someone.
+##### 2. **CAFE**
+* `balance` - Check your balance!
+* `donate-beancoins` - Donate some of your `beanCoins` to someone! (Only up to 25 every hour though!)
+* `menu` - Show the list of Cafe menu items.
+* `order` - Order a menu item for someone!
+* `serve` - Get beanCoins! Essentially you run this command by doing `/serve (dictionary word)`! This must be an english word. The longer the word, the more money you get. However, the more popular the word is, the less money you will get for it.
+##### 3. **FUN**
+* `avatar` - Get yours or someone else's avatar image!
+* `banner` - Get yours or someone else's profile banner!
+* `birthday` - Add, change, or remove your birthday! Even get someone else's birthday!
+* `coffee-meme` - Get a coffee meme!
+* `counting-statistics` - Get counting information for your server!
+* `joke` - Send a joke in the current channel. (SFW)
+* `meme` - Send a meme in the current channel. (SFW)
+* `rate` - Rate the percentages of someone! (*somewhat* NSFW)
+* `snipe` - Snipe a recently deleted message! (30 Seconds)
+* `tea-meme` - Get a tea meme!
+##### 4. **GAMES**
+* `8-ball` - Ask a yes or no question!
+* `coin-flip` - Flip a coin!
+* `connect-4` - Play connect four with someone!
+* `dice-roll` - Roll a dice!
+* `get-game-data` - See your win streaks for the mini-games that support it!
+* `tic-tac-toe` - Play tic tac toe with someone!
+##### 5. **SOCIAL**
+* `member-count` - Get the member count for your server!
+* `vent` - Anonymously vent to the server! ~~If the server has anonymous venting enabled...~~
+##### 6. **INTERACTION**
+* `bite` - Bite someone!
+* `blush` - Blush at someone!
+* `bonk` - Bonk someone! Send them to `h o r n i` jail.
+* `cry` - Cry at someone!
+* `cuddle` - Cuddle someone!
+* `dab` - Dab at someone!
+* `dance` - Dance with someone!
+* `die` - Just straight up die.
+* `headpat` - Give head pats to someone!
+* `hmph` - Hmph at someone!
+* `hug` - Hug someone!
+* `kiss` - Kiss someone!
+* `lick` - Lick... someone... ummm why?
+* `nom` - Nom at someone!
+* `poke` - Poke someone!
+* `pout` - Pout at someone!
+* `punch` - Punch someone!
+* `rage` - Rage at someone!
+* `shush` - Shush someone if they're being too loud!
+* `slap` - Slap someone!
+* `sleep` - Sleep! (Or sleep with someone...)
+* `smile` - Smile at someone!
+* `stab` - Stab someone! :O
+* `stare` - Stare at someone!
+* `throw` - Throw someone!
+* `tickle` - Tickle someone!
+* `welcome` - Welcome someone... for something!
+* `yell` - Yell at someone!
+##### 7. **TWITCH**
+* `twitch-channel` - Add or remove a twitch channel to receive notifications for!
+##### 8. **MODERATION**
+* `add-poll` - Create a poll! Currently, you can only have 3 polls due to server costs. This will go up in the future!
+* `add-raffle` - Create a raffle! Currently, you can only have 3 raffles due to server costs. This will go up in the future!
+* `bind` - Bind a role to a voice channel! This gives the user a role when they enter a voice channel, and removes it when they leave.
+* `clear-chat` - Clear the chat. (Only currently works from 2-99 messages).
+* `create-embed` - Send a customised `embedded message` in a specified channel!
+##### 9. **SETTINGS**
+* `birthday-channel` - Set or remove the birthday channel for the server!
+* `ai` - Sets the `AI Status` for the server. This can `enable` or `disable` the AI module. This is `disable` by default.
+* `bot-update` - `enable` or `disable` bot notifications. This is `enabled` by default.
+* `counting-channel` - Set or remove the counting channel. Users in this channel can count. You can also apply a custom role when a user sucks at counting!
+* `daily-channel` - Set or remove the daily channel. This channel resets daily!
+* `list-custom-channels` - Lists all of the custom channels in the server.
+* `log-channel` - Set or remove the log channel. If enabled, some logs will be sent to this channel.
+* `poll-channel` - Set or remove the poll channel. If enabled, created polls will be sent to this channel.
+* `raffle-channel` - Set or remove the raffle channel. If enabled, created raffles will be sent to this channel.
+* `twitch-notifications` - Set or remove the twitch notifications channel. If enabled, you will receive notifications for specified channels that you have added.
+* `venting-channel` - Set or remove the venting channel. If enabled, this will allow users to anonymously vent.
+* `welcome-channel` - Set or remove the welcome channel. If enabled, it will welcome users with a cute message when they join the server.
+##### 10. **EXPERIMENTAL**
+* `Nothing here yet!`
+
+
+
+[contributors-shield]: https://img.shields.io/github/contributors/beanbeanjuice/cafeBot.svg?style=for-the-badge
+[contributors-url]: https://github.com/beanbeanjuice/cafeBot/graphs/contributors
+[forks-shield]: https://img.shields.io/github/forks/beanbeanjuice/cafeBot.svg?style=for-the-badge
+[forks-url]: https://github.com/beanbeanjuice/cafeBot/network/members
+[stars-shield]: https://img.shields.io/github/stars/beanbeanjuice/cafeBot.svg?style=for-the-badge
+[stars-url]: https://github.com/beanbeanjuice/cafeBot/stargazers
+[product-title]: https://cdn.beanbeanjuice.com/images/cafeBot/readme/cafeBot.png
+[codefactor-shield]: https://www.codefactor.io/repository/github/beanbeanjuice/cafebot/badge?style=for-the-badge
+[codefactor-url]: https://www.codefactor.io/repository/github/beanbeanjuice/cafebot
\ No newline at end of file
diff --git a/README.md b/README.md
index 7ec4b993..1e42a6f8 100644
--- a/README.md
+++ b/README.md
@@ -35,6 +35,11 @@
+
+
+
+
+
From 3fc4491e7619f750682700af5ae7babf2082317b Mon Sep 17 00:00:00 2001
From: beanbeanjuice
Date: Tue, 26 Jul 2022 19:11:52 -0400
Subject: [PATCH 2/9] Updated README GIF for cafeBot
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 1e42a6f8..f464defd 100644
--- a/README.md
+++ b/README.md
@@ -13,7 +13,7 @@
-
+
cafeBot
From 0af58fa3563919615825f9a3a415bed44edb6d04 Mon Sep 17 00:00:00 2001
From: beanbeanjuice
Date: Fri, 29 Jul 2022 22:40:10 -0400
Subject: [PATCH 3/9] Fixed the Clear-Chat Command
The command will now notify the user when it has insufficient
permissions. Additionally, it has been completely refactored and
simplified. It no longer requires a timer task. Everything is done
async.
---
.../command/moderation/ClearChatCommand.java | 114 +++---------------
.../utility/handler/guild/CustomGuild.java | 34 ------
2 files changed, 17 insertions(+), 131 deletions(-)
diff --git a/src/main/java/com/beanbeanjuice/command/moderation/ClearChatCommand.java b/src/main/java/com/beanbeanjuice/command/moderation/ClearChatCommand.java
index feaad2bc..b33bfd18 100644
--- a/src/main/java/com/beanbeanjuice/command/moderation/ClearChatCommand.java
+++ b/src/main/java/com/beanbeanjuice/command/moderation/ClearChatCommand.java
@@ -2,122 +2,43 @@
import com.beanbeanjuice.utility.command.CommandCategory;
import com.beanbeanjuice.utility.command.ICommand;
-import com.beanbeanjuice.utility.handler.guild.CustomGuild;
-import com.beanbeanjuice.utility.handler.guild.GuildHandler;
import com.beanbeanjuice.utility.helper.Helper;
-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.MessageEmbed;
-import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
-import net.dv8tion.jda.api.exceptions.ErrorHandler;
-import net.dv8tion.jda.api.exceptions.ErrorResponseException;
+import net.dv8tion.jda.api.exceptions.InsufficientPermissionException;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import java.awt.*;
import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Timer;
-import java.util.TimerTask;
/**
* An {@link ICommand} used to clear a {@link net.dv8tion.jda.api.entities.TextChannel TextChannel}.
*
* @author beanbeanjuice
+ * @since v3.1.1
*/
public class ClearChatCommand implements ICommand {
@Override
public void handle(@NotNull SlashCommandInteractionEvent event) {
- if (GuildHandler.getCustomGuild(event.getGuild()).containsTextChannelDeletingMessages(event.getTextChannel())) {
- event.getHook().sendMessageEmbeds(alreadyDeletingMessagesEmbed()).queue();
- return;
- }
-
int amount = event.getOption("amount").getAsInt();
- // Send message that it is deleting, save the message and exclude it from being deleted.
- event.getHook().sendMessageEmbeds(beginDeletionEmbed(amount)).queue(e -> {
-
- // +1 is needed because it removes the one just sent.
- event.getChannel().getHistory().retrievePast(amount+1).queue(messages -> {
- messages.remove(e);
- startMessagesDeletions(new ArrayList<>(messages), e);
- });
- });
- }
-
- private MessageEmbed beginDeletionEmbed(@NotNull Integer amount) {
- return new EmbedBuilder()
- .setTitle("Starting Deletion")
- .setColor(Helper.getRandomColor())
- .setDescription("Deleting `" + amount + "` messages. This might take a while.")
- .build();
- }
-
- private MessageEmbed alreadyDeletingMessagesEmbed() {
- return new EmbedBuilder()
- .setTitle("Already Deleting Messages")
- .setDescription("You are already deleting messages in this channel. " +
- "Please use this command in another channel or wait for this action to stop.")
- .setColor(Color.red)
- .build();
- }
-
- private void startMessagesDeletions(@NotNull ArrayList messages, @NotNull Message deletionMessage) {
-
- Collections.reverse(messages);
-
- TextChannel textChannel = deletionMessage.getTextChannel();
- int messageCount = messages.size();
- CustomGuild guild = GuildHandler.getCustomGuild(deletionMessage.getGuild());
-
- guild.addTextChannelToDeletingMessages(deletionMessage.getTextChannel());
-
- Timer timer = new Timer();
- TimerTask timerTask = new TimerTask() {
-
- int count = 0;
-
- @Override
- public void run() {
-
- Message message = messages.get(count++);
-
- // Go through each message and delete it individually. Ignores the error response it might get.
- message.delete().queue(null, new ErrorHandler().ignore(ErrorResponseException.class));
-
- // If the messages is empty, cancel it.
- if (count == messageCount) {
- timer.cancel(); // Cancel the timer.
- textChannel.sendMessageEmbeds(completedDeletionEmbed(messageCount)).queue(e -> {
- try {
- // Makes the thread sleep for 10 seconds.
- Thread.sleep(10000);
- } catch (InterruptedException ignored) {}
-
- // Removes the current channel from channels having current deletions in it.
- guild.removeTextChannelFromDeletingMessages(e.getTextChannel());
- e.delete().queue();
- });
- }
- }
- };
- timer.scheduleAtFixedRate(timerTask, 0, 50);
- }
-
- private MessageEmbed completedDeletionEmbed(@NotNull Integer count) {
- return new EmbedBuilder()
- .setTitle("Completed Deletion")
- .setDescription("Successfully deleted `" + count + "` messages. " +
- "There might be a time lag for deleting messages. This message will disappear once " +
- "all of the messages have been successfully deleted from discord.")
- .setColor(Helper.getRandomColor())
- .build();
+ try {
+ event.getMessageChannel().getIterableHistory().takeAsync(amount)
+ .thenApply(messages -> event.getChannel().purgeMessages(messages));
+ event.getHook().sendMessageEmbeds(Helper.successEmbed(
+ "Deleting Messages",
+ "Attempting to delete `" + amount + "` messages. This might take a while..."
+ )).queue();
+ } catch (InsufficientPermissionException e) {
+ event.getHook().sendMessageEmbeds(Helper.errorEmbed(
+ "Error Deleting Messages",
+ "There was an error deleting your messages. The " +
+ "bot may have insufficient permissions. `" + e.getMessage() + "`"
+ )).queue();
+ }
}
@NotNull
@@ -136,8 +57,7 @@ public String exampleUsage() {
@Override
public ArrayList getOptions() {
ArrayList options = new ArrayList<>();
- options.add(new OptionData(OptionType.INTEGER, "amount", "The number of messages to clear.", true, false)
- .setRequiredRange(1, 99));
+ options.add(new OptionData(OptionType.INTEGER, "amount", "The number of messages to clear.", true));
return options;
}
diff --git a/src/main/java/com/beanbeanjuice/utility/handler/guild/CustomGuild.java b/src/main/java/com/beanbeanjuice/utility/handler/guild/CustomGuild.java
index a255af25..2af39844 100644
--- a/src/main/java/com/beanbeanjuice/utility/handler/guild/CustomGuild.java
+++ b/src/main/java/com/beanbeanjuice/utility/handler/guild/CustomGuild.java
@@ -32,8 +32,6 @@ public class CustomGuild {
private Boolean notifyOnUpdate;
private Boolean aiState;
- private final ArrayList deletingMessagesChannels;
-
private final HashMap customChannelIDs;
/**
@@ -84,8 +82,6 @@ public CustomGuild(@NotNull String guildID, @NotNull String prefix, @NotNull Str
// Checks if a Listener has already been created for that guild.
// This is so that if the cache is reloaded, it does not need to recreate the Listeners.
TwitchHandler.addTwitchChannels(guildID, this.twitchChannels);
-
- deletingMessagesChannels = new ArrayList<>();
}
/**
@@ -431,36 +427,6 @@ public Role getLiveNotificationsRole() {
return GuildHandler.getGuild(guildID).getRoleById(liveNotificationsRoleID);
}
- /**
- * Remove a {@link TextChannel} from the list of currently deleting {@link Message}s.
- *
- * @param channel The {@link TextChannel} to remove.
- */
- public void removeTextChannelFromDeletingMessages(@NotNull TextChannel channel) {
- deletingMessagesChannels.remove(channel);
- }
-
- /**
- * Add a {@link TextChannel} to the list of currently deleting {@link Message}s.
- *
- * @param channel The {@link TextChannel} to add.
- */
- public void addTextChannelToDeletingMessages(@NotNull TextChannel channel) {
- deletingMessagesChannels.add(channel);
- }
-
- /**
- * Checks to make sure that a {@link TextChannel} does not already have {@link Message}s being
- * currently deleted.
- *
- * @param channel The {@link TextChannel} to check.
- * @return True, if it already has {@link Message}s being deleted in it.
- */
- @NotNull
- public Boolean containsTextChannelDeletingMessages(@NotNull TextChannel channel) {
- return deletingMessagesChannels.contains(channel);
- }
-
/**
* @return The {@link String} ID of the live channel to send messages.
*/
From 61ce1fce40c6d105651f2cb36c2100aa2ebac112 Mon Sep 17 00:00:00 2001
From: beanbeanjuice
Date: Sun, 4 Sep 2022 15:35:14 -0400
Subject: [PATCH 4/9] Fixed the Issue
---
.../fun/birthday/SetBirthdaySubCommand.java | 17 +----------------
1 file changed, 1 insertion(+), 16 deletions(-)
diff --git a/src/main/java/com/beanbeanjuice/command/fun/birthday/SetBirthdaySubCommand.java b/src/main/java/com/beanbeanjuice/command/fun/birthday/SetBirthdaySubCommand.java
index b90b379b..7adfdfe5 100644
--- a/src/main/java/com/beanbeanjuice/command/fun/birthday/SetBirthdaySubCommand.java
+++ b/src/main/java/com/beanbeanjuice/command/fun/birthday/SetBirthdaySubCommand.java
@@ -13,7 +13,6 @@
import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
@@ -69,20 +68,6 @@ public void handle(@NotNull SlashCommandInteractionEvent event) {
}
}
- /**
- * Gets the {@link BirthdayMonth} from a {@link String}.
- * @param month The {@link String} to parse.
- * @return The parsed {@link BirthdayMonth}. Null, if there is an error.
- */
- @Nullable
- private BirthdayMonth getBirthdayMonth(@NotNull String month) {
- for (BirthdayMonth birthdayMonth : BirthdayMonth.values()) {
- if (birthdayMonth.toString().equalsIgnoreCase(month))
- return birthdayMonth;
- }
- return null;
- }
-
@NotNull
@Override
public String getDescription() {
@@ -115,7 +100,7 @@ public ArrayList getOptions() {
options.add(new OptionData(OptionType.INTEGER, "day", "The day you were born in the specified month!", true)
.setRequiredRange(1, 31));
- OptionData timeZoneOptions = new OptionData(OptionType.STRING, "timezone", "The timezone you are in! Start typing to see available options!", true, true);
+ OptionData timeZoneOptions = new OptionData(OptionType.STRING, "timezone", "Start typing to see available options!", true, true);
options.add(timeZoneOptions);
return options;
From 006d19a86314521a2a949529948eb56cf54bec8d Mon Sep 17 00:00:00 2001
From: beanbeanjuice
Date: Sun, 4 Sep 2022 15:43:37 -0400
Subject: [PATCH 5/9] Fixed the Issue
---
.../com/beanbeanjuice/command/cafe/ServeCommand.java | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/src/main/java/com/beanbeanjuice/command/cafe/ServeCommand.java b/src/main/java/com/beanbeanjuice/command/cafe/ServeCommand.java
index a6133545..e69c4f69 100644
--- a/src/main/java/com/beanbeanjuice/command/cafe/ServeCommand.java
+++ b/src/main/java/com/beanbeanjuice/command/cafe/ServeCommand.java
@@ -33,6 +33,15 @@ public class ServeCommand implements ICommand {
@Override
public void handle(@NotNull SlashCommandInteractionEvent event) {
String word = event.getOption("word").getAsString();
+
+ if (word.contains(" ")) {
+ event.getHook().sendMessageEmbeds(Helper.errorEmbed(
+ "Multiple Words Detected",
+ "Please only use singular words when running this command!"
+ )).queue();
+ return;
+ }
+
Word serveWord;
try {
// Checking if the word entered is a word.
From 2dc258b0b208c5346d61e4abb1e49ef0f9c3d8b2 Mon Sep 17 00:00:00 2001
From: beanbeanjuice
Date: Sun, 4 Sep 2022 16:06:11 -0400
Subject: [PATCH 6/9] Attempted Fix
---
.../utility/section/twitch/TwitchHandler.java | 14 ++++++++++----
.../section/twitch/TwitchMessageEventHandler.java | 15 ++++++++++++++-
2 files changed, 24 insertions(+), 5 deletions(-)
diff --git a/src/main/java/com/beanbeanjuice/utility/section/twitch/TwitchHandler.java b/src/main/java/com/beanbeanjuice/utility/section/twitch/TwitchHandler.java
index 87a0c7b0..3650a68c 100644
--- a/src/main/java/com/beanbeanjuice/utility/section/twitch/TwitchHandler.java
+++ b/src/main/java/com/beanbeanjuice/utility/section/twitch/TwitchHandler.java
@@ -19,7 +19,7 @@ public class TwitchHandler {
private static ArrayList alreadyAddedTwitchNames;
private static TwitchListener twitchListener;
- private static HashMap> guildTwitches;
+ private static HashMap> guildTwitches; // Twitch Name, Guild IDs
/**
* Starts the {@link TwitchHandler}.
@@ -54,6 +54,7 @@ public static void addTwitchChannel(@NotNull String twitchUsername) throws Hystr
// Check if the channel exists.
twitchListener.addStream(twitchUsername);
alreadyAddedTwitchNames.add(twitchUsername);
+ Bot.getLogger().log(TwitchHandler.class, LogLevel.DEBUG, "Adding " + twitchUsername); // TODO: Remove
}
}
@@ -65,6 +66,7 @@ public static void addTwitchChannel(@NotNull String twitchUsername) throws Hystr
public static void addTwitchChannels(@NotNull String guildID, @NotNull ArrayList twitchUsernames) {
for (String string : twitchUsernames) {
try {
+ // If the channel does not exist, remove the twitch discord CHANNEL from the database
if (!twitchListener.channelExists(string))
Bot.getCafeAPI().TWITCH.removeGuildTwitch(guildID, string);
else
@@ -99,10 +101,14 @@ private static void cacheTwitchChannels() {
try {
Bot.getCafeAPI().TWITCH.getAllTwitches().forEach((guild, twitchChannels) -> {
twitchChannels.forEach((twitchChannel) -> {
- if (!guildTwitches.containsKey(twitchChannel))
- guildTwitches.put(twitchChannel, new ArrayList<>());
- guildTwitches.get(twitchChannel).add(guild);
+ if (Bot.getBot().getGuildById(guild) != null) {
+ if (!guildTwitches.containsKey(twitchChannel))
+ guildTwitches.put(twitchChannel, new ArrayList<>());
+
+ guildTwitches.get(twitchChannel).add(guild);
+ }
+
});
});
} catch (CafeException e) {
diff --git a/src/main/java/com/beanbeanjuice/utility/section/twitch/TwitchMessageEventHandler.java b/src/main/java/com/beanbeanjuice/utility/section/twitch/TwitchMessageEventHandler.java
index 53771360..92e097b7 100644
--- a/src/main/java/com/beanbeanjuice/utility/section/twitch/TwitchMessageEventHandler.java
+++ b/src/main/java/com/beanbeanjuice/utility/section/twitch/TwitchMessageEventHandler.java
@@ -1,7 +1,9 @@
package com.beanbeanjuice.utility.section.twitch;
+import com.beanbeanjuice.Bot;
import com.beanbeanjuice.utility.handler.guild.CustomGuild;
import com.beanbeanjuice.utility.handler.guild.GuildHandler;
+import com.beanbeanjuice.utility.logging.LogLevel;
import com.github.philippheuer.events4j.simple.SimpleEventHandler;
import com.github.philippheuer.events4j.simple.domain.EventSubscriber;
import com.github.twitch4j.events.ChannelGoLiveEvent;
@@ -28,9 +30,12 @@ public class TwitchMessageEventHandler extends SimpleEventHandler {
@EventSubscriber
public void onChannelGoLive(@NotNull ChannelGoLiveEvent event) {
+
// Converts the Twitch Name to lower case.
String twitchName = event.getChannel().getName().toLowerCase();
+ Bot.getLogger().log(TwitchMessageEventHandler.class, LogLevel.DEBUG, "Starting Live Notification: " + twitchName);
+
// Gets the Guilds that are listening for that twitch name.
ArrayList guilds = TwitchHandler.getGuildsForChannel(twitchName);
@@ -41,7 +46,13 @@ public void onChannelGoLive(@NotNull ChannelGoLiveEvent event) {
// Go through each guild.
for (String guildID : guilds) {
CustomGuild customGuild = GuildHandler.getCustomGuild(guildID);
+
+ Bot.getLogger().log(TwitchMessageEventHandler.class, LogLevel.DEBUG, "Guild Contains Twitch Name: " + twitchName);
+
if (customGuild.getTwitchChannels().contains(twitchName)) {
+
+ Bot.getLogger().log(TwitchMessageEventHandler.class, LogLevel.DEBUG, "Attempting to Send Live Notification: " + twitchName);
+
String liveChannelID = GuildHandler.getCustomGuild(guildID).getLiveChannelID();
TextChannel liveChannel = GuildHandler.getGuild(guildID).getTextChannelById(liveChannelID);
@@ -50,7 +61,7 @@ public void onChannelGoLive(@NotNull ChannelGoLiveEvent event) {
try {
message.append(GuildHandler.getCustomGuild(guildID).getLiveNotificationsRole().getAsMention())
.append(", ");
- } catch (NumberFormatException | NullPointerException ignored) {}
+ } catch (NumberFormatException | NullPointerException ignored) { }
message.append(event.getChannel().getName())
.append(", is now live on ")
@@ -59,6 +70,8 @@ public void onChannelGoLive(@NotNull ChannelGoLiveEvent event) {
try {
liveChannel.sendMessage(message.toString()).setEmbeds(liveEmbed(event)).queue();
+
+ Bot.getLogger().log(TwitchMessageEventHandler.class, LogLevel.DEBUG, "Live Notification Sent: " + twitchName);
} catch (NullPointerException ignored) {
} // If the live channel no longer exists, then just don't print the message.
}
From 95a1d837022dd3c05c313a5534d39914bf2eb1cf Mon Sep 17 00:00:00 2001
From: beanbeanjuice
Date: Sun, 4 Sep 2022 16:10:28 -0400
Subject: [PATCH 7/9] Removed TODO Comment
---
.../com/beanbeanjuice/utility/section/twitch/TwitchHandler.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/com/beanbeanjuice/utility/section/twitch/TwitchHandler.java b/src/main/java/com/beanbeanjuice/utility/section/twitch/TwitchHandler.java
index 3650a68c..84da696c 100644
--- a/src/main/java/com/beanbeanjuice/utility/section/twitch/TwitchHandler.java
+++ b/src/main/java/com/beanbeanjuice/utility/section/twitch/TwitchHandler.java
@@ -54,7 +54,7 @@ public static void addTwitchChannel(@NotNull String twitchUsername) throws Hystr
// Check if the channel exists.
twitchListener.addStream(twitchUsername);
alreadyAddedTwitchNames.add(twitchUsername);
- Bot.getLogger().log(TwitchHandler.class, LogLevel.DEBUG, "Adding " + twitchUsername); // TODO: Remove
+ Bot.getLogger().log(TwitchHandler.class, LogLevel.DEBUG, "Adding " + twitchUsername);
}
}
From 74a11dab5c43f2e3186fa0e5506ca8b9eadab696 Mon Sep 17 00:00:00 2001
From: beanbeanjuice
Date: Sun, 4 Sep 2022 16:16:22 -0400
Subject: [PATCH 8/9] Fixed the Issue
---
src/main/java/com/beanbeanjuice/Bot.java | 2 +-
.../java/com/beanbeanjuice/utility/helper/Helper.java | 10 +++++-----
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/main/java/com/beanbeanjuice/Bot.java b/src/main/java/com/beanbeanjuice/Bot.java
index 7676d2d5..8a96329f 100644
--- a/src/main/java/com/beanbeanjuice/Bot.java
+++ b/src/main/java/com/beanbeanjuice/Bot.java
@@ -125,7 +125,7 @@ public Bot() throws LoginException, InterruptedException {
logger.log(Bot.class, LogLevel.OKAY, "The bot is online!");
new GitHubUpdateHelper().start(); // Notify Guilds of Update
- Helper.startHourlyUpdateTimer();
+ Helper.startUpdateTimer();
}
public static void main(String[] args) throws LoginException, InterruptedException {
diff --git a/src/main/java/com/beanbeanjuice/utility/helper/Helper.java b/src/main/java/com/beanbeanjuice/utility/helper/Helper.java
index 1fde1377..cbe7d348 100644
--- a/src/main/java/com/beanbeanjuice/utility/helper/Helper.java
+++ b/src/main/java/com/beanbeanjuice/utility/helper/Helper.java
@@ -25,9 +25,9 @@
public class Helper {
/**
- * Start an update {@link Timer} that restarts the {@link CafeAPI}.
+ * Start an update {@link Timer} that sends the owner updates.
*/
- public static void startHourlyUpdateTimer() {
+ public static void startUpdateTimer() {
Timer updateTimer = new Timer();
TimerTask updateTimerTask = new TimerTask() {
@Override
@@ -39,7 +39,7 @@ public void run() {
});
}
};
- updateTimer.scheduleAtFixedRate(updateTimerTask, 0, 3600000);
+ updateTimer.scheduleAtFixedRate(updateTimerTask, 0, TimeUnit.HOURS.toMillis(12));
}
/**
@@ -167,10 +167,10 @@ public static void startCafeAPIRefreshTimer(@NotNull RequestLocation requestLoca
public void run() {
Bot.setCafeAPI(new CafeAPI("beanbeanjuice", System.getenv("API_PASSWORD"), requestLocation));
Bot.getCafeAPI().setKawaiiAPI(System.getenv("KAWAII_API_TOKEN"));
- Bot.getLogger().log(Helper.class, LogLevel.INFO, "Updated the CafeAPI Token... Valid for 3600 Seconds", true, true);
+ Bot.getLogger().log(Helper.class, LogLevel.INFO, "Updated the CafeAPI Token... Valid for 3600 Seconds", true, false);
}
};
- cafeAPITimer.scheduleAtFixedRate(cafeAPITimerTask, 3000000, 3000000);
+ cafeAPITimer.scheduleAtFixedRate(cafeAPITimerTask, TimeUnit.MINUTES.toMillis(55), TimeUnit.MINUTES.toMillis(55));
}
/**
From f976e3bf6df4a8c1b1685a7606ce6febeed25d87 Mon Sep 17 00:00:00 2001
From: beanbeanjuice
Date: Sun, 4 Sep 2022 16:20:07 -0400
Subject: [PATCH 9/9] Added Message to Re-Invite Bot
---
.../com/beanbeanjuice/command/moderation/ClearChatCommand.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/main/java/com/beanbeanjuice/command/moderation/ClearChatCommand.java b/src/main/java/com/beanbeanjuice/command/moderation/ClearChatCommand.java
index b33bfd18..95af04ea 100644
--- a/src/main/java/com/beanbeanjuice/command/moderation/ClearChatCommand.java
+++ b/src/main/java/com/beanbeanjuice/command/moderation/ClearChatCommand.java
@@ -36,7 +36,8 @@ public void handle(@NotNull SlashCommandInteractionEvent event) {
event.getHook().sendMessageEmbeds(Helper.errorEmbed(
"Error Deleting Messages",
"There was an error deleting your messages. The " +
- "bot may have insufficient permissions. `" + e.getMessage() + "`"
+ "bot may have insufficient permissions. `" + e.getMessage() + "` " +
+ "Please click on my avatar and re-invite me to the server!"
)).queue();
}
}