@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: