Repository: olliequ/KittyBot
Pull request #149: Delete meme if it receives enough 💩 reactions
Author: login: olliequ
Created: 2025-03-23T09:56:52Z | Merged: 2025-03-24T10:34:58Z

- Tested locally.
- Has comments!
- Addresses #144 


Diff:
diff --git a/behaviours/__init__.py b/behaviours/__init__.py
index d76ea9e..8cb2165 100644
--- a/behaviours/__init__.py
+++ b/behaviours/__init__.py
@@ -43,7 +43,13 @@
 ]
 
 _reaction_add_chain: _Chain[hikari.GuildReactionAddEvent] = [
-    [userinfo.analyse_reaction, meme_rater.respond_to_question_mark]
+    [
+        meme_rater.respond_to_question_mark,
+        meme_rater.delete_meme,
+    ],
+    [
+        userinfo.analyse_reaction,
+    ],
 ]
 
 _reaction_remove_chain: _Chain[hikari.GuildReactionDeleteEvent] = [
diff --git a/behaviours/meme_rater.py b/behaviours/meme_rater.py
index 3dc7958..61c6d1d 100644
--- a/behaviours/meme_rater.py
+++ b/behaviours/meme_rater.py
@@ -1,12 +1,13 @@
 import os
 import logging
-
 import db
 import hikari
 import requests
+import asyncio
+import behaviours
+
 from commons import agents
 from typing import Final
-import asyncio
 
 RATER_LOCK = asyncio.Lock()
 
@@ -224,3 +225,41 @@ async def respond_to_question_mark(event: hikari.GuildReactionAddEvent) -> None:
                 content=f"{row[0]}",  # Idk how to tag people
             )
             explained.add(response_to_msg_id)
+
+        raise behaviours.EndProcessing()
+
+
+# Deletes a meme if 4 or more entities (including Kitti if she reacted) react to a meme with the shit emoji.
+async def delete_meme(event: hikari.GuildReactionAddEvent) -> None:
+    # Return early if not in the correct channel, wrong emoji, or if the member is a bot.
+    if (
+        event.channel_id != MEME_CHANNEL_ID
+        or event.emoji_name != "💩"
+        or event.member.is_bot
+    ):
+        return
+
+    # Fetch message object
+    message = await event.app.rest.fetch_message(
+        channel=event.channel_id, message=event.message_id
+    )
+
+    # Find the "💩" reaction.
+    shit_reaction = next(
+        (reaction for reaction in message.reactions if reaction.emoji == "💩"), None
+    )
+
+    if shit_reaction and shit_reaction.count >= 4:
+        await event.app.rest.delete_message(
+            channel=event.channel_id, message=event.message_id
+        )
+        await event.app.rest.create_message(
+            user_mentions=True,
+            channel=event.channel_id,
+            content=(
+                f"Hey {message.author.mention}, your meme has been deemed as 'too shit' "
+                "by the community. Try again with a better meme."
+            ),
+        )
+
+    raise behaviours.EndProcessing()


Reviews:
user: login: adamnwerbik
state: DISMISSED
author_association: COLLABORATOR
submitted_at: 2025-03-23T10:02:51Z
user: login: flukiluke
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-23T10:05:29Z
user: login: olliequ
state: COMMENTED
author_association: OWNER
submitted_at: 2025-03-23T10:07:22Z
user: login: olliequ
state: COMMENTED
author_association: OWNER
submitted_at: 2025-03-23T10:08:03Z
user: login: olliequ
state: COMMENTED
author_association: OWNER
submitted_at: 2025-03-23T10:08:25Z
user: login: adamnwerbik
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-23T10:08:44Z
user: login: flukiluke
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-23T10:09:15Z
user: login: flukiluke
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-23T10:12:17Z
user: login: flukiluke
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-23T10:46:52Z
user: login: jimbxb
state: CHANGES_REQUESTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-23T11:06:13Z

Review comments:
diff_hunk: @@ -224,3 +218,36 @@ async def respond_to_question_mark(event: hikari.GuildReactionAddEvent) -> None:
                 content=f"{row[0]}",  # Idk how to tag people
             )
             explained.add(response_to_msg_id)
