Example #1
0
    def run(self, m):
        url = "http://belikebill.azurewebsites.net/billgen-API.php"
        params = {"default": 1, "name": self.bot.info.first_name.split()[0], "sex": "f"}

        photo = download(url, params, extension=".jpg")

        if photo:
            return self.bot.send_message(m, photo, "photo")
        else:
            return self.bot.send_message(m, self.bot.trans.errors.download_failed)
Example #2
0
    def run(self, m):
        input = get_input(m, ignore_reply=False)
        if not input:
            return self.bot.send_message(m, self.bot.trans.errors.missing_parameter, extra={'format': 'HTML'})

        langs = [
            'af', 'aq', 'ar', 'hy', 'ca', 'zh', 'zh-cn', 'zh-tw', 'zh-yue',
            'hr', 'cs', 'da', 'nl', 'en-au', 'en-uk', 'en-us', 'eo',
            'fi', 'fr', 'de', 'el', 'ht', 'hu', 'is', 'id',
            'it', 'ja', 'ko', 'la', 'lv', 'mk', 'no', 'pl',
            'pt', 'pt-br', 'ro', 'ru', 'sr', 'sk', 'es', 'es-es',
            'es-us', 'sw', 'sv', 'ta', 'th', 'tr', 'vi', 'cy'
        ]

        for lang in langs:
            if first_word(input) == lang:
                language = lang
                text = all_but_first_word(input)
                break
            else:
                language = 'en-us'
                text = input
                
        if not text:
            return self.bot.send_message(m, self.bot.trans.errors.missing_parameter, extra={'format': 'HTML'})

        url = 'http://translate.google.com/translate_tts'
        params = {
            'tl': language,
            'q': text,
            'ie': 'UTF-8',
            'total': len(text),
            'idx': 0,
            'client': 'tw-ob',
            'key': self.bot.config.api_keys.google_developer_console
        }
        headers = {
            "Referer": 'http://translate.google.com/',
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.8 Safari/537.36"
        }
        file = download(url, params, headers)
        voice = mp3_to_ogg(file)

        if voice:
            return self.bot.send_message(m, voice, 'voice')
        else:
            return self.bot.send_message(m, self.bot.trans.errors.download_failed)
Example #3
0
    def send_message(self, message):
        if not message.extra:
            message.extra = {}

        if message.type != 'text' and message.content.startswith('http'):
            message.content = download(message.content)
        elif message.type != 'text' and not message.content.startswith('/'):
            message.content = self.sender.load_file(message.content)

        if not message.extra or not 'caption' in message.extra:
            message.extra['caption'] = None

        if message.type == 'text':
            self.sender.send_typing(self.peer(message.conversation.id), 1)

            if 'format' in message.extra and message.extra['format'] == 'Markdown':
                message.content = remove_markdown(message.content)
            elif 'format' in message.extra and message.extra['format'] == 'HTML':
                message.content = self.convert_links(message.content)

            try:
                if 'format' in message.extra and message.extra['format'] == 'HTML':
                    self.sender.raw('[html] msg %s %s' % (self.peer(message.conversation.id), self.escape(message.content)), enable_preview=False)
                else:
                    self.sender.send_msg(self.peer(message.conversation.id), message.content, enable_preview=False)
            except Exception as e:
                logging.exception(e)

        elif message.type == 'photo':
            self.sender.send_typing(self.peer(message.conversation.id), 1)  # 7
            try:
                if message.reply:
                    self.sender.reply_photo(message.reply, message.content, message.extra['caption'])
                else:
                    self.sender.send_photo(self.peer(message.conversation.id), message.content, message.extra['caption'])
            except Exception as e:
                logging.exception(e)

        elif message.type == 'audio':
            self.sender.send_typing(self.peer(message.conversation.id), 1)  # 6
            try:
                if message.reply:
                    self.sender.reply_audio(message.reply, message.content)
                else:
                    self.sender.send_audio(self.peer(message.conversation.id), message.content)
            except Exception as e:
                logging.exception(e)

        elif message.type == 'document':
            self.sender.send_typing(self.peer(message.conversation.id), 1)  # 8
            try:
                if message.reply:
                    self.sender.reply_document(message.reply, message.content, message.extra['caption'])
                else:
                    self.sender.send_document(self.peer(message.conversation.id), message.content, message.extra['caption'])
            except Exception as e:
                logging.exception(e)

        elif message.type == 'sticker':
            if message.reply:
                self.sender.reply_file(message.reply, message.content)
            else:
                self.sender.send_file(self.peer(message.conversation.id), message.content)

        elif message.type == 'video':
            self.sender.send_typing(self.peer(message.conversation.id), 1)  # 4
            try:
                if message.reply:
                    self.sender.reply_video(message.reply, message.content, message.extra['caption'])
                else:
                    self.sender.send_video(self.peer(message.conversation.id), message.content, message.extra['caption'])
            except Exception as e:
                logging.exception(e)

        elif message.type == 'voice':
            self.sender.send_typing(self.peer(message.conversation.id), 5)
            try:
                if message.reply:
                    self.sender.reply_audio(message.reply, message.content)
                else:
                    self.sender.send_audio(self.peer(message.conversation.id), message.content)
            except Exception as e:
                logging.exception(e)

        elif message.type == 'location':
            self.sender.send_typing(self.peer(message.conversation.id), 1)  # 9
            if message.reply:
                self.sender.reply_location(message.reply, message.content['latitude'], message.content['longitude'])
            else:
                self.sender.send_location(self.peer(message.conversation.id), message.content['latitude'], message.content['longitude'])

        else:
            print('UNKNOWN MESSAGE TYPE: ' + message.type)
            logging.debug("UNKNOWN MESSAGE TYPE")