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


Java Role类代码示例

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


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

示例1: getUserLevel

import net.dv8tion.jda.core.entities.Role; //导入依赖的package包/类
/**
 * Gets user level.
 *
 * @param guildID  the guild id
 * @param userID   the user id
 * @param roleList the role list
 * @return the user level
 */
public Integer getUserLevel(Long guildID, Long userID, List<Role> roleList) {
    Permissions permissions = listGuildPermissions.get(guildID);
    Integer userLevel = null;
    Integer roleLevel = null;

    if (permissions == null) {
        return null;
    }

    userLevel = permissions.getUserLevel(userID);
    if (userLevel != null) return userLevel; //userLevel take prioty over roleLevel
    Integer tempRole;
    for (Role r : roleList) {
        tempRole = permissions.getRoleLevel(r.getIdLong());
        if (tempRole != null) {
            if (roleLevel == null) {
                roleLevel = tempRole;
            } else if (tempRole < roleLevel) { //See if tempRole is a higher ranked level
                roleLevel = tempRole;
            }
        }
    }

    return roleLevel;
}
 
开发者ID:IANetworks,项目名称:Ducky-Mc-Duckerson,代码行数:34,代码来源:DatabaseManager.java

示例2: getRole

import net.dv8tion.jda.core.entities.Role; //导入依赖的package包/类
public final Role getRole(int index, boolean consume) {
    if (guild == null) {
        return null;
    }
    final String temp = getRaw(index);
    if (temp == null) {
        return null;
    }
    final Matcher matcher = PATTERN_MARKDOWN_ROLE.matcher(temp);
    if (!matcher.matches()) {
        return null;
    }
    if (consume) {
        consumeRaw(index);
    }
    return guild.getRoleById(matcher.group(1));
}
 
开发者ID:Panzer1119,项目名称:Supreme-Bot,代码行数:18,代码来源:ArgumentList.java

示例3: onGuildMemberJoin

import net.dv8tion.jda.core.entities.Role; //导入依赖的package包/类
@Override
public void onGuildMemberJoin(GuildMemberJoinEvent event)
{
    // Add roles to new member

    short rating = database.getUserRating(event.getUser());

    if(rating == -1)
        return;

    Role role = database.getRatingRole(event.getGuild(), rating);

    // Role is not null
    // Can interact with role
    // Can interact with member
    if(role != null && event.getGuild().getSelfMember().canInteract(role)
            && event.getGuild().getSelfMember().canInteract(event.getMember()))
    {
        event.getGuild().getController().addRolesToMember(event.getMember(), role).queue(v -> {}, v -> {});
    }
}
 
开发者ID:TheMonitorLizard,项目名称:BalloonBoat,代码行数:22,代码来源:Bot.java

示例4: getRoleRating

import net.dv8tion.jda.core.entities.Role; //导入依赖的package包/类
public short getRoleRating(Role role) throws SQLException
{
    short returns = -1;
    try (Statement statement = connection.createStatement())
    {
        try (ResultSet set = statement.executeQuery("SELECT * FROM "+table.name()+" " +
                                                    "WHERE GUILD_ID = "+role.getGuild().getIdLong()))
        {
            if(set.next())
            {
                for(short i = 1; i <= 5; i++)
                {
                    long forRole = set.getLong("ROLE_"+i);
                    if(forRole != 0L && forRole == role.getIdLong())
                    {
                        returns = i;
                        break;
                    }
                }
            }
        }
    }
    return returns;
}
 
开发者ID:TheMonitorLizard,项目名称:BalloonBoat,代码行数:25,代码来源:GuildSettingsTable.java

示例5: onGuildMemberJoin

