use of sx.blah.discord.handle.obj.IRole in project DisCal-Discord-Bot by NovaFox161.
the class DisCalCommand method moduleControlRole.
/**
* Sets the control role for the guild.
* @param args The args of the command.
* @param event The event received.
*/
private void moduleControlRole(String[] args, MessageReceivedEvent event, GuildSettings settings) {
if (PermissionChecker.hasSufficientRole(event)) {
if (args.length > 1) {
String roleName = GeneralUtils.getContent(args, 1);
IRole controlRole;
if (!"everyone".equalsIgnoreCase(roleName)) {
controlRole = RoleUtils.getRoleFromID(roleName, event);
if (controlRole != null) {
settings.setControlRole(controlRole.getStringID());
DatabaseManager.getManager().updateSettings(settings);
// Send message.
Message.sendMessage(MessageManager.getMessage("DisCal.ControlRole.Set", "%role%", controlRole.getName(), settings), event);
} else {
// Invalid role.
Message.sendMessage(MessageManager.getMessage("DisCal.ControlRole.Invalid", settings), event);
}
} else {
// Role is @everyone, set this so that anyone can control the bot.
settings.setControlRole("everyone");
DatabaseManager.getManager().updateSettings(settings);
// Send message
Message.sendMessage(MessageManager.getMessage("DisCal.ControlRole.Reset", settings), event);
}
} else {
Message.sendMessage(MessageManager.getMessage("DisCal.ControlRole.Specify", settings), event);
}
} else {
Message.sendMessage(MessageManager.getMessage("Notification.Perm.CONTROL_ROLE", settings), event);
}
}
use of sx.blah.discord.handle.obj.IRole in project Discord4J by Discord4J.
the class RoleBuilder method build.
/**
* Builds a role with the configuration specified by the builder.
*
* @return A role with the configuration specified by the builder.
*/
public IRole build() {
if (guild == null)
throw new RuntimeException("A guild must be set to create a role.");
Role role = (Role) guild.createRole();
role.edit(color != null ? color : role.getColor(), hoist, name != null ? name : role.getName(), permissions != null ? permissions : role.getPermissions(), mentionable);
return role;
}
use of sx.blah.discord.handle.obj.IRole in project DiscordSailv2 by Vaerys-Dawn.
the class TimerHandler method reportHandling.
private static void reportHandling(GuildObject task) {
List<UserRateObject> offenders = task.getRateLimiting();
IRole muteRole = task.getRoleByID(task.config.getMutedRoleID());
if (muteRole == null)
return;
IChannel admin = task.getChannelByType(ChannelSetting.ADMIN);
for (UserRateObject u : offenders) {
if (u.counter - 3 > task.config.messageLimit) {
List<IChannel> channels = u.getChannels(task);
if (admin == null && !channels.isEmpty()) {
admin = channels.get(channels.size() - 1);
}
StringHandler output = new StringHandler();
StringHandler modNote = new StringHandler();
IUser offender = u.getUser(task);
long rate = u.counter - task.config.messageLimit;
String formattedChannels = String.join(", ", channels.stream().map(channel -> channel.mention()).collect(Collectors.toList()));
// Admin Message output
output.append("> ").append(offender.mention());
output.append(" Has Been muted for breaking the guild rate limit (");
output.append(rate);
output.append(" Over Rate)");
if (channels.size() == 1) {
output.append(" in ").append(channels.get(0).mention());
} else if (channels.size() > 1) {
output.append(" in channels: ");
output.append(formattedChannels);
}
output.append(".");
// modNote Output
modNote.append("> Muted by Rate Limiter, ");
modNote.append(rate).append(" Over Rate, ");
modNote.append("Channel");
if (channels.size() > 1)
modNote.append("s");
modNote.append(": ").append(formattedChannels);
// logging
if (task.config.deleteLogging) {
Utility.sendLog("> **@" + offender.getName() + "#" + offender.getDiscriminator() + "** was muted for breaking rate limit.", task, true);
}
ProfileObject profile = task.users.getUserByID(u.getID());
profile.addSailModNote(modNote.toString(), u.timeStamp, false);
RequestHandler.sendMessage(output.toString(), admin);
}
}
}
use of sx.blah.discord.handle.obj.IRole in project DiscordSailv2 by Vaerys-Dawn.
the class GuildConfig method validateRoles.
public void validateRoles() {
IGuild guild = Globals.client.getGuildByID(guildID);
if (guild == null) {
return;
}
ListIterator iterator = cosmeticRoleIDs.listIterator();
while (iterator.hasNext()) {
IRole role = guild.getRoleByID((Long) iterator.next());
if (role == null) {
iterator.remove();
}
}
iterator = modifierRoleIDs.listIterator();
while (iterator.hasNext()) {
IRole role = guild.getRoleByID((Long) iterator.next());
if (role == null) {
iterator.remove();
}
}
IRole inviteAllowedRole = guild.getRoleByID(inviteAllowedID);
if (inviteAllowedRole == null) {
inviteAllowedID = -1;
}
IRole mutedRole = guild.getRoleByID(mutedRoleID);
if (mutedRole == null) {
mutedRoleID = -1;
}
IRole roleToMention = guild.getRoleByID(roleToMentionID);
if (roleToMention == null) {
roleToMentionID = -1;
}
iterator = rewardRoles.listIterator();
while (iterator.hasNext()) {
RewardRoleObject reward = (RewardRoleObject) iterator.next();
IRole role = guild.getRoleByID(reward.getRoleID());
if (role == null) {
iterator.remove();
}
}
}
use of sx.blah.discord.handle.obj.IRole in project DiscordSailv2 by Vaerys-Dawn.
the class GuildConfig method testIsTrusted.
public boolean testIsTrusted(IUser author, IGuild guild) {
validateRoles();
IRole inviteAllowed = guild.getRoleByID(inviteAllowedID);
if (inviteAllowed == null) {
return true;
} else {
return author.getRolesForGuild(guild).contains(inviteAllowed);
}
}
Aggregations