Пример #1
0
def main():
    for modname in ["sed", "help", "yesno"]:
        module = getattr(importlib.import_module('bot.modules.{}'.format(modname)), "module")
        logger.info("module imported: %s (handlers: %d)", module.name, len(module.handlers))
        for handler in module.handlers:
            dispatcher.add_handler(handler)

    updater.start_polling(clean=True)
    updater.idle()
def main():
    # Добавить все хэндлеры
    updater.dispatcher.add_handler(main_menu_handler)

    # Начинает проверку на наличие новых сообщений от пользователей
    updater.start_polling()

    # Запуск до тех пор, пока не будет нажата комбинация клавиш CTRL+C
    updater.idle()
Пример #3
0
def main():
    fs_utils.start_cleanup()
    # Check if the bot is restarting
    SUPPORT_GROUP = "tgelkayb0ts"
    if SUPPORT_GROUP is not None and isinstance(SUPPORT_GROUP, str):
        try:
            dispatcher.bot.sendMessage(f"@{SUPPORT_GROUP}", "Bot Restarted!")
        except Unauthorized:
            LOGGER.warning(
                "Bot isnt able to send message to support_chat, go and check!")
        except BadRequest as e:
            LOGGER.warning(e.message)
    if os.path.isfile(".restartmsg"):
        with open(".restartmsg") as f:
            chat_id, msg_id = map(int, f)
        bot.edit_message_text("Restarted successfully!", chat_id, msg_id)
        os.remove(".restartmsg")
    bot.set_my_commands(botcmds)

    start_handler = CommandHandler(BotCommands.StartCommand,
                                   start,
                                   run_async=True)
    ping_handler = CommandHandler(BotCommands.PingCommand,
                                  ping,
                                  filters=CustomFilters.authorized_chat
                                  | CustomFilters.authorized_user,
                                  run_async=True)
    restart_handler = CommandHandler(BotCommands.RestartCommand,
                                     restart,
                                     filters=CustomFilters.owner_filter
                                     | CustomFilters.sudo_user,
                                     run_async=True)
    help_handler = CommandHandler(BotCommands.HelpCommand,
                                  bot_help,
                                  filters=CustomFilters.authorized_chat
                                  | CustomFilters.authorized_user,
                                  run_async=True)
    stats_handler = CommandHandler(BotCommands.StatsCommand,
                                   stats,
                                   filters=CustomFilters.authorized_chat
                                   | CustomFilters.authorized_user,
                                   run_async=True)
    log_handler = CommandHandler(BotCommands.LogCommand,
                                 log,
                                 filters=CustomFilters.owner_filter
                                 | CustomFilters.sudo_user,
                                 run_async=True)
    dispatcher.add_handler(start_handler)
    dispatcher.add_handler(ping_handler)
    dispatcher.add_handler(restart_handler)
    dispatcher.add_handler(help_handler)
    dispatcher.add_handler(stats_handler)
    dispatcher.add_handler(log_handler)
    updater.start_polling(drop_pending_updates=IGNORE_PENDING_REQUESTS)
    LOGGER.info("Bot Started!")
    signal.signal(signal.SIGINT, fs_utils.exit_clean_up)
Пример #4
0
def main():
    dp.add_handler(CommandHandler("zoom", zoom))
    dp.add_handler(CommandHandler("meet", meet))
    dp.add_handler(CommandHandler("restart", restart))
    dp.add_handler(CommandHandler("status", status))
    dp.add_handler(CommandHandler("meetexit", meetexit))
    dp.add_handler(CommandHandler("zoomexit", zoomexit))
    logging.info("Bot started")

    updater.start_polling()
