Exemplo n.º 1
0
class DeleteFriendsController(Controller):
    def __init__(self):
        self.friendshipservice = KahlaFriendShipApiService()
        self.checkstatusservice = KahlaSignInStatusCheckService()

    # 定义参数
    def get_options(self):
        return [
            Option('-u', '--username', dest='username'),
        ]

    # 处理输入参数, 检查合法性
    def run(self, username):
        # 这条必须编写, 并且带上传入的参数
        self.compute(username)

    # 处理业务逻辑
    def main(self, username):
        if self.checkstatusservice.check() == True:
            friends = self.friendshipservice.Friends()
            friendsdata = json.loads(friends.text)["items"]
            for x in friendsdata:
                if x["displayName"] == username:
                    r = self.friendshipservice.DeleteFriend(x["userId"])
                    r = json.loads(r.text)
                    if r["code"] == 0:
                        return ""
                    else:
                        return r["message"]

            return "The user name you entered is incorrect!"
        else:
            return "You are not logged in!"
Exemplo n.º 2
0
class LeaveGroupsController(Controller):
    def __init__(self):
        self.friendshipservice = KahlaFriendShipApiService()
        self.checkstatusservice = KahlaSignInStatusCheckService()

    # 定义参数
    def get_options(self):
        return [
            Option('-g', '--group', dest='group'),
        ]

    # 处理输入参数, 检查合法性
    def run(self, group):
        # 这条必须编写, 并且带上传入的参数
        self.compute(group)

    # 处理业务逻辑
    def main(self, group):
        if self.checkstatusservice.check() == True:
            friends = self.friendshipservice.Friends()
            friendsdata = json.loads(friends.text)["items"]
            for x in friendsdata:
                if x["displayName"] == group:
                    if x["discriminator"] == "GroupConversation":
                        self.friendshipservice.LeaveGroup(x["displayName"])
                        return ""

            return "The user name you entered is incorrect!"
        else:
            return "You are not logged in!"
