prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Filter functionality for emoji-spam messages
  Now that someone's figured out you can cause havok by dumping massive amounts of emojis into a channel, we need a filter to automatically manage this ASAP. Detection should be fairly simple, a very high emoji count is required for the effect (>20/message to >250 for varying impact) but emoji variance is not required. 
  
  Tangentially: This is also likely related to a discord update that went out that has slowed the emoji loading process recently.
  
  I think we can safely filter out and autodelete high emoji messages without significant false positives. 
  
  We may want to handle both unicode emojis and server emojis. 
  
  It's possible for unicode emojis to get a higher "load" because they could as one character for message transmission purposes but server emojis count for more. However, server emojis may be animated, and will apply significant load by that fact as well.
  
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `bot/rules/discord_emojis.py`
  Content:
  ```
  1 import re
  2 from typing import Dict, Iterable, List, Optional, Tuple
  3 
  4 from discord import Member, Message
  5 
  6 
  7 DISCORD_EMOJI_RE = re.compile(r"<:\w+:\d+>")
  8 CODE_BLOCK_RE = re.compile(r"```.*?```", flags=re.DOTALL)
  9 
  10 
  11 async def apply(
  12     last_message: Message, recent_messages: List[Message], config: Dict[str, int]
  13 ) -> Optional[Tuple[str, Iterable[Member], Iterable[Message]]]:
  14     """Detects total Discord emojis (excluding Unicode emojis) exceeding the limit sent by a single user."""
  15     relevant_messages = tuple(
  16         msg
  17         for msg in recent_messages
  18         if msg.author == last_message.author
  19     )
  20 
  21     # Get rid of code blocks in the message before searching for emojis.
  22     total_emojis = sum(
  23         len(DISCORD_EMOJI_RE.findall(CODE_BLOCK_RE.sub("", msg.content)))
  24         for msg in relevant_messages
  25     )
  26 
  27     if total_emojis > config['max']:
  28         return (
  29             f"sent {total_emojis} emojis in {config['interval']}s",
  30             (last_message.author,),
  31             relevant_messages
  32         )
  33     return None
  34
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/bot/rules/discord_emojis.py b/bot/rules/discord_emojis.py
  --- a/bot/rules/discord_emojis.py
  +++ b/bot/rules/discord_emojis.py
  @@ -2,16 +2,17 @@
   from typing import Dict, Iterable, List, Optional, Tuple
   
   from discord import Member, Message
  +from emoji import demojize
   
   
  -DISCORD_EMOJI_RE = re.compile(r"<:\w+:\d+>")
  +DISCORD_EMOJI_RE = re.compile(r"<:\w+:\d+>|:\w+:")
   CODE_BLOCK_RE = re.compile(r"```.*?```", flags=re.DOTALL)
   
   
   async def apply(
       last_message: Message, recent_messages: List[Message], config: Dict[str, int]
   ) -> Optional[Tuple[str, Iterable[Member], Iterable[Message]]]:
  -    """Detects total Discord emojis (excluding Unicode emojis) exceeding the limit sent by a single user."""
  +    """Detects total Discord emojis exceeding the limit sent by a single user."""
       relevant_messages = tuple(
           msg
           for msg in recent_messages
  @@ -19,8 +20,9 @@
       )
   
       # Get rid of code blocks in the message before searching for emojis.
  +    # Convert Unicode emojis to :emoji: format to get their count.
       total_emojis = sum(
  -        len(DISCORD_EMOJI_RE.findall(CODE_BLOCK_RE.sub("", msg.content)))
  +        len(DISCORD_EMOJI_RE.findall(demojize(CODE_BLOCK_RE.sub("", msg.content))))
           for msg in relevant_messages
       )
  
verification_info: {"golden_diff": "diff --git a/bot/rules/discord_emojis.py b/bot/rules/discord_emojis.py\n--- a/bot/rules/discord_emojis.py\n+++ b/bot/rules/discord_emojis.py\n@@ -2,16 +2,17 @@\n from typing import Dict, Iterable, List, Optional, Tuple\n \n from discord import Member, Message\n+from emoji import demojize\n \n \n-DISCORD_EMOJI_RE = re.compile(r\"<:\\w+:\\d+>\")\n+DISCORD_EMOJI_RE = re.compile(r\"<:\\w+:\\d+>|:\\w+:\")\n CODE_BLOCK_RE = re.compile(r\"```.*?```\", flags=re.DOTALL)\n \n \n async def apply(\n     last_message: Message, recent_messages: List[Message], config: Dict[str, int]\n ) -> Optional[Tuple[str, Iterable[Member], Iterable[Message]]]:\n-    \"\"\"Detects total Discord emojis (excluding Unicode emojis) exceeding the limit sent by a single user.\"\"\"\n+    \"\"\"Detects total Discord emojis exceeding the limit sent by a single user.\"\"\"\n     relevant_messages = tuple(\n         msg\n         for msg in recent_messages\n@@ -19,8 +20,9 @@\n     )\n \n     # Get rid of code blocks in the message before searching for emojis.\n+    # Convert Unicode emojis to :emoji: format to get their count.\n     total_emojis = sum(\n-        len(DISCORD_EMOJI_RE.findall(CODE_BLOCK_RE.sub(\"\", msg.content)))\n+        len(DISCORD_EMOJI_RE.findall(demojize(CODE_BLOCK_RE.sub(\"\", msg.content))))\n         for msg in relevant_messages\n     )\n", "issue": "Filter functionality for emoji-spam messages\nNow that someone's figured out you can cause havok by dumping massive amounts of emojis into a channel, we need a filter to automatically manage this ASAP. Detection should be fairly simple, a very high emoji count is required for the effect (>20/message to >250 for varying impact) but emoji variance is not required. \r\n\r\nTangentially: This is also likely related to a discord update that went out that has slowed the emoji loading process recently.\r\n\r\nI think we can safely filter out and autodelete high emoji messages without significant false positives. \r\n\r\nWe may want to handle both unicode emojis and server emojis. \r\n\r\nIt's possible for unicode emojis to get a higher \"load\" because they could as one character for message transmission purposes but server emojis count for more. However, server emojis may be animated, and will apply significant load by that fact as well.\r\n\r\n\n", "before_files": [{"content": "import re\nfrom typing import Dict, Iterable, List, Optional, Tuple\n\nfrom discord import Member, Message\n\n\nDISCORD_EMOJI_RE = re.compile(r\"<:\\w+:\\d+>\")\nCODE_BLOCK_RE = re.compile(r\"```.*?```\", flags=re.DOTALL)\n\n\nasync def apply(\n    last_message: Message, recent_messages: List[Message], config: Dict[str, int]\n) -> Optional[Tuple[str, Iterable[Member], Iterable[Message]]]:\n    \"\"\"Detects total Discord emojis (excluding Unicode emojis) exceeding the limit sent by a single user.\"\"\"\n    relevant_messages = tuple(\n        msg\n        for msg in recent_messages\n        if msg.author == last_message.author\n    )\n\n    # Get rid of code blocks in the message before searching for emojis.\n    total_emojis = sum(\n        len(DISCORD_EMOJI_RE.findall(CODE_BLOCK_RE.sub(\"\", msg.content)))\n        for msg in relevant_messages\n    )\n\n    if total_emojis > config['max']:\n        return (\n            f\"sent {total_emojis} emojis in {config['interval']}s\",\n            (last_message.author,),\n            relevant_messages\n        )\n    return None\n", "path": "bot/rules/discord_emojis.py"}], "after_files": [{"content": "import re\nfrom typing import Dict, Iterable, List, Optional, Tuple\n\nfrom discord import Member, Message\nfrom emoji import demojize\n\n\nDISCORD_EMOJI_RE = re.compile(r\"<:\\w+:\\d+>|:\\w+:\")\nCODE_BLOCK_RE = re.compile(r\"```.*?```\", flags=re.DOTALL)\n\n\nasync def apply(\n    last_message: Message, recent_messages: List[Message], config: Dict[str, int]\n) -> Optional[Tuple[str, Iterable[Member], Iterable[Message]]]:\n    \"\"\"Detects total Discord emojis exceeding the limit sent by a single user.\"\"\"\n    relevant_messages = tuple(\n        msg\n        for msg in recent_messages\n        if msg.author == last_message.author\n    )\n\n    # Get rid of code blocks in the message before searching for emojis.\n    # Convert Unicode emojis to :emoji: format to get their count.\n    total_emojis = sum(\n        len(DISCORD_EMOJI_RE.findall(demojize(CODE_BLOCK_RE.sub(\"\", msg.content))))\n        for msg in relevant_messages\n    )\n\n    if total_emojis > config['max']:\n        return (\n            f\"sent {total_emojis} emojis in {config['interval']}s\",\n            (last_message.author,),\n            relevant_messages\n        )\n    return None\n", "path": "bot/rules/discord_emojis.py"}]}