当前位置: 首页>>代码示例>>Java>>正文


Java IRole类代码示例

本文整理汇总了Java中sx.blah.discord.handle.obj.IRole的典型用法代码示例。如果您正苦于以下问题:Java IRole类的具体用法?Java IRole怎么用?Java IRole使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


IRole类属于sx.blah.discord.handle.obj包,在下文中一共展示了IRole类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isAllowed

import sx.blah.discord.handle.obj.IRole; //导入依赖的package包/类
/**
 * Checks whether command sent is permissible
 * @param event message event triggered when command is invoke
 * @param command command the user is trying to invoke
 * @return whether user is allowed to invoke command
 */
public final boolean isAllowed(MessageReceivedEvent event, String command) {
    long userId = event.getAuthor().getLongID();
    ArrayList<String> userRoles = new ArrayList<>();

    for (IRole userRole
            : event.getAuthor().getRolesForGuild(event.getGuild())) {
        userRoles.add(userRole.getName());
    }

    for (Role role : roles) {
        //return true if user is eligible to execute command
        if (containsString(userRoles, role.getName())
                && (role.getBannedUsers() == null
                    || !role.getBannedUsers().contains(userId))
                && (containsString(role.getCommands(), "*")
                    || containsString(role.getCommands(), command))
                ) {
            return true;
        }
    }

    return false;
}
 
开发者ID:Pedro12909,项目名称:RexCord,代码行数:30,代码来源:PermissionConfiguration.java

示例2: getRole

import sx.blah.discord.handle.obj.IRole; //导入依赖的package包/类
public static long getRole(String toLookFor, IGuild guild) {
	toLookFor = GeneralUtils.trim(toLookFor);
	final String lower = toLookFor.toLowerCase();
	if (lower.matches("@&[0-9]+") || lower.matches("[0-9]+")) {
		final String parse = toLookFor.replaceAll("[<@&>]", "");
		IRole exists = guild.getRoleByID(Long.parseLong(toLookFor.replaceAll("[<@&>]", "")));
		if (exists != null) {
			return exists.getLongID();
		}
	}


	List<IRole> roles = new ArrayList<>();
	List<IRole> rs = guild.getRoles();
	roles.addAll(rs.stream().filter(r -> r.getName().equalsIgnoreCase(lower)).collect(Collectors.toList()));
	roles.addAll(rs.stream().filter(r -> r.getName().toLowerCase().contains(lower)).collect(Collectors.toList()));
	final StringBuilder builder = new StringBuilder(); // DEBUG
	roles.forEach(r -> builder.append(r.getName()).append(", ")); // DEBUG
	if (!roles.isEmpty()) {
		return roles.get(0).getLongID();
	}

	return 0;
}
 
开发者ID:NovaFox161,项目名称:DisCal-Discord-Bot,代码行数:25,代码来源:RoleUtils.java

示例3: hasPermission

import sx.blah.discord.handle.obj.IRole; //导入依赖的package包/类
public boolean hasPermission(IUser user, IGuild server, String permission) {
    boolean check = false;
    if (permission.equalsIgnoreCase(Globals.BOT_OWNER)) {
        if (user.equals(INIT.BOT.getApplicationOwner())) {
            check = true;
        }
    } else {
        for (IRole role : user.getRolesForGuild(server)) {
            if (grouppermissions.get(role) != null && grouppermissions.get(role).contains(permission)) {
                check = true;
            }
        }
    }
    if (DRIVER.getPropertyOnly(DRIVER.CONFIG, "ownerbypass").equals(true) && user.equals(INIT.BOT.getApplicationOwner())) {
        check = true;
    }
    return check;
}
 
开发者ID:ModdyLP,项目名称:MoMuOSB,代码行数:19,代码来源:PermissionController.java

示例4: addUsertoRole

