def cmdUnBind(account, params, r): """ # account % remove user % format: .unbind [user_id] % leaving user_id blank leads to command ".user" """ # break relation between account and a user if len(params)==0: return cmdUser(account, params, r) acc_entity = twig_db.getAccount(account) user_entity = twig_db.getUser(params) query = db.GqlQuery( "SELECT * FROM RelationAccountUser " "WHERE account = :1 AND user = :2 ", acc_entity, user_entity) e = query.get() if e is None: r.l("!cannot find this user") return if acc_entity.active_id == user_entity.uid: acc_entity.active_id = None acc_entity.put() r.l( "warn: active user removed") e.delete() r.l("user removed")
def post(self): sender = self.request.get('from').split('/')[0] acc_entity = twig_db.getAccount( sender ) if acc_entity is None: return q = db.GqlQuery( "SELECT * FROM RelationAccountUser " "WHERE account = :1 ", acc_entity ) text = ".h <cmd> for help, %d users available" % q.count() xmpp.send_presence(sender, status=text)
def cmdUser(account, params, r): """ # account % list avaliable users % format: .user * only users that have connection with account * can be seen """ if len( params ) > 0: r.l("!bad argument") return acc_entity = twig_db.getAccount(account) query = db.GqlQuery( "SELECT * FROM RelationAccountUser " "WHERE account = :1 ", acc_entity ) user_list = [] for e in query: user_list.append( e.user.uid ) r.l("%d user(s) are found" % len(user_list)) r.l( ("active_id", acc_entity.active_id) ) r.l( user_list )
def cmdSwitchID(account, params, r): """ # account % switch to another user % format: .switchid [user_id] % leaving user_id blank leads to command ".user" """ if len(params) == 0: return cmdUser(account, params, r) acc_entity = twig_db.getAccount(account) user_entity = twig_db.getUser(params) query = db.GqlQuery( "SELECT * FROM RelationAccountUser " "WHERE account = :1 AND user = :2 ", acc_entity, user_entity) e = query.get() if e is None: r.l("!cannot find this user") return acc_entity.active_id = user_entity.uid acc_entity.put() r.l("switch done")