コード例 #1
0
ファイル: run.py プロジェクト: skye-nlp/FIB-Chatbot
def main():
    global Fibot

    parser = argparse.ArgumentParser(description='')
    parser.add_argument('--thread_log',
                        action='store_true',
                        help='Whether to log the threads info')
    args = parser.parse_args()

    if args.thread_log: print(colored("LOG: Thread logging activo", 'cyan'))
    else: print(colored("LOG: Thread logging inactivo", 'cyan'))

    Fibot.load_components(thread_logging=bool(args.thread_log))
    print(colored("LOG: Todo inicializado", 'cyan'))
    # Create the Updater and pass it your bot's token.

    updater = Updater(Fibot.bot_token)

    dp = updater.dispatcher

    conv_handler = ConversationHandler(
        entry_points=[
            CommandHandler('start', start, pass_args=True),
            CommandHandler('login', start_authentication),
            CommandHandler('logout', logout),
            CommandHandler('updates_on', updates_on),
            CommandHandler('updates_off', updates_off),
            CommandHandler('set_lang', set_lang),
            MessageHandler(filters=Filters.text, callback=state_machine)
        ],
        states={
            MESSAGE_INCOME:
            [MessageHandler(filters=Filters.text, callback=state_machine)],
        },
        fallbacks=[RegexHandler('^Done$', done)],
        allow_reentry=True  #So users can use /login
    )

    dp.add_handler(conv_handler)

    # 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()
コード例 #2
0
ファイル: run.py プロジェクト: caoxu915683474/FIB-Chatbot
def main():
    global Fibot
    #Fibot = Fibot()
    Fibot.load_components()
    print("Everything initialisated")
    # Create the Updater and pass it your bot's token.

    updater = Updater(Fibot.bot_token)

    dp = updater.dispatcher

    conv_handler = ConversationHandler(
        entry_points=[
            CommandHandler('start', start),
            CommandHandler('login', start_authentication),
            CommandHandler('logout', logout),
            CommandHandler('updates_on', updates_on),
            CommandHandler('updates_off', updates_off),
            CommandHandler('train_on', training_on),
            CommandHandler('train_off', training_off)
        ],
        states={
            MESSAGE_INCOME:
            [MessageHandler(filters=Filters.text, callback=state_machine)],
            TRAINING:
            [MessageHandler(filters=Filters.text, callback=train_machine)],
            CORR_INCORR: [RegexHandler('^(Sí|No)$', callback=feedback_info)],
            GET_CORRECT:
            [MessageHandler(filters=Filters.text, callback=def_knowledge)],
        },
        fallbacks=[RegexHandler('^Done$', done)],
        allow_reentry=True  #So users can use /login
    )

    dp.add_handler(conv_handler)

    # 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()
コード例 #3
0
def main():
    CHAT_ID = None
    parser = argparse.ArgumentParser(description='')
    parser.add_argument('--thread_log',
                        action='store_true',
                        help='Whether to log the threads info')
    parser.add_argument('--chat_id',
                        required=False,
                        type=int,
                        default=469557458,
                        help="Chat_id for the conversation")
    parser.add_argument('--no_debug',
                        action='store_true',
                        required=False,
                        help="Prints debug information about queries")
    args = parser.parse_args()

    if args.chat_id:
        CHAT_ID = args.chat_id
    debug = not args.no_debug

    fibot = Fibot(local=True, debug=debug)

    if args.thread_log: print(colored("LOG: Thread logging activo", 'cyan'))
    else: print(colored("LOG: Thread logging inactivo", 'cyan'))

    fibot.load_components(thread_logging=bool(args.thread_log))

    print(colored("LOG: Todo inicializado", 'cyan'))
    print(
        colored(
            "INFO: Simulando conversación como usuario con chat_id {}".format(
                CHAT_ID), 'red'))
    print(colored("INFO: Escribe 'quit' para terminar conversación", 'red'))

    message = input('> ')
    while not message == 'quit':
        fibot.process_income_message(CHAT_ID, message)
        message = input('> ')