import sx.blah.discord.handle.obj.IRole; //导入依赖的package包/类
@Command(
        command = "addUserRole",
        description = "Add a User to a specific role",
        arguments = {"User Mention", "Role []"},
        prefix = Globals.ADMIN_PREFIX,
        permission = Globals.BOT_MANAGE,
        alias = "aur"
)
public void addUsertoRole(MessageReceivedEvent event, String[] args) {
    try {
        List<IRole> roles = event.getGuild().getRolesByName(Utils.makeArgsToString(args, new String[]{args[0]}));
        for (IUser user : event.getMessage().getMentions()) {
            for (IRole role : roles) {
                user.addRole(role);
                BotUtils.sendEmbMessage(event.getChannel(), SMB.shortMessage(String.format(LANG.getTranslation("role_add"), role.getName(), user.getName())), true);
            }
        }
    } catch (Exception ex) {
        BotUtils.sendEmbMessage(event.getChannel(), SMB.shortMessage(String.format(LANG.getTranslation("commonmessage_error"), Arrays.toString(ex.getStackTrace()))), true);
        Console.error(ex);
    }
}
 
开发者ID:ModdyLP,项目名称:MoMuOSB,代码行数:23,代码来源:RoleManagement.java

示例5: removeUsertoRole

import sx.blah.discord.handle.obj.IRole; //导入依赖的package包/类
@Command(
        command = "removeUserRole",
        description = "Add a User to a specific role",
        arguments = {"User Mention", "Role []"},
        prefix = Globals.ADMIN_PREFIX,
        permission = Globals.BOT_MANAGE,
        alias = "rmur"
)
public void removeUsertoRole(MessageReceivedEvent event, String[] args) {
    try {
        List<IRole> roles = event.getGuild().getRolesByName(Utils.makeArgsToString(args, new String[]{args[0]}));
        for (IUser user : event.getMessage().getMentions()) {
            for (IRole role : roles) {
                user.removeRole(role);
                BotUtils.sendEmbMessage(event.getChannel(), SMB.shortMessage(String.format(LANG.getTranslation("role_remove"), role.getName(), user.getName())), true);
            }
        }
    } catch (Exception ex) {
        BotUtils.sendEmbMessage(event.getChannel(), SMB.shortMessage(String.format(LANG.getTranslation("commonmessage_error"), Arrays.toString(ex.getStackTrace()))), true);
        Console.error(ex);
    }
}
 
开发者ID:ModdyLP,项目名称:MoMuOSB,代码行数:23,代码来源:RoleManagement.java

示例6: putvaluesfromlist

import sx.blah.discord.handle.obj.IRole; //导入依赖的package包/类
public static void putvaluesfromlist(String gender, JSONArray list) {
    if (list != null) {
        HashMap<IGuild, List<IRole>> serverrolesmap = new HashMap<>();
        for (int i = 0; i < list.length(); i++) {
            JSONObject serverroles = Utils.objectToJSONObject(list.get(i));
            if (serverroles != null) {
                for (Object serverid : serverroles.keySet()) {
                    JSONArray array = Utils.objectToJSONArray(serverroles.get(serverid.toString()));
                    ArrayList<IRole> roles = new ArrayList<>();
                    for (int j = 0; j < array.length(); j++) {
                        roles.add(INIT.BOT.getRoleByID(Long.valueOf(array.getString(i))));
                    }
                    serverrolesmap.put(INIT.BOT.getGuildByID(Long.valueOf(serverid.toString())), roles);
                }
            }

        }
        gendersave.put(gender, serverrolesmap);
    }
}
 
开发者ID:ModdyLP,项目名称:MoMuOSB,代码行数:21,代码来源:RoleManagement.java

示例7: setGenderRole

