Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

karma detection for heart reaction #252

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion cogs/commands/onmessage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

karma processing is done in ../database.py so this will cause all karma to be double counted

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):
Expand Down
Loading