def main():
    test_handler = CommandHandler("test", test)
    start_handler = CommandHandler("start", start, pass_args=True)

    IMDB_HANDLER = CommandHandler('imdb', imdb, pass_args=True)
    IMDB_SEARCHDATAHANDLER = CallbackQueryHandler(imdb_searchdata)

    start_callback_handler = CallbackQueryHandler(send_start,
                                                  pattern=r"bot_start")
    dispatcher.add_handler(start_callback_handler)

    help_handler = CommandHandler("help", get_help)
    help_callback_handler = CallbackQueryHandler(help_button, pattern=r"help_")

    settings_handler = CommandHandler("settings", get_settings)
    settings_callback_handler = CallbackQueryHandler(settings_button,
                                                     pattern=r"stngs_")

    source_handler = CommandHandler("source", source)

    migrate_handler = MessageHandler(Filters.status_update.migrate,
                                     migrate_chats)

    M_CONNECT_BTN_HANDLER = CallbackQueryHandler(m_connect_button,
                                                 pattern=r"main_connect")

    # dispatcher.add_handler(test_handler)
    dispatcher.add_handler(start_handler)
    dispatcher.add_handler(help_handler)
    dispatcher.add_handler(settings_handler)
    dispatcher.add_handler(help_callback_handler)
    dispatcher.add_handler(settings_callback_handler)
    dispatcher.add_handler(migrate_handler)
    dispatcher.add_handler(source_handler)
    dispatcher.add_handler(M_CONNECT_BTN_HANDLER)
    dispatcher.add_handler(IMDB_HANDLER)
    dispatcher.add_handler(IMDB_SEARCHDATAHANDLER)

    # dispatcher.add_error_handler(error_callback)

    if WEBHOOK:
        LOGGER.info("Using webhooks.")
        updater.start_webhook(listen="127.0.0.1", port=PORT, url_path=TOKEN)

        if CERT_PATH:
            updater.bot.set_webhook(url=URL + TOKEN,
                                    certificate=open(CERT_PATH, 'rb'))
        else:
            updater.bot.set_webhook(url=URL + TOKEN)

    else:
        LOGGER.info("bot running...")
        updater.start_polling(timeout=15, read_latency=4)

    updater.idle()
Пример #6
0
def main():
    #AutoRestart Print
    now = datetime.now(pytz.timezone('Asia/Kolkata'))
    current = now.strftime('%Y/%m/%d %I:%M:%P')
    f"Im Back!: {current}"
    fs_utils.start_cleanup()
    # Check if the bot is restarting
    if path.exists('restart.pickle'):
        with open('restart.pickle', 'rb') as status:
            restart_message = pickle.load(status)
        restart_message.edit_text("Restarted Successfully!")
        LOGGER.info('Restarted Successfully!')
        remove('restart.pickle')

    start_handler = CommandHandler(BotCommands.StartCommand,
                                   start,
                                   filters=CustomFilters.authorized_chat
                                   | CustomFilters.authorized_user)
    ping_handler = CommandHandler(BotCommands.PingCommand,
                                  ping,
                                  filters=CustomFilters.authorized_chat
                                  | CustomFilters.authorized_user)
    restart_handler = CommandHandler(BotCommands.RestartCommand,
                                     restart,
                                     filters=CustomFilters.owner_filter)
    help_handler = CommandHandler(BotCommands.HelpCommand,
                                  bot_help,
                                  filters=CustomFilters.authorized_chat
                                  | CustomFilters.authorized_user)
    stats_handler = CommandHandler(BotCommands.StatsCommand,
                                   stats,
                                   filters=CustomFilters.authorized_chat
                                   | CustomFilters.authorized_user)
    log_handler = CommandHandler(BotCommands.LogCommand,
                                 log,
                                 filters=CustomFilters.owner_filter)
    repo_handler = CommandHandler(BotCommands.RepoCommand,
                                  repo,
                                  filters=CustomFilters.authorized_chat
                                  | CustomFilters.authorized_user)
    authlist_handler = CommandHandler(BotCommands.AuthListCommand,
                                      chat_list,
                                      filters=CustomFilters.owner_filter)
    dispatcher.add_handler(start_handler)
    dispatcher.add_handler(ping_handler)
    dispatcher.add_handler(restart_handler)
    dispatcher.add_handler(help_handler)
    dispatcher.add_handler(stats_handler)
    dispatcher.add_handler(log_handler)
    dispatcher.add_handler(repo_handler)
    dispatcher.add_handler(authlist_handler)
    updater.start_polling()
    LOGGER.info("Bot Started!")
    signal.signal(signal.SIGINT, fs_utils.exit_clean_up)
Пример #7
0
def main():

    start_handler = CommandHandler(BotCommands.StartCommand, start, filters=CustomFilters.authorized_chat | CustomFilters.authorized_user)
    log_handler = CommandHandler(BotCommands.LogCommand, log, filters=CustomFilters.owner_filter)

    dispatcher.add_handler(start_handler)
    dispatcher.add_handler(log_handler)

    updater.start_polling()
    LOGGER.info("Yeah I'm running!")
    updater.idle()
Пример #8
0
def main():
    LOGGER.info("Bot iniciado!")
    clone_handler = CommandHandler('clone', cloneNode)
    start_handler = CommandHandler('start', start)
    help_handler = CommandHandler('help', helper)
    log_handler = CommandHandler('logs', sendLogs)
    dispatcher.add_handler(log_handler)
    dispatcher.add_handler(start_handler)
    dispatcher.add_handler(clone_handler)
    dispatcher.add_handler(help_handler)
    updater.start_polling()