import sx.blah.discord.handle.obj.IRole; //导入依赖的package包/类
public void setGenderRole(MessageReceivedEvent event, String gender) {
    List<IRole> roles = RoleManagement.getRoleforGender(user.get(event.getAuthor()), gender);
    StringBuilder rolename = new StringBuilder();
    if (roles != null) {
        for (IRole role : roles) {
            rolename.append(role.getName()).append(",");
            event.getAuthor().addRole(role);
        }
        if (roles.size() > 0) {
            user.remove(event.getAuthor());
        }
        BotUtils.sendPrivEmbMessage(event.getAuthor().getOrCreatePMChannel(), SMB.shortMessage(String.format(LANG.getTranslation("gender_role_added"), rolename.toString())), true);
    } else {
        BotUtils.sendPrivEmbMessage(event.getAuthor().getOrCreatePMChannel(), SMB.shortMessage(LANG.getTranslation("role_notfound")), true);
    }
}
 
开发者ID:ModdyLP,项目名称:MoMuOSB,代码行数:17,代码来源:UserEvents.java

示例8: execute

import sx.blah.discord.handle.obj.IRole; //导入依赖的package包/类
@Override
public void execute(Context context) throws MissingArgumentException {
	List<IUser> mentions = context.getMessage().getMentions();
	IUser user = mentions.isEmpty() ? context.getAuthor() : mentions.get(0);

	String creationDate = String.format("%s%n(%s)",
			TimeUtils.toLocalDate(user.getCreationDate()).format(dateFormatter),
			FormatUtils.formatLongDuration(user.getCreationDate()));

	String joinDate = String.format("%s%n(%s)",
			TimeUtils.toLocalDate(context.getGuild().getJoinTimeForUser(user)).format(dateFormatter),
			FormatUtils.formatLongDuration(context.getGuild().getJoinTimeForUser(user)));

	EmbedBuilder embed = EmbedUtils.getDefaultEmbed()
			.setLenient(true)
			.withAuthorName(String.format("Info about user \"%s\"%s", user.getName(), user.isBot() ? " (Bot)" : ""))
			.withThumbnail(user.getAvatarURL())
			.appendField("Display name", user.getDisplayName(context.getGuild()), true)
			.appendField("User ID", Long.toString(user.getLongID()), true)
			.appendField("Creation date", creationDate, true)
			.appendField("Join date", joinDate, true)
			.appendField("Roles", FormatUtils.format(user.getRolesForGuild(context.getGuild()), IRole::getName, "\n"), true)
			.appendField("Status", StringUtils.capitalize(user.getPresence().getStatus().toString()), true)
			.appendField("Playing text", user.getPresence().getText().orElse(null), true);
	BotUtils.sendMessage(embed.build(), context.getChannel());
}
 
开发者ID:Shadorc,项目名称:Shadbot,代码行数:27,代码来源:UserInfoCmd.java

示例9: execute

import sx.blah.discord.handle.obj.IRole; //导入依赖的package包/类
@Override
public MessageBuilder execute(CommandData<Baristron> commandData) {
	if (commandData.getChannel().isPrivate())
		return CommandResponse.withAutoDeleteMessage(Bot.getNewBuilder(commandData.getChannel())
				.withContent("Cannot execute in a private commandData.getChannel()!"), Bot.AUTO_DELETE_TIME);
	if (commandData.getArgs().size() < 1)
		return CommandResponse.getWrongArgumentsMessage(commandData.getChannel(), this, commandData.getCmdUsed(),
				commandData);

	MetadataMessageBuilder builder = Bot.getNewBuilder(commandData.getChannel());
	builder.withContent("__Role IDs that match the name:__\n");
	List<IRole> roles = commandData.getChannel().getGuild().getRolesByName(commandData.getFullContent());
	roles.forEach(role -> builder.appendContent(role.getName() + " - `" + role.getID() + "`\n"));

	Bot.sendMessage(builder);

	return null;
}
 
开发者ID:chrislo27,项目名称:Baristron,代码行数:19,代码来源:RoleSearchCommand.java

示例10: executeCommand

