diff --git a/BotResources.py b/BotResources.py index b0d9ec6..bcfab85 100644 --- a/BotResources.py +++ b/BotResources.py @@ -191,3 +191,14 @@ def check_negative(s): return False except ValueError: return False + + +# Check if message is a ping request and respond even if it is a bot +async def check_and_reply_to_ping(bot, message): + if "check_modules" in message.content: + ctx = await bot.get_context(message) + await bot.invoke(ctx) + return True + else: + await bot.process_commands(message) + return False diff --git a/bot.py b/bot.py index e35d144..82b2ae2 100644 --- a/bot.py +++ b/bot.py @@ -253,10 +253,6 @@ class Bot(commands.Bot): await self.check_for_modules() print("Bot started!") - @self.event - async def on_message(message): - await self.check_and_reply_to_ping(message) - # Check to see if other bots are online async def check_other_bots_online(self): print('Checking if other bots are online') @@ -272,7 +268,7 @@ class Bot(commands.Bot): await self.wait_until_ready() # Send the ping command with the prefix the current bot is using - await channel.send(f"{self.Command_Prefix}ping") + await channel.send(f"{self.Command_Prefix}check_modules") seconds_waited = 0 while seconds_waited < 3: @@ -480,13 +476,3 @@ class Bot(commands.Bot): message_body += f"Squelch: {self.squelch}" return message_body - - # 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: - await self.process_commands(message) - return False diff --git a/modules/LinkCop/cog.py b/modules/LinkCop/cog.py index 7556d3c..c180511 100644 --- a/modules/LinkCop/cog.py +++ b/modules/LinkCop/cog.py @@ -2,7 +2,7 @@ import re import discord from discord.ext import commands import random -from BotResources import PDB_KNOWN_BOT_IDS +from BotResources import PDB_KNOWN_BOT_IDS, check_and_reply_to_ping regex_link = re.compile('(http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+)') @@ -71,7 +71,7 @@ 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.check_and_reply_to_ping(ctx) + await check_and_reply_to_ping(self.bot, ctx) async def send_message(self, message): send_channel = self.bot.get_channel(id=self.reply_channel_id) diff --git a/modules/ModuleProbe/cog.py b/modules/ModuleProbe/cog.py new file mode 100644 index 0000000..b653bc9 --- /dev/null +++ b/modules/ModuleProbe/cog.py @@ -0,0 +1,24 @@ +from discord.ext import commands +from BotResources import check_and_reply_to_ping + + +class ModuleProbe(commands.Cog): + def __init__(self, bot): + self.bot = bot + self.channel_id = 767303243285790721 + + self.add_events() + + def add_events(self): + @self.bot.event + async def on_message(message): + await check_and_reply_to_ping(self.bot, message) + + @commands.command(help="This command is used by other bots to test if there are any bots online with modules.") + async def check_modules(self, ctx): + if ctx.author.id != self.bot.user.id: + await ctx.send('pong') + + +def setup(bot: commands.Bot): + bot.add_cog(ModuleProbe(bot))