Пример #9
0
def main():
    dp.add_handler(CommandHandler("zoom", zoom))
    dp.add_handler(CommandHandler("help", help))
    if Config.SCHEDULE == 'True':
        zJobQueue()
        dp.add_handler(CommandHandler("timetable", timeTable))
    dp.add_handler(CommandHandler("disable_schedule", disable_schedule))
    dp.add_handler(CommandHandler("enable_schedule", enable_schedule))
    dp.add_handler(CommandHandler("exit", exit))
    dp.add_handler(CommandHandler("status", status))
    logging.info("Bot started")
    updater.start_polling()
Пример #10
0
def main():
    fs_utils.start_cleanup()
    # Check if the bot is restarting
    if os.path.isfile(".restartmsg"):
        with open(".restartmsg") as f:
            chat_id, msg_id = map(int, f)
        bot.edit_message_text("Restarted successfully!", chat_id, msg_id)
        os.remove(".restartmsg")
    bot.set_my_commands(botcmds)

    start_handler = CommandHandler(
        BotCommands.StartCommand,
        start,
        filters=CustomFilters.authorized_chat | CustomFilters.authorized_user,
        run_async=True,
    )
    ping_handler = CommandHandler(
        BotCommands.PingCommand,
        ping,
        filters=CustomFilters.authorized_chat | CustomFilters.authorized_user,
        run_async=True,
    )
    restart_handler = CommandHandler(
        BotCommands.RestartCommand,
        restart,
        filters=CustomFilters.owner_filter,
        run_async=True,
    )
    help_handler = CommandHandler(
        BotCommands.HelpCommand,
        bot_help,
        filters=CustomFilters.authorized_chat | CustomFilters.authorized_user,
        run_async=True,
    )
    stats_handler = CommandHandler(
        BotCommands.StatsCommand,
        stats,
        filters=CustomFilters.authorized_chat | CustomFilters.authorized_user,
        run_async=True,
    )
    log_handler = CommandHandler(BotCommands.LogCommand,
                                 log,
                                 filters=CustomFilters.owner_filter,
                                 run_async=True)
    dispatcher.add_handler(start_handler)
    dispatcher.add_handler(ping_handler)
    dispatcher.add_handler(restart_handler)
    dispatcher.add_handler(help_handler)
    dispatcher.add_handler(stats_handler)
    dispatcher.add_handler(log_handler)
    updater.start_polling(drop_pending_updates=IGNORE_PENDING_REQUESTS)
    LOGGER.info("Bot Started!")
    signal.signal(signal.SIGINT, fs_utils.exit_clean_up)
Пример #11
0
def main():
    logger.info('starting...')

    for modname in ('help', 'someone', 'alias', 'registeruser'):
        handlers = getattr(importlib.import_module(f'handlers.{modname}'),
                           'HANDLERS')
        logger.info('module imported: %s (handlers: %d)', modname,
                    len(handlers))
        for handler in handlers:
            dispatcher.add_handler(handler)

    updater.start_polling(clean=True)
    updater.idle()
Пример #12
0
def main():
    fs_utils.start_cleanup()
    # Check if the bot is restarting
    if path.exists('restart.pickle'):
        with open('restart.pickle', 'rb') as status:
            restart_message = pickle.load(status)
        restart_message.edit_text("Restarted Successfully!")
        LOGGER.info('Restarted Successfully!')
        remove('restart.pickle')
    bot.set_my_commands(botcmds)

    start_handler = CommandHandler(BotCommands.StartCommand,
                                   start,
                                   filters=CustomFilters.authorized_chat
                                   | CustomFilters.authorized_user)
    ping_handler = CommandHandler(BotCommands.PingCommand,
                                  ping,
                                  filters=CustomFilters.authorized_chat
                                  | CustomFilters.authorized_user)
    restart_handler = CommandHandler(BotCommands.RestartCommand,
                                     restart,
                                     filters=CustomFilters.owner_filter)
    help_handler = CommandHandler(BotCommands.HelpCommand,
                                  bot_help,
                                  filters=CustomFilters.authorized_chat
                                  | CustomFilters.authorized_user)
    stats_handler = CommandHandler(BotCommands.StatsCommand,
                                   stats,
                                   filters=CustomFilters.authorized_chat
                                   | CustomFilters.authorized_user)
    log_handler = CommandHandler(BotCommands.LogCommand,
                                 log,
                                 filters=CustomFilters.owner_filter)
    repo_handler = CommandHandler(BotCommands.RepoCommand,
                                  repo,
                                  filters=CustomFilters.authorized_chat
                                  | CustomFilters.authorized_user)
    authlist_handler = CommandHandler(BotCommands.AuthListCommand,
                                      chat_list,
                                      filters=CustomFilters.owner_filter)
    dispatcher.add_handler(start_handler)
    dispatcher.add_handler(ping_handler)
    dispatcher.add_handler(restart_handler)
    dispatcher.add_handler(help_handler)
    dispatcher.add_handler(stats_handler)
    dispatcher.add_handler(log_handler)
    dispatcher.add_handler(repo_handler)
    dispatcher.add_handler(authlist_handler)
    updater.start_polling()
    LOGGER.info("Bot Started!")
    signal.signal(signal.SIGINT, fs_utils.exit_clean_up)
