-
Notifications
You must be signed in to change notification settings - Fork 0
/
commandHandler.py
56 lines (52 loc) · 2.01 KB
/
commandHandler.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import abc
import config
import commands
import exceptions
import utils
class CommandHandler:
def __init__(self, message_object):
self._author = message_object.sender
self._channel = message_object.channel
self._message = message_object.text
self._getCommandValue()
def _getCommandValue(self):
msg = self._message.split(" ")
self.command = msg[0][1:]
self.value = " ".join(msg[1:])
def _getKeyValue(self):
msg = self._message.split(" ")
key = msg[1]
value = " ".join(msg[2:])
return key, value
def handler(self):
# ---Command-managing---
if self.command == "addcom":
if not utils.isMod(self._author, self._channel):
return
if len(self.value.split()) < 2:
raise exceptions.NotEnoughArguments
keyValuePair = self._getKeyValue()
return commands.AddCommand(self._channel, *keyValuePair)
elif self.command == "delcom":
if not utils.isMod(self._author, self._channel):
return
if len(self.value.split()) < 1:
raise exceptions.NotEnoughArguments
key = self._getKeyValue()[0]
return commands.DeleteCommand(self._channel, key)
elif self.command == "addevent":
if not utils.isMod(self._author, self._channel):
return
if len(self.value.split()) < 2:
raise exceptions.NotEnoughArguments
keyValuePair = self._getKeyValue()
return commands.AddEventCommand(self._channel, *keyValuePair)
elif self.command == "delevent":
if not utils.isMod(self._author, self._channel):
return
if len(self.value.split()) < 1:
raise exceptions.NotEnoughArguments
return commands.DeleteEventCommand(self._channel, self.value)
# ----------------------
else:
return commands.StaticCommand(self._channel, self.command)