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 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")