diff --git a/bot.py b/bot.py index 4d56726..850d6ae 100644 --- a/bot.py +++ b/bot.py @@ -236,9 +236,7 @@ class Bot(commands.Bot): @self.event async def on_message(message): - print(message.content) - if "ping" in message.content: - await self.process_commands(message) + await self.check_and_reply_to_ping(message) # Check to see if other bots are online async def check_other_bots_online(self): @@ -266,6 +264,11 @@ class Bot(commands.Bot): print(f"Bots Online: {bots_online}") + if len(bots_online) == 0: + return False + elif len(bots_online) > 0: + return True + # Check the handler being used during init def check_handler(self): if self.Handler == "gqrx": @@ -304,16 +307,15 @@ class Bot(commands.Bot): # Search the ./modules folder for any modules to load async def check_for_modules(self): - print('Checking modules') - await self.check_other_bots_online() - - # A valid module must be built as a 'cog', refer to the docs for more information - for folder_name in os.listdir("modules"): - if str(folder_name)[0] == '.': - continue - elif os.path.exists(os.path.join("modules", folder_name, "cog.py")): - print(f"Loaded extension: {folder_name}") - self.load_extension(f"modules.{folder_name}.cog") + # Check to see if other bots are online and don't load the modules if they are + if not await self.check_other_bots_online(): + # A valid module must be built as a 'cog', refer to the docs for more information + for folder_name in os.listdir("modules"): + if str(folder_name)[0] == '.': + continue + elif os.path.exists(os.path.join("modules", folder_name, "cog.py")): + print(f"Loaded extension: {folder_name}") + self.load_extension(f"modules.{folder_name}.cog") # Reload a selected module for changes def reload_modules(self, module): @@ -433,3 +435,12 @@ class Bot(commands.Bot): return False else: return False + + # Check if message is a ping request and respond even if it is a bot + async def check_and_reply_to_ping(self, message): + if "ping" in message.content: + ctx = await self.get_context(message) + await self.invoke(ctx) + return True + else: + return False diff --git a/modules/LinkCop/cog.py b/modules/LinkCop/cog.py index 4942376..ab8fcbd 100644 --- a/modules/LinkCop/cog.py +++ b/modules/LinkCop/cog.py @@ -73,7 +73,8 @@ class LinkCop(commands.Cog): print(f"Link Cop Error: '{err}'") print(f"Bot or other non-user that has not been whitelisted sent a message") - await self.bot.process_commands(ctx) + if not await self.bot.check_and_reply_to_ping(ctx): + await self.bot.process_commands(ctx) async def send_message(self, message): send_channel = self.bot.get_channel(id=self.reply_channel_id)