import sx.blah.discord.handle.obj.IRole; //导入依赖的package包/类
@Override
public void executeCommand(IMessage msg) {
	EmbedBuilder em = new EmbedBuilder();
	String roleName = Util.getCommandContents(msg).toLowerCase();
	IRole role = null;
	for (IRole r : msg.getGuild().getRoles()) {
		if (r.getName().toLowerCase().equals(roleName)) {
			role = r;
			break;
		}
	}
	if(role == null) {
		em.withTitle("Error")
		.withColor(Color.RED)
		.withDesc("No users found for role " + roleName);
	} else {
		em.withTitle("Members with the role " + role.getName())
		.withColor(Color.CYAN)
		.withDesc(msg.getGuild().getUsersByRole(role)
				.stream()
				.map(u -> u.getDisplayName(msg.getGuild()))
				.collect(Collectors.joining(", ")));
	}
	MessageUtils.sendMessage(msg.getChannel(), em.build());
}
 
开发者ID:paul-io,项目名称:momo-discord-old,代码行数:26,代码来源:Role.java

示例11: fromGuild

import sx.blah.discord.handle.obj.IRole; //导入依赖的package包/类
public WebGuild fromGuild(IGuild g) {
	id = g.getStringID();
	name = g.getName();
	iconUrl = g.getIconURL();
	botNick = Main.client.getOurUser().getNicknameForGuild(g);

	settings = DatabaseManager.getManager().getSettings(g.getLongID());

	//Handle lists and stuffs
	for (IRole r : g.getRoles()) {
		roles.add(new WebRole().fromRole(r, settings));
	}

	WebChannel all = new WebChannel();
	all.setId(0);
	all.setName("All Channels");
	all.setDiscalChannel(settings.getDiscalChannel().equalsIgnoreCase("all"));
	channels.add(all);
	for (IChannel c : g.getChannels()) {
		channels.add(new WebChannel().fromChannel(c, settings));
	}
	announcements.addAll(DatabaseManager.getManager().getAnnouncements(g.getLongID()));

	calendar = new WebCalendar().fromCalendar(DatabaseManager.getManager().getMainCalendar(Long.valueOf(id)), settings);

	return this;
}
 
开发者ID:NovaFox161,项目名称:DisCal-Discord-Bot,代码行数:28,代码来源:WebGuild.java

示例12: fromRole

import sx.blah.discord.handle.obj.IRole; //导入依赖的package包/类
public WebRole fromRole(IRole r, GuildSettings settings) {
	id = r.getLongID();
	name = r.getName();

	managed = r.isManaged();

	if (r.isEveryoneRole() && settings.getControlRole().equalsIgnoreCase("everyone")) {
		controlRole = true;
	} else {
		controlRole = settings.getControlRole().equalsIgnoreCase(String.valueOf(id));
	}

	return this;
}
 
开发者ID:NovaFox161,项目名称:DisCal-Discord-Bot,代码行数:15,代码来源:WebRole.java

示例13: moduleControlRole

import sx.blah.discord.handle.obj.IRole; //导入依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:NovaFox161,项目名称:DisCal-Discord-Bot,代码行数:39,代码来源:DisCalCommand.java

示例14: getRoleFromMention

import sx.blah.discord.handle.obj.IRole; //导入依赖的package包/类
public static IRole getRoleFromMention(String mention, MessageReceivedEvent event) {
	for (IRole r : event.getMessage().getGuild().getRoles()) {
		if (mention.equalsIgnoreCase("<@&" + r.getStringID() + ">") || mention.equalsIgnoreCase("<@&!" + r.getStringID() + ">")) {
			return r;
		}
	}
	return null;
}
 
开发者ID:NovaFox161,项目名称:DisCal-Discord-Bot,代码行数:9,代码来源:RoleUtils.java

示例15: getRoleFromID

import sx.blah.discord.handle.obj.IRole; //导入依赖的package包/类
public static IRole getRoleFromID(String id, MessageReceivedEvent event) {
	for (IRole r : event.getMessage().getGuild().getRoles()) {
		if (id.equals(r.getStringID()) || id.equals(r.getName())) {
			return r;
		}
	}
	return null;
}
 
开发者ID:NovaFox161,项目名称:DisCal-Discord-Bot,代码行数:9,代码来源:RoleUtils.java


注:本文中的sx.blah.discord.handle.obj.IRole类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。