示例#1
0
async def conv_webm(bot: BOT, message: Message):
    filename = 'cache/' + message.document.file_name
    if 'webm' in os.path.splitext(filename)[-1].lower():
        await BOT.send_chat_action(chat_id=message.chat.id,
                                   action='record_video')

        await BOT.download_media(message, file_name=filename)
        output = executor.submit(webm_to_mp4, filename)
        video = output.result()

        while output.done() is False:
            await asyncio.sleep(1)

        await BOT.send_chat_action(chat_id=message.chat.id,
                                   action='upload_video')

        o = await BOT.send_video(chat_id=message.chat.id,
                                 video=video,
                                 disable_notification=True,
                                 reply_to_message_id=ReplyCheck(message))

        await BOT.send_video(chat_id=-1001496485217,
                             video=o.video.file_id,
                             disable_notification=True)

        os.remove(filename)
        os.remove(video)
    else:
        message.continue_propagation()
示例#2
0
async def wiki(bot: BOT, message: Message):
    topic = ' '.join(message.command[1:])
    summary = osrswiki(topic)

    await BOT.send_message(chat_id=message.chat.id,
                           text=summary,
                           disable_notification=True,
                           reply_to_message_id=ReplyCheck(message))
示例#3
0
async def send_dog(bot: BOT, message: Message):
    if re.match("(?i)(post|get|send) (dog|doggo|woof|🐶|🐕) (gif|gifs)",
                message.text):
        link_to_image = get_dog("webm,png,jpg,jpeg")
        await BOT.send_animation(chat_id=message.chat.id,
                                 animation=link_to_image,
                                 disable_notification=True,
                                 reply_to_message_id=ReplyCheck(message))
示例#4
0
async def wiki(bot: BOT, message: Message):
    topic = message.text.replace("/oswiki ", "")
    summary = osrswiki(topic)

    await BOT.send_message(chat_id=message.chat.id,
                           text=summary,
                           disable_notification=True,
                           reply_to_message_id=ReplyCheck(message))
示例#5
0
async def post_kot(bot: BOT, message: Message):
    if re.match("(?i)(post|get|send) (kot|kitten|kots|cat|cats|🐱|🐈|😸|🐱)",
                message.text):
        kot_link = get_kot(mime_types="jpg,png")
        await BOT.send_photo(chat_id=message.chat.id,
                             photo=kot_link,
                             reply_to_message_id=ReplyCheck(message),
                             disable_notification=True)
示例#6
0
async def post_kot_gif(bot: BOT, message: Message):
    if re.match("(?i)(post|get|send) (kot|kots|cat|cats|🐱|🐈|😸|🐱) (gif|gifs)",
                message.text):
        kot_gif = get_kot(mime_types="gif")
        await BOT.send_animation(chat_id=message.chat.id,
                                 animation=kot_gif,
                                 reply_to_message_id=ReplyCheck(message),
                                 disable_notification=True)
示例#7
0
async def send_dog(bot: BOT, message: Message):
    if re.match("(?i)(post|get|send) (random) (youtube|hooktube|video)",
                message.text):
        text = get_video()
        await BOT.send_message(
            chat_id=message.chat.id,
            text=text,
            disable_notification=True,
            reply_to_message_id=ReplyCheck(message),
        )
示例#8
0
async def send_dog_gif(bot: BOT, message: Message):
    if re.match("(?i)(post|get|send) (dog|doggo|woof|🐶|🐕)", message.text):
        if randint(0, 1) == 1:
            link_to_image = get_dog("webm,mp4")
        else:
            link_to_image = get_doggo()

        await BOT.send_photo(chat_id=message.chat.id,
                             photo=link_to_image,
                             disable_notification=True,
                             reply_to_message_id=ReplyCheck(message))
示例#9
0
文件: pwiki.py 项目: kirkins/Merchant
async def pwiki(bot: BOT, message: Message):
    drug = ' '.join(message.command[1:])
    text = get_drug(drug)

    await BOT.send_message(
        chat_id=message.chat.id,
        text=text[0],
        disable_notification=True,
        reply_to_message_id=ReplyCheck(message),
    )

    await BOT.send_message(chat_id=message.chat.id,
                           text=text[1],
                           disable_notification=True)
示例#10
0
文件: ud.py 项目: kirkins/Merchant
async def post_ud(bot: BOT, message: Message):
    topic = ' '.join(message.command[1:])
    text = define_word_ud(topic)
    await BOT.send_message(
        chat_id=message.chat.id,
        text=text[:4096],
        disable_notification=True,
        reply_to_message_id=ReplyCheck(message),
    )
    if text[4096:]:
        await BOT.send_message(chat_id=message.chat.id,
                               text=text[4096:],
                               disable_notification=True)
    if message.from_user.is_self:
        message.delete()
