GoldyBot.ext.extensions
1from __future__ import annotations 2import GoldyBot 3 4MODULE_NAME = "EXTENSION" 5 6class Extension(object): 7 """ 8 The base class for a Goldy Bot extension. 9 10 --------------- 11 ### ***``Example:``*** 12 13 This is how you set up an extension in a GoldyBot module. 😍 14 15 ```python 16 class YourExtension(GoldyBot.Extension): 17 def __init__(self, package_module=None): 18 super().__init__(self, package_module_name=package_module) 19 20 def loader(self): 21 22 @GoldyBot.command() 23 async def uwu(self:YourExtension, ctx): 24 await ctx.send(f'Hi, {ctx.author.mention}! UwU!') 25 26 def load(): 27 YourExtension(package_module_name=__name__) 28 pass 29 ``` 30 """ 31 32 def __init__(self, class_object, package_module_name:str=None): 33 """Tells Goldy Bot to Load this class as an extension.""" 34 self.class_object:object = class_object 35 self.module_name_ = package_module_name 36 self.ignored_extensions_list = GoldyBot.config.Config(GoldyBot.files.File(GoldyBot.paths.GOLDY_CONFIG_JSON)).read("ignored_extensions") 37 38 try: 39 if not self.code_name in self.ignored_extensions_list: 40 # Cache it. 41 #------------ 42 try: 43 if self.module.is_internal_module: 44 GoldyBot.cache.main_cache_dict["internal_modules"][f"{self.module_name}"]["extensions"][f"{self.code_name}"] = {} 45 GoldyBot.cache.main_cache_dict["internal_modules"][f"{self.module_name}"]["extensions"][f"{self.code_name}"]["commands"] = [] 46 GoldyBot.cache.main_cache_dict["internal_modules"][f"{self.module_name}"]["extensions"][f"{self.code_name}"]["object"] = self 47 else: 48 GoldyBot.cache.main_cache_dict["modules"][f"{self.module_name}"]["extensions"][f"{self.code_name}"] = {} 49 GoldyBot.cache.main_cache_dict["modules"][f"{self.module_name}"]["extensions"][f"{self.code_name}"]["commands"] = [] 50 GoldyBot.cache.main_cache_dict["modules"][f"{self.module_name}"]["extensions"][f"{self.code_name}"]["object"] = self 51 except AttributeError: 52 GoldyBot.logging.log("error", f"""[{MODULE_NAME}] Did you specify the module name when loading this extension. Looks like the module '{self.module_name}' did not get loaded by Goldy Bot. 53 Perhaps this is a package module and you forgot to specify the module name when loading this extension.\n""") 54 55 GoldyBot.Goldy().stop(f"I think you forgot to specify the module name when loading the '{self.code_name}' extension.") 56 57 GoldyBot.logging.log(f"[{self.code_name}] Loading my commands...") 58 self.loader() # Load commands. 59 60 else: 61 GoldyBot.logging.log("info", f"[{class_object.__class__.__name__}] Not loading commands as this extension is ignored.") 62 63 except TypeError as e: 64 what_is_incorrect = None 65 66 if self.ignored_extensions_list == None: what_is_incorrect = "ignored_extensions" 67 68 raise GoldyBot.errors.ConfigIsIncorrect(e, what_is_incorrect) 69 70 # Setting all variable shortcuts. 71 #----------------------------------- 72 self.client:GoldyBot.nextcord.Client = GoldyBot.cache.main_cache_dict["client"] 73 self.database:GoldyBot.database.Database = GoldyBot.cache.main_cache_dict["database"] 74 75 self.FindGuilds = GoldyBot.cache.FindGuilds() 76 77 self.msg = GoldyBot.utility.msgs 78 79 @property 80 def code_name(self): 81 return self.class_object.__class__.__name__ 82 83 @property 84 def module_name(self): 85 """Returns the name of the module this extension is being called from. This is much faster than grabbing the name with ``module().name``.""" 86 if self.module_name_ == None: 87 return self.class_object.__module__ 88 else: 89 return self.module_name_ 90 91 @property 92 def module(self) -> GoldyBot.modules.Module: 93 return GoldyBot.cache.FindModules().find_object_by_module_name(self.module_name) 94 95 def loader(self): 96 """The extension's command loader. This is what Goldy Bot uses to load your commands in an extension.""" 97 pass 98 99 def get_object(self): 100 """Returns the actual class object of the extension.""" 101 return self.class_object
class
Extension:
7class Extension(object): 8 """ 9 The base class for a Goldy Bot extension. 10 11 --------------- 12 ### ***``Example:``*** 13 14 This is how you set up an extension in a GoldyBot module. 😍 15 16 ```python 17 class YourExtension(GoldyBot.Extension): 18 def __init__(self, package_module=None): 19 super().__init__(self, package_module_name=package_module) 20 21 def loader(self): 22 23 @GoldyBot.command() 24 async def uwu(self:YourExtension, ctx): 25 await ctx.send(f'Hi, {ctx.author.mention}! UwU!') 26 27 def load(): 28 YourExtension(package_module_name=__name__) 29 pass 30 ``` 31 """ 32 33 def __init__(self, class_object, package_module_name:str=None): 34 """Tells Goldy Bot to Load this class as an extension.""" 35 self.class_object:object = class_object 36 self.module_name_ = package_module_name 37 self.ignored_extensions_list = GoldyBot.config.Config(GoldyBot.files.File(GoldyBot.paths.GOLDY_CONFIG_JSON)).read("ignored_extensions") 38 39 try: 40 if not self.code_name in self.ignored_extensions_list: 41 # Cache it. 42 #------------ 43 try: 44 if self.module.is_internal_module: 45 GoldyBot.cache.main_cache_dict["internal_modules"][f"{self.module_name}"]["extensions"][f"{self.code_name}"] = {} 46 GoldyBot.cache.main_cache_dict["internal_modules"][f"{self.module_name}"]["extensions"][f"{self.code_name}"]["commands"] = [] 47 GoldyBot.cache.main_cache_dict["internal_modules"][f"{self.module_name}"]["extensions"][f"{self.code_name}"]["object"] = self 48 else: 49 GoldyBot.cache.main_cache_dict["modules"][f"{self.module_name}"]["extensions"][f"{self.code_name}"] = {} 50 GoldyBot.cache.main_cache_dict["modules"][f"{self.module_name}"]["extensions"][f"{self.code_name}"]["commands"] = [] 51 GoldyBot.cache.main_cache_dict["modules"][f"{self.module_name}"]["extensions"][f"{self.code_name}"]["object"] = self 52 except AttributeError: 53 GoldyBot.logging.log("error", f"""[{MODULE_NAME}] Did you specify the module name when loading this extension. Looks like the module '{self.module_name}' did not get loaded by Goldy Bot. 54 Perhaps this is a package module and you forgot to specify the module name when loading this extension.\n""") 55 56 GoldyBot.Goldy().stop(f"I think you forgot to specify the module name when loading the '{self.code_name}' extension.") 57 58 GoldyBot.logging.log(f"[{self.code_name}] Loading my commands...") 59 self.loader() # Load commands. 60 61 else: 62 GoldyBot.logging.log("info", f"[{class_object.__class__.__name__}] Not loading commands as this extension is ignored.") 63 64 except TypeError as e: 65 what_is_incorrect = None 66 67 if self.ignored_extensions_list == None: what_is_incorrect = "ignored_extensions" 68 69 raise GoldyBot.errors.ConfigIsIncorrect(e, what_is_incorrect) 70 71 # Setting all variable shortcuts. 72 #----------------------------------- 73 self.client:GoldyBot.nextcord.Client = GoldyBot.cache.main_cache_dict["client"] 74 self.database:GoldyBot.database.Database = GoldyBot.cache.main_cache_dict["database"] 75 76 self.FindGuilds = GoldyBot.cache.FindGuilds() 77 78 self.msg = GoldyBot.utility.msgs 79 80 @property 81 def code_name(self): 82 return self.class_object.__class__.__name__ 83 84 @property 85 def module_name(self): 86 """Returns the name of the module this extension is being called from. This is much faster than grabbing the name with ``module().name``.""" 87 if self.module_name_ == None: 88 return self.class_object.__module__ 89 else: 90 return self.module_name_ 91 92 @property 93 def module(self) -> GoldyBot.modules.Module: 94 return GoldyBot.cache.FindModules().find_object_by_module_name(self.module_name) 95 96 def loader(self): 97 """The extension's command loader. This is what Goldy Bot uses to load your commands in an extension.""" 98 pass 99 100 def get_object(self): 101 """Returns the actual class object of the extension.""" 102 return self.class_object
The base class for a Goldy Bot extension.
Example:
This is how you set up an extension in a GoldyBot module. 😍
class YourExtension(GoldyBot.Extension):
def __init__(self, package_module=None):
super().__init__(self, package_module_name=package_module)
def loader(self):
@GoldyBot.command()
async def uwu(self:YourExtension, ctx):
await ctx.send(f'Hi, {ctx.author.mention}! UwU!')
def load():
YourExtension(package_module_name=__name__)
pass
Extension(class_object, package_module_name: str = None)
33 def __init__(self, class_object, package_module_name:str=None): 34 """Tells Goldy Bot to Load this class as an extension.""" 35 self.class_object:object = class_object 36 self.module_name_ = package_module_name 37 self.ignored_extensions_list = GoldyBot.config.Config(GoldyBot.files.File(GoldyBot.paths.GOLDY_CONFIG_JSON)).read("ignored_extensions") 38 39 try: 40 if not self.code_name in self.ignored_extensions_list: 41 # Cache it. 42 #------------ 43 try: 44 if self.module.is_internal_module: 45 GoldyBot.cache.main_cache_dict["internal_modules"][f"{self.module_name}"]["extensions"][f"{self.code_name}"] = {} 46 GoldyBot.cache.main_cache_dict["internal_modules"][f"{self.module_name}"]["extensions"][f"{self.code_name}"]["commands"] = [] 47 GoldyBot.cache.main_cache_dict["internal_modules"][f"{self.module_name}"]["extensions"][f"{self.code_name}"]["object"] = self 48 else: 49 GoldyBot.cache.main_cache_dict["modules"][f"{self.module_name}"]["extensions"][f"{self.code_name}"] = {} 50 GoldyBot.cache.main_cache_dict["modules"][f"{self.module_name}"]["extensions"][f"{self.code_name}"]["commands"] = [] 51 GoldyBot.cache.main_cache_dict["modules"][f"{self.module_name}"]["extensions"][f"{self.code_name}"]["object"] = self 52 except AttributeError: 53 GoldyBot.logging.log("error", f"""[{MODULE_NAME}] Did you specify the module name when loading this extension. Looks like the module '{self.module_name}' did not get loaded by Goldy Bot. 54 Perhaps this is a package module and you forgot to specify the module name when loading this extension.\n""") 55 56 GoldyBot.Goldy().stop(f"I think you forgot to specify the module name when loading the '{self.code_name}' extension.") 57 58 GoldyBot.logging.log(f"[{self.code_name}] Loading my commands...") 59 self.loader() # Load commands. 60 61 else: 62 GoldyBot.logging.log("info", f"[{class_object.__class__.__name__}] Not loading commands as this extension is ignored.") 63 64 except TypeError as e: 65 what_is_incorrect = None 66 67 if self.ignored_extensions_list == None: what_is_incorrect = "ignored_extensions" 68 69 raise GoldyBot.errors.ConfigIsIncorrect(e, what_is_incorrect) 70 71 # Setting all variable shortcuts. 72 #----------------------------------- 73 self.client:GoldyBot.nextcord.Client = GoldyBot.cache.main_cache_dict["client"] 74 self.database:GoldyBot.database.Database = GoldyBot.cache.main_cache_dict["database"] 75 76 self.FindGuilds = GoldyBot.cache.FindGuilds() 77 78 self.msg = GoldyBot.utility.msgs
Tells Goldy Bot to Load this class as an extension.
module_name
Returns the name of the module this extension is being called from. This is much faster than grabbing the name with module().name
.
module: GoldyBot.modules.Module