public RoleUpdateNameEvent(JDA api, long responseNumber, Role role, String oldName) { super(api, responseNumber, role, oldName, role.getName(), IDENTIFIER); }
@Override protected RequestBody finalizeData() { JSONObject object = new JSONObject().put("name", getRole().getName()); if (shouldUpdate(NAME)) object.put("name", name); if (shouldUpdate(PERMISSION)) object.put("permissions", permissions); if (shouldUpdate(HOIST)) object.put("hoist", hoist); if (shouldUpdate(MENTIONABLE)) object.put("mentionable", mentionable); if (shouldUpdate(COLOR)) object.put("color", color == Role.DEFAULT_COLOR_RAW ? 0 : color & 0xFFFFFF); reset(); return getRequestBody(object); }
if (role != null) replace(matcher.group(), "@"+role.getName()); break;
tmp = tmp.replace(mentionedRole.getAsMention(), '@' + mentionedRole.getName());
private boolean hasRole(List<Role> roles, String roleName) { for (Role role : roles) { if (role.getName().equalsIgnoreCase(roleName)) { return true; } } return false; } }
private boolean hasRole(List<Role> roles, String roleName) { for (Role role : roles) { if (role.getName().equalsIgnoreCase(roleName)) { return true; } } return false; }
public static Role hasRole(Guild guild, String roleName) { List<Role> roles = guild.getRoles(); Role containsRole = null; for (Role role : roles) { if (role.getName().equalsIgnoreCase(roleName)) { return role; } if (containsRole == null && role.getName().contains(roleName)) { containsRole = role; } } return containsRole; }
public static String listOfRoles(List<Role> list, String query) { String out = " Multiple text channels found matching \""+query+"\":"; for(int i=0; i<6 && i<list.size(); i++) out+="\n - "+list.get(i).getName()+" (ID:"+list.get(i).getId()+")"; if(list.size()>6) out+="\n**And "+(list.size()-6)+" more...**"; return out; }
/** * attempts to find a role within a guild * * @param guild the guild to search in * @param roleName the role name to search for * @return role or null */ public static Role findRole(Guild guild, String roleName) { List<Role> roles = guild.getRoles(); Role containsRole = null; for (Role role : roles) { if (role.getName().equalsIgnoreCase(roleName)) { return role; } if (containsRole == null && role.getName().contains(roleName)) { containsRole = role; } } return containsRole; }
@Override public String toDisplay(Guild guild, String value) { if (value == null || value.isEmpty() || !value.matches("\\d{10,}")) { return Emojibet.X; } Role role = guild.getRoleById(value); if (role != null) { return role.getName(); } return Emojibet.X; } }
private Role getRole(Guild guild, String role) { if (!role.contains(" ") && role.startsWith("<@&") && role.endsWith(">")) { return guild.getRoleById(role.replaceAll("[^0-9]+", "")); } // Since I know it is valid I can get the id from the name or just return the id since that will be the only other thing passed. for (Role iRole : guild.getRoles()) { if (iRole.getId().equals(role) || iRole.getName().equalsIgnoreCase(role)) return iRole; } return null; }
private static boolean canUseCommand(Member m, String command) { if (MagiBridge.getConfig().CHANNELS.COMMANDS_ROLE_OVERRIDE == null) return false; if (MagiBridge.getConfig().CHANNELS.COMMANDS_ROLE_OVERRIDE.get(command) != null) { if (MagiBridge.getConfig().CHANNELS.COMMANDS_ROLE_OVERRIDE.get(command).equalsIgnoreCase("everyone")) { return true; } } if (m.getRoles().stream().anyMatch(r -> r.getName().equalsIgnoreCase(MagiBridge.getConfig().CHANNELS.CONSOLE_REQUIRED_ROLE))) { return true; } return MagiBridge.getConfig().CHANNELS.COMMANDS_ROLE_OVERRIDE.get(command) != null && m.getRoles().stream().anyMatch(role -> role.getName().equalsIgnoreCase(MagiBridge.getConfig().CHANNELS.COMMANDS_ROLE_OVERRIDE.get(command))); }
public static String buildRoleData(List<Role> roles) { List<Map<String, Object>> rolesMap = new ArrayList<>(); for (Role role : roles) { if (role.isPublicRole()) { continue; } Map<String, Object> item = new HashMap<>(); item.put("id", role.getId()); item.put("name", role.getName()); item.put("position", role.getPosition()); item.put("permissions", role.getPermissionsRaw()); item.put("color", role.getColor() == null ? null : Integer.toHexString(role.getColor().getRGB()).substring(2) ); rolesMap.add(item); } return AvaIre.gson.toJson(rolesMap); }
/** * deletes the created roles * * @param guild the guild to clean up * @param ourUser the bot user */ public static void cleanUpRoles(Guild guild, User ourUser) { if (!canModifyRoles(guild, ourUser)) { return; } for (Role role : guild.getRoles()) { if (role.getName().equals("new role") || role.getName().contains(getPrefix(guild))) { role.delete().complete(); } else if (roleNames.contains(role.getName().toLowerCase())) { role.delete().complete(); } } }
private boolean hasDJRole(Message message) { if (message.getMember().hasPermission(Permissions.ADMINISTRATOR.getPermission())) { return true; } for (Role role : message.getMember().getRoles()) { if (role.getName().equalsIgnoreCase("DJ")) { return true; } } return false; } }
/** * Checks if the bot can interact with the given role by making sure the role * is not higher in the role hierarchy than any role the bot has, if the * method returns true the bot has at least one role which is in a * higher position in the role hierarchy. * * @param message The JDA message instance for the current guild. * @param role The role that the user should be able to interact with. * @return {@code True} if the user can interact with the given role, {@code False} otherwise */ public static boolean canBotInteractWithRole(@Nonnull Message message, @Nonnull Role role) { if (!RoleUtil.isRoleHierarchyHigher(message.getGuild().getSelfMember().getRoles(), role)) { return true; } 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; }
private void onRoleDelete(RoleDeleteEvent event, @Nonnull GuildWrapper wrapper) { if (cannotHandle(wrapper, ModlogEvent.ROLE_DELETE)) return; event.getGuild().getAuditLogs().queue(auditLog -> { AuditLogEntry entry = auditLog.get(0); ModlogHandler.getInstance().postToModlog(wrapper, ModlogEvent.ROLE_DELETE, entry.getUser(), new MessageEmbed.Field("Role", event.getRole().getName() + " (" + event.getRole().getId() + ")", true)); }); }
private void onRoleCreate(RoleCreateEvent event, @Nonnull GuildWrapper wrapper) { if (event.getGuild() == null) return; if (cannotHandle(wrapper, ModlogEvent.ROLE_CREATE)) return; event.getGuild().getAuditLogs().queue(auditLog -> { AuditLogEntry entry = auditLog.get(0); ModlogHandler.getInstance().postToModlog(wrapper, ModlogEvent.ROLE_CREATE, entry.getUser(), new MessageEmbed.Field("Role", event.getRole().getName() + " (" + event.getRole().getId() + ")", true)); }); }
public void onRoleUpdateName(RoleUpdateNameEvent event) { GuildTransformer transformer = GuildController.fetchGuild(avaire, event.getGuild()); if (transformer == null || transformer.getSelfAssignableRoles().isEmpty()) { return; } if (!transformer.getSelfAssignableRoles().containsKey(event.getRole().getId())) { return; } try { transformer.getSelfAssignableRoles().put(event.getRole().getId(), event.getRole().getName().toLowerCase()); avaire.getDatabase().newQueryBuilder(Constants.GUILD_TABLE_NAME) .useAsync(true) .where("id", event.getGuild().getId()) .update(statement -> { statement.set("claimable_roles", AvaIre.gson.toJson(transformer.getSelfAssignableRoles()), true); }); } catch (SQLException e) { e.printStackTrace(); } }
private PlaceholderMessage sendCurrentAutoRole(CommandMessage context, GuildTransformer transformer) { if (transformer.getAutorole() == null) { return context.makeWarning(context.i18n("disabled")); } Role role = context.getGuild().getRoleById(transformer.getAutorole()); if (role == null) { try { updateAutorole(transformer, context, null); } catch (SQLException ex) { ex.printStackTrace(); AvaIre.getLogger().error(ex.getMessage(), ex); } return context.makeWarning(context.i18n("disabled")); } return context.makeSuccess(context.i18n("status")) .set("role", role.getName()); }