Пример #1
0
 def loop_husky(self):
     time.sleep(0.001)
     response = comandos.parse({
         'chat_id': int(str(self.grupos_local[0])),
         'from_id': int(str(self.grupos_local[0])),
         'command_list': "/husky_pendentes",
         'command_type': 'grupo',
         'bot': self.bot,
         'config': self.config,
     })
     if response['status']:
         print(log_str.cmd(response['debug']))
         try:
             #        self.bot.sendMessage(self.usuarios_local[0], str(response['response']))
             #        self.bot.sendMessage(self.grupos_local[0], str(response['response']))
             self.bot.sendMessage(self.grupos_local[0],
                                  str(response['response']))
             shiva_1({
                 'numero': self.config['agenda']['numero_3'],
                 'config': self.config,
                 'bot': self.bot,
                 'telefones': response['response']['telefones'],
             })
         except telepot.exception.TelegramError as e:
             print(log_str.debug(e))
             pass
Пример #2
0
 def loop_cli(self, stdscr):
     #    wrapper(cli_wrapper)
     stdscr.addstr(u"Enviar (c)omando\tEscrever (v)elivery\t(s)air: ")
     while True:
         cmd = stdscr.getch()
         if cmd == ord('c'):
             stdscr.clear()
             stdscr.refresh()
             stdscr.addstr(u"Digite o comando (vazio para cancelar): ")
             command_list = stdscr.getstr(1, 0, 140)
             if command_list != "":
                 time.sleep(0.001)
                 response = comandos.parse({
                     'chat_id':
                     int(str(self.usuarios_debug[0])),
                     'from_id':
                     int(str(self.usuarios_debug[0])),
                     'command_list':
                     str(command_list.decode('utf-8')),
                     'command_type':
                     "curses",
                     'config':
                     self.config,
                     'stdscr':
                     stdscr,
                 })
                 if response['status']:
                     stdscr.addstr(
                         log_str.cmd(u"%s\n" % (response['debug'])))
                     try:
                         stdscr.addstr(u"%s\n" % (': '.join([
                             str(self.usuarios_debug[0]),
                             str(response['response'])
                         ])))
                     except Exception as e:
                         stdscr.addstr(u"%s\n" % (log_str.debug(e)))
                 else:
                     try:
                         stdscr.addstr(u"%s\n" % (': '.join([
                             str(self.usuarios_debug[0]),
                             str(response['response'])
                         ])))
                         stdscr.addstr(u"%s\n" % (': '.join(
                             [u"Debug", str(response['debug'])])))
                     except Exception as e:
                         stdscr.addstr(u"%s\n" % (log_str.debug(e)))
                 stdscr.refresh()
             else:
                 pass
             return 0
         elif cmd == ord('v'):
             stdscr.addstr(u"\nVelivery")
             return 0
         elif cmd == ord('s'):
             stdscr.addstr(u"\nTchau!")
             stdscr.refresh()
             time.sleep(1)
             return 1
         else:
             pass
Пример #3
0
 def loop_blog(self):
     time.sleep(0.001)
     response = comandos.parse({
         'chat_id': int(str(self.grupos_local[0])),
         'from_id': int(str(self.grupos_local[0])),
         'command_list': "/cmd_blog_matehackers",
         'command_type': 'grupo',
         'bot': self.bot,
         'config': self.config,
     })
     if response['status']:
         print(log_str.cmd(response['debug']))
         try:
             self.bot.sendMessage(self.grupos_local[0],
                                  str(response['response']))
         except telepot.exception.TelegramError as e:
             print(log_str.debug(e))
             pass
Пример #4
0
 def loop_pendentes(self):
     time.sleep(0.001)
     response = comandos.parse({
         'chat_id': int(str(self.usuarios_local[0])),
         'from_id': int(str(self.usuarios_local[0])),
         'command_list': "/pendentes",
         'command_type': 'grupo',
         'bot': self.bot,
         'config': self.config,
     })
     if response['status']:
         print(log_str.cmd(response['debug']))
         #      for grupo_local in self.grupos_local:
         #        self.enviarMensagem([grupo_local, grupos_debug[0]], response['response'], response['parse_mode'])
         #      for grupo_local in grupos_local:
         #        self.enviarMensagem([grupo_local, grupos_debug[0]], response['response'], response['parse_mode'])
         try:
             self.bot.sendMessage(self.grupos_local[0],
                                  str(response['response']))
         except telepot.exception.TelegramError as e:
             print(log_str.debug(e))
             pass
Пример #5
0
  def rcv(self, msg):
