fix
authorGeorgios Atheridis <georgios@atheridis.org>
Fri, 30 Jun 2023 20:16:16 +0000 (21:16 +0100)
committerGeorgios Atheridis <georgios@atheridis.org>
Fri, 30 Jun 2023 20:16:16 +0000 (21:16 +0100)
ihaspeks/scripts/subathon.py

index a71e1c013c8f8ae3504c72c4fb132420219425ef..c0fd89ce4d088904a2823096d671c4361750dcba 100644 (file)
@@ -166,39 +166,36 @@ def donations(bot: Bot, message: Message):
 
     @io.on("event")
     def event(data):
-        match data["type"]:
-            case "donation":
-                amount_cents = int(float(data["message"][0]["amount"]) * 100)
-                div_count = (amount_cents // 400) * calculate_increase(10)
-
-                # Add 3 seconds for every 1 cent under 400 cents
-                rest_count = (amount_cents % 400) * 3
-
-                timer_add = div_count + rest_count
-                display_name = data["message"][0]["from"]
-
-                total_timer = timer_add
-                with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as client:
-                    client.connect(socket_file)
-                    data = {
-                        "time": total_timer,
-                        "name": display_name,
-                    }
-                    client.send(json.dumps(data).encode())
-                    client.close()
-                logger.info("%s donated %s", display_name, amount_cents)
-
-                verb = (
-                    "INCREASED ihaspeHappy"
-                    if total_timer > 0
-                    else "DECREASED ihaspeAngi"
-                )
-                msg = (
-                    f"{display_name} has {verb} the timer "
-                    + f"by {abs(total_timer) // 60} minutes "
-                    + f"and {abs(total_timer) % 60} seconds."
-                )
-                tools.smart_privmsg.send_safe(bot, message.channel, msg)
+        if data["type"] == "donations":
+            amount_cents = int(float(data["message"][0]["amount"]) * 100)
+            div_count = (amount_cents // 400) * calculate_increase(10)
+
+            # Add 3 seconds for every 1 cent under 400 cents
+            rest_count = (amount_cents % 400) * 3
+
+            timer_add = div_count + rest_count
+            display_name = data["message"][0]["from"]
+
+            total_timer = timer_add
+            with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as client:
+                client.connect(socket_file)
+                data = {
+                    "time": total_timer,
+                    "name": display_name,
+                }
+                client.send(json.dumps(data).encode())
+                client.close()
+            logger.info("%s donated %s", display_name, amount_cents)
+
+            verb = (
+                "INCREASED ihaspeHappy" if total_timer > 0 else "DECREASED ihaspeAngi"
+            )
+            msg = (
+                f"{display_name} has {verb} the timer "
+                + f"by {abs(total_timer) // 60} minutes "
+                + f"and {abs(total_timer) % 60} seconds."
+            )
+            tools.smart_privmsg.send_safe(bot, message.channel, msg)
 
 
 def calculate_increase(sub_count: int) -> int: