Exemplo n.º 1
0
def launch():
    if environ['DEVELOPMENT']:
        launch_ip = servers.get_least_popular_server()
    else:
        launch_ip = servers.get_most_popular_server()

    if not os.path.isfile(config.DF_EXE_PATH):
        logging.info("Could not find engine or it was not provided. You will have to start the engine and the bot manually. ")
        return None

    # Make sure to set proper CWD when using subprocess.Popen from another directory
    # iDFe will automatically take focus when launching
    subprocess.Popen(args=[config.DF_EXE_PATH, "+cl_title", "TwitchBot Engine", "+con_title", "TwitchBot Console", "+connect", launch_ip], cwd=os.path.dirname(config.DF_EXE_PATH))
Exemplo n.º 2
0
def launch():
    connect_ip = servers.get_most_popular_server()

    if not os.path.isfile(config.DF_EXE_P):
        print(
            "Could not find engine or it was not provided. You will have to start the engine and the bot manually. "
        )
        return None

    # Make sure to set proper CWD when using subprocess.Popen from another directory
    # iDFe will automatically take focus when launching
    process = subprocess.Popen(args=[config.DF_EXE_P, "+map", "q3ctf1"],
                               stdout=subprocess.PIPE,
                               creationflags=0x08000000,
                               cwd=os.path.dirname(config.DF_EXE_P))
Exemplo n.º 3
0
def check_status():
    global SERVER
    global STOP_STATE

    MAX_STRIKES = 10  # TODO: move this over to configurable setting by user
    continue_refresh = True
    spectating_self = SERVER.curr_dfn == 'twitchbot'
    spectating_nospec = SERVER.current_player_id not in SERVER.spec_ids

    if spectating_self or spectating_nospec:
        follow_id = random.choice(
            SERVER.spec_ids) if SERVER.spec_ids != [] else -1

        if follow_id != -1:
            msg = "Spectating self, switching..." if spectating_self else "Switching to non-nospec player..."
            print(colored(msg, 'green'))
            display_player_name(follow_id)
            api.exec_command(f"follow {follow_id}")
            SERVER.idle_counter = 0
        else:
            if SERVER.current_player_id != -1:
                api.exec_command(f"follow {follow_id}", verbose=False)
                SERVER.current_player_id = -1

            SERVER.idle_counter += 1
            print(
                f"Not spectating. Strike {SERVER.idle_counter}/{MAX_STRIKES}")

            if SERVER.idle_counter >= MAX_STRIKES:  # There's been no one on the server to spec, switch servers.
                new_ip = servers.get_most_popular_server(ignore_ip=SERVER.ip)
                STOP_STATE.set()
                connection_success = connect(new_ip)
                return connection_success  # if false, continue working as normal. Else, stop refresh.
        SERVER.current_player_id = follow_id

    return continue_refresh
