class DeleteFriendsController(Controller): def __init__(self): self.friendshipservice = FriendShipApiService() # 定义参数 def get_options(self): return [ Option('-u', '--username', dest='username'), ] # 处理输入参数, 检查合法性 def run(self, username): DeleteFriendsChecker.Check(username) # 这条必须编写, 并且带上传入的参数 self.compute(username) # 处理业务逻辑 @loginchecker def main(self, username): mines = self.friendshipservice.Mine() friendslist = json.loads(mines.text) if friendslist["code"] == 0: return "" else: return friendslist["message"] for x in friendslist["users"]: if x["nickName"] == username: err = self.friendshipservice.DeleteFriend(x["userId"]) err = json.loads(err.text) if err["code"] == 0: return "" else: return err["message"] return "The user name you entered is incorrect!"
class LeaveGroupsController(Controller): def __init__(self): self.friendshipservice = FriendShipApiService() self.groupservice = GroupApiService() # 定义参数 def get_options(self): return [ Option('-g', '--group', dest='group'), ] # 处理输入参数, 检查合法性 def run(self, group): # 这条必须编写, 并且带上传入的参数 self.compute(group) # 处理业务逻辑 @loginchecker def main(self, group): mines = self.friendshipservice.Mine() friendslist = json.loads(mines.text)["groups"] for x in friendslist: if x["name"] == group: err = self.groupservice.LeaveGroup(x["name"]) err = json.loads(err.text) if err["code"] == 0: return "" else: return err["message"] return "The user name you entered is incorrect!"
class SearchGroupsController(Controller): def __init__(self): self.friendshipservice = FriendShipApiService() self.checkstatusservice = SignInStatusCheckService() # 定义参数 def get_options(self): return [ Option('-si', '--searchinput', dest='searchinput'), ] # 处理输入参数, 检查合法性 def run(self, searchinput): SearchGroupsChecker.Check(searchinput) # 这条必须编写, 并且带上传入的参数 self.compute(searchinput) # 处理业务逻辑 @loginchecker def main(self, searchinput): mines = self.friendshipservice.Mine() friendslist = json.loads(mines.text)["groups"] datas = [] for x in friendslist: if x["name"].lower().find(searchinput.lower()) >= 0: datas.append(x["name"]) return datas
class FriendsController(Controller): def __init__(self): self.friendshipservice = FriendShipApiService() # 定义参数 def get_options(self): return [] # 处理输入参数, 检查合法性 def run(self): # 这条必须编写, 并且带上传入的参数 self.compute() # 处理业务逻辑 @loginchecker def main(self): mines = self.friendshipservice.Mine() userslist = json.loads(mines.text)["users"] datas = [] for user in userslist: datas.append(user["nickName"]) return datas
def __init__(self): self.friendshipservice = FriendShipApiService() self.groupservice = GroupApiService()
def __init__(self): self.friendshipservice = FriendShipApiService() self.checkstatusservice = SignInStatusCheckService() self.conversionservice = ConversationApiService()
def __init__(self): self.friendshipservice = FriendShipApiService() self.conversionservice = ConversationApiService() self.authservice = AuthApiService() self.processmessage = ProcessMessage()
class GetMessagesController(Controller): def __init__(self): self.friendshipservice = FriendShipApiService() self.conversionservice = ConversationApiService() self.authservice = AuthApiService() self.processmessage = ProcessMessage() # 定义参数 def get_options(self): return [ Option('-u', '--username', dest='username'), Option('-t', '--take', dest='take', default="15") ] # 处理输入参数, 检查合法性 def run(self, username, take): GetMessagesChecker.Check(username, take) # 这条必须编写, 并且带上传入的参数 self.compute(username, take) # 处理业务逻辑 @loginchecker def main(self, username, take): friends = self.conversionservice.All() friendsdata = json.loads(friends.text)["items"] datas = [] for x in friendsdata: if x['displayName'] == username: me = json.loads(self.authservice.Me().text)["value"] r = self.conversionservice.GetMesssages(x['conversationId'], take) resultdata = json.loads(r.text) if resultdata["code"] == 0: for xx in resultdata["items"]: if x["discriminator"] == "PrivateConversation": if xx["senderId"] != me["id"]: result = str( decrypt( bytes( xx["content"], "UTF-8"), bytes( x["aesKey"], "UTF-8")), "UTF-8") result = self.processmessage.processMessage(result) datas.append("{0} | {1}".format(x["displayName"], result)) else: result = str( decrypt( bytes( xx["content"], "UTF-8"), bytes( x["aesKey"], "UTF-8")), "UTF-8") result = self.processmessage.processMessage(result) datas.append("{0} | {1}".format(me["nickName"], result)) else: data = json.loads( self.friendshipservice.UserDetail( xx['senderId']).text)["user"] result = str( decrypt( bytes( xx["content"], "UTF-8"), bytes( x["aesKey"], "UTF-8")), "UTF-8") result = self.processmessage.processMessage(result) datas.append( "{0} | {1} | {2}".format( x["displayName"], data["nickName"], result)) return datas else: return ["unknown error!"] return ["Your user name is incorrect!"]