Search in sources :

Example 1 with UserRoleUpdateEvent

use of sx.blah.discord.handle.impl.events.guild.member.UserRoleUpdateEvent in project DiscordSailv2 by Vaerys-Dawn.

the class RequestHandler method muteUser.

public static boolean muteUser(long guildID, long userID, boolean isMuting) {
    GuildObject content = Globals.getGuildContent(guildID);
    IUser user = Globals.getClient().getUserByID(userID);
    IGuild guild = Globals.getClient().getGuildByID(guildID);
    IRole mutedRole = Globals.client.getRoleByID(content.config.getMutedRoleID());
    List<IRole> oldRoles = user.getRolesForGuild(guild);
    if (mutedRole != null) {
        roleManagement(Globals.getClient().getUserByID(userID), Globals.client.getGuildByID(guildID), mutedRole.getLongID(), isMuting);
        List<IRole> newRoles = user.getRolesForGuild(guild);
        Globals.getClient().getDispatcher().dispatch(new UserRoleUpdateEvent(guild, user, oldRoles, newRoles));
        return true;
    }
    return false;
}
Also used : GuildObject(com.github.vaerys.masterobjects.GuildObject) UserRoleUpdateEvent(sx.blah.discord.handle.impl.events.guild.member.UserRoleUpdateEvent)

Example 2 with UserRoleUpdateEvent

use of sx.blah.discord.handle.impl.events.guild.member.UserRoleUpdateEvent in project DiscordSailv2 by Vaerys-Dawn.

the class SpamHandler method checkMentionCount.

public static boolean checkMentionCount(CommandObject command) {
    IMessage message = command.message.get();
    GuildConfig guildconfig = command.guild.config;
    IUser author = command.user.get();
    List<IRole> oldRoles = command.user.roles;
    IGuild guild = command.guild.get();
    List<IChannel> channels = command.guild.getChannelsByType(ChannelSetting.IGNORE_SPAM);
    if (channels.contains(command.channel.get()))
        return false;
    if (GuildHandler.testForPerms(command, Permissions.MENTION_EVERYONE))
        return false;
    if (message.toString().contains("@everyone") || message.toString().contains("@here")) {
        return false;
    }
    if (guildconfig.maxMentions) {
        if (message.getMentions().size() > 8) {
            RequestHandler.deleteMessage(message);
            int i = 0;
            boolean offenderFound = false;
            for (OffenderObject o : guildconfig.getOffenders()) {
                if (author.getLongID() == o.getID()) {
                    guildconfig.addOffence(o.getID());
                    command.guild.sendDebugLog(command, "STOP_MASS_MENTIONS", "OFFENCE_ADDED", message.getMentions().size() + " Mentions");
                    offenderFound = true;
                    i++;
                    if (o.getCount() >= Globals.maxWarnings) {
                        String report = "> %s has been muted for repeat offences of spamming mentions.";
                        RequestHandler.roleManagement(author, guild, guildconfig.getMutedRoleID(), true);
                        command.guild.sendDebugLog(command, "STOP_MASS_MENTIONS", "MUTE", o.getCount() + " Offences");
                        command.client.get().getDispatcher().dispatch(new UserRoleUpdateEvent(guild, author, oldRoles, command.user.get().getRolesForGuild(guild)));
                        // add strike in modnote
                        command.user.getProfile(command.guild).addSailModNote(String.format(report, author.mention()), command, false);
                        // send admin notification
                        RequestHandler.sendMessage(String.format(report, author.mention()), command.channel.get());
                    }
                }
            }
            if (!offenderFound) {
                guildconfig.addOffender(new OffenderObject(author.getLongID()));
            }
            String response = "> <mentionAdmin>, " + author.mention() + "  has attempted to post more than " + guildconfig.getMaxMentionLimit() + " Mentions in a single message in " + command.channel.mention + ".";
            IRole roleToMention = command.guild.getRoleByID(guildconfig.getRoleToMentionID());
            if (roleToMention != null) {
                response = response.replaceAll("<mentionAdmin>", roleToMention.mention());
            } else {
                response = response.replaceAll("<mentionAdmin>", "Admin");
            }
            RequestHandler.sendMessage(response, command.channel.get());
            return true;
        }
    }
    return false;
}
Also used : UserRoleUpdateEvent(sx.blah.discord.handle.impl.events.guild.member.UserRoleUpdateEvent) OffenderObject(com.github.vaerys.objects.OffenderObject) GuildConfig(com.github.vaerys.pogos.GuildConfig)

Example 3 with UserRoleUpdateEvent

