diff options
Diffstat (limited to 'lib/commands.py')
-rw-r--r-- | lib/commands.py | 17 |
1 files changed, 3 insertions, 14 deletions
diff --git a/lib/commands.py b/lib/commands.py index 1b5a5a8..61c3eaf 100644 --- a/lib/commands.py +++ b/lib/commands.py @@ -1,4 +1,4 @@ -from classes import userexist, PersonalError, r, host, clear, Colors +from classes import PersonalError, r, clear, Colors from listcommands import ListCommands from config import config as co @@ -16,17 +16,12 @@ class Commands(object): if len(cmd[2]) > 10: raise PersonalError('lunghezza maggiore del consetito. Max 10') - if userexist(cmd[2]) == True: #check if the user exists - raise PersonalError('questo nome utente esiste giĆ ') - if len(cmd) > ListCommands.info['set'][1]: raise PersonalError(Colors.grey + 'set user' + Colors.red + ' accetta 1 parametro') - if self.user != '': r.zrem('usersname', self.user) #if user already exists, del the name from set self.user = cmd[2] - r.hset('user:'+host, 'name', self.user) #change name of user:0.0.0.0 - r.zadd('usersname', self.user, 0) #insert new name into the set + r.set('user', self.user) #change name of user print('Ok') elif cmd[1] is not ListCommands.commands['set']: @@ -46,19 +41,13 @@ class Commands(object): if cmd[2] == 'user': #if self.user is empty, print 'nil' if self.user != '': - print(r.hget('user:'+host, 'name').decode('utf-8')) + print(r.get('user').decode('utf-8')) else: print('nil') elif cmd[2] not in ListCommands.commands['get'][1]: #check if the word after 'i' exists ListCommands.err('keyword') else: print(co[cmd[2]]) - elif cmd[1] == 'user?': - #if there are more than 2 word after 'get', the func doens't work - if len(cmd) > 3: - raise PersonalError(Colors.grey + 'get user?' + Colors.red + ' accetta 1 parametro') - #return 1 if the user exists - print((lambda x: '0' if x == False else '1')(userexist(cmd[2]))) else: raise KeyError except IndexError: |