+
+
+# Deletes a meme if 4 or more entities (including Kitti if she reacted) react to a meme with the shit emoji.
+async def delete_meme(event: hikari.GuildReactionAddEvent) -> None:
+    # Return early if not in the correct channel, wrong emoji, or if the member is a bot.
+    if (
+        event.channel_id != MEME_CHANNEL_ID
+        or event.emoji_name != "💩"
+        or event.member.is_bot
+    ):
+        return
+
+    # Fetch message object
+    message = await event.app.rest.fetch_message(
+        channel=event.channel_id, message=event.message_id
+    )
+
+    # Find the "💩" reaction and return early.
path: behaviours/meme_rater.py
user: login: flukiluke
body: Comment doesn't match the code, there's no early return here
created_at: 2025-03-23T10:02:16Z
author_association: COLLABORATOR
diff_hunk: @@ -1,12 +1,6 @@
-import os
-import logging
-
-import db
-import hikari
-import requests
+import os, logging, db, hikari, requests, asyncio
path: behaviours/meme_rater.py
user: login: flukiluke
body: Whyyyyyyyyy
created_at: 2025-03-23T10:02:31Z
author_association: COLLABORATOR
diff_hunk: @@ -43,7 +43,11 @@
 ]
 
 _reaction_add_chain: _Chain[hikari.GuildReactionAddEvent] = [
-    [userinfo.analyse_reaction, meme_rater.respond_to_question_mark]
+    [
path: behaviours/__init__.py
user: login: flukiluke
body: As it stands this means the 💩/❓ get added to a user's total emoji stats, is that what we want?
created_at: 2025-03-23T10:03:30Z
author_association: COLLABORATOR
diff_hunk: @@ -224,3 +218,36 @@ async def respond_to_question_mark(event: hikari.GuildReactionAddEvent) -> None:
                 content=f"{row[0]}",  # Idk how to tag people
             )
             explained.add(response_to_msg_id)
+
+
+# Deletes a meme if 4 or more entities (including Kitti if she reacted) react to a meme with the shit emoji.
+async def delete_meme(event: hikari.GuildReactionAddEvent) -> None:
+    # Return early if not in the correct channel, wrong emoji, or if the member is a bot.
+    if (
+        event.channel_id != MEME_CHANNEL_ID
+        or event.emoji_name != "💩"
+        or event.member.is_bot
+    ):
+        return
+
+    # Fetch message object
+    message = await event.app.rest.fetch_message(
+        channel=event.channel_id, message=event.message_id
+    )
+
+    # Find the "💩" reaction and return early.
+    shit_reaction = next(
+        (reaction for reaction in message.reactions if reaction.emoji == "💩"), None
+    )
+
+    if shit_reaction and shit_reaction.count >= 4:
+        await event.app.rest.delete_message(
+            channel=event.channel_id, message=event.message_id
+        )
+        await event.app.rest.create_message(
path: behaviours/meme_rater.py
user: login: flukiluke
body: Do you need to set something like user_mentions=True?
created_at: 2025-03-23T10:05:25Z
author_association: COLLABORATOR
diff_hunk: @@ -1,12 +1,6 @@
-import os
-import logging
-
-import db
-import hikari
-import requests
+import os, logging, db, hikari, requests, asyncio
path: behaviours/meme_rater.py
user: login: olliequ
body: Cleaner. And wastes less bytes.
created_at: 2025-03-23T10:07:22Z
author_association: OWNER
diff_hunk: @@ -43,7 +43,11 @@
 ]
 
 _reaction_add_chain: _Chain[hikari.GuildReactionAddEvent] = [
-    [userinfo.analyse_reaction, meme_rater.respond_to_question_mark]
+    [
path: behaviours/__init__.py
user: login: olliequ
body: That's not what we want. How to prevent this?
created_at: 2025-03-23T10:08:03Z
author_association: OWNER
diff_hunk: @@ -224,3 +218,36 @@ async def respond_to_question_mark(event: hikari.GuildReactionAddEvent) -> None:
                 content=f"{row[0]}",  # Idk how to tag people
             )
             explained.add(response_to_msg_id)
+
+
+# Deletes a meme if 4 or more entities (including Kitti if she reacted) react to a meme with the shit emoji.
+async def delete_meme(event: hikari.GuildReactionAddEvent) -> None:
+    # Return early if not in the correct channel, wrong emoji, or if the member is a bot.
+    if (
+        event.channel_id != MEME_CHANNEL_ID
+        or event.emoji_name != "💩"
+        or event.member.is_bot
+    ):
+        return
+
+    # Fetch message object
+    message = await event.app.rest.fetch_message(
+        channel=event.channel_id, message=event.message_id
+    )
+
+    # Find the "💩" reaction and return early.
+    shit_reaction = next(
+        (reaction for reaction in message.reactions if reaction.emoji == "💩"), None
+    )
+
+    if shit_reaction and shit_reaction.count >= 4:
+        await event.app.rest.delete_message(
+            channel=event.channel_id, message=event.message_id
+        )
+        await event.app.rest.create_message(
path: behaviours/meme_rater.py
user: login: olliequ
body: To do what?
created_at: 2025-03-23T10:08:25Z
author_association: OWNER
diff_hunk: @@ -43,7 +43,11 @@
 ]
 
 _reaction_add_chain: _Chain[hikari.GuildReactionAddEvent] = [
-    [userinfo.analyse_reaction, meme_rater.respond_to_question_mark]
+    [
path: behaviours/__init__.py
user: login: adamnwerbik
body: exclude those 2 emojis in meme channel only IMO
created_at: 2025-03-23T10:08:44Z
author_association: COLLABORATOR
diff_hunk: @@ -224,3 +218,36 @@ async def respond_to_question_mark(event: hikari.GuildReactionAddEvent) -> None:
                 content=f"{row[0]}",  # Idk how to tag people
             )
             explained.add(response_to_msg_id)
+
+
+# Deletes a meme if 4 or more entities (including Kitti if she reacted) react to a meme with the shit emoji.
+async def delete_meme(event: hikari.GuildReactionAddEvent) -> None:
+    # Return early if not in the correct channel, wrong emoji, or if the member is a bot.
+    if (
+        event.channel_id != MEME_CHANNEL_ID
+        or event.emoji_name != "💩"
+        or event.member.is_bot
+    ):
+        return
+
+    # Fetch message object
+    message = await event.app.rest.fetch_message(
+        channel=event.channel_id, message=event.message_id
+    )
+
+    # Find the "💩" reaction and return early.
+    shit_reaction = next(
+        (reaction for reaction in message.reactions if reaction.emoji == "💩"), None
+    )
+
+    if shit_reaction and shit_reaction.count >= 4:
+        await event.app.rest.delete_message(
+            channel=event.channel_id, message=event.message_id
+        )
+        await event.app.rest.create_message(
path: behaviours/meme_rater.py
user: login: flukiluke
body: Idk but most of the other message sending calls do it
created_at: 2025-03-23T10:09:14Z
author_association: COLLABORATOR
diff_hunk: @@ -43,7 +43,11 @@
 ]
 
 _reaction_add_chain: _Chain[hikari.GuildReactionAddEvent] = [
-    [userinfo.analyse_reaction, meme_rater.respond_to_question_mark]
+    [
path: behaviours/__init__.py
user: login: flukiluke
body: Move the two meme rater actions to a new list in the chain, then have each raise EndProcessing if they action the event.
created_at: 2025-03-23T10:12:17Z
author_association: COLLABORATOR
diff_hunk: @@ -43,7 +43,11 @@
 ]
 
 _reaction_add_chain: _Chain[hikari.GuildReactionAddEvent] = [
-    [userinfo.analyse_reaction, meme_rater.respond_to_question_mark]
+    [
path: behaviours/__init__.py
user: login: flukiluke
body: The meme rater actions need to come _before_ the userinfo. Chains are evaluated from the top down.
created_at: 2025-03-23T10:46:52Z
author_association: COLLABORATOR
diff_hunk: @@ -224,3 +225,41 @@ async def respond_to_question_mark(event: hikari.GuildReactionAddEvent) -> None:
                 content=f"{row[0]}",  # Idk how to tag people
             )
             explained.add(response_to_msg_id)
+
+        raise behaviours.EndProcessing()
+
+
+# Deletes a meme if 4 or more entities (including Kitti if she reacted) react to a meme with the shit emoji.
+async def delete_meme(event: hikari.GuildReactionAddEvent) -> None:
+    # Return early if not in the correct channel, wrong emoji, or if the member is a bot.
+    if (
+        event.channel_id != MEME_CHANNEL_ID
+        or event.emoji_name != "💩"
+        or event.member.is_bot
+    ):
+        return
+
+    # Fetch message object
+    message = await event.app.rest.fetch_message(
+        channel=event.channel_id, message=event.message_id
+    )
+
+    # Find the "💩" reaction.
+    shit_reaction = next(
+        (reaction for reaction in message.reactions if reaction.emoji == "💩"), None
+    )
+
+    if shit_reaction and shit_reaction.count >= 4:
path: behaviours/meme_rater.py
user: login: jimbxb
body: Make this configuraable
created_at: 2025-03-23T11:04:52Z
author_association: CONTRIBUTOR

PR comments:
user: login: adamnwerbik
created_at: 2025-03-23T10:06:48Z
body: average ollie code quality
author_association: COLLABORATOR
user: login: MRDGH2821
created_at: 2025-03-23T10:08:46Z
body: Maybe inform the user that their meme was deleted?
(Preferably in kitti's configured persona)
author_association: CONTRIBUTOR
user: login: olliequ
created_at: 2025-03-23T10:10:30Z
body: @MRDGH2821 That already happens.
author_association: OWNER