Skip to content

Commit

Permalink
hearts thank you messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Mole1424 committed Oct 11, 2023
1 parent 1ee02b3 commit c42f116
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions cogs/database.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from re import search

from discord import Message
from discord.abc import GuildChannel
Expand Down Expand Up @@ -61,11 +62,34 @@ async def on_message(self, message: Message):
if not any(
message.content.startswith(prefix) for prefix in command_prefixes
):
reply = process_karma(
message, message.id, db_session, CONFIG.KARMA_TIMEOUT
)
if reply:
await message.channel.send(reply)
# process karma if apropriate
if search(r"\+\+|--|\+\-", message.content):
reply = process_karma(
message, message.id, db_session, CONFIG.KARMA_TIMEOUT
)
if reply:
await message.channel.send(reply)
elif "th" in message.content.lower():
# if maybe some kind of thanks, process it
await self.process_thanks(message)

async def process_thanks(self, message: Message):
# to whoever sees this, you're welcome for the not having a fuck off massive indented if
if message.author.id == self.bot.user.id:
# dont thank itself
return
# Get the previous message (list comprehension my beloved)
previous_message = [
message async for message in message.channel.history(limit=2)
][1]
if previous_message.author.id != self.bot.user.id:
# can only thank replies to bot
return
thanks = ["thx", "thanks", "thank you"]
if not any(word in message.content.lower() for word in thanks):
# not a thank you
return
return await message.add_reaction("💜")


async def setup(bot: Bot):
Expand Down

0 comments on commit c42f116

Please sign in to comment.