diff options
Diffstat (limited to 'commands.py')
-rw-r--r-- | commands.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/commands.py b/commands.py index e69de29..2c7b57f 100644 --- a/commands.py +++ b/commands.py @@ -0,0 +1,28 @@ +from classes import userexist, PersonalError, r, host +from listcommands import ListCommands + +class Commands(object): + + def command(self, what, cmd): + if what == 'clear': + clear() + elif what == 'set': + try: + if cmd[1] == 'user' and cmd[2] is not None: + if len(cmd[2]) > 10: raise PersonalError("lunghezza maggiore del consetito. Max 10") + + if userexist(cmd[2]) == True: raise PersonalError("questo nome utente esiste giĆ ") + + if self.user != '': r.zrem('usersname', self.user) + + self.user = cmd[2] + r.hset('user:'+host, 'name', self.user) + r.zadd('usersname', self.user, 0) + + print("Ok") + elif cmd[1] is not ListCommands.commands['set']: + raise IndexError + except IndexError: + ListCommands.err('wrong') + except PersonalError as e: + ListCommands.err('personal', e.value) |