Exemplo n.º 4
0
async def event_message(ctx):
    """Activates for every message"""
    debounce = 1  # interval between consecutive commands and messages
    author = ctx.author.name
    message = ctx.content

    if ";" in message:  # prevent q3 command injections
        message = message[:message.index(";")]

    # bot.py, at the bottom of event_message
    if message.startswith("?"):  # spectator client customization and controls
        message = message.strip('?').lower()
        split_msg = message.split(' ')
        cmd = split_msg[0]
        args = split_msg[1:] if len(split_msg) > 0 else None
        print("Command received:", cmd)

        if cmd == "connect":
            serverstate.connect(args[0])
        elif cmd == "restart":
            connect_ip = servers.get_most_popular_server()
            api.press_key_mult("{Esc}", 2)
            api.press_key("{Enter}")
            api.press_key_mult("{Tab}", 10)
            api.press_key("{Enter}")
            time.sleep(1)
            serverstate.connect(connect_ip)
        elif cmd == "next":
            serverstate.switch_spec('next')
        elif cmd == "prev":
            serverstate.switch_spec('prev')
        elif cmd == "scores":
            api.hold_key(config.get_bind("+scores"), 3.5)
        elif cmd == "clear":
            api.press_key(config.get_bind_fuzzy("clear"))
        elif cmd == "triggers":
            api.press_key(config.get_bind_fuzzy("scr_triggers_draw"))
        elif cmd == "clips":
            api.press_key(config.get_bind_fuzzy("scr_clips_draw"))
        elif cmd == "snaps":
            api.press_key(config.get_bind_fuzzy("mdd_snap"))
        elif cmd == "cgaz":
            api.press_key(config.get_bind_fuzzy("mdd_cgaz"))
        elif cmd == "checkpoints":
            api.press_key(config.get_bind_fuzzy("df_checkpoints"))
        elif cmd == "nodraw":
            api.press_key(config.get_bind_fuzzy("df_mp_NoDrawRadius"))
        elif cmd == "angles":
            api.press_key(config.get_bind("toggle df_chs1_Info6 0 40"))
        elif cmd == "obs":
            api.press_key(config.get_bind("toggle df_chs1_Info7 0 50"))
        elif cmd == "clean":
            api.press_key(config.get_bind_fuzzy("cg_draw2D"))
        elif cmd == "sky":
            api.press_key(config.get_bind_fuzzy("r_fastsky"))
        elif cmd == "vote":
            api.press_key(config.get_bind(f"vote {args[0]}"))
        elif cmd == "speedinfo":
            api.press_key(config.get_bind("toggle df_chs1_Info5 0 1"))
        elif cmd == "speedorig":
            api.press_key(config.get_bind_fuzzy("df_drawSpeed"))
        elif cmd == "huds":
            api.press_key(config.get_bind("toggle mdd_hud 0 1"))
        elif cmd == "inputs":
            api.press_key(config.get_bind_fuzzy("df_chs0_draw"))
        elif cmd == "n1":
            api.exec_command(
                api.exec_command(
                    f"varcommand say ^{author[0]}{author} ^7> ^2Nice one, $chsinfo(117) ^2!"
                ))

        # Mod commands
        elif cmd == "brightness":
            if not ctx.author.is_mod:
                await ctx.channel.send(
                    f"{author}, you do not have the correct permissions to use this command."
                )
                return
            value = args[0]
            if value.isdigit() and (0 < int(value) <= 5):
                api.exec_command(f"r_mapoverbrightbits {value};vid_restart")
            else:
                await ctx.channel.send(
                    f" {author}, the valid values for brightness are 1-5.")
        elif cmd == "picmip":
            if not ctx.author.is_mod:
                await ctx.channel.send(
                    f"{author}, you do not have the correct permissions to use this command."
                )
                return
            value = args[0]
            if value.isdigit() and (0 <= int(value) <= 6):
                api.exec_command(f"r_picmip {value};vid_restart")
            else:
                await ctx.channel.send(
                    f"{author}, the allowed values for picmip are 0-5.")

        # Currently disabled. Possibly useful for the future:

        # elif cmd == "cgaz":
        #     mode = args[0] if len(args) > 0 and 0 < int(args[0]) <= 15 else "toggle"
        #     if mode == "toggle":
        #         api.press_key(config.get_bind("toggle mdd_cgaz 0 1"))
        #     else:
        #         api.exec_command(f"df_hud_cgaz {mode}")

        # elif cmd == "cv" and "kick" not in message:
        #     api.exec_command(f"{message}")

        time.sleep(debounce)

    elif message.startswith(">") or message.startswith("<"):  # chat bridge
        if author.lower() == 'nightbot'.lower(
        ):  # ignore twitch Nightbot's name
            author = ''
            author_color_char = 0
        else:
            author += ' ^7> '
            author_color_char = author[0]
        message = message.lstrip('>').lstrip('<')
        api.exec_command(f"say ^{author_color_char}{author} ^2{message}")
        print("Chat message sent")
        time.sleep(debounce)

    elif message.startswith("!"):  # proxy mod commands (!top, !rank, etc.)
        print("proxy command received")
        api.exec_command(message)
        time.sleep(debounce)

    return
Exemplo n.º 5
0
            break
        except:
            if input(
                    "Your DeFRaG engine is not running. Would you like us to launch it for you? [Y/n]: "
            ).lower() == "y":
                launch()
                time.sleep(2)

    logfile_path = config.DF_DIR + '\\qconsole.log'
    con_process = threading.Thread(target=console.read,
                                   args=(logfile_path, ),
                                   daemon=True)
    con_process.start()

    flask_process = threading.Thread(target=app.run, daemon=True)
    flask_process.start()

    ws_loop = asyncio.new_event_loop()
    ws_process = threading.Thread(target=ws_worker,
                                  args=(
                                      console.WS_Q,
                                      ws_loop,
                                  ),
                                  daemon=True)
    ws_process.start()

    connect_ip = servers.get_most_popular_server()
    serverstate.connect(connect_ip)

    bot.run()
Exemplo n.º 6
0
async def restart(ctx, author, args):
    serverstate.IGNORE_IPS = []
    connect_ip = servers.get_most_popular_server()
    serverstate.connect(connect_ip)