use of ml.duncte123.skybot.Variables in project SkyBot by duncte123.
the class SQLiteTimers method checkUnbansAndUnmutes.
private static void checkUnbansAndUnmutes(Variables variables) {
variables.getDatabaseAdapter().getExpiredBansAndMutes((bans, mutes) -> {
final DatabaseAdapter adapter = variables.getDatabaseAdapter();
handleUnban(bans, adapter, variables);
handleUnmute(mutes, adapter, variables);
return null;
});
}
use of ml.duncte123.skybot.Variables in project SkyBot by duncte123.
the class MessageListener method handleMessageEventChecked.
private void handleMessageEventChecked(String raw, Guild guild, GuildMessageReceivedEvent event) {
final GuildSetting settings = GuildSettingsUtils.getGuild(guild.getIdLong(), this.variables);
final String customPrefix = settings.getCustomPrefix();
final Message message = event.getMessage();
if (settings.isMessageLogging()) {
final MessageData data = MessageData.from(message);
this.redis.storeMessage(data, isGuildPatron(guild));
}
if (!commandManager.isCommand(customPrefix, raw) && doAutoModChecks(event, settings, raw)) {
return;
}
final User selfUser = event.getJDA().getSelfUser();
final long selfId = selfUser.getIdLong();
final String selfRegex = "<@!?" + selfId + '>';
if (raw.matches(selfRegex)) {
sendMsg(new MessageConfig.Builder().setChannel(event.getChannel()).setMessageFormat("Hey %s, try `%shelp` for a list of commands. If it doesn't work scream at _duncte123#1245_", event.getAuthor(), customPrefix).build());
return;
}
final String[] split = raw.replaceFirst(Pattern.quote(Settings.PREFIX), "").split("\\s+");
final List<CustomCommand> autoResponses = commandManager.getAutoResponses(guild.getIdLong());
if (!autoResponses.isEmpty() && invokeAutoResponse(autoResponses, split, event)) {
return;
}
if (doesNotStartWithPrefix(selfId, raw, customPrefix) || !canRunCommands(raw, customPrefix, event)) {
return;
}
if (raw.matches(selfRegex + "(.*)")) {
// Handle the chat command
Objects.requireNonNull(commandManager.getCommand("chat")).executeCommand(new CommandContext("chat", Arrays.asList(split).subList(1, split.length), event, variables));
} else {
// Handle the command
commandManager.runCommand(event, customPrefix);
}
}
use of ml.duncte123.skybot.Variables in project SkyBot by duncte123.
the class MessageListener method doAutoModChecks.
private boolean doAutoModChecks(@Nonnull GuildMessageReceivedEvent event, GuildSetting settings, String raw) {
final Guild guild = event.getGuild();
if (guild.getSelfMember().hasPermission(Permission.MESSAGE_MANAGE) && !Objects.requireNonNull(event.getMember()).hasPermission(Permission.MESSAGE_MANAGE)) {
checkMessageForInvites(guild, event, settings, raw);
final Message messageToCheck = event.getMessage();
final DunctebotGuild dbG = new DunctebotGuild(event.getGuild(), variables);
if (blacklistedWordCheck(dbG, messageToCheck, event.getMember(), settings.getBlacklistedWords())) {
return true;
}
if (checkSwearFilter(messageToCheck, event, dbG)) {
return true;
}
checkSpamFilter(messageToCheck, event, settings, dbG);
}
return false;
}
use of ml.duncte123.skybot.Variables in project SkyBot by duncte123.
the class MessageListener method onGuildMessageUpdate.
protected void onGuildMessageUpdate(GuildMessageUpdateEvent event) {
// ignore bots
final Message message = event.getMessage();
final User author = message.getAuthor();
if (author.isBot() || author.isSystem() || message.isWebhookMessage() || event.getMember() == null) {
return;
}
if (topicContains(event.getChannel(), PROFANITY_DISABLE)) {
return;
}
this.handlerThread.submit(() -> {
try {
final DunctebotGuild guild = new DunctebotGuild(event.getGuild(), variables);
final GuildSetting settings = guild.getSettings();
if (settings.isMessageLogging()) {
final MessageData edited = MessageData.from(message);
final MessageData original = this.redis.getAndUpdateMessage(message.getId(), edited, isGuildPatron(guild));
// data will be null if the message expired
if (original != null) {
this.logEditedMessage(original, edited, guild);
}
}
if (guild.getSelfMember().hasPermission(Permission.MESSAGE_MANAGE) && !event.getMember().hasPermission(Permission.MESSAGE_MANAGE)) {
if (blacklistedWordCheck(guild, message, event.getMember(), settings.getBlacklistedWords())) {
return;
}
checkSwearFilter(message, event, guild);
}
} catch (Exception e) {
LOGGER.error("Exception on message update", e);
}
});
}
use of ml.duncte123.skybot.Variables in project SkyBot by duncte123.
the class MessageListener method onMessageBulkDelete.
@SuppressWarnings("PMD.UseConcurrentHashMap")
protected void onMessageBulkDelete(final MessageBulkDeleteEvent event) {
this.handlerThread.submit(() -> {
try {
final DunctebotGuild guild = new DunctebotGuild(event.getGuild(), variables);
if (!guild.getSettings().isMessageLogging()) {
// just delete the message here as we don't want to keep it around
this.redis.deleteMessages(event.getMessageIds());
return;
}
final List<MessageData> dataList = this.redis.getAndDeleteMessages(event.getMessageIds());
final StringBuilder builder = new StringBuilder();
// temporarily store the users to prevent spamming discord for the data
final Map<Long, User> tmpUsers = new HashMap<>();
final JDA jda = event.getJDA();
// reverse the list to preserve the correct order
Collections.reverse(dataList);
for (final MessageData data : dataList) {
final long authorId = data.getAuthorId();
final Consumer<User> userConsumer = (user) -> {
builder.append('[').append(data.getCratedAt().format(DateTimeFormatter.RFC_1123_DATE_TIME)).append("] (").append(user.getAsTag()).append(" - ").append(user.getIdLong()).append(") [").append(data.getMessageId()).append("]: ").append(data.getContent()).append('\n');
};
if (tmpUsers.containsKey(authorId)) {
userConsumer.accept(tmpUsers.get(authorId));
} else {
// try to fetch the user since we don't cache them
// calls are sequential making sure the messages are still in order
jda.retrieveUserById(authorId).queue((user) -> {
tmpUsers.put(authorId, user);
userConsumer.accept(user);
}, (error) -> userConsumer.accept(new UnknownUser(authorId)));
}
}
final TextChannel channel = event.getChannel();
final EmbedBuilder embed = EmbedUtils.embedField("Bulk Delete", "Bulk deleted messages from <#%s> are available in the attached file.".formatted(channel.getIdLong())).setColor(0xE67E22).setTimestamp(Instant.now());
modLog(new MessageConfig.Builder().addEmbed(true, embed).setActionConfig((action) -> action.addFile(builder.toString().getBytes(), "bulk_delete_%s.txt".formatted(System.currentTimeMillis()))), guild);
} catch (Exception e) {
LOGGER.error("Exception on message bulk delete", e);
}
});
}
Aggregations