async def update_role_list(self, ctx, add_or_remove: str, role_id: str, member: discord.Member = None): """ Update the configured role list to add or remove a group. Command is executed via the `role` command. Examples: > role add Test Configuration file updated. > role add Test Role already added. > role test Test Please specify if I am adding or removing a role. > role remove Test Configuration file updated. :param ctx: discord.py Context :param add_or_remove: (str) [add, remove] passed in string to determine if a role is being added or removed :param role_id: discord snowflake ID for the role, can be added via direct pinging of the role :param member: optional discord.Member object :return: """ member = ctx.message.author server_id = str(ctx.message.server.id) if member is not None: if add_or_remove != 'add' and add_or_remove != 'remove': return await self.bot.say( "Please specify if I am adding or removing a role.") current_role_list = ConfigLoader().load_server_string_setting( server_id, 'RoleAssignment', 'role_list') # Somewhat ugly fix for when mentioning the role to strip stuff out role_id = role_id.replace('<@&', '') role_id = role_id.replace('>', '') role_id = role_id.strip() updated_role_list = '' if add_or_remove == 'add': if not BotResources().contains_word(current_role_list, role_id): if current_role_list == 'NOT_SET': updated_role_list = role_id else: updated_role_list = current_role_list + " " + role_id else: return await self.bot.say("Role already added.") if add_or_remove == 'remove': if BotResources().contains_word(current_role_list, role_id): updated_role_list = current_role_list.replace(role_id, '') if updated_role_list.isspace() or len(updated_role_list) == 0: updated_role_list = 'NOT_SET' filename = ctx.message.server.id await ConfigCommands(self.bot).update_config_file( filename, 'RoleAssignment', 'role_list', updated_role_list.strip(), ctx.message)
async def update_role_list(self, ctx, add_or_remove: str, user_or_role: str, role_id: str): """ Update the configured role list to add or remove a group. :param ctx: discord.py Context :param add_or_remove: (str) [add, remove] passed in string to determine if a role is being added or removed :param user_or_role: (str) [user, role] passed in string to determine if it's a user or a role that is being updated :param role_id: the discord snowflake ID for the role, the pinged username :return: """ member_id = ctx.message.author.id server_id = str(ctx.message.server.id) updated_id_list = '' if member_id == ctx.message.server.owner_id or \ int(member_id) == ConfigLoader().load_config_setting_int( 'BotSettings', 'owner_id' ): if add_or_remove != 'add' and add_or_remove != 'remove': return await self.bot.say("Please specify if I am adding or removing a botadmin.") if user_or_role != 'user' and user_or_role != 'role': return await self.bot.say( "Please specify if it's the user or role " "list I am updating." ) current_id_list = ConfigLoader().load_server_string_setting( server_id, 'BotAdmins', 'bot_admin_users' if user_or_role == 'user' else 'bot_admin_roles' ) # @TODO : verify this works and remove commented out code # role_id = role_id.replace('<@&', '') # role_id = role_id.replace('<@!', '') # role_id = role_id.replace('>', '') # role_id = role_id.strip() role_id = re.sub('[^0-9]', '', role_id) if add_or_remove == 'add': if not BotResources().contains_word(current_id_list, role_id): if current_id_list == 'NOT_SET': updated_id_list = role_id else: updated_id_list = current_id_list + " " + role_id else: return await self.bot.say("Role already added.") if add_or_remove == 'remove': if BotResources().contains_word(current_id_list, role_id): updated_id_list = current_id_list.replace(role_id, '') if updated_id_list.isspace() or len(updated_id_list) == 0: updated_id_list = 'NOT_SET' filename = ctx.message.server.id await ConfigCommands(self.bot).update_config_file( filename, 'BotAdmins', 'bot_admin_users' if user_or_role == 'user' else 'bot_admin_roles', updated_id_list.strip(), ctx.message )