from bot import loaded_modules_dict from bot import telnet_prefixes from os import path, pardir module_name = path.basename(path.normpath(path.join(path.abspath(__file__), pardir, pardir))) trigger_name = path.basename(path.abspath(__file__))[:-3] def main_function(origin_module, module, regex_result): command = regex_result.group("command") active_dataset = module.dom.data.get("module_game_environment", {}).get("active_dataset", None) player_steamid = regex_result.group("player_steamid") existing_player_dict = ( module.dom.data .get("module_players", {}) .get("elements", {}) .get(active_dataset, {}) .get(player_steamid, None) ) if command == "connected": # we want to mute completely new players and players that are not authenticated on login. if existing_player_dict is not None: default_player_password = module.default_options.get("default_player_password", None) player_is_authenticated = existing_player_dict.get("is_authenticated", False) if not player_is_authenticated and default_player_password is not None: is_muted = True else: is_muted = False event_data = ['set_player_mute', { 'dataset': module.dom.data.get("module_game_environment", {}).get("active_dataset", None), 'player_steamid': player_steamid, 'is_muted': is_muted }] module.trigger_action_hook(origin_module, event_data=event_data) trigger_meta = { "description": "reacts to telnets player discovery messages for real time responses!", "main_function": main_function, "triggers": [ { "regex": ( telnet_prefixes["telnet_log"]["timestamp"] + r"\[Steamworks.NET\]\s" r"(?P.*)\s" r"player:\s(?P.*)\s" r"SteamId:\s(?P\d+)\s(.*)" ), "callback": main_function }, { "regex": ( telnet_prefixes["telnet_log"]["timestamp"] + r"Player\s" r"(?P.*), " r"entityid=(?P.*), " r"name=(?P.*), " r"steamid=(?P.*), " r"steamOwner=(?P.*), " r"ip=(?P.*)" ), "callback": main_function } ] } loaded_modules_dict["module_" + module_name].register_trigger(trigger_name, trigger_meta)