Exemplo n.º 1
0
 def add_contact(self):
     contact_name = w.newContactInput.text()
     if contact_name:
         self.__client.send(
             jim.Message(action='add_contact', user_name=contact_name))
         time.sleep(0.2)
         w.contactList.clear()
         self.__client.send(jim.Message(action='get_contacts'))
Exemplo n.º 2
0
 def delete_contact(self):
     selected_index = w.contactList.currentIndex()
     if selected_index:
         self.__client.send(
             jim.Message(action='del_contact',
                         user_name=selected_index.data()))
         time.sleep(0.2)
         w.contactList.clear()
         self.__client.send(jim.Message(action='get_contacts'))
Exemplo n.º 3
0
 def run_action(self, request):
     if request.action == 'presence':
         self._repo.add_client(request.user_account_name)
         return jim.success()
     elif request.action == 'quit':
         return jim.success()
     elif request.action == 'msg':
         client = self._repo.get_user_by_name(request.client_name)
         contacts = client.contacts
         responses = [jim.success()]
         for contact in contacts:
             responses.append(
                 jim.Message(action='msg',
                             text=request.text,
                             to=contact.name,
                             _from=request.client_name))
         return responses
     elif request.action == 'get_contacts':
         contacts = self._repo.get_contact_list(request.client_name)
         count = len(contacts)
         responses = [jim.success(response=202, quantity=count)]
         for contact in contacts:
             account_name = contact.name
             responses.append(
                 jim.Message(action='contact_list',
                             account_name=account_name))
         return responses
     elif request.action == 'add_contact':
         if request.client_name == request.user_name:
             return jim.error('It is not possible to add yourself')
         try:
             self._repo.add_contact(request.client_name, request.user_name)
             return jim.success()
         except:
             return jim.error('Contact does not exist')
     elif request.action == 'del_contact':
         try:
             self._repo.remove_contact(request.client_name,
                                       request.user_name)
             return jim.success()
         except:
             return jim.error('Contact does not exist')
     elif request.action == 'error':
         return jim.error('Error action')
     else:
         return jim.error('Action is not available')
Exemplo n.º 4
0
 def __send_presence(self, status="Yep, I'am here!"):
     request = jim.Message(action='presence',
                           user={
                               'account_name': self.name,
                               'status': status
                           })
     self.send(request)
     parcels = jim.receive(self.__sock, self.__logger)
     return parcels[0].response == 200
Exemplo n.º 5
0
    def __init__(self, client):
        self.__client = client
        w.sendButton.clicked.connect(self.send_message)
        w.newContactButton.clicked.connect(self.add_contact)
        w.deleteContactButton.clicked.connect(self.delete_contact)
        w.newContactInput.returnPressed.connect(w.newContactButton.click)
        w.setWindowTitle('Echo ({})'.format(client.name))
        w.show()

        client.send(jim.Message(action='get_contacts'))
Exemplo n.º 6
0
 def send_message(self):
     text = w.messageInput.toPlainText()
     if text:
         params = {'action': 'msg', 'text': text}
         selected_index = w.contactList.currentIndex()
         if selected_index:
             user_name = selected_index.data()
             params['to'] = user_name
         if self.__client.send(jim.Message(**params)):
             w.chatArea.addItem('{}: {}'.format(self.__client.name, text))
             w.messageInput.clear()
Exemplo n.º 7
0
def interact():
    print('\n'.join(['{}. {}'.format(key, action['name']) for key, action in enumerate(ACTIONS, 1)]))
    try:
        num = abs(int(input('Choose action: ')))
    except ValueError:
        num = 0
    config = ACTIONS[num - 1] if num <= len(ACTIONS) else ACTIONS[0]
    params = {'action': config['action']}
    if 'params' in config:
        for param in config['params']:
            p = str(input('Choose parameter "{}": '.format(param)))
            params[param] = p
    return jim.Message(**params)