Add message listener portion of birthday fun.

This commit is contained in:
2023-08-26 22:52:02 -04:00
parent 25833364d7
commit df8cb3dd49
2 changed files with 45 additions and 0 deletions
+43
View File
@@ -0,0 +1,43 @@
"""
Defines cog for on message listener.
"""
import nextcord
from nextcord.ext import commands
from dakiny_bot import birthday_list
class SubmissionListener(commands.Cog, name="Message Listener"):
"""Sets up message listener."""
def __init__(self, bot: commands.Bot):
self.bot = bot
@commands.Cog.listener()
async def on_message(self, message: nextcord.Message):
"""Listener for message creation. Adds score and attachments to submission."""
# don't want to process any messages from bot.
if message.author.id == self.bot.user.id:
return
await birthday_action(message)
# This function will be called when this extension is loaded.
# It is necessary to add these functions to the bot.
def setup(bot: commands.Bot):
"""Adds function to bot"""
bot.add_cog(SubmissionListener(bot))
async def birthday_action(message: nextcord.Message) -> None:
"""
Checks a message's auther and mentions to see if they are in the birthday list.
Args:
message (nextcord.Message): The message to check for a birthday person.
"""
if message.author.id in birthday_list or bool(set(message.raw_mentions) & set(birthday_list)):
await message.add_reaction("🎂")
+2
View File
@@ -12,6 +12,8 @@ from config import DakinyConfig
cs = ConfigStore.instance() cs = ConfigStore.instance()
cs.store(name="dakiny_config", node=DakinyConfig) cs.store(name="dakiny_config", node=DakinyConfig)
birthday_list: list[int] = []
@hydra.main(config_path="conf", config_name="config") @hydra.main(config_path="conf", config_name="config")
def main(cfg: DakinyConfig): def main(cfg: DakinyConfig):