import net.dv8tion.jda.core.entities.Role; //导入依赖的package包/类
@Override
public void onGuildMemberJoin(GuildMemberJoinEvent event) {
    Member member = event.getMember();
    Guild guild = member.getGuild();
    try {
        for (DefaultRole dr : Bot.defaultRoles) {
            if (dr.getGuildID().equals(guild.getId())) {
                for (Role role : guild.getRoles()) {
                    if (role.getId().equals(dr.getRoleID())) {
                        guild.getController().addRolesToMember(member, role).complete();
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:ExidCuter,项目名称:JDodoBot,代码行数:19,代码来源:OnJoinListener.java

示例6: sendCurrentAutoRole

import net.dv8tion.jda.core.entities.Role; //导入依赖的package包/类
private PlaceholderMessage sendCurrentAutoRole(Message message, GuildTransformer transformer) {
    if (transformer.getAutorole() == null) {
        return MessageFactory.makeWarning(message, ":user **Auto assign role** on user join is currently **disabled**.");
    }

    Role role = message.getGuild().getRoleById(transformer.getAutorole());
    if (role == null) {
        try {
            updateAutorole(transformer, message, null);
        } catch (SQLException ex) {
            ex.printStackTrace();
            AvaIre.getLogger().error(ex.getMessage(), ex);
        }
        return MessageFactory.makeWarning(message, ":user **Auto assign role** on user join is currently **disabled**.");
    }

    return MessageFactory.makeSuccess(message, ":user The **auto assign role** is currently set to **:role**")
        .set("role", role.getName());
}
 
开发者ID:avaire,项目名称:avaire,代码行数:20,代码来源:AutoAssignRoleCommand.java

示例7: handle

import net.dv8tion.jda.core.entities.Role; //导入依赖的package包/类
@Override
public boolean handle(Message message, MiddlewareStack stack, String... args) {
    if (!message.getChannelType().isGuild()) {
        return stack.next();
    }

    if (message.getMember().hasPermission(Permissions.ADMINISTRATOR.getPermission())) {
        return stack.next();
    }

    List<Role> roles = message.getMember().getRoles();
    for (String roleName : args) {
        if (!hasRole(roles, roleName)) {
            MessageFactory.makeError(message, "You don't have the required role to execute this command:\n`:role`")
                .set("role", roleName)
                .queue();
            return false;
        }
    }

    return stack.next();
}
 
开发者ID:avaire,项目名称:avaire,代码行数:23,代码来源:HasRole.java

示例8: getHighestFrom

import net.dv8tion.jda.core.entities.Role; //导入依赖的package包/类
/**
 * Get the role that is position highest in the role hierarchy for the given member.
 *
 * @param member The member whos roles should be used.
 * @return Possibly-null, if the user has any roles the role that is ranked highest in the role hierarchy will be returned.
 */
public static Role getHighestFrom(Member member) {
    Checks.notNull(member, "Member object can not be null");

    List<Role> roles = member.getRoles();
    if (roles.isEmpty()) {
        return null;
    }

    return roles.stream().sorted((first, second) -> {
        if (first.getPosition() == second.getPosition()) {
            return 0;
        }
        return first.getPosition() > second.getPosition() ? -1 : 1;
    }).findFirst().get();
}
 
开发者ID:avaire,项目名称:avaire,代码行数:22,代码来源:RoleUtil.java

示例9: canInteractWithRole

import net.dv8tion.jda.core.entities.Role; //导入依赖的package包/类
/**
 * Checks if the user can interact with the given role by making sure the role is
 * not higher in the role hierarchy then any role the user and the bot instance
 * for the current guild has, if the method returns true the bot should be
 * able to give the role to the users, and the given user has at least
 * one role which is in a higher position in the role hierarchy.
 *
 * @param message The JDA message object for the current guild.
 * @param role    The role that should be used in the checks.
 * @return True if both the given user and bot can interact with the role, false otherwise.
 */
public static boolean canInteractWithRole(Message message, Role role) {
    if (RoleUtil.isRoleHierarchyHigher(message.getMember().getRoles(), role)) {
        MessageFactory.makeWarning(message,
            ":user The **:role** role is positioned higher in the hierarchy than any role you have, you can't add roles with a higher ranking than you have."
        ).set("role", role.getName()).queue();
        return false;
    }

    if (RoleUtil.isRoleHierarchyHigher(message.getGuild().getSelfMember().getRoles(), role)) {
        MessageFactory.makeWarning(message,
            ":user The **:role** role is positioned higher in the hierarchy, I can't give/remove this role from users."
        ).set("role", role.getName()).queue();
        return false;
    }

    return true;
}
 
开发者ID:avaire,项目名称:avaire,代码行数:29,代码来源:RoleUtil.java

示例10: executeCommand

import net.dv8tion.jda.core.entities.Role; //导入依赖的package包/类
@Override
public void executeCommand(Message msg) {
	EmbedBuilder em = new EmbedBuilder();
	String roleName = Util.getCommandContents(msg).toLowerCase();
	Role role = null;
	for (Role r : msg.getGuild().getRoles()) {
		if (r.getName().toLowerCase().equals(roleName)) {
			role = r;
			break;
		}
	}
	if(role == null) {
		em.setTitle("Error", null)
		.setColor(Color.RED)
		.setDescription("No users found for role " + roleName);
	} else {
		em.setTitle("Members with the role " + role.getName(), null)
		.setColor(Color.CYAN)
		.setDescription(msg.getGuild().getMembersWithRoles(role)
				.stream()
				.map(Member::getEffectiveName)
				.collect(Collectors.joining(", ")));
	}
	msg.getChannel().sendMessage(em.build()).queue();
}
 
开发者ID:paul-io,项目名称:momo-2,代码行数:26,代码来源:InRole.java

示例11: executeCommand

import net.dv8tion.jda.core.entities.Role; //导入依赖的package包/类
@Override
public void executeCommand(Message msg) {
	EmbedBuilder em = new EmbedBuilder();
	String role = Util.combineStringArray(Util.removeFirstArrayEntry(msg.getContent().split(" ")));
	em.setTitle("Error", null)
	.setColor(Color.RED)
	.setDescription("**" + role + " is not a joinable role");
	for(Role r : msg.getGuild().getRoles()) {
		if(r.getName().equalsIgnoreCase(role)
				&& GuildObject.guildMap.get(msg.getGuild().getId()).removeJoinableRole(r.getId())) {
			em.setTitle("Success", null)
			.setColor(Color.GREEN)
			.setDescription("**" + role + "** is not joinable anymore");
			break;
		}
	}
	msg.getChannel().sendMessage(em.build()).queue();
}
 
开发者ID:paul-io,项目名称:momo-2,代码行数:19,代码来源:RemoveOptInRole.java

示例12: getRewards

import net.dv8tion.jda.core.entities.Role; //导入依赖的package包/类
private List<RewardDetails> getRewards(long serverId, RankingConfig config) {
    if (discordService.isConnected() && CollectionUtils.isNotEmpty(config.getRewards())) {
        Guild guild = discordService.getJda().getGuildById(serverId);
        if (guild != null) {
            List<RewardDetails> details = new ArrayList<>();
            for (Reward reward : config.getRewards()) {
                Role role = guild.getRoleById(reward.getRoleId());
                if (role != null) {
                    details.add(new RewardDetails(role, reward));
                }
            }
            details.sort(Comparator.comparing(RewardDetails::getLevel));
            return details;
        }

    }
    return null;
}
 
开发者ID:GoldRenard,项目名称:JuniperBotJ,代码行数:19,代码来源:RankingController.java

示例13: assignRole

import net.dv8tion.jda.core.entities.Role; //导入依赖的package包/类
public static void assignRole(UserData data) {
    User user = ZLevels.jda.getUserById(data.getUserId());
    Guild guild = ZLevels.jda.getGuildById(Config.SERVER);
    int level = data.getLevel();

    for (int requiredLevel : roles.keySet()) {
        if (level < requiredLevel) return;

        Member member = guild.getMember(user);
        Role role = guild.getRolesByName(roles.get(requiredLevel).getString("name"), false).get(0);

        if (member == null || role == null) return;
        if (member.getRoles().contains(role)) return;

        try {
            guild.getController().addRolesToMember(member, role).queue();
        } catch (Exception e) {
            ZLogger.warn("Could not assign role to " + user.getName() + "!");
        }
    }
}
 
开发者ID:ZP4RKER,项目名称:zlevels,代码行数:22,代码来源:AutoRole.java

示例14: getRoleNameForRole

import net.dv8tion.jda.core.entities.Role; //导入依赖的package包/类
public final String getRoleNameForRole(Role role) {
    if (role == null) {
        return null;
    }
    if (role.getGuild().getMembersWithRoles(role).stream().anyMatch((member) -> isGuildUserNotMentionedInLogs(role.getGuild().getIdLong(), member.getUser().getIdLong()) || isUserNotMentionedInLogs(member.getUser().getIdLong()))) {
        return Standard.getCompleteName(role);
    }
    return role.getAsMention();
}
 
开发者ID:Panzer1119,项目名称:Supreme-Bot,代码行数:10,代码来源:Config.java

示例15: deleterole

import net.dv8tion.jda.core.entities.Role; //导入依赖的package包/类
@Command(
        name = "deleterole",
        description = "Deletes a role",
        usage = "`>>deleterole <role name>`",
        permission = CommandPermission.ADMIN,
        category = CommandCategory.MODERATION
)
public static void deleterole(@Argument("event") GuildMessageReceivedEvent event, @Argument("this") CommandReference thiz, @Argument("args") String[] args) {
    if(args.length == 0) {
        thiz.onHelp(event);
        return;
    }
    String role = String.join(" ", args);
    List<Role> roles = event.getGuild().getRolesByName(role, false);
    if(roles.isEmpty()) {
        roles = event.getGuild().getRolesByName(role, true);
        if(roles.isEmpty()) {
            event.getChannel().sendMessage("No role named " + role + " found").queue();
            return;
        }
    }
    Role r = roles.get(0);
    if(!event.getGuild().getSelfMember().canInteract(r)) {
        event.getChannel().sendMessage("I can't delete that role because it's above me in the hierarchy").queue();
        return;
    }
    r.delete().reason("Deleted by " + event.getAuthor().getName() + "#" + event.getAuthor().getDiscriminator()).queue();
    event.getChannel().sendMessage("Successfully deleted role " + r.getName()).queue();
}
 
开发者ID:natanbc,项目名称:GabrielBot,代码行数:30,代码来源:RoleCommands.java


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