Пример #13
0
def main():
    fs_utils.start_cleanup()
    # Check if the bot is restarting
    if path.exists('restart.pickle'):
        with open('restart.pickle', 'rb') as status:
            restart_message = pickle.load(status)
        restart_message.edit_text("Restarted Successfully!")
        remove('restart.pickle')

    start_handler = CommandHandler(BotCommands.StartCommand,
                                   start,
                                   filters=CustomFilters.authorized_chat
                                   | CustomFilters.authorized_user)
    ping_handler = CommandHandler(BotCommands.PingCommand,
                                  ping,
                                  filters=CustomFilters.authorized_chat
                                  | CustomFilters.authorized_user)
    restart_handler = CommandHandler(BotCommands.RestartCommand,
                                     restart,
                                     filters=CustomFilters.owner_filter)
    help_handler = CommandHandler(BotCommands.HelpCommand,
                                  bot_help,
                                  filters=CustomFilters.authorized_chat
                                  | CustomFilters.authorized_user)
    stats_handler = CommandHandler(BotCommands.StatsCommand,
                                   stats,
                                   filters=CustomFilters.authorized_chat
                                   | CustomFilters.authorized_user)
    log_handler = CommandHandler(BotCommands.LogCommand,
                                 log,
                                 filters=CustomFilters.owner_filter)
    dispatcher.add_handler(start_handler)
    dispatcher.add_handler(ping_handler)
    dispatcher.add_handler(restart_handler)
    dispatcher.add_handler(help_handler)
    dispatcher.add_handler(stats_handler)
    dispatcher.add_handler(log_handler)
    if USE_WEBHOOKS:
        from bot import (BOT_TOKEN, WEBHOOK_PORT, WEBHOOK_HOST, WEBHOOK_URL)
        updater.start_webhook(
            listen=WEBHOOK_HOST,
            # (c) https://t.me/c/1186975633/22915
            port=WEBHOOK_PORT,
            url_path=BOT_TOKEN)
        updater.bot.set_webhook(url=WEBHOOK_URL + "/" + BOT_TOKEN)
    else:
        updater.start_polling()
    LOGGER.info("Bot Started!")
    signal.signal(signal.SIGINT, fs_utils.exit_clean_up)
Пример #14
0
def main():
    LOGGER.info("Bot Started!")
    clone_handler = CommandHandler('copy', cloneNode)
    start_handler = CommandHandler('start', start)
    help_handler = CommandHandler('hellp', helper)
    log_handler = CommandHandler('logs', sendLogs)
    sas_handler = CommandHandler('config', dl_sas)
    helpp_handler = CommandHandler('help', helpp)
    dispatcher.add_handler(helpp_handler)
    dispatcher.add_handler(sas_handler)
    dispatcher.add_handler(log_handler)
    dispatcher.add_handler(start_handler)
    dispatcher.add_handler(clone_handler)
    dispatcher.add_handler(help_handler)
    updater.start_polling()
Пример #15
0
def main():
    setattr(updater.bot, 'restart', start)

    dispatcher = updater.dispatcher
    dispatcher.add_handler(CommandHandler('start', start))
    dispatcher.add_handler(admin_menu)
    dispatcher.add_handler(connect_conversation)
    dispatcher.add_handler(MessageHandler(Filters.all, clean))
    dispatcher.add_error_handler(error)

    updater.start_polling()
    logging.info("Bot started!")

    updater.idle()
    logging.info("Turned off.")
Пример #16
0
def main():
    logger.info('adding special priority handler...')
    dispatcher.add_handler(PRIORITY_HANDLER, group=0)

    logger.info('registering handlers...')
    for modname in HANDLERS:
        handlers = getattr(importlib.import_module('bot.handlers.{}'.format(modname)), 'HANDLERS')
        logger.info('importing module: %s (handlers: %d)', modname, len(handlers))
        for handler in handlers:
            dispatcher.add_handler(handler, group=1)

    dispatcher.add_error_handler(error_callback)

    logger.info('starting polling loop as @%s...', updater.bot.username)
    updater.start_polling(clean=True)
    updater.idle()
