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;
}
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;
}
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);
}
}
Aggregations