GoldyBot.utility.guilds.config
1import GoldyBot 2from GoldyBot.errors import FailedToFindGuildRole, FailedToFindRole 3 4class GuildConfig(): 5 """This class gives you access to all the configuration settings a Goldy Bot guild possess.""" 6 def __init__(self, guild_config:GoldyBot.config.Config): 7 self.guild_config = guild_config 8 9 @property 10 def prefix(self) -> str: 11 return self.guild_config.read("prefix") 12 13 def is_extension_allowed(self, extension_name:str): 14 15 if extension_name == None: 16 return True 17 18 if extension_name in ["Admin"]: 19 return True 20 21 config = self.guild_config.read("config") 22 allowed_extensions = config["allowed_extensions"] 23 disallowed_extensions = config["disallowed_extensions"] 24 25 if extension_name in allowed_extensions: 26 return True 27 28 if extension_name in disallowed_extensions: 29 return False 30 31 if allowed_extensions == ["."]: 32 return True 33 34 if disallowed_extensions == ["."]: 35 return False 36 37 return True 38 39 def get_role(self, ctx, role_code_name) -> GoldyBot.objects.role.Role: 40 """Finds and returns a Goldy Bot role from the guild's config with given code name.""" 41 try: 42 role_id = self.guild_config.read("roles")[f"{role_code_name}"] 43 return GoldyBot.objects.role.Role(ctx, role_id=role_id) 44 except KeyError: 45 raise FailedToFindGuildRole(f"Could not find the role '{role_code_name}'! Have you declared it in the guild's config.") 46 47 #TODO: Finish this! 48 #TODO: #24 Add logging to the guild config class.
class
GuildConfig:
5class GuildConfig(): 6 """This class gives you access to all the configuration settings a Goldy Bot guild possess.""" 7 def __init__(self, guild_config:GoldyBot.config.Config): 8 self.guild_config = guild_config 9 10 @property 11 def prefix(self) -> str: 12 return self.guild_config.read("prefix") 13 14 def is_extension_allowed(self, extension_name:str): 15 16 if extension_name == None: 17 return True 18 19 if extension_name in ["Admin"]: 20 return True 21 22 config = self.guild_config.read("config") 23 allowed_extensions = config["allowed_extensions"] 24 disallowed_extensions = config["disallowed_extensions"] 25 26 if extension_name in allowed_extensions: 27 return True 28 29 if extension_name in disallowed_extensions: 30 return False 31 32 if allowed_extensions == ["."]: 33 return True 34 35 if disallowed_extensions == ["."]: 36 return False 37 38 return True 39 40 def get_role(self, ctx, role_code_name) -> GoldyBot.objects.role.Role: 41 """Finds and returns a Goldy Bot role from the guild's config with given code name.""" 42 try: 43 role_id = self.guild_config.read("roles")[f"{role_code_name}"] 44 return GoldyBot.objects.role.Role(ctx, role_id=role_id) 45 except KeyError: 46 raise FailedToFindGuildRole(f"Could not find the role '{role_code_name}'! Have you declared it in the guild's config.") 47 48 #TODO: Finish this! 49 #TODO: #24 Add logging to the guild config class.
This class gives you access to all the configuration settings a Goldy Bot guild possess.
GuildConfig(guild_config: GoldyBot.config.Config)
def
is_extension_allowed(self, extension_name: str):
14 def is_extension_allowed(self, extension_name:str): 15 16 if extension_name == None: 17 return True 18 19 if extension_name in ["Admin"]: 20 return True 21 22 config = self.guild_config.read("config") 23 allowed_extensions = config["allowed_extensions"] 24 disallowed_extensions = config["disallowed_extensions"] 25 26 if extension_name in allowed_extensions: 27 return True 28 29 if extension_name in disallowed_extensions: 30 return False 31 32 if allowed_extensions == ["."]: 33 return True 34 35 if disallowed_extensions == ["."]: 36 return False 37 38 return True
40 def get_role(self, ctx, role_code_name) -> GoldyBot.objects.role.Role: 41 """Finds and returns a Goldy Bot role from the guild's config with given code name.""" 42 try: 43 role_id = self.guild_config.read("roles")[f"{role_code_name}"] 44 return GoldyBot.objects.role.Role(ctx, role_id=role_id) 45 except KeyError: 46 raise FailedToFindGuildRole(f"Could not find the role '{role_code_name}'! Have you declared it in the guild's config.")
Finds and returns a Goldy Bot role from the guild's config with given code name.