Пример #17
0
def main():
    fs_utils.start_cleanup()
    # Check if the bot is restarting
    if path.exists('restart.pickle'):
        with open('restart.pickle', 'rb') as status:
            restart_message = pickle.load(status)
        restart_message.edit_text("Restarted Successfully!")
        remove('restart.pickle')

    def getConfig(name: str):
        return environ[name]

    DOWNLOAD_DIR = getConfig('DOWNLOAD_DIR')
    mkdir(DOWNLOAD_DIR)
    LOGGER.info(f'Created Directory {DOWNLOAD_DIR}')

    start_handler = CommandHandler(BotCommands.StartCommand,
                                   start,
                                   filters=CustomFilters.authorized_chat
                                   | CustomFilters.authorized_user)
    ping_handler = CommandHandler(BotCommands.PingCommand,
                                  ping,
                                  filters=CustomFilters.authorized_chat
                                  | CustomFilters.authorized_user)
    restart_handler = CommandHandler(BotCommands.RestartCommand,
                                     restart,
                                     filters=CustomFilters.owner_filter)
    help_handler = CommandHandler(BotCommands.HelpCommand,
                                  bot_help,
                                  filters=CustomFilters.authorized_chat
                                  | CustomFilters.authorized_user)
    stats_handler = CommandHandler(BotCommands.StatsCommand,
                                   stats,
                                   filters=CustomFilters.authorized_chat
                                   | CustomFilters.authorized_user)
    log_handler = CommandHandler(BotCommands.LogCommand,
                                 log,
                                 filters=CustomFilters.owner_filter)
    dispatcher.add_handler(start_handler)
    dispatcher.add_handler(ping_handler)
    dispatcher.add_handler(restart_handler)
    dispatcher.add_handler(help_handler)
    dispatcher.add_handler(stats_handler)
    dispatcher.add_handler(log_handler)
    updater.start_polling()
    LOGGER.info("Bot Started!")
    signal.signal(signal.SIGINT, fs_utils.exit_clean_up)
Пример #18
0
def main():
    bot.set_my_commands(botcmds)
    start_handler = CommandHandler(BotCommands.StartCommand,
                                   start,
                                   run_async=True)
    log_handler = CommandHandler(BotCommands.LogCommand,
                                 log,
                                 filters=CustomFilters.owner_filter,
                                 run_async=True)

    dispatcher.add_handler(start_handler)
    dispatcher.add_handler(log_handler)

    updater.start_polling(drop_pending_updates=True)
    LOGGER.info("Yeah I'm running!")
    signal.signal(signal.SIGINT, exit(1))
    updater.idle()
Пример #19
0
def main():
    j = updater.job_queue

    dp.add_handler(CommandHandler("zoom", zoom))
    dp.add_handler(CommandHandler("meet", meet))

    if Config.SCHEDULE == True:
        mJobQueue()
        zJobQueue()
        dp.add_handler(CommandHandler("timetable", timeTable))

    dp.add_handler(CommandHandler("exit", exit))
    dp.add_handler(CommandHandler("status", status))
    dp.add_handler(CommandHandler("help", help))
    logging.info("Bot started")

    updater.start_polling()
Пример #20
0
def main():
    fs_utils.start_cleanup()
    # Check if the bot is restarting
    if path.exists('restart.pickle'):
        with open('restart.pickle', 'rb') as status:
            restart_message = pickle.load(status)
        restart_message.edit_text("Restarted Successfully!")
        remove('restart.pickle')

    start_handler = CommandHandler(BotCommands.StartCommand,
                                   start,
                                   run_async=True)
    ping_handler = CommandHandler(BotCommands.PingCommand,
                                  ping,
                                  filters=CustomFilters.authorized_chat
                                  | CustomFilters.authorized_user,
                                  run_async=True)
    restart_handler = CommandHandler(BotCommands.RestartCommand,
                                     restart,
                                     filters=CustomFilters.owner_filter
                                     | CustomFilters.sudo_user,
                                     run_async=True)
    help_handler = CommandHandler(BotCommands.HelpCommand,
                                  bot_help,
                                  filters=CustomFilters.authorized_chat
                                  | CustomFilters.authorized_user,
                                  run_async=True)
    stats_handler = CommandHandler(BotCommands.StatsCommand,
                                   stats,
                                   filters=CustomFilters.authorized_chat
                                   | CustomFilters.authorized_user,
                                   run_async=True)
    log_handler = CommandHandler(BotCommands.LogCommand,
                                 log,
                                 filters=CustomFilters.owner_filter
                                 | CustomFilters.sudo_user,
                                 run_async=True)
    dispatcher.add_handler(start_handler)
    dispatcher.add_handler(ping_handler)
    dispatcher.add_handler(restart_handler)
    dispatcher.add_handler(help_handler)
    dispatcher.add_handler(stats_handler)
    dispatcher.add_handler(log_handler)
    updater.start_polling()
    LOGGER.info("Yeah I'm running!")
    signal.signal(signal.SIGINT, fs_utils.exit_clean_up)
