python类document()的实例源码

bp.py 文件源码 项目:bpastebot 作者: mostafaasadi 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def filef(bot,update):
    # get file id
    file = bot.getFile(update.message.document.file_id)
    # create a randon temp file name
    tf = tempfile.mkstemp()
    # download file
    file.download(tf[1])
    # read file content
    try:
        tfco = open(tf[1],"r")
        tfc = tfco.read()
        tfco.close()
    except Exception as e:
        # if it is not text file
        bot.sendMessage(chat_id=update.message.chat_id,reply_to_message_id=update.message.message_id,text=" ?? Please send me a text file")

    # get user name for author
    try:
        author = update.message.from_user.first_name + " " + update.message.from_user.last_name
    except Exception:
        author = "Anonymous user"
    # call paste function
    url = paste(tfc , author)
    # replay the url to user
    bot.sendMessage(chat_id=update.message.chat_id,reply_to_message_id=update.message.message_id,text=url)
bot.py 文件源码 项目:JackOfAllGroups-telegram-bot 作者: Kyraminol 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def send_media(bot, chat_id, media_type, media_id, text, reply_to_id=None):
    if media_type == "audio":
        bot.send_audio(chat_id=chat_id, audio=media_id, reply_to_message_id=reply_to_id)
    elif media_type == "document":
        bot.send_document(chat_id=chat_id, document=media_id, caption=text, reply_to_message_id=reply_to_id)
    elif media_type == "photo":
        bot.send_photo(chat_id=chat_id, photo=media_id, caption=text, reply_to_message_id=reply_to_id)
    elif media_type == "sticker":
        bot.send_sticker(chat_id=chat_id, sticker=media_id, reply_to_message_id=reply_to_id)
    elif media_type == "video":
        bot.send_video(chat_id=chat_id, video=media_id, caption=text, reply_to_message_id=reply_to_id)
    elif media_type == "voice":
        bot.send_voice(chat_id=chat_id, voice=media_id, reply_to_message_id=reply_to_id)
bot.py 文件源码 项目:JackOfAllGroups-telegram-bot 作者: Kyraminol 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def main():
    updater = Updater("INSERT TOKEN HERE")
    dp = updater.dispatcher
    dp.add_handler(CommandHandler("start", cmd_start))
    dp.add_handler(CommandHandler("md", cmd_markdown, allow_edited=True))
    dp.add_handler(CommandHandler("markdown", cmd_markdown, allow_edited=True))
    dp.add_handler(CommandHandler("pin", cmd_pin, allow_edited=True))
    dp.add_handler(CommandHandler("welcome", cmd_welcome, allow_edited=True))
    dp.add_handler(CommandHandler("goodbye", cmd_goodbye, allow_edited=True))
    dp.add_handler(CommandHandler("del_welcome", cmd_clear_welcome))
    dp.add_handler(CommandHandler("del_goodbye", cmd_clear_goodbye))
    dp.add_handler(CommandHandler("set_bot_admin", cmd_set_bot_admin, allow_edited=True))
    dp.add_handler(CommandHandler("remove_bot_admin", cmd_remove_bot_admin, allow_edited=True))
    dp.add_handler(CommandHandler("settings", cmd_settings))
    dp.add_handler(CommandHandler("shortcut", cmd_shortcut_set, allow_edited=True))
    dp.add_handler(CommandHandler("del_shortcut", cmd_shortcut_del, allow_edited=True))
    dp.add_handler(CommandHandler("shortcuts", cmd_shortcut_getall, allow_edited=True))
    dp.add_handler(MessageHandler(Filters.audio |
                                  Filters.command |
                                  Filters.contact |
                                  Filters.document |
                                  Filters.photo |
                                  Filters.sticker |
                                  Filters.text |
                                  Filters.video |
                                  Filters.voice |
                                  Filters.status_update, msg_parse, allow_edited=True))
    dp.add_handler(CallbackQueryHandler(inline_button_callback))
    dp.add_error_handler(error)
    updater.start_polling()
    updater.idle()
bp.py 文件源码 项目:bpastebot 作者: mostafaasadi 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def main():
    # manage conversation
    conv_handler = ConversationHandler(
            entry_points=[CommandHandler('start', start)],
            states={
                second: [MessageHandler(Filters.text,second)],
                 },
            fallbacks=[CommandHandler('cancel', cancel)])

    # it handle start command
    start_handler = CommandHandler('start', start)
    # handle all text
    second_handler = MessageHandler(Filters.text , second)

    filef_handler = MessageHandler(Filters.document, filef)
    # handle cancel
    cancel_handler = CommandHandler('cancel', cancel)
    # handle cancel
    about_handler = CommandHandler('about', about)

    # handle dispatcher
    dispatcher.add_handler(InlineQueryHandler(inlinequery))
    dispatcher.add_handler(start_handler)
    dispatcher.add_handler(second_handler)
    dispatcher.add_handler(conv_handler)
    dispatcher.add_handler(cancel_handler)
    dispatcher.add_handler(about_handler)
    dispatcher.add_handler(filef_handler)

    # run
    updater.start_polling()
    updater.idle()
    updater.stop()
locks.py 文件源码 项目:tgbot 作者: PaulSonOfLars 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def del_document(bot, update):
    chat = update.effective_chat
    if sql.is_locked(chat.id, "document") and can_delete(chat, bot.id):
        update.effective_message.delete()


问题


面经


文章

微信
公众号

扫码关注公众号