def __init__(self, mod_name, embed_color): # Config var init self.config = DataManager.JSON("Mods/Shops/ShopsConfig.json") self.delete_delay = self.config.get_data("Message Delete Delay") # Init shop DB self.shop_info_database = DataManager.add_manager( "shop_info_database", "Mods/Shops/ShopsInfo.db", file_type=DataManager.FileType.SQL) self.shops_database = DataManager.add_manager( "shops_database", "Mods/Shops/Shops.db", file_type=DataManager.FileType.SQL) # Create a shop table withing the DB if there isn't one self.shop_info_database.execute( "CREATE TABLE IF NOT EXISTS shops(channel_id TEXT UNIQUE, shop_name TEXT, is_purge BIT)" ) self.shop_info_database.execute( "CREATE TABLE IF NOT EXISTS messages(shop_name TEXT UNIQUE, message_id TEXT, channel_id TEXT)" ) # Verify DB - Check for deleted channels that shops exist in self.verify_db() # Build command objects self.commands = Utils.parse_command_config( self, mod_name, self.config.get_data('Commands')) # Init the super with all the info from this mod super().__init__(mod_name, self.config.get_data('Mod Description'), self.commands, embed_color)
def parse_command_config(parent, parent_name, config): mod_config = DataManager.get_manager("mod_config").get_data() # Remove commands that don't exist anymore to_remove = [command_name for command_name in mod_config[parent_name]["Commands"] if command_name not in config] for command_name in to_remove: mod_config[parent_name]["Commands"].pop(command_name) # Generate config if it doesn't exist for command_name in config: if command_name not in mod_config[parent_name]["Commands"]: mod_config[parent_name]["Commands"][command_name] = { "Disabled Channels": [], "Disabled Servers": [], "Minimum Permissions": "" } DataManager.get_manager("mod_config").write_data(mod_config) # Delete old mods and commands? # Spawn command objects based on config and return a dictionary with them return {command_name: (Command(parent, command_name, config[command_name]['Aliases'], config[command_name]["Enabled"], mod_config[parent_name]["Commands"][command_name]["Minimum Permissions"], config[command_name]['Help'], ''.join(use + "\n" for use in config[command_name]['Useage'])[0:-1], int(config[command_name]["Cool Down"]) if "Cool Down" in config[ command_name] else 0, config[command_name]["Bypass Server Restrictions"] if "Bypass Server Restrictions" in config[command_name] else False, config[command_name]["Bypass Channel Restrictions"] if "Bypass Channel Restrictions" in config[command_name] else False, config[command_name]["DM Enabled"] if "DM Enabled" in config[command_name] else False)) for command_name in config}
def __init__(self, mod_name, embed_color): # Config var init self.config = DataManager.JSON("Mods/Waifu/WaifuConfig.json") # Make sure all gifts follow a proper naming convention for gift_name in self.config.get_data("Gifts"): if not re.fullmatch(r"[A-Za-z0-9 ]*", gift_name): raise Exception( "Waifu gift name \"%s\" can only contain spaces, A-Z, a-z, 0-9" % gift_name) # Build command objects self.commands = Utils.parse_command_config( self, mod_name, self.config.get_data('Commands')) # Init DBs self.waifus_db = DataManager.add_manager( "shop_database", "Mods/Waifu/Waifus.db", file_type=DataManager.FileType.SQL) self.gifts_db = DataManager.add_manager( "shop_database", "Mods/Waifu/Gifts.db", file_type=DataManager.FileType.SQL) # Generate and Update DB self.generate_db() # Super... super().__init__(mod_name, self.config.get_data("Mod Description"), self.commands, embed_color)
def __init__(self, mod_name, embed_color): super().__init__(mod_name, "Just an example mod.", {}, embed_color) # Config var init self.config = DataManager.JSON("Mods/Gacha/GachaConfig.json") # Init DBs self.gacha_database = DataManager.add_manager("gacha_database", "Mods/Gacha/GachaDatabase.db", file_type=DataManager.FileType.SQL) self.generate_db() # Build command objects self.commands = Utils.parse_command_config(self, mod_name, self.config.get_data('Commands')) # Init the super with all the info from this mod super().__init__(mod_name, self.config.get_data('Mod Description'), self.commands, embed_color)
def load_permissions(): global default_perm global owner_perm print("[Loading permissions]", end='') permissions_config = DataManager.get_manager("bot_config").get_data(key="Permissions") # Build the permissions from the config for permission_name in permissions_config: # Grab info from each permission permission_config = permissions_config[permission_name] permission = Permission(permission_name, permission_config["Has Permissions"], permission_config["Is Owner"], permission_config["Inherits"], permission_config["Associated Roles"]) permissions[permission_name] = permission # Check if it's the default permission, making sure there is a max of 1 if permission_config["Is Default"]: assert default_perm is None, "Bot config contains more than one default role." default_perm = permission # Check if it's the owner permission, making sure there is a max of 1 if permission_config["Is Owner"]: assert owner_perm is None, "Bot config contains more than one owner permission." owner_perm = permission # Check that there is a min of 1 owner and default permission assert owner_perm is not None, "There must be one owner permission" assert default_perm is not None, "There must be one default permission" print("[Done]")
def __init__(self, mod_name, embed_color): super().__init__(mod_name, "Just an example mod.", {}, embed_color) # Config var init self.config = DataManager.JSON("Mods/Gamble/GambleConfig.json") # Build command objects self.commands = Utils.parse_command_config(self, mod_name, self.config.get_data('Commands')) # Init the super with all the info from this mod super().__init__(mod_name, self.config.get_data('Mod Description'), self.commands, embed_color)
def __init__(self, mod_name, embed_color): # Config var init self.config = DataManager.JSON( "Mods/DailyEconomy/DailyEconomyConfig.json") # Build command objects self.commands = Utils.parse_command_config( self, mod_name, self.config.get_data('Commands')) # Init the super with all the info from this mod super().__init__(mod_name, self.config.get_data('Mod Description'), self.commands, embed_color)
async def load_mods(self): print("[Loading Mods]") mod_config_manager = DataManager.get_manager("mod_config") mod_configs = mod_config_manager.get_data() new_mod_config = {} # Cycle through all the mods in the mod directory # If the mod config doesn't contain the mod -> Generate config # If the mod config contains the mod -> Keep Same config for mod_name in os.listdir("Mods/"): if mod_name not in mod_configs.keys(): new_mod_config[mod_name] = { "Commands": {}, "Enabled": True, "Disabled Servers": [], "Disabled Channels": [] } else: # Append for config cleaning new_mod_config[mod_name] = mod_configs[mod_name] mod_config_manager.write_data(new_mod_config) # Cycle through all the files within the mod dir for mod_name in os.listdir("Mods/"): # Store the mod names to return them # Check if it's a newly installed mod or if the mod is enabled # Mod doesn't exist -> Newly installed -> Load it # Mod exists -> Not disabled -> Load it if mod_name not in mod_configs.keys( ) or mod_configs[mod_name]['Enabled'] is not False: # Make the python files importable and import them sys.path.insert(0, 'Mods/' + mod_name) print("[+][Loading: %s]" % mod_name) # Import and call mod init to get object mod = getattr(__import__(mod_name), mod_name)(mod_name, self.embed_color) # Check for command conflicts and store commands for command_name in mod.commands: command_alias = mod.commands[command_name] for alias in command_alias: assert alias != mod.name.lower( ), "Mod name and command alias conflict - " + mod.name # Check for conflicting commands assert alias not in self.mod_command_aliases, "Duplicate mod commands - " + alias # Add as known alias for further conflict checks self.mod_command_aliases.append(alias) # Register command self.commands.append(command_alias) # Get mod's info # Store mod's info self.mods[mod.name] = mod print("[Done loading " + mod_name + "]") # Mod exists -> Disabled -> Don't load it, as per config else: print("[-][Not Loading: " + mod_name + "]") self.done_loading = True print("[Done loading Mods]")
def __init__(self, mod_name, embed_color): # Vars self.user_times = {} # User : Join Time # Config var init self.config = DataManager.JSON( "Mods/VoiceTimeout/VoiceTimeoutConfig.json") # Build command objects # self.commands = Utils.parse_command_config(self, mod_name, self.config.get_data('Commands')) self.commands = {} # Init the super with all the info from this mod super().__init__(mod_name, self.config.get_data('Mod Description'), self.commands, embed_color)
def __init__(self, mod_name, embed_color): # General var init self.name = mod_name self.embed_color = embed_color self.applied_interest = False # Config var init self.config = DataManager.JSON("Mods/Economy/EconomyConfig.json") # Set the currency for mods to use EconomyUtils.currency = self.config.get_data("Currency") # Build command objects self.commands = Utils.parse_command_config( self, mod_name, self.config.get_data('Commands')) # Generate Update and Init DBs EconomyUtils.init_database() self.generate_db() # Init the super with all the info from this mod super().__init__(mod_name, self.config.get_data('Mod Description'), self.commands, embed_color)
def init_database(): global database database = DataManager.add_manager("bank_database", "Mods/Economy/Bank.db", file_type=DataManager.FileType.SQL) return database
async def command_called(self, message, command_alias): split_message = message.content.split(" ") server = message.guild channel = message.channel # Make sure everything initialized if self.done_loading: bot_config = DataManager.get_manager("bot_config") # Try to get the command by its alias command = self.get_command_by_alias(command_alias) # If it's a known command -> call it if it's enabled / allowed to be called if command is not None: if server is not None: # Grab mod config to check for enabled servers / channels mod_config = DataManager.get_manager( "mod_config").get_data()[command.parent_mod.name] # Check if the command bypasses server restrictions if command.bypass_server_restrictions: await command.call_command(message) # Check if the bot is disabled in the current server elif int(server.id) not in bot_config.get_data( "Disabled Servers"): # Check if command's parent mod is disabled in the current server if int(server.id ) not in mod_config["Disabled Servers"]: # Check if the command bypasses channel restrictions if command.bypass_channel_restrictions: await command.call_command(message) # Check if the bot is disabled in the current channel elif int(channel.id) not in bot_config.get_data( "Disabled Channels"): # Check if command's parent mod is disabled in the current channel if int( channel.id ) not in mod_config["Disabled Channels"]: await command.call_command(message) else: # Check if command's parent mod is disabled in the current server if int(server.id) not in bot_config.get_data( "Disabled Servers"): # Check if command's parent mod is disabled in the current channel if int(channel.id) not in bot_config.get_data( "Disabled Channels"): if Permissions.has_permission( message.author, self.minimum_suggestion_permission): # No command called -> Not a known command most_similar_command = most_similar_string( command_alias, self.mod_command_aliases) # No similar commands -> Reply with an error if most_similar_command is None: # Reply that neither that mod nor command exists await Utils.simple_embed_reply( channel, "[Help]", "Unknown mod or command - %s" % split_message[1]) # Similar-looking command exists -> Reply with it else: # Reply with a similar command await Utils.simple_embed_reply( channel, "[Unknown command]", "Did you mean `" + most_similar_command + "`?") # It's a PM / DM, so check if the command can be called in DMs elif command.dm_enabled: await command.call_command(message) # Mods are still loading -> Let the author know else: await Utils.simple_embed_reply( channel, "[Error]", "The bot is still loading, please wait.")