Search in sources :

Example 1 with IRole

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);
    }
}
Also used : IRole(sx.blah.discord.handle.obj.IRole)

Example 2 with IRole

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;
}
Also used : IRole(sx.blah.discord.handle.obj.IRole) Role(sx.blah.discord.handle.impl.obj.Role)

Example 3 with IRole

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);
        }
    }
}
Also used : IChannel(sx.blah.discord.handle.obj.IChannel) IRole(sx.blah.discord.handle.obj.IRole) IUser(sx.blah.discord.handle.obj.IUser)

Example 4 with IRole

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();
        }
    }
}
Also used : RewardRoleObject(com.github.vaerys.objects.RewardRoleObject) IRole(sx.blah.discord.handle.obj.IRole) IGuild(sx.blah.discord.handle.obj.IGuild) ListIterator(java.util.ListIterator)

Example 5 with IRole

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);
    }
}
Also used : IRole(sx.blah.discord.handle.obj.IRole)

Aggregations

IRole (sx.blah.discord.handle.obj.IRole)39 IUser (sx.blah.discord.handle.obj.IUser)8 IChannel (sx.blah.discord.handle.obj.IChannel)7 ArrayList (java.util.ArrayList)6 UserObject (com.github.vaerys.masterobjects.UserObject)5 SplitFirstObject (com.github.vaerys.objects.SplitFirstObject)5 XEmbedBuilder (com.github.vaerys.objects.XEmbedBuilder)5 IGuild (sx.blah.discord.handle.obj.IGuild)5 CommandObject (com.github.vaerys.commands.CommandObject)4 ChannelSetting (com.github.vaerys.enums.ChannelSetting)4 SAILType (com.github.vaerys.enums.SAILType)4 RewardRoleObject (com.github.vaerys.objects.RewardRoleObject)4 CharacterObject (com.github.vaerys.objects.CharacterObject)3 ProfileObject (com.github.vaerys.objects.ProfileObject)3 Command (com.github.vaerys.templates.Command)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 DBGuild (me.shadorc.shadbot.data.db.DBGuild)3 Permissions (sx.blah.discord.handle.obj.Permissions)3 GuildHandler (com.github.vaerys.handlers.GuildHandler)2