-
Notifications
You must be signed in to change notification settings - Fork 1
/
decorators.py
40 lines (30 loc) · 1.11 KB
/
decorators.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import calculations
def nick_command(fn):
def wrapped(self, respond_target, cmd, arguments, e, nick=None):
if nick is None:
nick = _get_cmd_nick(arguments, e)
if nick == None:
return
command = '{} {}'.format(cmd, arguments)
executor = self.db.create_executor(command)
r = fn(self, executor, respond_target, cmd, arguments, e, nick)
executor.print_stats()
return r
return wrapped
def stats_command(string):
def decorator(fn):
def wrapped(self, executor, respond_target, cmd, arguments, e, nick):
stat_name = fn(self, executor, respond_target, cmd, arguments, e, nick)
if stat_name != None:
answer = getattr(calculations, stat_name)(executor, nick)
self.connection.privmsg(respond_target, string.format(answer, nick))
return wrapped
return decorator
def _get_cmd_nick(arguments, e):
arguments = arguments.split()
if len(arguments) > 1:
return None
elif len(arguments) == 1:
return arguments[0]
else:
return e.source.nick