Пример #21
0
def main():
    fs_utils.start_cleanup()
    # Check if the bot is restarting
    if path.exists('restart.pickle'):
        with open('restart.pickle', 'rb') as status:
            restart_message = pickle.load(status)
        restart_message.edit_text("Restarted Successfully!")
        remove('restart.pickle')

    start_handler = CommandHandler(BotCommands.StartCommand, start,
                                   filters=CustomFilters.authorized_chat | CustomFilters.authorized_user)
    help_handler = CommandHandler(BotCommands.HelpCommand,
                                  bot_help, filters=CustomFilters.authorized_chat | CustomFilters.authorized_user)
    dispatcher.add_handler(start_handler)
    dispatcher.add_handler(help_handler)
    updater.start_polling()
    LOGGER.info("Bot Started!")
    signal.signal(signal.SIGINT, fs_utils.exit_clean_up)
Пример #22
0
def main():
    start_handler = CommandHandler(BotCommands.StartCommand, start,
                                   filters=CustomFilters.authorized_chat | CustomFilters.authorized_user)
    ping_handler = CommandHandler(BotCommands.PingCommand, ping,
                                  filters=CustomFilters.authorized_chat | CustomFilters.authorized_user)
    help_handler = CommandHandler(BotCommands.HelpCommand,
                                  bot_help, filters=CustomFilters.authorized_chat | CustomFilters.authorized_user)
    stats_handler = CommandHandler(BotCommands.StatsCommand,
                                   stats, filters=CustomFilters.authorized_chat | CustomFilters.authorized_user)
    log_handler = CommandHandler(BotCommands.LogCommand, log, filters=CustomFilters.owner_filter)
    dispatcher.add_handler(start_handler)
    dispatcher.add_handler(ping_handler)
    dispatcher.add_handler(help_handler)
    dispatcher.add_handler(stats_handler)
    dispatcher.add_handler(log_handler)
    updater.start_polling()
    LOGGER.info("Bot Started!")
    signal.signal(signal.SIGINT, fs_utils.exit_clean_up)
Пример #23
0
def main():
    # bot.set_my_commands(botcmds)
    start_cleanup()
    if IS_VPS:
        asyrun(start_server_async(PORT))
    # Check if the bot is restarting
    if ospath.isfile(".restartmsg"):
        with open(".restartmsg") as f:
            chat_id, msg_id = map(int, f)
        bot.edit_message_text("Restarted successfully!", chat_id, msg_id)
        osremove(".restartmsg")
    elif OWNER_ID:
        try:
            text = "<b>Bot Restarted!</b>"
            bot.sendMessage(chat_id=OWNER_ID, text=text, parse_mode=ParseMode.HTML)
            if AUTHORIZED_CHATS:
                for i in AUTHORIZED_CHATS:
                    bot.sendMessage(chat_id=i, text=text, parse_mode=ParseMode.HTML)
        except Exception as e:
            LOGGER.warning(e)

    start_handler = CommandHandler(BotCommands.StartCommand, start, run_async=True)
    ping_handler = CommandHandler(BotCommands.PingCommand, ping,
                                  filters=CustomFilters.authorized_chat | CustomFilters.authorized_user, run_async=True)
    restart_handler = CommandHandler(BotCommands.RestartCommand, restart,
                                     filters=CustomFilters.owner_filter | CustomFilters.sudo_user, run_async=True)
    help_handler = CommandHandler(BotCommands.HelpCommand,
                                  bot_help, filters=CustomFilters.authorized_chat | CustomFilters.authorized_user, run_async=True)
    stats_handler = CommandHandler(BotCommands.StatsCommand,
                                   stats, filters=CustomFilters.authorized_chat | CustomFilters.authorized_user, run_async=True)
    log_handler = CommandHandler(BotCommands.LogCommand, log, filters=CustomFilters.owner_filter | CustomFilters.sudo_user, run_async=True)
    dispatcher.add_handler(start_handler)
    dispatcher.add_handler(ping_handler)
    dispatcher.add_handler(restart_handler)
    dispatcher.add_handler(help_handler)
    dispatcher.add_handler(stats_handler)
    dispatcher.add_handler(log_handler)
    updater.start_polling(drop_pending_updates=IGNORE_PENDING_REQUESTS)
    LOGGER.info("Bot Started!")
    signal.signal(signal.SIGINT, exit_clean_up)
    if rss_session is not None:
        rss_session.start()
