コード例 #1
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")

    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)
    repo_handler = CommandHandler(BotCommands.RepoCommand,
                                  repo,
                                  filters=CustomFilters.authorized_chat
                                  | CustomFilters.authorized_user,
                                  run_async=True)
    authlist_handler = CommandHandler(BotCommands.AuthListCommand,
                                      chat_list,
                                      filters=CustomFilters.owner_filter,
                                      run_async=True)
    config_handler = editor.handler
    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)
    dispatcher.add_handler(config_handler)
    updater.start_polling()
    LOGGER.info("Bot Started!")
    signal.signal(signal.SIGINT, fs_utils.exit_clean_up)
コード例 #2
0
def main():
    fs_utils.start_cleanup()
    # Check if the bot is restarting
    if path.exists('restart_msg.txt'):
        restart_msg_dat = open('restart_msg.txt', 'rt').read().split(' ')
        bot.editMessageText(text='Sync Completed!\nRestarted Successfully!',
                            chat_id=restart_msg_dat[0],
                            message_id=restart_msg_dat[1])
        LOGGER.info('Restarted Successfully!')
        remove('restart_msg.txt')
    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)
    repo_handler = CommandHandler(BotCommands.RepoCommand,
                                  repo,
                                  filters=CustomFilters.authorized_chat
                                  | CustomFilters.authorized_user,
                                  run_async=True)
    owner_handler = CommandHandler(BotCommands.OwnerCommand,
                                   owner,
                                   filters=CustomFilters.authorized_chat
                                   | CustomFilters.authorized_user,
                                   run_async=True)
    config_handler = editor.handler
    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(owner_handler)
    dispatcher.add_handler(config_handler)
    updater.start_polling()
    LOGGER.info("Bot Started!")
    signal.signal(signal.SIGINT, fs_utils.exit_clean_up)