Various things and fixes

This commit is contained in:
anthorob committed 2023-12-20 20:54:00 -05:00
1 parent 38bd0cd4e2
commit 93437ab8aa
22 files changed
+217 -192

No files matched your search

+1 -1
View File
@@ -108,7 +108,7 @@
<dependency> <dependency>
<groupId>net.dv8tion</groupId> <groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId> <artifactId>JDA</artifactId>
<version>5.0.0-beta.12</version> <version>5.0.0-beta.18</version>
</dependency> </dependency>
<!-- <dependency>--> <!-- <dependency>-->
<!-- <groupId>com.sedmelluq</groupId>--> <!-- <groupId>com.sedmelluq</groupId>-->
@@ -34,7 +34,7 @@ public abstract class AbstractMusicCommand extends AbstractCommand {
@Override @Override
public boolean canBeExecutedBy(Guild guild, Member member) { public boolean canBeExecutedBy(Guild guild, Member member) {
String roleDb = GuildManager.getManager(guild).getSetting(GSettings.MUSIC_ROLE); String roleDb = GuildManager.getManager(guild).getGuildConfigManager().getSetting(GSettings.MUSIC_ROLE);
if (roleDb != null && !roleDb.isEmpty()) { if (roleDb != null && !roleDb.isEmpty()) {
if (UserFunction.isAdmin(member)) { if (UserFunction.isAdmin(member)) {
@@ -44,7 +44,7 @@ public abstract class AbstractMusicCommand extends AbstractCommand {
Role neededRole = guild.getRoleById(roleDb); Role neededRole = guild.getRoleById(roleDb);
if (neededRole == null) { if (neededRole == null) {
// Role doesn't exist on guild anymore, remove from db // Role doesn't exist on guild anymore, remove from db
GuildManager.getManager(guild).setSettingValue(GSettings.MUSIC_ROLE, null); GuildManager.getManager(guild).getGuildConfigManager().setSettingValue(GSettings.MUSIC_ROLE, null);
return true; return true;
} }
@@ -59,7 +59,7 @@ public abstract class AbstractMusicCommand extends AbstractCommand {
if (channel.getType() != ChannelType.TEXT) if (channel.getType() != ChannelType.TEXT)
return false; return false;
String channelDb = GuildManager.getManager(guild).getSetting(GSettings.MUSIC_CHANNEL); String channelDb = GuildManager.getManager(guild).getGuildConfigManager().getSetting(GSettings.MUSIC_CHANNEL);
if (channelDb != null && !channelDb.isEmpty()) { if (channelDb != null && !channelDb.isEmpty()) {
return channelDb.equals(channel.getId()); return channelDb.equals(channel.getId());
@@ -38,6 +38,7 @@ public interface ICommand {
boolean canBeExecutedFrom(Guild guild, MessageChannel channel); boolean canBeExecutedFrom(Guild guild, MessageChannel channel);
@Deprecated
void execute(MessageCommandContext context); void execute(MessageCommandContext context);
void execute(SlashCommandContext context); void execute(SlashCommandContext context);
@@ -89,7 +89,7 @@ public class ConfigureCommand extends AbstractCommand {
// Role for music commands // Role for music commands
if (context.getArgument(0).equals("music-role")) { if (context.getArgument(0).equals("music-role")) {
if (args.length == 1) { if (args.length == 1) {
String roleDb = guildManager.getSetting(GSettings.MUSIC_ROLE); String roleDb = guildManager.getGuildConfigManager().getSetting(GSettings.MUSIC_ROLE);
Role role = null; Role role = null;
if (!roleDb.isEmpty()) { if (!roleDb.isEmpty()) {
role = context.getGuild().getRoleById(roleDb); role = context.getGuild().getRoleById(roleDb);
@@ -101,8 +101,8 @@ public class ConfigureCommand extends AbstractCommand {
if (args.length == 2) { if (args.length == 2) {
if (context.getArgument(1).equals("reset")) { if (context.getArgument(1).equals("reset")) {
if (!guildManager.getSetting(GSettings.MUSIC_ROLE).isEmpty()) { if (!guildManager.getGuildConfigManager().getSetting(GSettings.MUSIC_ROLE).isEmpty()) {
guildManager.setSettingValue(GSettings.MUSIC_ROLE, null); guildManager.getGuildConfigManager().setSettingValue(GSettings.MUSIC_ROLE, null);
} }
context.reply("Successful reset of the role"); context.reply("Successful reset of the role");
@@ -112,7 +112,7 @@ public class ConfigureCommand extends AbstractCommand {
if (roles.size() == 1) { if (roles.size() == 1) {
Role role = roles.get(0); Role role = roles.get(0);
if (role.getGuild().getId().equals(context.getGuild().getId())) { if (role.getGuild().getId().equals(context.getGuild().getId())) {
guildManager.setSettingValue(GSettings.MUSIC_ROLE, role.getId()); guildManager.getGuildConfigManager().setSettingValue(GSettings.MUSIC_ROLE, role.getId());
context.reply("Successfully set %s as the role needed for music command", role.getAsMention()); context.reply("Successfully set %s as the role needed for music command", role.getAsMention());
} }
} }
@@ -122,7 +122,7 @@ public class ConfigureCommand extends AbstractCommand {
// Role for music commands // Role for music commands
if (context.getArgument(0).equals("music-channel")) { if (context.getArgument(0).equals("music-channel")) {
if (args.length == 1) { if (args.length == 1) {
String channelDb = guildManager.getSetting(GSettings.MUSIC_CHANNEL); String channelDb = guildManager.getGuildConfigManager().getSetting(GSettings.MUSIC_CHANNEL);
TextChannel channel = null; TextChannel channel = null;
if (!channelDb.isEmpty()) { if (!channelDb.isEmpty()) {
channel = context.getGuild().getTextChannelById(channelDb); channel = context.getGuild().getTextChannelById(channelDb);
@@ -134,8 +134,8 @@ public class ConfigureCommand extends AbstractCommand {
if (args.length == 2) { if (args.length == 2) {
if (context.getArgument(1).equals("reset")) { if (context.getArgument(1).equals("reset")) {
if (!guildManager.getSetting(GSettings.MUSIC_CHANNEL).isEmpty()) { if (!guildManager.getGuildConfigManager().getSetting(GSettings.MUSIC_CHANNEL).isEmpty()) {
guildManager.setSettingValue(GSettings.MUSIC_CHANNEL, null); guildManager.getGuildConfigManager().setSettingValue(GSettings.MUSIC_CHANNEL, null);
} }
context.reply("Successful reset of the channel"); context.reply("Successful reset of the channel");
@@ -145,7 +145,7 @@ public class ConfigureCommand extends AbstractCommand {
if (channels.size() == 1) { if (channels.size() == 1) {
TextChannel channel = channels.get(0); TextChannel channel = channels.get(0);
if (channel.getGuild().getId().equals(context.getGuild().getId())) { if (channel.getGuild().getId().equals(context.getGuild().getId())) {
guildManager.setSettingValue(GSettings.MUSIC_CHANNEL, channel.getId()); guildManager.getGuildConfigManager().setSettingValue(GSettings.MUSIC_CHANNEL, channel.getId());
context.reply("Successfully set %s as the channel required to execute music command", channel.getAsMention()); context.reply("Successfully set %s as the channel required to execute music command", channel.getAsMention());
} }
} }
@@ -155,7 +155,7 @@ public class ConfigureCommand extends AbstractCommand {
// Default volume for music player // Default volume for music player
if (context.getArgument(0).equals("music-volume")) { if (context.getArgument(0).equals("music-volume")) {
if (args.length == 1) { if (args.length == 1) {
int volume = Integer.parseInt(guildManager.getSetting(GSettings.MUSIC_VOLUME)); int volume = Integer.parseInt(guildManager.getGuildConfigManager().getSetting(GSettings.MUSIC_VOLUME));
context.reply("Default volume for music player: %d", volume); context.reply("Default volume for music player: %d", volume);
context.reply("Set using 'conf music-volume <value between 0 and 100>'"); context.reply("Set using 'conf music-volume <value between 0 and 100>'");
@@ -166,7 +166,7 @@ public class ConfigureCommand extends AbstractCommand {
int volume = Integer.parseInt(args[1]); int volume = Integer.parseInt(args[1]);
if (volume > 0 && volume <= 100) { if (volume > 0 && volume <= 100) {
guildManager.setSettingValue(GSettings.MUSIC_VOLUME, String.valueOf(volume)); guildManager.getGuildConfigManager().setSettingValue(GSettings.MUSIC_VOLUME, String.valueOf(volume));
MusicManager.get(context.getGuild()).setVolume(volume); MusicManager.get(context.getGuild()).setVolume(volume);
context.reply("Default volume for music player is now %d", volume); context.reply("Default volume for music player is now %d", volume);
@@ -218,13 +218,13 @@ public class ConfigureCommand extends AbstractCommand {
assert role != null; assert role != null;
if (role.getPosition() == -1) { if (role.getPosition() == -1) {
guildManager.setSettingValue(GSettings.MUSIC_ROLE, null); guildManager.getGuildConfigManager().setSettingValue(GSettings.MUSIC_ROLE, null);
context.replyEphemeral("Everyone can now use music commands"); context.replyEphemeral("Everyone can now use music commands");
return; return;
} }
if (role.getGuild().getId().equals(context.getGuild().getId())) { if (role.getGuild().getId().equals(context.getGuild().getId())) {
guildManager.setSettingValue(GSettings.MUSIC_ROLE, role.getId()); guildManager.getGuildConfigManager().setSettingValue(GSettings.MUSIC_ROLE, role.getId());
context.replyEphemeral("Successfully set %s as the role needed for music command", role.getAsMention()); context.replyEphemeral("Successfully set %s as the role needed for music command", role.getAsMention());
return; return;
} }
@@ -234,14 +234,14 @@ public class ConfigureCommand extends AbstractCommand {
GuildChannelUnion channel = context.getEvent().getOption("channel", OptionMapping::getAsChannel); GuildChannelUnion channel = context.getEvent().getOption("channel", OptionMapping::getAsChannel);
if (channel == null) { if (channel == null) {
guildManager.setSettingValue(GSettings.MUSIC_CHANNEL, null); guildManager.getGuildConfigManager().setSettingValue(GSettings.MUSIC_CHANNEL, null);
context.replyEphemeral("No channel restrictions for music commands"); context.replyEphemeral("No channel restrictions for music commands");
return; return;
} }
if (channel instanceof TextChannel) { if (channel instanceof TextChannel) {
if (channel.getGuild().getId().equals(context.getGuild().getId())) { if (channel.getGuild().getId().equals(context.getGuild().getId())) {
guildManager.setSettingValue(GSettings.MUSIC_CHANNEL, channel.getId()); guildManager.getGuildConfigManager().setSettingValue(GSettings.MUSIC_CHANNEL, channel.getId());
context.replyEphemeral("Successfully set %s as the channel required to execute music command", channel.getAsMention()); context.replyEphemeral("Successfully set %s as the channel required to execute music command", channel.getAsMention());
return; return;
} }
@@ -251,7 +251,7 @@ public class ConfigureCommand extends AbstractCommand {
if ("music-volume".equals(sub)) { if ("music-volume".equals(sub)) {
int volume = context.getEvent().getOption("volume", 30, OptionMapping::getAsInt); int volume = context.getEvent().getOption("volume", 30, OptionMapping::getAsInt);
guildManager.setSettingValue(GSettings.MUSIC_VOLUME, String.valueOf(volume)); guildManager.getGuildConfigManager().setSettingValue(GSettings.MUSIC_VOLUME, String.valueOf(volume));
MusicManager.get(context.getGuild()).setVolume(volume); MusicManager.get(context.getGuild()).setVolume(volume);
context.replyEphemeral("Default volume for music player is now %d", volume); context.replyEphemeral("Default volume for music player is now %d", volume);
@@ -267,7 +267,7 @@ public class ConfigureCommand extends AbstractCommand {
} }
if ("show-all".equals(sub)) { if ("show-all".equals(sub)) {
Map<String, String> settings = guildManager.getSettings(); Map<String, String> settings = guildManager.getGuildConfigManager().getSettings();
MessageCreateBuilder builder = new MessageCreateBuilder(); MessageCreateBuilder builder = new MessageCreateBuilder();
for (GSettings o : GSettings.values()) { for (GSettings o : GSettings.values()) {
@@ -6,7 +6,7 @@ package netneutrality.core;
* https://discord.gg/CdFcyQ * https://discord.gg/CdFcyQ
*/ */
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
import netneutrality.music.MusicManager; import netneutrality.music.MusicManager;
import netneutrality.music.TrackScheduler; import netneutrality.music.TrackScheduler;
import org.json.JSONArray; import org.json.JSONArray;
@@ -35,7 +35,7 @@ public class BotState {
JSONObject music = new JSONObject(); JSONObject music = new JSONObject();
guild.put("id", manager.getGuild().getId()); guild.put("id", manager.getGuild().getId());
TextChannel currentChannel = trackScheduler.getTextChannel(); MessageChannel currentChannel = trackScheduler.getTextChannel();
if (currentChannel == null) { if (currentChannel == null) {
music.put("current_channel", "null"); music.put("current_channel", "null");
} else { } else {
@@ -0,0 +1,96 @@
package netneutrality.core;/*
* Copyright (c) anthorob
*
* https://xtremcommunity.com/
* https://discord.gg/CdFcyQ
*/
import net.dv8tion.jda.api.entities.Guild;
import netneutrality.db.GSettings;
import netneutrality.db.entities.OGuild;
import netneutrality.db.entities.OGuildSetting;
import netneutrality.utils.JpaUtils;
import org.hibernate.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class GuildConfigManager {
private static final Logger logger = LoggerFactory.getLogger(GuildConfigManager.class);
private final Guild guild;
private final OGuild guildEntity;
private final Map<String, String> settingsCache = new HashMap<>();
public GuildConfigManager(Guild guild, OGuild guildEntity) {
this.guild = guild;
this.guildEntity = guildEntity;
reloadSettingsCache();
}
public Map<String, String> getSettings() {
return settingsCache;
}
public String getSetting(GSettings setting) {
String value = settingsCache.get(setting.getName());
if (value == null) {
value = setting.getDefaultValue();
}
return value;
}
public void setSettingValue(GSettings setting, String value) {
Session session = SessionManager.getSessionFactory().openSession();
JpaUtils.tryLoad(session, guildEntity, guildEntity.getGuildId());
OGuildSetting oGuildSetting = guildEntity.getSettingByName(setting.getName());
session.beginTransaction();
if (value == null || setting.getDefaultValue().equals(value)) {
if (oGuildSetting != null) {
session.delete(oGuildSetting);
}
} else {
if (oGuildSetting == null) {
oGuildSetting = new OGuildSetting();
oGuildSetting.setGuild(guildEntity);
oGuildSetting.setName(setting.getName());
oGuildSetting.setValue(value);
session.save(oGuildSetting);
} else {
oGuildSetting.setValue(value);
session.update(oGuildSetting);
}
}
session.getTransaction().commit();
session.close();
reloadSettingsCache();
}
public void reloadSettingsCache() {
logger.debug("Reloading settings cache for guild: " + guild.getId());
settingsCache.clear();
JpaUtils.getWithSession(guildEntity, session -> {
Set<OGuildSetting> settingSet = guildEntity.getGuildSettings();
for (OGuildSetting setting : settingSet) {
settingsCache.put(setting.getName(), setting.getValue());
}
});
}
}
@@ -9,14 +9,12 @@ package netneutrality.core;
import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
import netneutrality.NetNeutrality; import netneutrality.NetNeutrality;
import netneutrality.db.DBController; import netneutrality.db.DBController;
import netneutrality.db.GSettings;
import netneutrality.db.controllers.DBMessage; import netneutrality.db.controllers.DBMessage;
import netneutrality.db.entities.OBlacklist; import netneutrality.db.entities.OBlacklist;
import netneutrality.db.entities.OGuild; import netneutrality.db.entities.OGuild;
import netneutrality.db.entities.OGuildSetting;
import netneutrality.thread.ThreadManager; import netneutrality.thread.ThreadManager;
import netneutrality.utils.JpaUtils; import netneutrality.utils.JpaUtils;
import netneutrality.utils.MessageFunction; import netneutrality.utils.MessageFunction;
@@ -25,7 +23,6 @@ import org.hibernate.SessionFactory;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@@ -36,18 +33,18 @@ public class GuildManager {
private static final Logger logger = LoggerFactory.getLogger(GuildManager.class); private static final Logger logger = LoggerFactory.getLogger(GuildManager.class);
private static final Map<String, GuildManager> managers = new ConcurrentHashMap<>(); private static final Map<String, GuildManager> managers = new ConcurrentHashMap<>();
private static final SessionFactory sessionFactory = SessionManager.getSessionFactory(); private static final SessionFactory sessionFactory = SessionManager.getSessionFactory();
private final Map<String, String> settingsCache = new HashMap<>();
private final Set<String> blacklistCache = new HashSet<>(); private final Set<String> blacklistCache = new HashSet<>();
private final GuildConfigManager guildConfigManager;
private final Guild guild; private final Guild guild;
private OGuild guildEntity; private OGuild guildEntity;
private GuildManager(Guild guild) { private GuildManager(Guild guild) {
this.guild = guild; this.guild = guild;
this.guildEntity = loadGuildFromDb(guild.getId()); this.guildEntity = loadGuildFromDb(guild.getId());
this.guildConfigManager = new GuildConfigManager(guild, this.guildEntity);
managers.put(guild.getId(), this); managers.put(guild.getId(), this);
reloadBlacklistCache(); reloadBlacklistCache();
reloadSettingsCache();
} }
private GuildManager(String guildId) { private GuildManager(String guildId) {
@@ -57,10 +54,10 @@ public class GuildManager {
this.guild = temp; this.guild = temp;
this.guildEntity = loadGuildFromDb(guild.getId()); this.guildEntity = loadGuildFromDb(guild.getId());
this.guildConfigManager = new GuildConfigManager(guild, this.guildEntity);
managers.put(guild.getId(), this); managers.put(guild.getId(), this);
reloadBlacklistCache(); reloadBlacklistCache();
reloadSettingsCache();
} }
public static GuildManager getManager(Guild guild) { public static GuildManager getManager(Guild guild) {
@@ -96,8 +93,8 @@ public class GuildManager {
return blacklistCache; return blacklistCache;
} }
public Map<String, String> getSettings() { public GuildConfigManager getGuildConfigManager() {
return settingsCache; return guildConfigManager;
} }
// Methods // Methods
@@ -109,47 +106,6 @@ public class GuildManager {
return guildEntity.getDebug(); return guildEntity.getDebug();
} }
public String getSetting(GSettings setting) {
String value = settingsCache.get(setting.getName());
if (value == null) {
value = setting.getDefaultValue();
}
return value;
}
public void setSettingValue(GSettings setting, String value) {
Session session = sessionFactory.openSession();
JpaUtils.tryLoad(session, guildEntity, guildEntity.getGuildId());
OGuildSetting oGuildSetting = guildEntity.getSettingByName(setting.getName());
session.beginTransaction();
if (value == null || setting.getDefaultValue().equals(value)) {
if (oGuildSetting != null) {
session.delete(oGuildSetting);
}
} else {
if (oGuildSetting == null) {
oGuildSetting = new OGuildSetting();
oGuildSetting.setGuild(guildEntity);
oGuildSetting.setName(setting.getName());
oGuildSetting.setValue(value);
session.save(oGuildSetting);
} else {
oGuildSetting.setValue(value);
session.update(oGuildSetting);
}
}
session.getTransaction().commit();
reloadSettingsCache(false);
session.close();
}
public void setDebug(boolean toggle) { public void setDebug(boolean toggle) {
if (toggle == isDebugEnabled()) if (toggle == isDebugEnabled())
return; return;
@@ -157,30 +113,11 @@ public class GuildManager {
JpaUtils.updateWithTransaction(guildEntity, () -> guildEntity.setDebug(toggle)); JpaUtils.updateWithTransaction(guildEntity, () -> guildEntity.setDebug(toggle));
} }
public boolean reloadSettingsCache(boolean close) { public void reloadBlacklistCache() {
logger.debug("Reloading settings cache for guild: " + guild.getId());
settingsCache.clear();
JpaUtils.getWithSession(guildEntity, close, session -> {
Set<OGuildSetting> settingSet = guildEntity.getGuildSettings();
for (OGuildSetting setting : settingSet) {
settingsCache.put(setting.getName(), setting.getValue());
}
});
return true;
}
public boolean reloadSettingsCache() {
return reloadSettingsCache(true);
}
public void reloadBlacklistCache(boolean close) {
logger.debug("Reloading blacklist cache for guild: " + guild.getId()); logger.debug("Reloading blacklist cache for guild: " + guild.getId());
blacklistCache.clear(); blacklistCache.clear();
JpaUtils.getWithSession(guildEntity, close, session -> { JpaUtils.getWithSession(guildEntity, session -> {
Set<OBlacklist> oBlacklistSet = guildEntity.getBlacklists(); Set<OBlacklist> oBlacklistSet = guildEntity.getBlacklists();
for (OBlacklist bl : oBlacklistSet) { for (OBlacklist bl : oBlacklistSet) {
@@ -191,17 +128,13 @@ public class GuildManager {
}); });
} }
public void reloadBlacklistCache() { public void checkAndLogMessage(Message message, Member member, MessageChannel channel) {
reloadBlacklistCache(true);
}
public void checkAndLogMessage(Message message, Member member, TextChannel channel) {
if (isLoggingEnabled()) { if (isLoggingEnabled()) {
ThreadManager.getExecutor().submit(() -> DBController.get(DBMessage.class).log(this, channel, member, message)); ThreadManager.getExecutor().submit(() -> DBController.get(DBMessage.class).log(this, channel, member, message));
} }
} }
public void checkBlacklist(Message message, TextChannel channel) { public void checkBlacklist(Message message, MessageChannel channel) {
MessageFunction.testMessageAgainstBlacklist(message, channel, blacklistCache); MessageFunction.testMessageAgainstBlacklist(message, channel, blacklistCache);
} }
@@ -10,6 +10,7 @@ import io.sentry.Sentry;
import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import netneutrality.core.context.CommandContext; import netneutrality.core.context.CommandContext;
import netneutrality.core.context.SlashCommandContext;
import netneutrality.exceptions.CommandException; import netneutrality.exceptions.CommandException;
import netneutrality.exceptions.CommandExecutionException; import netneutrality.exceptions.CommandExecutionException;
import netneutrality.utils.MessageFunction; import netneutrality.utils.MessageFunction;
@@ -30,6 +31,8 @@ public class LogHandler {
Sentry.captureException(e); Sentry.captureException(e);
logInternally((CommandExecutionException) e); logInternally((CommandExecutionException) e);
tryLogToDebugChannel((CommandExecutionException) e); tryLogToDebugChannel((CommandExecutionException) e);
tryGracefulSlashContextError((CommandExecutionException) e);
return; return;
} }
@@ -75,4 +78,12 @@ public class LogHandler {
} }
} }
} }
private static void tryGracefulSlashContextError(CommandExecutionException error) {
CommandContext context = error.getCommandContext();
if (context instanceof SlashCommandContext slashCommandContext) {
slashCommandContext.replyEphemeral("Error during command execution");
}
}
} }
@@ -52,4 +52,6 @@ public interface CommandContext {
default void replyToMessage(String format, Object... arguments) { default void replyToMessage(String format, Object... arguments) {
replyToMessage(String.format(format, arguments)); replyToMessage(String.format(format, arguments));
} }
void dispatchToCommand(String commandName);
} }
@@ -14,6 +14,7 @@ import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.utils.messages.MessageCreateData; import net.dv8tion.jda.api.utils.messages.MessageCreateData;
import netneutrality.command.AbstractCommand; import netneutrality.command.AbstractCommand;
import netneutrality.core.CommandManager;
import netneutrality.core.GuildManager; import netneutrality.core.GuildManager;
import netneutrality.core.LogHandler; import netneutrality.core.LogHandler;
import netneutrality.exceptions.CommandExecutionException; import netneutrality.exceptions.CommandExecutionException;
@@ -193,7 +194,12 @@ public class MessageCommandContext implements CommandContext {
return creatorId.equals(member.getId()); return creatorId.equals(member.getId());
} }
public void dispatch(AbstractCommand command) { public void dispatchToCommand(String commandName) {
if (!CommandManager.isValidCommand(commandName)) {
return;
}
AbstractCommand command = CommandManager.getCommand(commandName);
this.command = command; this.command = command;
//TODO: Add usage check //TODO: Add usage check
@@ -21,7 +21,6 @@ import netneutrality.command.AbstractCommand;
import netneutrality.core.CommandManager; import netneutrality.core.CommandManager;
import netneutrality.core.LogHandler; import netneutrality.core.LogHandler;
import netneutrality.exceptions.CommandExecutionException; import netneutrality.exceptions.CommandExecutionException;
import netneutrality.utils.UserFunction;
import java.util.Collection; import java.util.Collection;
@@ -180,7 +179,6 @@ public class SlashCommandContext implements CommandContext {
Sentry.configureScope(scope -> { Sentry.configureScope(scope -> {
scope.setContexts("command", command.getCommandName()); scope.setContexts("command", command.getCommandName());
scope.setContexts("isAdmin", UserFunction.isAdmin(member));
scope.setContexts("canBeExecuted", command.canBeExecutedBy(guild, member)); scope.setContexts("canBeExecuted", command.canBeExecutedBy(guild, member));
scope.setTag("channel", channel.getId()); scope.setTag("channel", channel.getId());
scope.setTag("interactionId", event.getInteraction().getId()); scope.setTag("interactionId", event.getInteraction().getId());
@@ -22,11 +22,13 @@ public class DBBlacklist extends AbstractController {
public void add(String word, CommandContext context) { public void add(String word, CommandContext context) {
GuildManager guildManager = GuildManager.getManager(context.getGuild()); GuildManager guildManager = GuildManager.getManager(context.getGuild());
Session session = getSessionFactory().openSession();
OBlacklist bl = getWordFromDb(word, context.getGuild().getId()); OBlacklist bl = getWordFromDb(word, context.getGuild().getId());
if (bl == null) { if (bl == null) {
Session session = getSessionFactory().openSession();
session.beginTransaction(); session.beginTransaction();
bl = new OBlacklist(); bl = new OBlacklist();
bl.setGuild(guildManager.getGuildEntity()); bl.setGuild(guildManager.getGuildEntity());
@@ -36,73 +38,81 @@ public class DBBlacklist extends AbstractController {
session.save(bl); session.save(bl);
session.getTransaction().commit(); session.getTransaction().commit();
guildManager.reloadBlacklistCache(false); session.close();
guildManager.reloadBlacklistCache();
context.reply(String.format("Added the word [%s] to the blacklist.", word)); context.reply(String.format("Added the word [%s] to the blacklist.", word));
} else { } else {
context.reply("Word is already blacklisted"); context.reply("Word is already blacklisted");
} }
session.close();
} }
public void delete(String word, CommandContext context) { public void delete(String word, CommandContext context) {
GuildManager guildManager = GuildManager.getManager(context.getGuild()); GuildManager guildManager = GuildManager.getManager(context.getGuild());
Session session = getSessionFactory().openSession();
OBlacklist bl = getWordFromDb(word, context.getGuild().getId()); OBlacklist bl = getWordFromDb(word, context.getGuild().getId());
if (bl != null) { if (bl != null) {
Session session = getSessionFactory().openSession();
session.beginTransaction(); session.beginTransaction();
session.delete(bl); session.delete(bl);
session.getTransaction().commit(); session.getTransaction().commit();
guildManager.reloadBlacklistCache(false); session.close();
guildManager.reloadBlacklistCache();
context.reply("Removed the word [%s] from the blacklist.", word); context.reply("Removed the word [%s] from the blacklist.", word);
} else { } else {
context.reply("Can't delete word because it doesn't exist"); context.reply("Can't delete word because it doesn't exist");
} }
session.close();
} }
public void enable(String word, CommandContext context) { public void enable(String word, CommandContext context) {
GuildManager guildManager = GuildManager.getManager(context.getGuild()); GuildManager guildManager = GuildManager.getManager(context.getGuild());
Session session = getSessionFactory().openSession();
OBlacklist bl = getWordFromDb(word, context.getGuild().getId()); OBlacklist bl = getWordFromDb(word, context.getGuild().getId());
if (bl != null && !bl.getEnabled()) { if (bl != null && !bl.getEnabled()) {
Session session = getSessionFactory().openSession();
session.beginTransaction(); session.beginTransaction();
bl.setEnabled(true); bl.setEnabled(true);
session.update(bl); session.update(bl);
session.getTransaction().commit(); session.getTransaction().commit();
guildManager.reloadBlacklistCache(false); session.close();
guildManager.reloadBlacklistCache();
context.reply("Enabled the word [%s] for the blacklist.", word); context.reply("Enabled the word [%s] for the blacklist.", word);
} else { } else {
context.reply("Either word doesn't exist or is already enabled"); context.reply("Either word doesn't exist or is already enabled");
} }
session.close();
} }
public void disable(String word, CommandContext context) { public void disable(String word, CommandContext context) {
GuildManager guildManager = GuildManager.getManager(context.getGuild()); GuildManager guildManager = GuildManager.getManager(context.getGuild());
Session session = getSessionFactory().openSession();
OBlacklist bl = getWordFromDb(word, context.getGuild().getId()); OBlacklist bl = getWordFromDb(word, context.getGuild().getId());
if (bl != null && bl.getEnabled()) { if (bl != null && bl.getEnabled()) {
Session session = getSessionFactory().openSession();
session.beginTransaction(); session.beginTransaction();
bl.setEnabled(false); bl.setEnabled(false);
session.update(bl); session.update(bl);
session.getTransaction().commit(); session.getTransaction().commit();
guildManager.reloadBlacklistCache(false); session.close();
guildManager.reloadBlacklistCache();
context.reply("Disabled the word [%s] for the blacklist.", word); context.reply("Disabled the word [%s] for the blacklist.", word);
} else { } else {
context.reply("Either word doesn't exist or is already disabled"); context.reply("Either word doesn't exist or is already disabled");
} }
session.close();
} }
public ArrayList<OBlacklist> getBlacklistForGuild(Guild guild) { public ArrayList<OBlacklist> getBlacklistForGuild(Guild guild) {
@@ -1,5 +1,4 @@
package netneutrality.db.controllers; package netneutrality.db.controllers;
/* /*
* Copyright (c) anthorob * Copyright (c) anthorob
* *
@@ -9,7 +8,7 @@ package netneutrality.db.controllers;
import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
import netneutrality.core.GuildManager; import netneutrality.core.GuildManager;
import netneutrality.db.AbstractController; import netneutrality.db.AbstractController;
import netneutrality.db.entities.OLogMessage; import netneutrality.db.entities.OLogMessage;
@@ -24,7 +23,7 @@ public class DBMessage extends AbstractController {
private final static Logger logger = LoggerFactory.getLogger(DBMessage.class); private final static Logger logger = LoggerFactory.getLogger(DBMessage.class);
public void log(GuildManager guildManager, TextChannel channel, Member author, Message message) { public void log(GuildManager guildManager, MessageChannel channel, Member author, Message message) {
Session session = getSessionFactory().openSession(); Session session = getSessionFactory().openSession();
session.beginTransaction(); session.beginTransaction();
@@ -15,6 +15,7 @@ import netneutrality.core.SessionManager;
import netneutrality.db.DBController; import netneutrality.db.DBController;
import netneutrality.db.controllers.DBMessage; import netneutrality.db.controllers.DBMessage;
import netneutrality.db.entities.OGuild; import netneutrality.db.entities.OGuild;
import netneutrality.utils.JpaUtils;
import netneutrality.utils.MessageFunction; import netneutrality.utils.MessageFunction;
import org.hibernate.Session; import org.hibernate.Session;
@@ -34,7 +35,7 @@ public class EditHandler extends ListenerAdapter {
if (guildEntity.getLogChannel() != null && !guildEntity.getLogChannel().isEmpty()) { if (guildEntity.getLogChannel() != null && !guildEntity.getLogChannel().isEmpty()) {
Session session = SessionManager.getSessionFactory().openSession(); Session session = SessionManager.getSessionFactory().openSession();
session.load(guildEntity, guildEntity.getGuildId()); JpaUtils.tryLoad(session, guildEntity, guildEntity.getGuildId());
int size = guildEntity.getLoggings() int size = guildEntity.getLoggings()
.stream() .stream()
@@ -8,14 +8,9 @@ package netneutrality.hooks.message;
import io.sentry.Breadcrumb; import io.sentry.Breadcrumb;
import io.sentry.Sentry; import io.sentry.Sentry;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter; import net.dv8tion.jda.api.hooks.ListenerAdapter;
import netneutrality.command.AbstractCommand;
import netneutrality.core.CommandManager;
import netneutrality.core.GuildManager; import netneutrality.core.GuildManager;
import netneutrality.core.context.MessageCommandContext; import netneutrality.core.context.MessageCommandContext;
import netneutrality.utils.Settings; import netneutrality.utils.Settings;
@@ -32,15 +27,11 @@ public class MessageReceivedHandler extends ListenerAdapter {
return; return;
Message message = event.getMessage(); Message message = event.getMessage();
Member member = event.getMember();
Guild guild = event.getGuild();
TextChannel channel = (TextChannel) event.getChannel();
Sentry.addBreadcrumb(Breadcrumb.info("New message from " + member.getEffectiveName()));
MessageCommandContext context = MessageCommandContext.createContext(event); MessageCommandContext context = MessageCommandContext.createContext(event);
Sentry.addBreadcrumb(Breadcrumb.info("New message from " + context.getGuildUser().getEffectiveName()));
GuildManager.getManager(guild).checkAndLogMessage(message, member, channel); GuildManager.getManager(context.getGuild()).checkAndLogMessage(message, context.getGuildUser(), context.getChannel());
String rawMessage = message.getContentDisplay().trim(); String rawMessage = message.getContentDisplay().trim();
String prefix = Settings.getInstance().get("BOT_PREFIX", "$"); String prefix = Settings.getInstance().get("BOT_PREFIX", "$");
@@ -50,13 +41,7 @@ public class MessageReceivedHandler extends ListenerAdapter {
// rawMessage = rawMessage.substring(prefix.length()).trim(); // rawMessage = rawMessage.substring(prefix.length()).trim();
String commandString = rawMessage.split(" ", 2)[0]; String commandString = rawMessage.split(" ", 2)[0];
context.dispatchToCommand(commandString);
if (CommandManager.isValidCommand(commandString)) {
AbstractCommand command = CommandManager.getCommand(commandString);
context.dispatch(command);
}
} }
} }
} }
@@ -49,7 +49,7 @@ public class ActionHandler extends AbstractHandler {
Guild guild = NetNeutrality.getJDA().getGuildById(guildId); Guild guild = NetNeutrality.getJDA().getGuildById(guildId);
if (guild != null) { if (guild != null) {
GuildManager manager = GuildManager.getManager(guild); GuildManager manager = GuildManager.getManager(guild);
Map<String, String> settings = manager.getSettings(); Map<String, String> settings = manager.getGuildConfigManager().getSettings();
JSONObject setting = new JSONObject(settings); JSONObject setting = new JSONObject(settings);
json.put("status", "ok"); json.put("status", "ok");
@@ -68,11 +68,11 @@ public class ActionHandler extends AbstractHandler {
String guildId = args[args.length - 1]; String guildId = args[args.length - 1];
Guild guild = NetNeutrality.getJDA().getGuildById(guildId); Guild guild = NetNeutrality.getJDA().getGuildById(guildId);
boolean ok; boolean ok = true; //TODO: add bool
if (guild == null) if (guild == null)
ok = GuildManager.getManager(guildId).reloadSettingsCache(); GuildManager.getManager(guildId).getGuildConfigManager().reloadSettingsCache();
else else
ok = GuildManager.getManager(guild).reloadSettingsCache(); GuildManager.getManager(guild).getGuildConfigManager().reloadSettingsCache();
json.put("status", String.valueOf(ok)); json.put("status", String.valueOf(ok));
@@ -17,6 +17,7 @@ import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel; import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel;
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
import netneutrality.core.GuildManager; import netneutrality.core.GuildManager;
import netneutrality.core.LogHandler; import netneutrality.core.LogHandler;
import netneutrality.core.context.CommandContext; import netneutrality.core.context.CommandContext;
@@ -55,7 +56,7 @@ public class MusicManager {
this.guild = guild; this.guild = guild;
this.player = playerManager.createPlayer(); this.player = playerManager.createPlayer();
this.scheduler = new TrackScheduler(this); this.scheduler = new TrackScheduler(this);
this.baseVolume = Integer.parseInt(GuildManager.getManager(guild).getSetting(GSettings.MUSIC_VOLUME)); this.baseVolume = Integer.parseInt(GuildManager.getManager(guild).getGuildConfigManager().getSetting(GSettings.MUSIC_VOLUME));
guild.getAudioManager().setSendingHandler(new AudioPlayerSendHandler(player)); guild.getAudioManager().setSendingHandler(new AudioPlayerSendHandler(player));
player.addListener(scheduler); player.addListener(scheduler);
@@ -92,11 +93,10 @@ public class MusicManager {
player.setVolume(baseVolume); player.setVolume(baseVolume);
if (autoDisconnectThread == null) if (autoDisconnectThread == null)
autoDisconnectThread = executor.scheduleWithFixedDelay(new MusicPlayerAutoDisconnectThread(this), 120, 120, TimeUnit.SECONDS); autoDisconnectThread = executor.scheduleWithFixedDelay(new MusicPlayerAutoDisconnectThread(this), 240, 240, TimeUnit.SECONDS);
} else { } else {
throw new RuntimeException("Error connecting to voice channel"); throw new RuntimeException("Error connecting to voice channel");
} }
} }
public boolean isConnected() { public boolean isConnected() {
@@ -165,11 +165,11 @@ public class MusicManager {
public void play(List<LoadableSong> songs, CommandContext context, boolean needToBeConnected, boolean silent) { public void play(List<LoadableSong> songs, CommandContext context, boolean needToBeConnected, boolean silent) {
Member member = context.getGuildUser(); Member member = context.getGuildUser();
TextChannel channel = (TextChannel) context.getChannel(); MessageChannel channel = context.getChannel();
if (member.getVoiceState() == null) { if (member.getVoiceState() == null) {
logger.error("Guild {}: Voice state is null", guild.getId()); logger.error("Guild {}: Voice state is null", guild.getId());
context.replyToMessage("Voice state is null, something has gone wrong."); context.replyToMessage("Voice state is null, something has gone terribly wrong.");
LogHandler.log(new CommandExecutionException("Voice state is null", context, null)); LogHandler.log(new CommandExecutionException("Voice state is null", context, null));
return; return;
@@ -119,6 +119,7 @@ public class TrackLoader implements Runnable {
} }
} catch (InterruptedException exception) { } catch (InterruptedException exception) {
stopLoading(); stopLoading();
context.replyToMessage("Loading of tracks was interrupted due to an exception");
LogHandler.log(exception); LogHandler.log(exception);
} }
@@ -14,6 +14,7 @@ import com.sedmelluq.discord.lavaplayer.track.AudioTrackEndReason;
import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.MessageEmbed; import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
import netneutrality.core.LogHandler; import netneutrality.core.LogHandler;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -24,7 +25,7 @@ public class TrackScheduler extends AudioEventAdapter {
private final QueueManager queueManager; private final QueueManager queueManager;
private final MusicManager manager; private final MusicManager manager;
private final AudioPlayer player; private final AudioPlayer player;
private TextChannel currentChannel; private MessageChannel currentChannel;
private final Guild guild; private final Guild guild;
public TrackScheduler(MusicManager manager) { public TrackScheduler(MusicManager manager) {
@@ -50,11 +51,11 @@ public class TrackScheduler extends AudioEventAdapter {
return guild; return guild;
} }
public TextChannel getTextChannel() { public MessageChannel getTextChannel() {
return currentChannel; return currentChannel;
} }
public synchronized void attachTextChannel(TextChannel channel) { public synchronized void attachTextChannel(MessageChannel channel) {
this.currentChannel = channel; this.currentChannel = channel;
} }
@@ -1,4 +1,5 @@
package netneutrality.thread;/* package netneutrality.thread;
/*
* Copyright (c) anthorob * Copyright (c) anthorob
* *
* https://xtremcommunity.com/ * https://xtremcommunity.com/
@@ -18,6 +19,7 @@ public class MusicPlayerAutoDisconnectThread implements Runnable {
final MusicManager manager; final MusicManager manager;
//TODO: move to scheduler
public MusicPlayerAutoDisconnectThread(MusicManager musicManager) { public MusicPlayerAutoDisconnectThread(MusicManager musicManager) {
manager = musicManager; manager = musicManager;
} }
@@ -27,13 +29,26 @@ public class MusicPlayerAutoDisconnectThread implements Runnable {
Guild guild = manager.getGuild(); Guild guild = manager.getGuild();
VoiceChannel channel = (VoiceChannel) guild.getAudioManager().getConnectedChannel(); VoiceChannel channel = (VoiceChannel) guild.getAudioManager().getConnectedChannel();
try {
if (channel != null) { if (channel != null) {
List<Member> members = channel.getMembers().stream().filter(member -> !member.getId().equals(NetNeutrality.getSelf().getId())).toList(); if (conditionsMetToDisconnect(channel)) {
// Sleep 30 seconds then check again (prevents disconnecting right after a track ends)
Thread.sleep(30000);
if (members.size() == 0 || manager.getScheduler().getQueueManager().isEmpty()) { if (conditionsMetToDisconnect(channel)) {
LoggerFactory.getLogger(MusicPlayerAutoDisconnectThread.class).debug("Guild {}: auto-disconnect player from voice channel: {}", guild.getId(), channel.getId()); LoggerFactory.getLogger(MusicPlayerAutoDisconnectThread.class).debug("Guild {}: auto-disconnect player from voice channel: {}", guild.getId(), channel.getId());
manager.leave(); manager.leave();
} }
} }
} }
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
private boolean conditionsMetToDisconnect(VoiceChannel channel) {
List<Member> members = channel.getMembers().stream().filter(member -> !member.getId().equals(NetNeutrality.getSelf().getId())).toList();
return members.size() == 0 || manager.getScheduler().getQueueManager().isEmpty();
}
} }
@@ -70,28 +70,17 @@ public class JpaUtils {
getWithSession(oGuild, oGuild.getGuildId(), consumer); getWithSession(oGuild, oGuild.getGuildId(), consumer);
} }
public static void getWithSession(OGuild oGuild, boolean close, Consumer<Session> consumer) {
getWithSession(oGuild, oGuild.getGuildId(), close, consumer);
}
public static void getWithSession(Object persistantEntity, Serializable id, Consumer<Session> consumer) {
getWithSession(persistantEntity, id, true, consumer);
}
/** /**
* @param persistantEntity The entity to load * @param persistantEntity The entity to load
* @param id The identifier for the entity * @param id The identifier for the entity
* @param close If the session should be closed after consumer is executed * @param close If the session should be closed after consumer is executed
* @param consumer The comsumer, which exposes the session * @param consumer The comsumer, which exposes the session
*/ */
public static void getWithSession(Object persistantEntity, Serializable id, boolean close, Consumer<Session> consumer) { public static void getWithSession(Object persistantEntity, Serializable id, Consumer<Session> consumer) {
Session session = SessionManager.getSessionFactory().openSession(); Session session = SessionManager.getSessionFactory().openSession();
tryLoad(session, persistantEntity, id); tryLoad(session, persistantEntity, id);
consumer.accept(session); consumer.accept(session);
if (close)
session.close(); session.close();
} }
} }
@@ -14,8 +14,7 @@ import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.MessageEmbed; import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.channel.ChannelType; import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import netneutrality.command.AbstractCommand; import netneutrality.command.AbstractCommand;
import netneutrality.command.CommandType; import netneutrality.command.CommandType;
import netneutrality.core.CommandManager; import netneutrality.core.CommandManager;
@@ -39,28 +38,6 @@ public class MessageFunction {
private final static Logger logger = LoggerFactory.getLogger(MessageFunction.class); private final static Logger logger = LoggerFactory.getLogger(MessageFunction.class);
public static Member getStartingMention(Message message) {
if (isStartingWithMention(message)) {
return message.getMentions().getMembers().get(0);
}
return null;
}
public static boolean isStartingWithMention(Message message) {
if (!message.isFromType(ChannelType.TEXT))
return false;
List<Member> mentions = message.getMentions().getMembers();
for (Member member : mentions) {
if (message.getContentDisplay().startsWith("@" + member.getUser().getName()))
return true;
}
return false;
}
public static MessageEmbed buildCurrentlyPlayingMessage(MusicManager manager) { public static MessageEmbed buildCurrentlyPlayingMessage(MusicManager manager) {
AudioTrack current = manager.getCurrentlyPlaying(); AudioTrack current = manager.getCurrentlyPlaying();
@@ -81,7 +58,7 @@ public class MessageFunction {
String url = track.getIdentifier(); String url = track.getIdentifier();
String thumbnail = null; String thumbnail = null;
if (type == SourceFinder.AudioSourceType.Youtube || type == SourceFinder.AudioSourceType.YTSearch) { if (type == SourceFinder.AudioSourceType.Youtube || type == SourceFinder.AudioSourceType.YTSearch || type == SourceFinder.AudioSourceType.YTMusic) {
url = String.format("https://youtu.be/%s", track.getIdentifier()); url = String.format("https://youtu.be/%s", track.getIdentifier());
thumbnail = String.format("https://i3.ytimg.com/vi/%s/hqdefault.jpg", track.getIdentifier()); thumbnail = String.format("https://i3.ytimg.com/vi/%s/hqdefault.jpg", track.getIdentifier());
} }
@@ -275,7 +252,7 @@ public class MessageFunction {
return editEmbed.build(); return editEmbed.build();
} }
public static void testMessageAgainstBlacklist(Message message, TextChannel channel, Set<String> cache) { public static void testMessageAgainstBlacklist(Message message, MessageChannel channel, Set<String> cache) {
boolean found = false; boolean found = false;
for (String word : cache) { for (String word : cache) {
if (message.getContentRaw().toLowerCase().contains(word)) { if (message.getContentRaw().toLowerCase().contains(word)) {