#    self.log(log_str.rcv(str(msg['chat']['id']), str(msg)))
    self.log(log_str.rcv(str(msg['chat']['id']), json.dumps(msg, sort_keys=True, indent=2)))
    glance = telepot.glance(msg)
    if glance[0] == 'text':
      chat_id = self.config['plugins_grupos']['admin']
      command_list = list()
      try:
        from_id = int(msg['from']['id'])
        chat_id = int(msg['chat']['id'])
        message_id = int(msg['message_id'])
        command_list = msg['text']
      except Exception as e:
        self.log(log_str.err(u'Erro do Telepot tentando receber mensagem: %s' % (e)))

      if self.interativo > 0:
        args.update
        automatico(args)
      elif command_list[0][0] == '/':
        self.log(log_str.cmd(command_list))
        response = comandos.parse(
          {
            'chat_id': chat_id,
            'from_id': from_id,
            'message_id': message_id,
            'command_list': command_list,
            'bot': self.bot,
            'config': self.config,
            'command_type': 'grupo',
          }
        )
        try:
          ## Log
          if str(response['type']) == 'erro':
            self.log(log_str.err(response['debug']))
          elif str(response['type']) == 'feedback':
            self.log('#feedback enviado de %s por %s:\n\n%s' % (chat_id, from_id, response['feedback']))
          elif str(response['type']) == "whisper":
            self.log('#whisper enviado de %s por %s para %s:\n\n%s' % (chat_id, from_id, response['to_id'], response['response']))
          else:
            self.log(log_str.info(response['debug']))
          ## Enviando resultado do comando
          ## TODO solução temporária, isto serve para controlar exibição em HTML ou Markdown.
          ## TODO https://core.telegram.org/bots/api#sendmessage
          if not 'parse_mode' in response:
            response.update(parse_mode = None)
            print(log_str.debug(u"parse_mode nao exisitia!"))
          ## TODO mais solução temporária
          if not 'reply_to_message_id' in response:
            response.update(reply_to_message_id = False)
            print(log_str.debug(u"reply_to_message_id nao exisitia!"))
          if str(response['type']) == 'nada':
            self.log(u"#nada\n\nresponse:\n%s\n\ndebug:\n%s" % (response['response'], response['debug']))
            pass
          elif str(response['type']) == 'feedback':
            self.enviarMensagem([from_id, chat_id], response['response'], response['parse_mode'], response['reply_to_message_id'])
          elif str(response['type']) == "image":
            self.enviarImagem((from_id, chat_id), response['response'], response['parse_mode'], response['reply_to_message_id'])
          elif str(response['type']) == 'qrcode':
            self.enviarImagem((from_id, chat_id), response['response'], response['parse_mode'], response['reply_to_message_id'])
          elif str(response['type']) == 'mensagem':
            if response['multi']:
              for chunk in response['response'].split('$$$EOF$$$'):
                self.enviarMensagem([from_id, chat_id], chunk, response['parse_mode'], response['reply_to_message_id'])
            else:
              self.enviarMensagem([from_id, chat_id], response['response'], response['parse_mode'], response['reply_to_message_id'])
          elif str(response['type']) == 'grupo':
            if response['multi']:
              for chunk in response['response'].split('$$$EOF$$$'):
                self.enviarMensagem([chat_id, chat_id], chunk, response['parse_mode'], response['reply_to_message_id'])
            else:
              self.enviarMensagem([chat_id, chat_id], response['response'], response['parse_mode'], response['reply_to_message_id'])
          elif str(response['type']) == 'erro':
            self.enviarMensagem([from_id, chat_id], response['response'], response['parse_mode'], response['reply_to_message_id'])
          elif str(response['type']) == 'whisper':
            self.enviarMensagem([response['to_id'], chat_id], response['response'], response['parse_mode'], False)
          elif str(response['type']) == 'comando':
            ## TODO não lembro qual era a relevância disto
#            mensagem = comandos.parse(chat_id, from_id, [''.join(['/', response['response'][0]]), response['response'][1:]])
            self.enviarMensagem([chat_id, from_id], mensagem['response'], response['parse_mode'], response['reply_to_message_id'])
          else:
            self.enviarMensagem([str(json.loads(self.config['plugins_usuarios']['admin'])[0]), str(json.loads(self.config['plugins_usuarios']['admin'])[0])], log_str.debug(response['debug']), response['parse_mode'], response['reply_to_message_id'])
        except Exception as e:
          raise
          self.log(log_str.debug(u'%s de %s para %s falhou.\nResponse: %s\nException: %s' % (command_list, from_id, chat_id, response, e)))