use of sx.blah.discord.handle.impl.events.guild.member.UserRoleUpdateEvent in project DiscordSailv2 by Vaerys-Dawn.

the class LoggingHandler method doRoleUpdateLog.

public static void doRoleUpdateLog(UserRoleUpdateEvent event) {
    IGuild guild = event.getGuild();
    GuildObject content = Globals.getGuildContent(guild.getLongID());
    if (!content.config.moduleLogging)
        return;
    if (content.config.userRoleLogging) {
        ArrayList<String> oldRoles = new ArrayList<>();
        ArrayList<String> newRoles = new ArrayList<>();
        oldRoles.addAll(event.getOldRoles().stream().filter(r -> !r.isEveryoneRole()).map(IRole::getName).collect(Collectors.toList()));
        newRoles.addAll(event.getNewRoles().stream().filter(r -> !r.isEveryoneRole()).map(IRole::getName).collect(Collectors.toList()));
        StringBuilder oldRoleList = new StringBuilder();
        StringBuilder newRoleList = new StringBuilder();
        for (String r : oldRoles) {
            oldRoleList.append(r + ", ");
        }
        for (String r : newRoles) {
            newRoleList.append(r + ", ");
        }
        String prefix = "> **@" + event.getUser().getName() + "#" + event.getUser().getDiscriminator() + "'s** Role have been Updated.";
        Utility.sendLog(prefix + "\nOld Roles: " + Utility.listFormatter(oldRoles, true) + "\nNew Roles: " + Utility.listFormatter(newRoles, true), content, false);
    }
}
Also used : GuildObject(com.github.vaerys.masterobjects.GuildObject) GuildMemberEvent(sx.blah.discord.handle.impl.events.guild.member.GuildMemberEvent) ChannelUpdateEvent(sx.blah.discord.handle.impl.events.guild.channel.ChannelUpdateEvent) UserBanEvent(sx.blah.discord.handle.impl.events.guild.member.UserBanEvent) ZonedDateTime(java.time.ZonedDateTime) ChannelSetting(com.github.vaerys.enums.ChannelSetting) LoggerFactory(org.slf4j.LoggerFactory) Client(com.github.vaerys.main.Client) MessageUpdateEvent(sx.blah.discord.handle.impl.events.guild.channel.message.MessageUpdateEvent) ArrayList(java.util.ArrayList) DiscordUtils(sx.blah.discord.api.internal.DiscordUtils) AuditLogEntry(sx.blah.discord.handle.audit.entry.AuditLogEntry) TargetedEntry(sx.blah.discord.handle.audit.entry.TargetedEntry) ActionType(sx.blah.discord.handle.audit.ActionType) ZoneOffset(java.time.ZoneOffset) CommandObject(com.github.vaerys.commands.CommandObject) Globals(com.github.vaerys.main.Globals) Logger(org.slf4j.Logger) ChannelCreateEvent(sx.blah.discord.handle.impl.events.guild.channel.ChannelCreateEvent) EmbedObject(sx.blah.discord.api.internal.json.objects.EmbedObject) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) List(java.util.List) sx.blah.discord.handle.obj(sx.blah.discord.handle.obj) ChannelDeleteEvent(sx.blah.discord.handle.impl.events.guild.channel.ChannelDeleteEvent) Comparator(java.util.Comparator) Utility(com.github.vaerys.main.Utility) UserRoleUpdateEvent(sx.blah.discord.handle.impl.events.guild.member.UserRoleUpdateEvent) GuildObject(com.github.vaerys.masterobjects.GuildObject) ArrayList(java.util.ArrayList)

Aggregations

UserRoleUpdateEvent (sx.blah.discord.handle.impl.events.guild.member.UserRoleUpdateEvent)3 GuildObject (com.github.vaerys.masterobjects.GuildObject)2 CommandObject (com.github.vaerys.commands.CommandObject)1 ChannelSetting (com.github.vaerys.enums.ChannelSetting)1 Client (com.github.vaerys.main.Client)1 Globals (com.github.vaerys.main.Globals)1 Utility (com.github.vaerys.main.Utility)1 OffenderObject (com.github.vaerys.objects.OffenderObject)1 GuildConfig (com.github.vaerys.pogos.GuildConfig)1 Instant (java.time.Instant)1 ZoneOffset (java.time.ZoneOffset)1 ZonedDateTime (java.time.ZonedDateTime)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 DiscordUtils (sx.blah.discord.api.internal.DiscordUtils)1 EmbedObject (sx.blah.discord.api.internal.json.objects.EmbedObject)1