Search in sources :

Example 1 with GuildPermissions

use of fredboat.db.transfer.GuildPermissions in project FredBoat by Frederikam.

the class PermissionsCommand method list.

public void list(CommandContext context) {
    Guild guild = context.guild;
    Member invoker = context.invoker;
    GuildPermissions gp = Launcher.getBotController().getGuildPermsService().fetchGuildPermissions(guild);
    List<IMentionable> mentionables = idsToMentionables(guild, gp.getFromEnum(permissionLevel));
    String roleMentions = "";
    String memberMentions = "";
    for (IMentionable mentionable : mentionables) {
        if (mentionable instanceof Role) {
            if (((Role) mentionable).isPublicRole()) {
                // Prevents ugly double double @@
                roleMentions = roleMentions + "@everyone" + "\n";
            } else {
                roleMentions = roleMentions + mentionable.getAsMention() + "\n";
            }
        } else {
            memberMentions = memberMentions + mentionable.getAsMention() + "\n";
        }
    }
    PermissionLevel invokerPerms = PermsUtil.getPerms(invoker);
    boolean invokerHas = PermsUtil.checkPerms(permissionLevel, invoker);
    if (roleMentions.isEmpty())
        roleMentions = "<none>";
    if (memberMentions.isEmpty())
        memberMentions = "<none>";
    EmbedBuilder eb = CentralMessaging.getColoredEmbedBuilder().setTitle(context.i18nFormat("permsListTitle", permissionLevel)).setAuthor(invoker.getEffectiveName(), null, invoker.getUser().getAvatarUrl()).addField("Roles", roleMentions, true).addField("Members", memberMentions, true).addField(TextUtils.escapeMarkdown(invoker.getEffectiveName()), (invokerHas ? ":white_check_mark:" : ":x:") + " (" + invokerPerms + ")", false);
    context.reply(CentralMessaging.addFooter(eb, guild.getSelfMember()).build());
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) GuildPermissions(fredboat.db.transfer.GuildPermissions) PermissionLevel(fredboat.definitions.PermissionLevel)

Aggregations

GuildPermissions (fredboat.db.transfer.GuildPermissions)1 PermissionLevel (fredboat.definitions.PermissionLevel)1 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)1