def __setitem__(self,key,values): del self[key] #delete the old values if type(values) is str: #probably a mistake, just one value is wanted values=(values,) for value in values: database.query('INSERT INTO `users` VALUES (%s,%s,%s)', (self.username,key,value))
def search(self,names): if type(names) is str: #probably a mistake, only one is wanted return (self[names],) string = ' OR '.join(map(lambda name: '`id` = "%s"' % name,names)) database.query('SELECT * FROM `bans` WHERE %s ORDER BY `bans`.`expires` DESC' % (string)) return tuple(database.cursor.fetchall())
def __getitem__(self,name): database.query('SELECT * FROM `bans` WHERE `id` = "%s" ORDER BY `bans`.`expires` DESC LIMIT 1' % (name)) if database.cursor.rowcount==0: raise KeyError("No such ban: %s" % (name)) return database.cursor.fetchone()
def search(self,key,value): database.query('SELECT `user` FROM `users` WHERE `key` = %s and `value` = %s', (key, value)) result=database.cursor.fetchone() if result is not None: return self[result[0]] else: return None
def __getitem__(self,username): database.query('SELECT `user` FROM `users` WHERE `user` = %s AND `key` = "privileges"', (username,)) if database.cursor.rowcount==0: raise KeyError("No such user: %s" % (username,)) return User(username)
def __setitem__(self, name, values): try: del self[name] except: pass database.query("INSERT INTO `bans` VALUES (%s,%s,%s)", (name, values[0], values[1]))
def cleargbans(self): database.query('DELETE FROM `bans` WHERE `reason` = "gban"')
def __delitem__(self,name): database.query('DELETE FROM `bans` WHERE `id` = "%s"' % (name))
def __setitem__(self,name,values): try: del self[name] except: pass database.query('INSERT INTO `bans` VALUES ("%s","%s","%s")' % (name,values[0],values[1]))
def items(self): database.query('SELECT * FROM `bans` ORDER BY `bans`.`expires` DESC') return tuple(database.cursor.fetchall())
def items(self): database.query('SELECT * FROM `users` where `key` = "privileges"') return tuple(database.cursor.fetchall())
def __delitem__(self, key): database.query('DELETE FROM `users` WHERE `user` = %s AND `key` = %s', (self.username,key))
def __delitem__(self, name): database.query("DELETE FROM `bans` WHERE `id` = %s", (name))
def __getitem__(self,key): database.query('SELECT value FROM `users` WHERE `user` = %s AND `key` = %s', (self.username,key)) return tuple(row[0] for row in database.cursor.fetchall())
def items(self): database.query('SELECT `key`,`value` FROM `users` WHERE `user` = %s', (self.username,)) return (("username",self.username),)+tuple(database.cursor.fetchall())
def __delitem__(self,username): database.query('DELETE FROM `users` WHERE `user` = %s', (username,))
def __delitem__(self,username): database.query('DELETE FROM `users` WHERE `user` = "%s"' % (username))
def clearbans(self): database.query( "DELETE FROM `bans` WHERE `expires` < DATE_ADD(UTC_TIMESTAMP(),interval 60 minute) AND `expires` NOT LIKE '0000-00-00 00:00:00'" )