Merge pull request 'Moved the startup ping response to a module, so it will only reply if the modules are enabled' (#6) from ModuleProbe into master

Reviewed-on: http://git.vpn.cusano.net/Discord_Bot_Gang/Discord-Radio-Bot/pulls/6
This commit is contained in:
2022-03-17 00:00:46 -04:00
4 changed files with 38 additions and 17 deletions

View File

@@ -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

16
bot.py
View File

@@ -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

View File

@@ -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)

View File

@@ -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))