Пример #24
0
def main():
    logger.info('registering handlers...')
    for modname in HANDLERS:
        handlers = getattr(
            importlib.import_module('bot.handlers.{}'.format(modname)),
            'HANDLERS')
        logger.info('importing module: %s (handlers: %d)', modname,
                    len(handlers))
        for handler in handlers:
            dispatcher.add_handler(handler, group=1)

    dispatcher.add_error_handler(error_callback)

    jobs.run_repeating(fetch_releases,
                       interval=config.tntvillage.update_frequency,
                       first=config.tntvillage.first_job_after)

    logger.info('starting polling loop...')
    updater.start_polling(clean=True)
    updater.idle()
Пример #25
0
def main():
    test_handler = CommandHandler("test", test)
    start_handler = CommandHandler("start", start, pass_args=True)

    help_handler = CommandHandler("help", get_help)
    help_callback_handler = CallbackQueryHandler(help_button, pattern=r"help_")

    settings_handler = CommandHandler("settings", get_settings)
    settings_callback_handler = CallbackQueryHandler(settings_button,
                                                     pattern=r"stngs_")

    donate_handler = CommandHandler("donate", donate)
    migrate_handler = MessageHandler(Filters.status_update.migrate,
                                     migrate_chats)

    # dispatcher.add_handler(test_handler)
    dispatcher.add_handler(start_handler)
    dispatcher.add_handler(help_handler)
    dispatcher.add_handler(settings_handler)
    dispatcher.add_handler(help_callback_handler)
    dispatcher.add_handler(settings_callback_handler)
    dispatcher.add_handler(migrate_handler)
    dispatcher.add_handler(donate_handler)

    dispatcher.add_error_handler(error_callback)

    if WEBHOOK:
        LOGGER.info("Using webhooks.")
        updater.start_webhook(listen="127.0.0.1", port=PORT, url_path=TOKEN)

        if CERT_PATH:
            updater.bot.set_webhook(url=URL + TOKEN,
                                    certificate=open(CERT_PATH, 'rb'))
        else:
            updater.bot.set_webhook(url=URL + TOKEN)

    else:
        LOGGER.info("Using long polling.")
        updater.start_polling(timeout=15, read_latency=4, clean=True)

    updater.idle()
Пример #26
0
def main():
    start_handler = CommandHandler(BotCommand.StartCommand, start)
    dispatcher.add_handler(start_handler)

    hello_handler = CommandHandler('hello', hello)
    dispatcher.add_handler(hello_handler)

    help_handler = CommandHandler(BotCommand.HelpCommand, help_message)
    dispatcher.add_handler(help_handler)

    latest_handler = CommandHandler(BotCommand.LatestCommand, latest)
    dispatcher.add_handler(latest_handler)

    add_show_handler = CommandHandler(BotCommand.AddCommand, add_show)
    dispatcher.add_handler(add_show_handler)

    add_show_handler = CommandHandler(BotCommand.MyShowsCommand, add_show)
    dispatcher.add_handler(add_show_handler)

    remove_show_handler = CommandHandler(BotCommand.RemoveCommand, remove_show)
    dispatcher.add_handler(remove_show_handler)

    list_match_handler = CommandHandler(BotCommand.ListCommand, list_match)
    dispatcher.add_handler(list_match_handler)

    quality_handler = CommandHandler(BotCommand.SetQualityCommand, set_quality)
    dispatcher.add_handler(quality_handler)

    reset_handler = CommandHandler(BotCommand.ResetCommand, reset)
    dispatcher.add_handler(reset_handler)

    daemon_handler = CommandHandler(BotCommand.RunCommand, daemon, pass_job_queue=True)
    dispatcher.add_handler(daemon_handler)

    stop_handler = CommandHandler(BotCommand.StopCommand, stop_daemon, pass_job_queue=True)
    dispatcher.add_handler(stop_handler)

    dispatcher.add_error_handler(error_handler)

    updater.start_polling()
    updater.idle()
