anosora233 / majsoul-hook-mitm

A majsoul message hook based on mitmproxy.
GNU General Public License v3.0
27 stars 6 forks source link

Feat request: Excludes cheering emotes. #10

Closed ls-gs closed 1 year ago

ls-gs commented 1 year ago

There're some cheering emotes (eg. 🥮, 🎉) provided during festivals.

So far these emotes are numbered in range(13, 19). The emote list will look clean if they're excluded.

Would mhm consider to exclude them as well when generating emote list, or to add an excluding option in configuration file? Thank you.

@@ -1,5 +1,6 @@
 from rich.console import Console
 from rich.logging import RichHandler
+from collections import defaultdict
 from dataclasses import dataclass, asdict, field
 from os.path import exists
 from os import environ
@@ -104,9 +105,14 @@ def fetch_resver():
     response.raise_for_status()
     res_data: dict = response.json()

-    emos: dict[str, list] = {}
+    emos: defaultdict[str, list[int]] = defaultdict(list)
     pattern = rf"en\/extendRes\/emo\/e(\d+)\/(\d+)\.png"

+    EMOS_EXCLUDED = {
+        13,
+        14, 15, 16, 17, 18,
+    }
+
     for text in res_data.get("res"):
         matches = re.search(pattern, text)

@@ -114,10 +120,8 @@ def fetch_resver():
             charid = matches.group(1)
             emo = int(matches.group(2))

-            if emo == 13:
+            if emo in EMOS_EXCLUDED:
                 continue
-            if charid not in emos:
-                emos[charid] = []
             emos[charid].append(emo)
     for value in emos.values():
         value.sort()
anosora233 commented 1 year ago

That's a good suggestion. I have added an option for this feature called no_cheering_emotes.