Skip to content

Commit e41dd83

Browse files
committed
Merge branch 'python3.4'
2 parents a172b7d + e3dab55 commit e41dd83

21 files changed

+172
-313
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
## Changelog
2+
- **1.0.3** - More minor changes to plugins, fixed rate-limiting properly, banished SCP to CloudBotIRC/Plugins, added wildcard support to permissions (note: don't use this yet, it's still not entirely finalized!)
23
- **1.0.2** - Minor internal changes and fixes, banished minecraft_bukget and worldofwarcraft to CloudBotIRC/Plugins
34
- **1.0.1** - Fix history.py tracking
45
- **1.0.0** - Initial stable release

cloudbot/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import logging
1111
import os
1212

13-
__version__ = "1.0.2"
13+
__version__ = "1.0.3"
1414

1515
__all__ = ["util", "bot", "connection", "config", "permissions", "plugin", "event", "hook", "log_dir"]
1616

cloudbot/bot.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import asyncio
22
import time
33
import logging
4+
import collections
45
import re
56
import os
67
import gc
@@ -61,6 +62,9 @@ def __init__(self, loop=asyncio.get_event_loop()):
6162
# for plugins
6263
self.logger = logger
6364

65+
# for plugins to abuse
66+
self.memory = collections.defaultdict()
67+
6468
# declare and create data folder
6569
self.data_dir = os.path.abspath('data')
6670
if not os.path.exists(self.data_dir):

cloudbot/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import asyncio
22
import logging
3+
import collections
34

45
from cloudbot.permissions import PermissionManager
56

@@ -48,6 +49,9 @@ def __init__(self, bot, name, nick, *, channels=None, config=None):
4849
# create permissions manager
4950
self.permissions = PermissionManager(self)
5051

52+
# for plugins to abuse
53+
self.memory = collections.defaultdict()
54+
5155
def describe_server(self):
5256
raise NotImplementedError
5357

cloudbot/clients/irc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def send(self, line):
277277
# make sure we are connected before sending
278278
if not self._connected:
279279
yield from self._connected_future
280-
line = line.splitlines()[0][:500] + "\r\n"
280+
line = line[:510] + "\r\n"
281281
data = line.encode("utf-8", "replace")
282282
self._transport.write(data)
283283

cloudbot/permissions.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,15 @@ def has_perm_mask(self, user_mask, perm, notice=True):
7575
if fnmatch(user_mask.lower(), backdoor.lower()):
7676
return True
7777

78-
if not perm.lower() in self.perm_users:
79-
# no one has access
80-
return False
81-
82-
allowed_users = self.perm_users[perm.lower()]
83-
84-
for allowed_mask in allowed_users:
85-
if fnmatch(user_mask.lower(), allowed_mask):
86-
if notice:
87-
logger.info("[{}|permissions] Allowed user {} access to {}".format(self.name, user_mask, perm))
88-
return True
78+
perm = perm.lower()
79+
80+
for user_perm, allowed_users in self.perm_users.items():
81+
if fnmatch(perm, user_perm):
82+
for allowed_mask in allowed_users:
83+
if fnmatch(allowed_mask, user_mask.lower()):
84+
if notice:
85+
logger.info("[{}|permissions] Allowed user {} access to {}".format(self.name, user_mask, perm))
86+
return True
8987

9088
return False
9189

cloudbot/util/cleverbot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,6 @@ def quote(s, safe='/'):
122122
safe_map[c] = (c in safe) and c or ('%%%02X' % i)
123123
try:
124124
res = list(map(safe_map.__getitem__, s))
125-
except:
125+
except Exception:
126126
return ''
127127
return ''.join(res)

cloudbot/util/formatting.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,13 @@ def dict_format(args, formats):
202202
m = f.format(**args)
203203
# Insert match and number of matched values (max matched values if already in dict)
204204
matches[m] = max([matches.get(m, 0), len(re.findall(r'(\{.*?\})', f))])
205-
except:
205+
except Exception:
206206
continue
207207

208208
# Return most complete match, ranked by values matched and then my match length or None
209209
try:
210210
return max(matches.items(), key=lambda x: (x[1], len(x[0])))[0]
211-
except:
211+
except Exception:
212212
return None
213213

214214

plugins/core_sieve.py

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,37 @@
66
from cloudbot import hook
77
from cloudbot.util.tokenbucket import TokenBucket
88

9-
inited = []
10-
11-
# when STRICT is enabled, every time a user gets ratelimted it wipes
12-
# their tokens so they have to wait at least X seconds to regen
13-
9+
ready = False
1410
buckets = {}
15-
1611
logger = logging.getLogger("cloudbot")
1712

1813

1914
def task_clear(loop):
20-
for uid, _bucket in buckets:
15+
global buckets
16+
for uid, _bucket in buckets.copy().items():
2117
if (time() - _bucket.timestamp) > 600:
2218
del buckets[uid]
23-
loop.call_later(600, task_clear, loop)
19+
loop.call_later(10, task_clear, loop)
2420

2521

2622
@asyncio.coroutine
2723
@hook.irc_raw('004')
2824
def init_tasks(loop, conn):
29-
global inited
30-
if conn.name in inited:
25+
global ready
26+
if ready:
3127
# tasks already started
3228
return
3329

3430
logger.info("[{}|sieve] Bot is starting ratelimiter cleanup task.".format(conn.name))
35-
loop.call_later(600, task_clear, loop)
36-
inited.append(conn.name)
31+
loop.call_later(10, task_clear, loop)
32+
ready = True
3733

3834

3935
@asyncio.coroutine
4036
@hook.sieve
4137
def sieve_suite(bot, event, _hook):
42-
"""
43-
this function stands between your users and the commands they want to use. it decides if they can or not
44-
:type bot: cloudbot.bot.CloudBot
45-
:type event: cloudbot.event.Event
46-
:type _hook: cloudbot.plugin.Hook
47-
"""
38+
global buckets
39+
4840
conn = event.conn
4941
# check ignore bots
5042
if event.irc_command == 'PRIVMSG' and event.nick.endswith('bot') and _hook.ignore_bots:
@@ -83,8 +75,7 @@ def sieve_suite(bot, event, _hook):
8375

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

8980
tokens = conn.config.get('ratelimit', {}).get('tokens', 17.5)
9081
restore_rate = conn.config.get('ratelimit', {}).get('restore_rate', 2.5)
@@ -110,5 +101,3 @@ def sieve_suite(bot, event, _hook):
110101
return None
111102

112103
return event
113-
114-

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)