Skip to content

Commit e02e0f4

Browse files
committed
I hate asyncio now
1 parent b5866f2 commit e02e0f4

2 files changed

Lines changed: 7 additions & 12 deletions

File tree

plugins/core_sieve.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212

1313

1414
def task_clear(loop):
15-
for uid, _bucket in buckets.copy():
15+
global buckets
16+
for uid, _bucket in buckets.copy().items():
1617
if (time() - _bucket.timestamp) > 600:
1718
del buckets[uid]
18-
loop.call_later(600, task_clear, loop)
19+
loop.call_later(10, task_clear, loop)
1920

2021

2122
@asyncio.coroutine
@@ -27,19 +28,15 @@ def init_tasks(loop, conn):
2728
return
2829

2930
logger.info("[{}|sieve] Bot is starting ratelimiter cleanup task.".format(conn.name))
30-
loop.call_later(600, task_clear, loop)
31+
loop.call_later(10, task_clear, loop)
3132
ready = True
3233

3334

3435
@asyncio.coroutine
3536
@hook.sieve
3637
def sieve_suite(bot, event, _hook):
37-
"""
38-
this function stands between your users and the commands they want to use. it decides if they can or not
39-
:type bot: cloudbot.bot.CloudBot
40-
:type event: cloudbot.event.Event
41-
:type _hook: cloudbot.plugin.Hook
42-
"""
38+
global buckets
39+
4340
conn = event.conn
4441
# check ignore bots
4542
if event.irc_command == 'PRIVMSG' and event.nick.endswith('bot') and _hook.ignore_bots:
@@ -78,8 +75,7 @@ def sieve_suite(bot, event, _hook):
7875

7976
# check command spam tokens
8077
if _hook.type == "command":
81-
# right now ratelimiting is per-channel, but this can be changed
82-
uid = (event.chan, event.nick.lower())
78+
uid = "!".join([conn.name, event.chan, event.nick]).lower()
8379

8480
tokens = conn.config.get('ratelimit', {}).get('tokens', 17.5)
8581
restore_rate = conn.config.get('ratelimit', {}).get('restore_rate', 2.5)

plugins/core_tracker.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import asyncio
44
import logging
55
import re
6-
import functools
76
from collections import deque
87

98
from cloudbot import hook

0 commit comments

Comments
 (0)