Пример #1
0
def listenForMsg():
    global avatar_state_var
    while running:
        if has_message():
            msg = receive()
            # If current user is Dorothy,
            # parse message for avatar commands
            avatar_state = False
            avatar_model = False
            if not Im_a_wizard_harry:
                if parser.getCommand(msg.lower()) == "avatar":
                    avatar_state = parser.getAvatar(msg)
                elif parser.getCommand(msg.lower()) == "model":
                    avatar_model = parser.getArguments(msg)[0]
            if avatar_state != False:
                avatar_state_var.set(avatar_state)
            elif avatar_model != False:
                avatar_model_var.set(avatar_model)
            else:
                print(msg)
                display_message(msg)
            log = "Message Received-" + str(msg)
            appendToLog(log)
        else:
            time.sleep(1)
Пример #2
0
def sendMessage(event=None):
    global name
    global Im_a_wizard_harry
    if (len(entry.get(1.0, END)) > 0):
        # check for wizard command
        if parser.getCommand(entry.get(1.0, END).lower()) == "wizard":
            sendHagrid()  # Im_a_wizard_harry = true
            entry.delete(1.0, END)
        else:
            # check for avatar state command
            if parser.getCommand(entry.get(1.0,END).lower()) == "avatar"\
                    and Im_a_wizard_harry:
                # update local avatar state
                # then send message unaltered
                msg = entry.get(1.0, END)
                avatar_state = parser.getAvatar(msg)
                avatar_state_var.set(avatar_state)
                send(msg)
                entry.delete(1.0, END)
            # check for avatar model command
            elif parser.getCommand(entry.get(1.0,END).lower()) == "model"\
                    and Im_a_wizard_harry:
                # update local avatar model
                # then send message unaltered
                msg = entry.get(1.0, END)
                avatar_model = parser.getArguments(msg)[0]
                avatar_model_var.set(avatar_model)
                send(msg)
                entry.delete(1.0, END)
            elif (name == None):
                name = entry.get(1.0, END)
                name.rstrip()
                send(name)
                entry.delete(1.0, END)
            else:
                msg = name.rstrip() + ": "
                #text = entry.get(1.0,END)
                #print(text)
                msg = msg + entry.get(1.0, END)
                send(msg)
                chat.config(state=NORMAL)
                display_message(msg)
                entry.delete(1.0, END)
Пример #3
0
 def test_no_arguments(self):
   self.assertEqual(parser.getArguments('/connect'), [])
Пример #4
0
 def test_empty(self):
   self.assertEqual(parser.getCommand(''), False)
   self.assertEqual(parser.getArguments(''), [])
Пример #5
0
 def test_arguments(self):
   self.assertEqual(parser.getArguments('/connect 127.0.0.1 8080'), ['127.0.0.1', '8080'])