Exemplo n.º 3
0
class GetMessagesController(Controller):
    def __init__(self):
            self.friendshipservice = KahlaFriendShipApiService()
            self.checkstatusservice = KahlaSignInStatusCheckService()
            self.conversionservice = KahlaConversationApiService()
            self.processmessage = ProcessMessage()

    # 定义参数
    def get_options(self):
	    return [
			Option('-u', '--username', dest='username'),
			Option('-t', '--take', dest='take')
	    ]

	# 处理输入参数, 检查合法性
    def run(self, username, take):
        # 这条必须编写, 并且带上传入的参数
        self.compute(username, take)

	# 处理业务逻辑
    def main(self, username, take):
        if self.checkstatusservice.check() == True:
            friends = self.friendshipservice.Friends()
            friendsdata = json.loads(friends.text)["items"]
            datas = []
            for x in friendsdata:
                if x['displayName'] == username:
                    me = json.loads(self.friendshipservice.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!"]
        else:
            return ["You are not logged in!"]
Exemplo n.º 4
0
class SearchGroupsController(Controller):
	def __init__(self):
		self.friendshipservice = KahlaFriendShipApiService()
		self.checkstatusservice = KahlaSignInStatusCheckService()

	# 定义参数
	def get_options(self):
		return [
			Option('-si', '--searchinput', dest='searchinput'),	
		]

	# 处理输入参数, 检查合法性
	def run(self, searchinput):
		# 这条必须编写, 并且带上传入的参数
		self.compute(searchinput)

	# 处理业务逻辑
	def main(self, searchinput):
		if self.checkstatusservice.check() == True:
			friends = self.friendshipservice.Friends()
			friendsdata = json.loads(friends.text)["items"]
			datas = []
			for x in friendsdata:
					if x["displayName"].lower().find(searchinput.lower()) >= 0:
							if x["discriminator"] != "PrivateConversation":
								pingdata = "{0}".format(x["displayName"])
								datas.append(pingdata)
			return datas
		else:
			return ["You are not logged in!"]
Exemplo n.º 5
0
class GroupsController(Controller):
    def __init__(self):
        self.friendshipservice = KahlaFriendShipApiService()
        self.checkstatusservice = KahlaSignInStatusCheckService()

    # 定义参数
    def get_options(self):
        return []

    # 处理输入参数, 检查合法性
    def run(self):
        # 这条必须编写, 并且带上传入的参数
        self.compute()

    # 处理业务逻辑
    def main(self):
        if self.checkstatusservice.check() == True:
            friends = self.friendshipservice.Friends()
            friendsdata = json.loads(friends.text)["items"]
            datas = []
            for x in friendsdata:
                if x["discriminator"] != "PrivateConversation":
                    datas.append(x["displayName"])
            return datas
        else:
            return ["You are not logged in!"]
Exemplo n.º 6
0
    def received_message(self, message):
        self.processmessage = ProcessMessage()
        self.kfs = KahlaFriendShipApiService()
        me = self.kfs.Me()
        me = json.loads(me.text)["value"]
        messagedata = json.loads(str(message))
        if messagedata["typeDescription"] == "NewMessage":
            message = str(
                decrypt(bytes(messagedata["content"], "UTF-8"),
                        bytes(messagedata["aesKey"], "UTF-8")), "UTF-8")
            message = self.processmessage.processMessage(message)
            print("{0} | {1}".format(messagedata["sender"]["nickName"],
                                     message))
            return

        if messagedata["typeDescription"] == "WereDeletedEvent":
            print("The {0} deleted you from his friends.".format(
                messagedata["trigger"]["nickName"]))
            return

        if messagedata["typeDescription"] == "NewFriendRequestEvent":
            print("The {0} wants to be your friend.".format(
                messagedata["requester"]["nickName"]))
            return

        if messagedata["typeDescription"] == "FriendAcceptedEvent":
            print("The {0} agrees to your friend request.".format(
                messagedata["target"]["nickName"]))
            return

        if messagedata["typeDescription"] == "TimerUpdatedEvent":
            conversation = json.loads(
                self.conversionservice.ConversationDetail(
                    messagedata["conversationId"]).text)["value"]
            nikename = ""
            if conversation["requestUser"]["id"] != me["id"]:
                nikename = conversation["requestUser"]["nickName"]

            if conversation["targetUser"]["id"] != me["id"]:
                nikename = conversation["targetUser"]["nickName"]

            print(
                "The {0} modified the message self-destruct time of your session with him. The current self-destruct time is {1}"
                .format(nikename, second2time(messagedata["newTimer"])))
            return
Exemplo n.º 7
0
class SendController(Controller):
    def __init__(self):
	    self.friendshipservice = KahlaFriendShipApiService()
	    self.checkstatusservice = KahlaSignInStatusCheckService()
	    self.conversionservice = KahlaConversationApiService()

    # 定义参数
    def get_options(self):
	    return [
			Option('-u', '--username', dest='username'),
			Option('-m', '--message', dest='message')
	    ]

	# 处理输入参数, 检查合法性
    def run(self, username, message):
        # 这条必须编写, 并且带上传入的参数
        self.compute(username, message)

	# 处理业务逻辑
    def main(self, username, message):
        if self.checkstatusservice.check() == True:
            friends = self.friendshipservice.Friends()
            friendsdata = json.loads(friends.text)["items"]
            for x in friendsdata:
                if x['displayName'] == username:
                    message = encrypt(bytes(message, "utf-8"), bytes(x["aesKey"], "utf-8"))
                    r = self.conversionservice.SendMessage(x['conversationId'], message)
                    resultdata = json.loads(r.text)
                    if resultdata["code"] == 0:
                        return ""
                    else:
                        return "The message could not be sent successfully!"
			
            return "Your user name is incorrect!"
        else:
            return "You are not logged in!"
Exemplo n.º 8
0
 def __init__(self):
     self.friendshipservice = KahlaFriendShipApiService()
     self.checkstatusservice = KahlaSignInStatusCheckService()
Exemplo n.º 9
0
 def __init__(self):
         self.friendshipservice = KahlaFriendShipApiService()
         self.checkstatusservice = KahlaSignInStatusCheckService()
         self.conversionservice = KahlaConversationApiService()
         self.processmessage = ProcessMessage()