Пример #27
0
def main():
    fs_utils.start_cleanup()
    # Check if the bot is restarting
    if path.exists('restart.pickle'):
        with open('restart.pickle', 'rb') as status:
            restart_message = pickle.load(status)
        restart_message.edit_text("Khởi động lại máy chủ thành công!")
        remove('restart.pickle')

    start_handler = CommandHandler(BotCommands.StartCommand,
                                   start,
                                   filters=CustomFilters.authorized_chat
                                   | CustomFilters.authorized_user)
    ping_handler = CommandHandler(BotCommands.PingCommand,
                                  ping,
                                  filters=CustomFilters.authorized_chat
                                  | CustomFilters.authorized_user)
    restart_handler = CommandHandler(BotCommands.RestartCommand,
                                     restart,
                                     filters=CustomFilters.owner_filter)
    help_handler = CommandHandler(BotCommands.HelpCommand,
                                  bot_help,
                                  filters=CustomFilters.authorized_chat
                                  | CustomFilters.authorized_user)
    stats_handler = CommandHandler(BotCommands.StatsCommand,
                                   stats,
                                   filters=CustomFilters.authorized_chat
                                   | CustomFilters.authorized_user)
    log_handler = CommandHandler(BotCommands.LogCommand,
                                 log,
                                 filters=CustomFilters.owner_filter)
    dispatcher.add_handler(start_handler)
    dispatcher.add_handler(ping_handler)
    dispatcher.add_handler(restart_handler)
    dispatcher.add_handler(help_handler)
    dispatcher.add_handler(stats_handler)
    dispatcher.add_handler(log_handler)
    updater.start_polling()
    LOGGER.info("Bot Started!")
    signal.signal(signal.SIGINT, fs_utils.exit_clean_up)
Пример #28
0
def main():

    # Check if the bot is restarting
    if path.exists('restart.pickle'):
        with open('restart.pickle', 'rb') as status:
            restart_message = pickle.load(status)
        restart_message.edit_text("Restarted Successfully!")
        remove('restart.pickle')

    start_handler = CommandHandler(BotCommands.StartCommand,
                                   start,
                                   filters=CustomFilters.authorized_chat
                                   | CustomFilters.authorized_user)
    ping_handler = CommandHandler(BotCommands.PingCommand,
                                  ping,
                                  filters=CustomFilters.authorized_chat
                                  | CustomFilters.authorized_user)

    help_handler = CommandHandler(BotCommands.HelpCommand,
                                  bot_help,
                                  filters=CustomFilters.authorized_chat
                                  | CustomFilters.authorized_user)
    stats_handler = CommandHandler(BotCommands.StatsCommand,
                                   stats,
                                   filters=CustomFilters.authorized_chat
                                   | CustomFilters.authorized_user)
    log_handler = CommandHandler(BotCommands.LogCommand,
                                 log,
                                 filters=CustomFilters.owner_filter)
    dispatcher.add_handler(start_handler)
    dispatcher.add_handler(ping_handler)
    #    dispatcher.add_handler(restart_handler)
    dispatcher.add_handler(help_handler)
    dispatcher.add_handler(stats_handler)
    dispatcher.add_handler(log_handler)
    updater.start_polling()
    LOGGER.info("Bot Started!")
Пример #29
0
def main(hook=False):

    from bot import updater
    init()

    if not hook:
        updater.start_polling()
    else:
        WEBHOOK_HOST = sys.argv[3]
        WEBHOOK_PORT = 443  # 443, 80, 88 или 8443
        WEBHOOK_LISTEN = '0.0.0.0'

        WEBHOOK_SSL_CERT = './webhook_cert.pem'
        WEBHOOK_SSL_PRIV = './webhook_pkey.pem'

        WEBHOOK_URL = "https://%s:%d/%s" % (WEBHOOK_HOST, WEBHOOK_PORT,
                                            sys.argv[1])

        updater.start_webhook(listen=WEBHOOK_LISTEN,
                              port=WEBHOOK_PORT,
                              url_path=sys.argv[1],
                              cert=WEBHOOK_SSL_CERT,
                              key=WEBHOOK_SSL_PRIV,
                              webhook_url='%s' % WEBHOOK_URL)
Пример #30
0
def start_bot():
    from bot import updater
    updater.start_polling()
    updater.idle()
Пример #31
0
#!/usr/bin/env python
import argparse

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("command", help="", choices=[
        'start', 'send_photo', 'dbcreate'
    ])
    args = parser.parse_args()
    if args.command == 'start':
        from bot import updater
        updater.start_polling()

    if args.command == 'send_photo':
        from tgm import send_photo
        send_photo()

    if args.command == 'dbcreate':
        import models
        models.Base.metadata.create_all(models.engine)