Skip to content

Commit

Permalink
Merge pull request #586 from beanbeanjuice/544-goodbye-channel
Browse files Browse the repository at this point in the history
Created the Goodbye Channel
  • Loading branch information
beanbeanjuice committed Sep 18, 2023
2 parents 75a90f5 + e7052f6 commit 7475468
Show file tree
Hide file tree
Showing 15 changed files with 490 additions and 13 deletions.
1 change: 1 addition & 0 deletions README-small.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ As you can see, this was shown using the command `/help order`. It shows each pa
* `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.
* `goodbye-channel` - Set or remove the goodbye channel. If enabled, it will say goodbye to users with a cute message when they leave the server.
##### 10. **EXPERIMENTAL**
* `Nothing here yet!`

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ As you can see, this was shown using the command `/help order`. It shows each pa
* `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.
* `goodbye-channel` - Set or remove the goodbye channel. If enabled, it will say goodbye to users with a cute message when they leave the server.
##### 10. **EXPERIMENTAL**
* `Nothing here yet!`

Expand Down
30 changes: 24 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M7</version>
<version>3.1.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.3.0</version>
<version>3.6.0</version>
<executions>
<execution>
<goals>
Expand Down Expand Up @@ -72,26 +72,38 @@
</pluginManagement>
</build>

<repositories>
<repository>
<id>ossrh-snapshots</id>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
</repository>
<repository>
<id>ossrh</id>
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</repositories>

<dependencies>
<!-- Maven Dependency Plugin -->
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.3.0</version>
<version>3.6.0</version>
</dependency>

<!-- Café API -->
<!-- TODO: Change to Release -->
<dependency>
<groupId>com.beanbeanjuice</groupId>
<artifactId>cafe-api-wrapper</artifactId>
<version>1.3.1</version>
<version>1.4.0-SNAPSHOT</version>
</dependency>

