Beispiel #1
0
    def _handler(self):
        self.module = Module(self.update, self.bot)
        if self.isCommand:
            # Verificar ID do chat
            if self.command in ['cid', 'chatid']:
                self._send_message('O ***ID*** do chat atual é: ```{0}```'.format(self.chat_id), self._message.message_id)

             # Conversation Module
            if self._message.chat.username in self.config.owner_name:
                self.module = _owner(self.update, self.bot, self.command, self.message)

            # TTS Module
            if self.command in ['tts', 'ttss']:
                self.module = TTS(self.update, self.bot, self.command, self.message)

            # Translate Module
            if self.command in ['trt', 'translate']:
                self.module = TRT(self.update, self.bot, self.command, self.message)

            # Upload Module
            if self.command in ['up', 'upload']:
                self.module = upload(self.update, self.bot, self.command, self.message)

            # YouTube Module
            if self.command in ['yt', 'youtube']:
                self.module = search_YouTube(self.update, self.bot, self.command, self.message)
                
            # Poll Module
            if self.command in ['npll', 'newpoll', 'cpll', 'closepoll']:
                self.module = _poll(self.update, self.bot, self.command, self.message)

            # EXEC Module
            if self.command in ['exex']:
                if self._message.from_user.username in self.config.owner_name:
                    exec(compile(str(self.message), "<string>", "exec"))
                    self._send_message('Script executado com sucesso!', self._message.message_id)

        else:
            # Conversation Module
            if self._message.chat.username in self.config.owner_name:
                self.module = _owner(self.update, self.bot, 'sendmessage', self.message)

            if self._message.chat.id == self.config.chat_connected:
                if self.config.conversation:
                    self._send_message(text='***U:*** @{0}    \n***M: 👇🏾***\n{1}    \n\n***Responda:*** ``` {2} ```👆🏾'.format(self._message.from_user.username, self.message, '!rm '+str(self._message.message_id)), chat_id=self.config.owner_chat_id)
                    return

                for owner in self.config.owner_name:
                    owner_user = '******'+owner
                    if owner_user.lower() in self.message.lower():
                        self._send_message('No momento {0}, {1} está ocupado, deixe seu recado no grupo ou no privado, assim que ele tiver tempo ele vai lhe responder, obrigado pela atenção.'.format(self._message.from_user.first_name, owner), self._message.message_id)
                        return

        try:
            self.module._handler()
        except Exception as ERROR:
            l = open('./error.log', 'a')
            l.write('\n'+('='*25)+'\n- Tempo: {0}\n Erro: \n'.format(time.strftime("%d/%m/%Y - %H:%M:%S")))
            traceback.print_exc(file=l)
            l.close()
Beispiel #2
0
def start_bot(bot, update):
    msg = update.message.text
    msg = str(msg)
    user_id = update.message.from_user.id
    user_id = str(user_id)
    if "|" in msg:
        user_cmd, url = msg.split("|")
        user_cmd = user_cmd.strip()
        user_cmd = user_cmd.lower()
        url = url.strip()
    else:
        user_cmd = None
        url = msg
    #site = requests.get(url)
    #if site.status_code == 200:
    #site = httplib.HTTPConnection(url)
    #site.request("HEAD", '')
    #if site.getresponse().status == 200:
    sent_message = bot.send_message(chat_id=update.message.chat_id,
                                    text=Text.VERIFYING_URL)
    time.sleep(1)
    if validators.url(url):
        sent_message.edit_text(Text.PROCESSING)
        if user_cmd:
            if (user_cmd == "video"):
                filename = download_video.download(url)
                if "ERROR" in filename:
                    sent_message.edit_text(Text.FAILED + filename,
                                           parse_mode=telegram.ParseMode.HTML)
                else:
                    bot.send_chat_action(chat_id=update.message.chat_id,
                                         action=telegram.ChatAction.TYPING)
                    sent_message.edit_text(Text.UPLOADING_GD)
                    dwnld_url = upload.upload(filename)
                    size = (os.path.getsize(filename)) / 1048576
                    sent_message.edit_text(Text.DONE.format(
                        filename, size, dwnld_url),
                                           parse_mode=telegram.ParseMode.HTML)
                    os.remove(filename)
            elif (user_cmd == "audio"):
                if ("youtube" in url or "youtu" in url):
                    filename = download_audio.download(url)
                    if "ERROR" in filename:
                        sent_message.edit_text(
                            Text.FAILED + filename,
                            parse_mode=telegram.ParseMode.HTML)
                    else:
                        bot.send_chat_action(chat_id=update.message.chat_id,
                                             action=telegram.ChatAction.TYPING)
                        sent_message.edit_text(Text.UPLOADING_TG)
                        audio = open(filename, 'rb')
                        bot.send_audio(chat_id=update.message.chat_id,
                                       audio=audio,
                                       caption=filename.replace(".mp3", ""))
                        audio.close()
                        os.remove(filename)
                        sent_message.edit_text(Text.DONE)
                else:
                    sent_message.edit_text(Text.NOT_SUPPORTED,
                                           parse_mode=telegram.ParseMode.HTML)
            else:
                if download.is_downloadable(url):
                    size = download.check_filesize(url)
                    if size <= 10000:
                        filename = user_cmd
                        raw_file = download.download(url, filename)
                        if "ERROR" in raw_file:
                            sent_message.edit_text(
                                Text.FAILED + raw_file,
                                parse_mode=telegram.ParseMode.HTML)
                        else:
                            bot.send_chat_action(
                                chat_id=update.message.chat_id,
                                action=telegram.ChatAction.TYPING)
                            sent_message.edit_text(Text.UPLOADING_GD)
                            dwnld_url = upload.upload(raw_file)
                            sent_message.edit_text(
                                Text.DONE.format(raw_file, size, dwnld_url),
                                parse_mode=telegram.ParseMode.HTML)

                    else:
                        sent_message.edit_text(Text.MAXLIMITEXCEEDED)
                else:
                    sent_message.edit_text(Text.ISNOT_DOWNLOADABLE,
                                           parse_mode=telegram.ParseMode.HTML)
        else:
            if download.is_downloadable(url):
                size = download.check_filesize(url) / 1048576
                if size <= 10000:
                    raw_file = download.download(url, None)
                    bot.send_chat_action(chat_id=update.message.chat_id,
                                         action=telegram.ChatAction.TYPING)
                    sent_message.edit_text(Text.UPLOADING_GD)
                    dwnld_url = upload.upload(raw_file)
                    sent_message.edit_text(Text.DONE.format(
                        raw_file, size, dwnld_url),
                                           parse_mode=telegram.ParseMode.HTML)
                else:
                    sent_message.edit_text(Text.MAXLIMITEXCEEDED)
            else:
                sent_message.edit_text(Text.ISNOT_DOWNLOADABLE,
                                       parse_mode=telegram.ParseMode.HTML)
    elif ("help" not in url and "start" not in url and "broadcast" not in url
          and "donate" not in url and "add_user" not in url
          and "revoke_user" not in url):
        bot.send_chat_action(chat_id=update.message.chat_id,
                             action=telegram.ChatAction.TYPING)
        time.sleep(1)
        sent_message.edit_text(Text.RETARD)