Browse Source

add funny missing ping idea

Kirk Trombley 1 month ago
parent
commit
5ef553a4e9
1 changed files with 24 additions and 2 deletions
  1. 24 2
      drivers/discord_driver.py

+ 24 - 2
drivers/discord_driver.py

@@ -25,8 +25,8 @@ class DiscordBot(rollbot.Rollbot[discord.Message]):
         super().__init__(config, database_file, loop=loop)
         self.discord_client = client
         client.event(self.on_message)
-        if secrets["discord"].get("enable_react_notifs", False):
-            client.event(self.on_reaction_add)
+        client.event(self.on_reaction_add)
+        self.missing_pings = []
 
     def read_config(self, key: str) -> Any:
         cfg = secrets
@@ -45,6 +45,28 @@ class DiscordBot(rollbot.Rollbot[discord.Message]):
     async def on_reaction_add(
         self, reaction: discord.Reaction, user: discord.Member | discord.User
     ):
+        try:
+            if (
+                not isinstance(reaction.emoji, str)
+                and reaction.emoji.name == "missingping"
+            ):
+                if not self.missing_pings:
+                    # note this probably breaks if used across multiple servers...
+                    await client.fetch_guild(reaction.message.guild.id)
+                    self.missing_pings = [
+                        discord.utils.get(client.emojis, name=name)
+                        for name in (
+                            "missingping2",
+                            "missingping3",
+                            "missingping4",
+                            "missingping5",
+                        )
+                    ]
+                for ping in self.missing_pings:
+                    await reaction.message.add_reaction(ping)
+        except Exception:
+            self.context.logger.exception("Failed to do the funny missing ping bit")
+
         sender_id = getattr(reaction.message.author, "id", None)
         if (
             str(sender_id) not in secrets["discord"].get("wants_react_notifs", [])