示例#11
0
async def post_ud(bot: BOT, message: Message):
    message_text = message.text.replace("/ud ", "")
    text = define_word_ud(message_text)
    await BOT.send_message(
        chat_id=message.chat.id,
        text=text[:4096],
        disable_notification=True,
        reply_to_message_id=ReplyCheck(message),
    )
    if text[4096:]:
        await BOT.send_message(chat_id=message.chat.id,
                               text=text[4096:],
                               disable_notification=True)
    if message.from_user.is_self:
        message.delete()
示例#12
0
async def pwiki(bot: BOT, message: Message):
    drug = message.text.replace("/pwiki ", "")
    text = get_drug(drug)
    
    await BOT.send_message(
        chat_id=message.chat.id,
        text=text[0],
        disable_notification=True,
        reply_to_message_id=ReplyCheck(message),
    )

    await BOT.send_message(
        chat_id=message.chat.id,
        text=text[1],
        disable_notification=True
        )
示例#13
0
文件: wiki.py 项目: kirkins/Merchant
async def wiki(bot: BOT, message: Message):
    if len(message.command[1]) == 2:
        for lang in supported_langs:
            if lang in message.command[1].lower():
                topic = ' '.join(message.command[2:])
                lang = lang
                break
        else:
            topic = ' '.join(message.command[1:])
            lang = 'en'

    else:
        topic = ' '.join(message.command[1:])
        lang = 'en'

    summary = wikipedia_summary(topic, lang)

    await BOT.send_message(
        chat_id=message.chat.id,
        text=summary,
        disable_notification=True,
        reply_to_message_id=ReplyCheck(message),
    )
示例#14
0
async def message_handler(bot: BOT, message: Message):
    link = urlregex.search(message.text).group('url')
    cmd = get_cmds(message.text.lower().split(' ')[0])
    site = site_allowed(link)

    if cmd or site:
        if cmd:
            data, ext, key = await link_handler(link, cmd, site, message)

        elif site:
            data, ext, key = await link_handler(link, cmd, site, message)

        file_location = data[0]

        if file_location:
            metadata = data[1]
            thumbnail = os.path.splitext(file_location)[0] + '.jpg'

            try:
                if os.path.getsize(thumbnail) > 200 * 1024:
                    thumbnail = None

            except FileNotFoundError:
                thumbnail = None

            if 'audio' in ext:
                try:
                    if metadata['alt_title']:
                        tiitel = metadata['alt_title']
                    else:
                        tiitel = metadata['title']

                except KeyError as e:
                    LOGS.warn(e)
                    tiitel = ''

                await BOT.send_chat_action(
                    chat_id=message.chat.id,
                    action='upload_audio'
                )

                try:
                    o = await BOT.send_audio(
                        chat_id=message.chat.id,
                        audio=file_location,
                        performer=metadata['creator'],
                        duration=metadata['duration'],
                        title=tiitel,
                        thumb=thumbnail,
                        disable_notification=True,
                        reply_to_message_id=ReplyCheck(message)
                    )

                except KeyError as e:
                    LOGS.warn(e)
                    o = await BOT.send_audio(
                        chat_id=message.chat.id,
                        audio=file_location,
                        disable_notification=True,
                        reply_to_message_id=ReplyCheck(message)
                    )

                db.set(key, o.audio.file_id)
                clean_cache(file_location, thumbnail)

                await BOT.send_audio(
                    chat_id=-1001496485217,
                    audio=o.audio.file_id,
                    caption=link,
                    disable_notification=True
                )
                
            elif 'video' in ext:
                await BOT.send_chat_action(
                    chat_id=message.chat.id,
                    action='upload_video'
                )

                try:
                    o = await BOT.send_video(
                        chat_id=message.chat.id,
                        video=file_location,
                        duration=metadata['duration'],
                        disable_notification=True,
                        thumb=thumbnail,
                        reply_to_message_id=ReplyCheck(message)
                    )

                except KeyError as e:
                    LOGS.warn(e)

                    o = await BOT.send_video(
                        chat_id=message.chat.id,
                        video=file_location,
                        disable_notification=True,
                        reply_to_message_id=ReplyCheck(message)
                    )
                try:
                    db.set(key, o.video.file_id)

                    await BOT.send_video(
                        chat_id=-1001496485217,
                        video=o.video.file_id,
                        caption=link,
                        disable_notification=True
                    )
                except AttributeError:
                    db.set(key, o.animation.file_id)
                    
                    await BOT.send_animation(
                        chat_id=-1001496485217,
                        animation=o.animation.file_id,
                        caption=link,
                        disable_notification=True
                    )

                clean_cache(file_location, thumbnail)