use of com.dunctebot.models.settings.GuildSetting 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 com.dunctebot.models.settings.GuildSetting in project SkyBot by duncte123.
the class MessageListener method checkMessageForInvites.
// / <editor-fold desc="auto moderation" defaultstate="collapsed">
private void checkMessageForInvites(Guild guild, GuildMessageReceivedEvent event, GuildSetting settings, String raw) {
if (settings.isFilterInvites() && guild.getSelfMember().hasPermission(Permission.MANAGE_SERVER)) {
final Matcher matcher = Message.INVITE_PATTERN.matcher(raw);
if (matcher.find()) {
// Get the invite Id from the message
final String inviteID = matcher.group(matcher.groupCount());
// Prohibiting failure because the bot is currently banned from the other guild.
guild.retrieveInvites().queue((invites) -> {
// Check if the invite is for this guild, if it is not delete the message
if (invites.stream().noneMatch((invite) -> invite.getCode().equals(inviteID))) {
event.getMessage().delete().reason("Contained unauthorized invite.").queue((it) -> sendMsg(MessageConfig.Builder.fromEvent(event).setMessage(event.getAuthor().getAsMention() + ", please don't post invite links here.").setSuccessAction(m -> m.delete().queueAfter(4, TimeUnit.SECONDS)).build()), new ErrorHandler().ignore(UNKNOWN_MESSAGE, MISSING_PERMISSIONS));
}
});
}
}
}
use of com.dunctebot.models.settings.GuildSetting 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 com.dunctebot.models.settings.GuildSetting in project SkyBot by duncte123.
the class MessageListener method checkSwearFilter.
private boolean checkSwearFilter(Message messageToCheck, GenericGuildMessageEvent event, DunctebotGuild guild) {
final GuildSetting settings = guild.getSettings();
if (settings.isEnableSwearFilter() && !topicContains(event.getChannel(), PROFANITY_DISABLE)) {
final float score = PerspectiveApi.checkSwearFilter(messageToCheck.getContentRaw(), event.getChannel().getId(), variables.getConfig().apis.googl, settings.getFilterType(), variables.getJackson());
// if the score is less than our target value it's not swearing
if (score < settings.getAiSensitivity()) {
return false;
}
final String display = messageToCheck.getContentDisplay();
messageToCheck.delete().reason("Blocked for swearing: " + display).queue(null, new ErrorHandler().ignore(UNKNOWN_MESSAGE, MISSING_PERMISSIONS));
sendMsg(new MessageConfig.Builder().setChannel(event.getChannel()).setMessageFormat(// TODO: allow patrons to customise this message
"Hello there, %s please do not use cursive language within this server.", messageToCheck.getAuthor().getAsMention()).setSuccessAction((m) -> m.delete().queueAfter(5, TimeUnit.SECONDS, null, new ErrorHandler().ignore(UNKNOWN_MESSAGE, MISSING_PERMISSIONS))).build());
modLog(String.format("Message with score %.2f by %#s deleted in %s for profanity, message content was:```\n%s```", score, messageToCheck.getAuthor(), event.getChannel().getAsMention(), // Just to be safe
StringUtils.abbreviate(display, Message.MAX_CONTENT_LENGTH - 150)), guild);
return true;
}
return false;
}
use of com.dunctebot.models.settings.GuildSetting in project SkyBot by duncte123.
the class UnmuteCommand method execute.
@Override
public void execute(@Nonnull CommandContext ctx) {
final List<Member> mentioned = ctx.getMentionedArg(0);
if (mentioned.isEmpty()) {
this.sendUsageInstructions(ctx);
return;
}
final GuildSetting settings = ctx.getGuildSettings();
if (settings.getMuteRoleId() <= 0) {
sendMsg(ctx, "No mute/spamrole is set, use `" + ctx.getPrefix() + "muterole <Role>` to set it");
return;
}
final Role role = ctx.getGuild().getRoleById(settings.getMuteRoleId());
if (role == null) {
sendMsg(ctx, "The current mute role does not exist on this server, please contact your server administrator about this.");
return;
}
final Member toMute = mentioned.get(0);
final Member mod = ctx.getMember();
if (!canInteract(mod, toMute, "unmute", ctx.getChannel())) {
return;
}
final Member self = ctx.getSelfMember();
if (!self.canInteract(role)) {
sendMsg(ctx, "I cannot unmute this member, is the mute role above mine?");
return;
}
String reason = "";
final var flags = ctx.getParsedFlags(this);
final List<String> args = ctx.getArgs();
if (flags.containsKey("r")) {
reason = String.join(" ", flags.get("r"));
} else if (args.size() > 1) {
final var example = "\nExample: `%sunmute %s -r %s`".formatted(ctx.getPrefix(), args.get(0), String.join(" ", args.subList(1, args.size())));
sendMsg(ctx, "Hint: if you want to set a reason, use the `-r` flag" + example);
}
final String fReason = reason;
ctx.getGuild().removeRoleFromMember(toMute, role).reason("Unmute by " + String.format("%#s: %s", ctx.getAuthor(), fReason)).queue(success -> {
ModerationUtils.modLog(ctx.getAuthor(), toMute.getUser(), "unmuted", fReason, null, ctx.getGuild());
sendSuccess(ctx.getMessage());
});
}
Aggregations