async def permission_type(self, ctx): self.update_response() responses = self.responses['permissions']['permission_type'] data = get_servers_data() guild_id = str(ctx.guild.id) guild_exists(guild_id) permission_type = data[guild_id]["permission_type"] embed = embed_template( title=responses["embed_data"]["title"].format( server=ctx.guild.name), description=responses["embed_data"]["description"]) embed.add_field(name=f"Permission type:", value=permission_type) if permission_type == "custom": user_ids = data[guild_id]['custom_has_permission'] users = [] for user_id in user_ids: user_obj = discord.utils.get(ctx.guild.members, id=user_id) users.append(f"{user_obj.name}#{user_obj.discriminator}") users.append( f"{ctx.guild.owner.name}#{ctx.guild.owner.discriminator} (server owner)" ) embed.add_field(name="Custom permission access", value=', '.join(users)) await ctx.send(content=None, embed=embed)
async def help(self, ctx, specific=None): self.update_response() guild_exists(str(ctx.guild.id)) if specific is not None: specific = specific.lower() embed = embed_template() content = None # dictionary of lower cog name: cog cogs = {cog.qualified_name.lower(): cog for cog in self.client.cogs.values()} # dictionary of all lower command name: command # commands = {command.name.lower(): command for cog in self.client.cogs.values() for command in cog.get_commands() } # have to include command aliases commands = {} for cog in self.client.cogs.values(): for command in cog.get_commands(): commands[command.name.lower()] = command for alias in command.aliases: commands[alias.lower()] = command if specific is None: content = self.help_embed(ctx, embed) elif specific in cogs: content = self.module_help_embed(ctx, cogs[specific], embed) elif specific in commands: self.command_help_embed(commands[specific], embed) else: # print(f"{specific} not found") self.help_embed(ctx, embed) content = f"Specific command or module \"{specific}\" was not found. Here is the main help page." await ctx.send(content=content, embed=embed)
async def set_prefix(self, ctx, new_prefix: str): self.update_response() responses = self.responses['settings']['set_prefix'] guild_exists(str(ctx.guild.id)) if ctx.prefix != new_prefix: update_setting(str(ctx.guild.id), 'prefix', new_prefix) self.client.command_prefix = new_prefix await ctx.send(responses['success'].format( prefix=format(ctx.prefix, "single_code"), new_prefix=format(new_prefix, "single_code"))) else: raise commands.BadArgument(new_prefix, "invalid_new_prefix")
async def server_config(self, ctx): self.update_response() responses = self.responses['settings']['server_config'] guild_exists(str(ctx.guild.id)) guild_id = str(ctx.guild.id) guild_data = get_servers_data()[guild_id] prefix = ctx.prefix number_of_profiles = len(guild_data["profiles"]) permission_type = guild_data["permission_type"] jail_role = discord.utils.get(ctx.guild.roles, id=guild_data["jail_role"]) jail_role = jail_role.mention if jail_role is not None else jail_role jail_channel = discord.utils.get(ctx.guild.text_channels, id=guild_data["jail_channel"]) jail_channel = jail_channel.mention if jail_channel is not None else jail_channel embed = embed_template( title=responses["embed_data"]["title"].format( server=ctx.guild.name), description=responses["embed_data"]["description"]) embed.add_field(name="Bot prefix", value=f'`{prefix}`', inline=True) embed.add_field(name="Number of profiles", value=number_of_profiles, inline=True) embed.add_field(name="Permission type", value=permission_type, inline=True) if permission_type == "custom": user_ids = guild_data['custom_has_permission'] users = [] for user_id in user_ids: user_obj = discord.utils.get(ctx.guild.members, id=user_id) if user_obj is not None: users.append(f"{user_obj.name}#{user_obj.discriminator}") else: users.append(str(user_id)) users.append( f"{ctx.guild.owner.name}#{ctx.guild.owner.discriminator} (server owner)" ) embed.add_field(name="Custom permission access", value=', '.join(users)) embed.add_field(name="Jail role", value=jail_role) embed.add_field(name="Jail channel", value=jail_channel) await ctx.send(content=None, embed=embed)
async def create_profile( self, ctx, name: str, *role_sources: commands.Greedy[typing.Union[discord.Member, discord.Role]]): # self.update_responses() responses = self.responses['profile']['create_profile'] # get a list of the roles the user wants to add to this newly created profile add_roles = [] for source in role_sources: if hasattr(source, 'roles'): # if it is a member for role in source.roles: add_roles.append(role) else: add_roles.append(source) # filter out any duplicates add_roles = set(add_roles) # filter out the '@everyone' role you may get from members add_roles = self.filter_everyone_role(add_roles) role_names = [role.name for role in add_roles] role_ids = [role.id for role in add_roles] guild_id = str(ctx.guild.id) message = "" if role_names and role_ids: guild_exists(guild_id) # read server configs data = get_servers_data() if name in data[guild_id]['profiles']: message += f"{responses['replace'].format(name=format(name, 'single_code'))}\n" data[guild_id]['profiles'][name] = role_ids set_servers_data(data) message += responses['success'].format(roles=', '.join([ format(role_name, "single_code") for role_name in role_names ]), name=format( name, "single_code")) await ctx.send(message) else: raise commands.BadArgument("invalid_role_sources")
async def set_permission_type(self, ctx, new_permission_type: str): self.update_response() responses = self.responses['permissions']['set_permission_type'] data = get_servers_data() guild_id = str(ctx.guild.id) guild_exists(guild_id) permission_type = data[guild_id]["permission_type"] if new_permission_type.lower() in ["administrator", "admin"]: new_permission_type = "administrator" elif new_permission_type.lower() in [ "manage_server", "server", "manage" ]: new_permission_type = "manage_server" elif new_permission_type.lower() in ["everyone", "every"]: new_permission_type = "everyone" elif new_permission_type.lower() in ["custom"]: new_permission_type = "custom" else: print( f"error to be implemented: {new_permission_type} is not a permission type" ) return False if permission_type != new_permission_type: if permission_type == 'custom': update_setting(guild_id, 'custom_has_permission', []) update_setting(guild_id, 'permission_type', new_permission_type) await ctx.send(responses['success'].format( permission_type=format(permission_type, "single_code"), new_permission_type=format(new_permission_type, "single_code"))) else: raise commands.BadArgument(permission_type, "invalid_permission_type")
async def delete_profile(self, ctx, profile: str): # self.update_responses() responses = self.responses['profile']['delete_profile'] guild_id = str(ctx.guild.id) if guild_exists(guild_id): data = get_servers_data() if profile in data[guild_id]['profiles']: del data[guild_id]['profiles'][profile] set_servers_data(data) await ctx.send(responses["success"].format( name=format(profile, "single_code"))) else: raise commands.BadArgument(profile, "invalid_profile") else: raise commands.BadArgument(profile, "invalid_profile")
async def on_guild_join(self, guild): guild_id = str(guild.id) guild_exists(guild_id)