From 3d07d3d9ddb78ccbbf22c9baeed7cbeacc6eb0ca Mon Sep 17 00:00:00 2001 From: Ali Aljishi Date: Thu, 13 Jun 2024 00:16:42 +0100 Subject: [PATCH] karma detection for heart reaction --- cogs/commands/onmessage.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/cogs/commands/onmessage.py b/cogs/commands/onmessage.py index ce22a66..b4675df 100644 --- a/cogs/commands/onmessage.py +++ b/cogs/commands/onmessage.py @@ -5,6 +5,10 @@ from discord.ext import commands from discord.ext.commands import Bot, Cog +from config import CONFIG +from karma.karma import process_karma +from models import db_session + class OnMessage(commands.Cog): def __init__(self, bot: Bot): @@ -42,7 +46,7 @@ async def thanks(self, message: Message): replied_message = await message.channel.fetch_message( message.reference.message_id ) - if replied_message.author != self.bot.user.id: + if replied_message.author.id != self.bot.user.id: return elif ( previous_message.author.id != self.bot.user.id @@ -56,6 +60,22 @@ async def thanks(self, message: Message): search(r"\b" + thank + r"\b", message.content.lower()) for thank in thanks ): return + + # get all command prefixes + command_prefixes = self.bot.command_prefix(self.bot, message) + # if message is not command, check for karma + if not any(message.content.startswith(prefix) for prefix in command_prefixes): + # process karma if apropriate + if search(r"\+\+|--|\+\-", message.content): + reply = process_karma( + message, message.id, db_session, CONFIG.KARMA_TIMEOUT + ) + # if message is a valid karma + if reply: + return + else: + # message is command, so don't run + return return await message.add_reaction("💜") async def scan_replace(self, message: Message, regex, replace):