animebot.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:animebot 作者: EV3REST 项目源码 文件源码
def idd(bot, update, tags=None, chat_id=None):
    randomint = randint(1000, 10000000)
    try:
        bot.sendChatAction(chat_id, "upload_document")
        tags = update.message.text.split(' ', 1)[1]
        chat_id = update.message.chat_id
        try:
            client = Pybooru('Yandere')
            posts = client.posts_list(tags="id:"+str(tags), limit=1)
            for post in posts:
                urllib.request.urlretrieve(post['file_url'], "tmp/anime_bot_" + str(randomint) + ".jpg")
                tmp_data = "Uploader: " + post['author']  + "\nID: " + str(post['id'])
                globalarray[chat_id] = dict(data=tmp_data)
            photo = open('tmp/anime_bot_' + str(randomint) + ".jpg", 'rb')
            reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton("More", callback_data='More')]])
            bot.sendDocument(chat_id, photo, reply_markup=reply_markup)
            os.remove('tmp/anime_bot_' + str(randomint) + ".jpg")
        except Exception as e:
            print(e)
    except:
        bot.sendChatAction(chat_id, "upload_document")
        client = Pybooru('Yandere')
        try:
            posts = client.posts_list(tags="id:"+str(tags), limit=1)
            for post in posts:
                urllib.request.urlretrieve(post['file_url'], "tmp/anime_bot_" + str(randomint) + ".jpg")
                tmp_data = "Uploader: " + post['author']  + "\nID: " + str(post['id'])
                globalarray[chat_id] = dict(data=tmp_data)
            photo = open('tmp/anime_bot_' + str(randomint) + ".jpg", 'rb')
            reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton("More", callback_data='More')]])
            bot.sendDocument(chat_id, photo, reply_markup=reply_markup)
            os.remove('tmp/anime_bot_' + str(randomint) + ".jpg")
        except Exception as e:
            print(e)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号