예제 #1
0
def main():
    updater = Updater(token=TELEGRAM_TOKEN, use_context=True)

    dispatcher = updater.dispatcher

    dispatcher.add_handler(CommandHandler("start", start))
    dispatcher.add_handler(
        CommandHandler("boas_vindas_imagem", boas_vindas_imagem))
    dispatcher.add_handler(
        CommandHandler("boas_vindas_nova_imagem",
                       boas_vindas_nova_imagem_info))
    dispatcher.add_handler(
        MessageHandler(
            filters=Filters.photo
            & (Filters.caption([
                "/boas_vindas_nova_imagem",
                "/boas_vindas_nova_imagem@PyLadiesBrasilBot",
            ])),
            callback=boas_vindas_nova_imagem,
        ))
    dispatcher.add_handler(CommandHandler("boas_vindas", boas_vindas))
    dispatcher.add_handler(CommandHandler("help", help))

    dispatcher.add_handler(
        MessageHandler(Filters.status_update.new_chat_members, welcome))
    dispatcher.add_handler(MessageHandler(Filters.command, unknown))

    updater.start_polling()
    updater.idle()
예제 #2
0
파일: bot.py 프로젝트: myl7/ayachanbot
def main():
    load_dotenv()
    logging.basicConfig(
        format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
        level=logging.INFO)

    token = os.getenv('BOT_TOKEN')
    updater = Updater(token=token)
    dispatcher = updater.dispatcher

    start_handler = CommandHandler('start', handlers.handle_start)
    dispatcher.add_handler(start_handler)

    anime_image_searching_handler = MessageHandler(
        Filters.photo & Filters.caption(['anime']),
        handlers.handle_anime_image_searching)
    dispatcher.add_handler(anime_image_searching_handler)

    updater.start_polling()
예제 #3
0
 def test_filters_caption_strings(self, update):
     update.message.caption = 'test'
     assert Filters.caption({'test', 'test1'})(update)
     assert not Filters.caption(['test1', 'test2'])(update)
예제 #4
0
def main():
    # Create the Updater and pass it your bot's token.
    # Make sure to set use_context=True to use the new context based callbacks
    # Post version 12 this will no longer be necessary

    myBot = DrawingTelegram()

    pp = PicklePersistence(filename='DrawingTelegram')
    updater = Updater(os.environ["TELEGRAM_TOKEN"],
                      persistence=pp,
                      use_context=True)
    # print(pp.get_user_data())
    # for i in PicklePersistence(filename='DrawingTelegram').get_bot_data():

    # Get the dispatcher to register handlers
    dp = updater.dispatcher

    # Add conversation handler with the states KEYWORD, SELECTPHOTO, LAUNCHPRINT and BIO

    dp.add_handler(CommandHandler("search", myBot.fetchImage, pass_args=True))

    dp.add_handler(
        MessageHandler((Filters.reply & Filters.regex('^\/gcode$')),
                       myBot.selectPhoto))
    dp.add_handler(
        MessageHandler((Filters.photo & Filters.caption(["/gcode"])),
                       myBot.selectPhoto))

    dp.add_handler(
        MessageHandler((Filters.reply & Filters.regex('^\/print$')),
                       myBot.launchPrint))
    dp.add_handler(
        MessageHandler((Filters.photo & Filters.caption(["/print"])),
                       myBot.launchPrint))

    conv_config = ConversationHandler(
        entry_points=[CommandHandler('config', config)],
        states={
            HOME: [
                CallbackQueryHandler(chooseConfig,
                                     pattern='^' + '|'.join(config_kw[:-1]) +
                                     '$'),
                CallbackQueryHandler(sumup, pattern='^' + config_kw[-1] + '$')
            ],
            SET: [CallbackQueryHandler(setConfig)]
        },
        fallbacks=[CommandHandler('cancel', cancel)])

    # dp.add_handler(conv_draw)
    dp.add_handler(conv_config)

    # log all errors
    # dp.add_error_handler(error)

    # Start the Bot
    updater.start_polling()

    # Run the bot until you press Ctrl-C or the process receives SIGINT,
    # SIGTERM or SIGABRT. This should be used most of the time, since
    # start_polling() is non-blocking and will stop the bot gracefully.
    updater.idle()