-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler.py
35 lines (28 loc) · 1.03 KB
/
handler.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
import logging
class Handler(object):
def __init__(self):
self.registered = []
self.default = None
self._current = 100
def register(self, command, function):
self.registered.append((command, function))
self._current += 100
self.registered.sort()
def register_default(self, command):
self.default = command
def handle(self, connection, event):
command, sep, args = event.arguments[0].partition(' ')
logging.debug("Looking for registred command: %s" % (command))
if type(event.target) == "NickMask":
source = event.source.nick
else:
source = event.target
if self.default is not None:
logging.debug("Executing default command")
self.default(connection, event)
if event.arguments[0][0] == '.':
for funct in self.registered:
if funct[0] == command:
funct[1](connection, source, args)
return True
return False