<!-- Discord JDA -->
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>5.0.0-alpha.21</version>
<version>5.0.0-beta.12</version>
<exclusions>
<exclusion>
<groupId>club.minnced</groupId>
Expand Down Expand Up @@ -120,7 +132,13 @@
<dependency>
<groupId>com.github.twitch4j</groupId>
<artifactId>twitch4j</artifactId>
<version>1.12.0</version>
<version>1.15.0</version>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>24.0.1</version>
<scope>compile</scope>
</dependency>
</dependencies>

Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/beanbeanjuice/Bot.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public Bot() throws LoginException, InterruptedException {
new MessageListener(), // Listening for specific messages
new MessageDeleteListener(), // Listening for message deletions
new WelcomeListener(), // Listening for user joins for a guild.
new GoodbyeListener(), // Listening for user leaves for a guild.
new AIResponseListener(), // Listening for messages.
new VoiceChatRoleBindListener(), // Listening for voice joins/leaves
new CommandAutoCompleteHandler() // Listens for auto complete interactions
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package com.beanbeanjuice.command.settings.goodbye;

import com.beanbeanjuice.Bot;
import com.beanbeanjuice.cafeapi.cafebot.goodbyes.GuildGoodbye;
import com.beanbeanjuice.cafeapi.exception.api.CafeException;
import com.beanbeanjuice.cafeapi.exception.api.ConflictException;
import com.beanbeanjuice.utility.command.CommandCategory;
import com.beanbeanjuice.utility.command.ISubCommand;
import com.beanbeanjuice.utility.helper.Helper;
import com.beanbeanjuice.utility.listener.GoodbyeListener;
import com.beanbeanjuice.utility.logging.LogLevel;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;

public class EditGoodbyeMessageSubCommand implements ISubCommand {

@Override
public void handle(@NotNull SlashCommandInteractionEvent event) {
User user = event.getUser();
String description = event.getOption("inner_message").getAsString();
String message = null;
String imageURL = null;
String thumbnailURL = null;

if (event.getOption("outer_message") != null)
message = event.getOption("outer_message").getAsString();

if (event.getOption("image") != null)
imageURL = event.getOption("image").getAsAttachment().getUrl();

if (event.getOption("thumbnail") != null)
thumbnailURL = event.getOption("thumbnail").getAsAttachment().getUrl();

GuildGoodbye guildGoodbye = new GuildGoodbye(event.getGuild().getId(), description, thumbnailURL, imageURL, message);

// Sets it in the API
if (setGuildGoodbye(guildGoodbye)) {
if (guildGoodbye.getMessage() != null)
event.getHook().sendMessage(guildGoodbye.getMessage()).addEmbeds(GoodbyeListener.getGoodbyeEmbed(guildGoodbye, user)).queue();
else
event.getHook().sendMessageEmbeds(GoodbyeListener.getGoodbyeEmbed(guildGoodbye, user)).queue();
return;
}

event.getHook().sendMessageEmbeds(Helper.sqlServerError()).queue();
}

/**
* Sets the {@link GuildGoodbye} in the {@link com.beanbeanjuice.cafeapi.CafeAPI CafeAPI}.
* @param guildGoodbye The {@link GuildGoodbye} to set.
* @return True, if the {@link GuildGoodbye} was set successfully.
*/
@NotNull
public Boolean setGuildGoodbye(@NotNull GuildGoodbye guildGoodbye) {
try {
return Bot.getCafeAPI().GOODBYE.createGuildGoodbye(guildGoodbye);
} catch (ConflictException e) {
return Bot.getCafeAPI().GOODBYE.updateGuildGoodbye(guildGoodbye);
} catch (CafeException e) {
Bot.getLogger().log(this.getClass(), LogLevel.ERROR, "Error Setting Guild Goodbye: " + e.getMessage(), e);
return false;
}
}

@NotNull
@Override
public String getDescription() {
return "Edit the goodbye channel message!";
}

@NotNull
@Override
public String exampleUsage() {
return "`/goodbye-channel edit-message message:@awesomerole, someone left the server... description:Sadly, {user} left the server` or `/goodbye-channel edit-message description:Goodbye!!`";
}

@NotNull
@Override
public ArrayList<OptionData> getOptions() {
ArrayList<OptionData> options = new ArrayList<>();
options.add(new OptionData(OptionType.STRING, "inner_message", "The inner message to send when someone joins. " +
"You can use `\\n` and use {user}.", true));
options.add(new OptionData(OptionType.STRING, "outer_message", "The outer message to send when someone joins. " +
"You can use `\\n` and use {user}.", false));
options.add(new OptionData(OptionType.ATTACHMENT, "image", "The image to show when someone joins.", false));
options.add(new OptionData(OptionType.ATTACHMENT, "thumbnail", "The thumbnail image to show when someone joins.", false));
return options;
}

@NotNull
@Override
public CommandCategory getCategoryType() {
return CommandCategory.SETTINGS;
}

@NotNull
@Override
public String getName() {
return "edit-message";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.beanbeanjuice.command.settings.goodbye;

import com.beanbeanjuice.utility.command.CommandCategory;
import com.beanbeanjuice.utility.command.ICommand;
import com.beanbeanjuice.utility.command.ISubCommand;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;

public class GoodbyeChannelCommand implements ICommand {

@Override
public void handle(@NotNull SlashCommandInteractionEvent event) { }

@NotNull
@Override
public String getDescription() {
return "Set/Remove the goodbye channel or edit the goodbye message!";
}

@NotNull
@Override
public String exampleUsage() {
return "`/goodbye-channel set` or `/goodbye-channel remove` or `/goodbye-channel edit-message`";
}

@NotNull
@Override
public CommandCategory getCategoryType() {
return CommandCategory.SETTINGS;
}

@NotNull
@Override
public ArrayList<ISubCommand> getSubCommands() {
ArrayList<ISubCommand> subCommands = new ArrayList<>();
subCommands.add(new SetGoodbyeChannelSubCommand());
subCommands.add(new RemoveGoodbyeChannelSubCommand());
subCommands.add(new EditGoodbyeMessageSubCommand());
return subCommands;
}

@NotNull
@Override
public Boolean isHidden() {
return true;
}

@Nullable
@Override
public ArrayList<Permission> getPermissions() {
ArrayList<Permission> permissions = new ArrayList<>();
permissions.add(Permission.MANAGE_SERVER);
return permissions;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.beanbeanjuice.command.settings.goodbye;

import com.beanbeanjuice.utility.command.CommandCategory;
import com.beanbeanjuice.utility.command.ISubCommand;
import com.beanbeanjuice.utility.handler.guild.GuildHandler;
import com.beanbeanjuice.utility.helper.Helper;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import org.jetbrains.annotations.NotNull;

public class RemoveGoodbyeChannelSubCommand implements ISubCommand {

@Override
public void handle(@NotNull SlashCommandInteractionEvent event) {
if (GuildHandler.getCustomGuild(event.getGuild()).setGoodbyeChannelID("0")) {
event.getHook().sendMessageEmbeds(Helper.successEmbed(
"Removed Goodbye Channel",
"The goodbye channel has been successfully removed!"
)).queue();
return;
}
event.getHook().sendMessageEmbeds(Helper.sqlServerError()).queue();
}

@NotNull
@Override
public String getDescription() {
return "Remove the current goodbye channel!";
}

@NotNull
@Override
public String exampleUsage() {
return "`/goodbye-channel remove`";
}

@NotNull
@Override
public CommandCategory getCategoryType() {
return CommandCategory.SETTINGS;
}

@NotNull
@Override
public String getName() {
return "remove";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.beanbeanjuice.command.settings.goodbye;

import com.beanbeanjuice.utility.command.CommandCategory;
import com.beanbeanjuice.utility.command.ISubCommand;
import com.beanbeanjuice.utility.handler.guild.GuildHandler;
import com.beanbeanjuice.utility.helper.Helper;
import net.dv8tion.jda.api.entities.channel.ChannelType;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;

public class SetGoodbyeChannelSubCommand implements ISubCommand {

@Override
public void handle(@NotNull SlashCommandInteractionEvent event) {

// Checking if a text channel.
if (!Helper.isTextChannel(event.getChannel())) {
event.getHook().sendMessageEmbeds(Helper.notATextChannelEmbed(event.getChannelType())).queue();
return;
}

TextChannel channel = event.getChannel().asTextChannel();
if (event.getOption("goodbye_channel") != null)
channel = event.getOption("goodbye_channel").getAsChannel().asTextChannel();

// If the channel is already set, notify them that this cannot be done.
if (GuildHandler.getCustomGuild(event.getGuild()).isDailyChannel(channel.getId())) {
event.getHook().sendMessageEmbeds(Helper.alreadyDailyChannel()).queue();
return;
}

if (GuildHandler.getCustomGuild(event.getGuild()).setGoodbyeChannelID(channel.getId())) {
event.getHook().sendMessageEmbeds(Helper.successEmbed(
"Set Goodbye Channel",
"This channel has been set to the goodbye channel! Make sure to " +
"edit the goodbye message with the `/goodbye-channel edit-message` command!"
)).queue();
return;
}
event.getHook().sendMessageEmbeds(Helper.sqlServerError()).queue();
}

@NotNull
@Override
public ArrayList<OptionData> getOptions() {
ArrayList<OptionData> options = new ArrayList<>();
options.add(new OptionData(OptionType.CHANNEL, "goodbye_channel", "The text channel to send goodbye information to.", false)
.setChannelTypes(ChannelType.TEXT));
return options;
}

@NotNull
@Override
public String getDescription() {
return "Set a channel to goodbye channel!";
}

@NotNull
@Override
public String exampleUsage() {
return "`/goodbye-channel set`";
}

@NotNull
@Override
public CommandCategory getCategoryType() {
return CommandCategory.SETTINGS;
}

@NotNull
@Override
public String getName() {
return "set";
}

}

0 comments on commit 7475468

Please sign in to comment.