Release 0.9.0
This commit is contained in:
64
bot/modules/locations/commands/add_location.py
Normal file
64
bot/modules/locations/commands/add_location.py
Normal file
@@ -0,0 +1,64 @@
|
||||
from bot import loaded_modules_dict
|
||||
from bot import telnet_prefixes
|
||||
from os import path, pardir
|
||||
import re
|
||||
|
||||
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")
|
||||
steamid = regex_result.group("player_steamid")
|
||||
|
||||
result = re.match(r"^.*add\slocation\s(?P<location_name>.*)", command)
|
||||
if result:
|
||||
location_name = result.group("location_name")
|
||||
|
||||
active_dataset = module.dom.data.get("module_game_environment", {}).get("active_dataset", None)
|
||||
|
||||
player_dict = module.dom.data.get("module_players", {}).get("elements", {}).get(active_dataset, {}).get(steamid, {})
|
||||
if len(player_dict) >= 1 and result:
|
||||
event_data = ['edit_location', {
|
||||
'location_coordinates': {
|
||||
"x": player_dict["pos"]["x"],
|
||||
"y": player_dict["pos"]["y"],
|
||||
"z": player_dict["pos"]["z"]
|
||||
},
|
||||
'location_name': location_name,
|
||||
'action': 'create_new',
|
||||
'last_changed': module.game_environment.get_last_recorded_gametime_string()
|
||||
}]
|
||||
module.trigger_action_hook(origin_module, event_data=event_data, dispatchers_steamid=steamid)
|
||||
|
||||
|
||||
triggers = {
|
||||
"add location": r"\'(?P<player_name>.*)\'\:\s(?P<command>\/add location.*)"
|
||||
}
|
||||
|
||||
trigger_meta = {
|
||||
"description": "catches location commands from the players chat and then adds them to the database",
|
||||
"main_function": main_function,
|
||||
"triggers": [
|
||||
{
|
||||
"identifier": "add location (Alloc)",
|
||||
"regex": (
|
||||
telnet_prefixes["telnet_log"]["timestamp"] +
|
||||
telnet_prefixes["Allocs"]["chat"] +
|
||||
triggers["add location"]
|
||||
),
|
||||
"callback": main_function
|
||||
},
|
||||
{
|
||||
"identifier": "add location (BCM)",
|
||||
"regex": (
|
||||
telnet_prefixes["telnet_log"]["timestamp"] +
|
||||
telnet_prefixes["BCM"]["chat"] +
|
||||
triggers["add location"]
|
||||
),
|
||||
"callback": main_function
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
loaded_modules_dict["module_" + module_name].register_trigger(trigger_name, trigger_meta)
|
||||
77
bot/modules/locations/commands/export_location.py
Normal file
77
bot/modules/locations/commands/export_location.py
Normal file
@@ -0,0 +1,77 @@
|
||||
from bot import loaded_modules_dict
|
||||
from bot import telnet_prefixes
|
||||
from os import path, pardir
|
||||
import re
|
||||
|
||||
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")
|
||||
player_steamid = regex_result.group("player_steamid")
|
||||
|
||||
location_dict = None
|
||||
result = re.match(r"^.*export\slocation\s(?P<location_identifier>.*)(?:\s)?(?P<spawn_in_place>.*)?", command)
|
||||
if result:
|
||||
active_dataset = module.dom.data.get("module_game_environment", {}).get("active_dataset", None)
|
||||
location_identifier = result.group("location_identifier")
|
||||
location_dict = (
|
||||
module.dom.data.get("module_locations", {})
|
||||
.get("elements", {})
|
||||
.get(active_dataset, {})
|
||||
.get(player_steamid, {})
|
||||
.get(location_identifier, None)
|
||||
)
|
||||
location_name = location_dict.get("name")
|
||||
else:
|
||||
location_name = "None Provided"
|
||||
location_identifier = "None"
|
||||
|
||||
if location_dict is not None:
|
||||
event_data = ['bc-export', {
|
||||
"location_identifier": location_identifier
|
||||
}]
|
||||
module.trigger_action_hook(origin_module.locations, event_data=event_data, dispatchers_steamid=player_steamid)
|
||||
|
||||
else:
|
||||
event_data = ['say_to_player', {
|
||||
'steamid': player_steamid,
|
||||
'message': '[FFFFFF]Could not find [66FF66]{location_name} ({location_identifier})[-]'.format(
|
||||
location_name=location_name,
|
||||
location_identifier=location_identifier
|
||||
)
|
||||
}]
|
||||
module.trigger_action_hook(origin_module.players, event_data=event_data)
|
||||
|
||||
|
||||
triggers = {
|
||||
"export location": r"\'(?P<player_name>.*)\'\:\s(?P<command>\/export location.*)"
|
||||
}
|
||||
|
||||
trigger_meta = {
|
||||
"description": "will issue the BCM mods bc-export command on the specified location",
|
||||
"main_function": main_function,
|
||||
"triggers": [
|
||||
{
|
||||
"identifier": "export location",
|
||||
"regex": (
|
||||
telnet_prefixes["telnet_log"]["timestamp"] +
|
||||
telnet_prefixes["Allocs"]["chat"] +
|
||||
triggers["export location"]
|
||||
),
|
||||
"callback": main_function
|
||||
},
|
||||
{
|
||||
"identifier": "export location",
|
||||
"regex": (
|
||||
telnet_prefixes["telnet_log"]["timestamp"] +
|
||||
telnet_prefixes["BCM"]["chat"] +
|
||||
triggers["export location"]
|
||||
),
|
||||
"callback": main_function
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
loaded_modules_dict["module_" + module_name].register_trigger(trigger_name, trigger_meta)
|
||||
78
bot/modules/locations/commands/import_location.py
Normal file
78
bot/modules/locations/commands/import_location.py
Normal file
@@ -0,0 +1,78 @@
|
||||
from bot import loaded_modules_dict
|
||||
from bot import telnet_prefixes
|
||||
from os import path, pardir
|
||||
import re
|
||||
|
||||
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")
|
||||
player_steamid = regex_result.group("player_steamid")
|
||||
|
||||
location_dict = None
|
||||
spawn_in_place = False
|
||||
result = re.match(r"^.*import\slocation\s(?P<location_identifier>\S+)(?:\s)?(?P<spawn_in_place>here)?", command)
|
||||
if result:
|
||||
active_dataset = module.dom.data.get("module_game_environment", {}).get("active_dataset", None)
|
||||
location_identifier = result.group("location_identifier")
|
||||
location_dict = (
|
||||
module.dom.data
|
||||
.get("module_locations", {})
|
||||
.get("elements", {})
|
||||
.get(active_dataset, {})
|
||||
.get(player_steamid, {})
|
||||
.get(location_identifier, None)
|
||||
)
|
||||
spawn_in_place = result.group("spawn_in_place") == "here"
|
||||
|
||||
if location_dict is not None:
|
||||
event_data = ['bc-import', {
|
||||
"location_identifier": location_identifier,
|
||||
"spawn_in_place": spawn_in_place
|
||||
}]
|
||||
module.trigger_action_hook(origin_module.locations, event_data=event_data, dispatchers_steamid=player_steamid)
|
||||
|
||||
else:
|
||||
event_data = ['say_to_player', {
|
||||
'steamid': player_steamid,
|
||||
'message': '[FFFFFF]Could not find [66FF66]{location_name} ({location_identifier})[-]'.format(
|
||||
location_name="None Provided",
|
||||
location_identifier="None"
|
||||
)
|
||||
}]
|
||||
module.trigger_action_hook(origin_module.players, event_data=event_data)
|
||||
|
||||
|
||||
triggers = {
|
||||
"import location": r"\'(?P<player_name>.*)\'\:\s(?P<command>\/import location.*)"
|
||||
}
|
||||
|
||||
|
||||
trigger_meta = {
|
||||
"description": "will issue the BCM mods bc-import command on the specified location",
|
||||
"main_function": main_function,
|
||||
"triggers": [
|
||||
{
|
||||
"identifier": "import location (Allocs)",
|
||||
"regex": (
|
||||
telnet_prefixes["telnet_log"]["timestamp"] +
|
||||
telnet_prefixes["Allocs"]["chat"] +
|
||||
triggers["import location"]
|
||||
),
|
||||
"callback": main_function
|
||||
},
|
||||
{
|
||||
"identifier": "import location (BCM)",
|
||||
"regex": (
|
||||
telnet_prefixes["telnet_log"]["timestamp"] +
|
||||
telnet_prefixes["BCM"]["chat"] +
|
||||
triggers["import location"]
|
||||
),
|
||||
"callback": main_function
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
loaded_modules_dict["module_" + module_name].register_trigger(trigger_name, trigger_meta)
|
||||
59
bot/modules/locations/commands/send_me_home.py
Normal file
59
bot/modules/locations/commands/send_me_home.py
Normal file
@@ -0,0 +1,59 @@
|
||||
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):
|
||||
player_steamid = regex_result.group("player_steamid")
|
||||
|
||||
found_home = False
|
||||
location_dict = {}
|
||||
for home in origin_module.get_elements_by_type("is_home"):
|
||||
if home.get("owner") == player_steamid:
|
||||
location_dict = home
|
||||
found_home = True
|
||||
|
||||
if found_home is True and len(location_dict) >= 1:
|
||||
event_data = ['teleport_to_coordinates', {
|
||||
'location_coordinates': {
|
||||
"x": location_dict.get("teleport_entry", {}).get("x", location_dict["coordinates"]["x"]),
|
||||
"y": location_dict.get("teleport_entry", {}).get("y", location_dict["coordinates"]["y"]),
|
||||
"z": location_dict.get("teleport_entry", {}).get("z", location_dict["coordinates"]["z"])
|
||||
}
|
||||
}]
|
||||
module.trigger_action_hook(origin_module, event_data=event_data, dispatchers_steamid=player_steamid)
|
||||
|
||||
|
||||
triggers = {
|
||||
"send me home": r"\'(?P<player_name>.*)\'\:\s(?P<command>\/send\sme\shome)"
|
||||
}
|
||||
|
||||
trigger_meta = {
|
||||
"description": "sends the player to his home, if available",
|
||||
"main_function": main_function,
|
||||
"triggers": [
|
||||
{
|
||||
"identifier": "send me home",
|
||||
"regex": (
|
||||
telnet_prefixes["telnet_log"]["timestamp"] +
|
||||
telnet_prefixes["Allocs"]["chat"] +
|
||||
triggers["send me home"]
|
||||
),
|
||||
"callback": main_function
|
||||
},
|
||||
{
|
||||
"identifier": "send me home",
|
||||
"regex": (
|
||||
telnet_prefixes["telnet_log"]["timestamp"] +
|
||||
telnet_prefixes["BCM"]["chat"] +
|
||||
triggers["send me home"]
|
||||
),
|
||||
"callback": main_function
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
loaded_modules_dict["module_" + module_name].register_trigger(trigger_name, trigger_meta)
|
||||
102
bot/modules/locations/commands/send_me_to_location.py
Normal file
102
bot/modules/locations/commands/send_me_to_location.py
Normal file
@@ -0,0 +1,102 @@
|
||||
from bot import loaded_modules_dict
|
||||
from bot import telnet_prefixes
|
||||
from os import path, pardir
|
||||
import re
|
||||
|
||||
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")
|
||||
player_steamid = regex_result.group("player_steamid")
|
||||
|
||||
result = re.match(r"^.*send\sme\sto\slocation\s(?P<location_identifier>.*)", command)
|
||||
if result:
|
||||
location_identifier = result.group("location_identifier")
|
||||
else:
|
||||
return
|
||||
|
||||
active_dataset = module.dom.data.get("module_game_environment", {}).get("active_dataset", None)
|
||||
|
||||
location_dict = (
|
||||
module.dom.data.get("module_locations", {})
|
||||
.get("elements", {})
|
||||
.get(active_dataset, {})
|
||||
.get(player_steamid, {})
|
||||
.get(location_identifier, {})
|
||||
)
|
||||
|
||||
player_dict = (
|
||||
module.dom.data.get("module_players", {})
|
||||
.get("elements", {})
|
||||
.get(active_dataset, {})
|
||||
.get(player_steamid, {})
|
||||
)
|
||||
|
||||
if len(player_dict) >= 1 and len(location_dict) >= 1:
|
||||
teleport_entry = location_dict.get("teleport_entry", {})
|
||||
teleport_entry_x = teleport_entry.get("x", None)
|
||||
teleport_entry_y = teleport_entry.get("y", None)
|
||||
teleport_entry_z = teleport_entry.get("z", None)
|
||||
|
||||
if any([
|
||||
teleport_entry_x is None,
|
||||
teleport_entry_y is None,
|
||||
teleport_entry_z is None,
|
||||
all([
|
||||
int(teleport_entry_x) == 0,
|
||||
int(teleport_entry_y) == 0,
|
||||
int(teleport_entry_z) == 0,
|
||||
])
|
||||
]):
|
||||
location_coordinates = {
|
||||
"x": location_dict["coordinates"]["x"],
|
||||
"y": location_dict["coordinates"]["y"],
|
||||
"z": location_dict["coordinates"]["z"]
|
||||
}
|
||||
else:
|
||||
location_coordinates = {
|
||||
"x": teleport_entry_x,
|
||||
"y": teleport_entry_y,
|
||||
"z": teleport_entry_z
|
||||
}
|
||||
|
||||
event_data = ['teleport_to_coordinates', {
|
||||
'location_coordinates': location_coordinates
|
||||
}]
|
||||
module.trigger_action_hook(origin_module, event_data=event_data, dispatchers_steamid=player_steamid)
|
||||
|
||||
|
||||
triggers = {
|
||||
"send me to location": r"\'(?P<player_name>.*)\'\:\s(?P<command>\/send\sme\sto\slocation.*)"
|
||||
}
|
||||
|
||||
trigger_meta = {
|
||||
"description": (
|
||||
"sends player to the location of their choosing, will use the teleport_entry coordinates if available"
|
||||
),
|
||||
"main_function": main_function,
|
||||
"triggers": [
|
||||
{
|
||||
"identifier": "add location (Alloc)",
|
||||
"regex": (
|
||||
telnet_prefixes["telnet_log"]["timestamp"] +
|
||||
telnet_prefixes["Allocs"]["chat"] +
|
||||
triggers["send me to location"]
|
||||
),
|
||||
"callback": main_function
|
||||
},
|
||||
{
|
||||
"identifier": "add location (BCM)",
|
||||
"regex": (
|
||||
telnet_prefixes["telnet_log"]["timestamp"] +
|
||||
telnet_prefixes["BCM"]["chat"] +
|
||||
triggers["send me to location"]
|
||||
),
|
||||
"callback": main_function
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
loaded_modules_dict["module_" + module_name].register_trigger(trigger_name, trigger_meta)
|
||||
116
bot/modules/locations/commands/start_onslaught.py
Normal file
116
bot/modules/locations/commands/start_onslaught.py
Normal file
@@ -0,0 +1,116 @@
|
||||
from bot import loaded_modules_dict
|
||||
from bot import telnet_prefixes
|
||||
from os import path, pardir
|
||||
import re
|
||||
|
||||
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")
|
||||
steamid = regex_result.group("player_steamid")
|
||||
active_dataset = module.dom.data.get("module_game_environment", {}).get("active_dataset", None)
|
||||
|
||||
player_dict = (
|
||||
module.dom.data.get("module_players", {})
|
||||
.get("elements", {})
|
||||
.get(active_dataset, {})
|
||||
.get(steamid, {})
|
||||
)
|
||||
|
||||
if len(player_dict) < 1:
|
||||
return False
|
||||
|
||||
result = re.match(r"^.*st.*\sonslaught\s(?P<onslaught_options>.*)", command)
|
||||
if result:
|
||||
onslaught_options = result.group("onslaught_options")
|
||||
else:
|
||||
""" no options provided
|
||||
might later chose the location one is standing in and owns, or let some other stuff happen
|
||||
"""
|
||||
onslaught_options = None
|
||||
|
||||
if command.startswith("/start onslaught"):
|
||||
""" check if the player is inside a location which allows onslaught to be enabled """
|
||||
# let's iterate through all suitable locations
|
||||
for onslaught_location in origin_module.get_elements_by_type("is_onslaught"):
|
||||
# only proceed with the player is inside a dedicated location
|
||||
if any([
|
||||
onslaught_options in ["everywhere", onslaught_location["identifier"]],
|
||||
origin_module.position_is_inside_boundary(player_dict, onslaught_location)
|
||||
]):
|
||||
# fire onslaught in all selected locations
|
||||
event_data = ['onslaught', {
|
||||
'onslaught_options': onslaught_options,
|
||||
'location_owner': onslaught_location['owner'],
|
||||
'location_identifier': onslaught_location['identifier'],
|
||||
'action': 'start onslaught'
|
||||
}]
|
||||
module.trigger_action_hook(origin_module, event_data=event_data, dispatchers_steamid=steamid)
|
||||
|
||||
elif command.startswith("/stop onslaught"):
|
||||
for onslaught_location in origin_module.get_elements_by_type("is_onslaught"):
|
||||
# only proceed with the player is inside a dedicated location
|
||||
if any([
|
||||
onslaught_options in ["everywhere", onslaught_location["identifier"]],
|
||||
origin_module.position_is_inside_boundary(player_dict, onslaught_location)
|
||||
]):
|
||||
# fire onslaught in all selected locations
|
||||
event_data = ['onslaught', {
|
||||
'location_owner': onslaught_location['owner'],
|
||||
'location_identifier': onslaught_location['identifier'],
|
||||
'action': 'stop onslaught'
|
||||
}]
|
||||
module.trigger_action_hook(origin_module, event_data=event_data, dispatchers_steamid=steamid)
|
||||
|
||||
|
||||
triggers = {
|
||||
"start onslaught": r"\'(?P<player_name>.*)\'\:\s(?P<command>\/start\sonslaught.*)",
|
||||
"stop onslaught": r"\'(?P<player_name>.*)\'\:\s(?P<command>\/stop\sonslaught.*)"
|
||||
}
|
||||
|
||||
trigger_meta = {
|
||||
"description": "will start the onslaught event in a specified location",
|
||||
"main_function": main_function,
|
||||
"triggers": [
|
||||
{
|
||||
"identifier": "start onslaught (Alloc)",
|
||||
"regex": (
|
||||
telnet_prefixes["telnet_log"]["timestamp"] +
|
||||
telnet_prefixes["Allocs"]["chat"] +
|
||||
triggers["start onslaught"]
|
||||
),
|
||||
"callback": main_function
|
||||
},
|
||||
{
|
||||
"identifier": "stop onslaught (Alloc)",
|
||||
"regex": (
|
||||
telnet_prefixes["telnet_log"]["timestamp"] +
|
||||
telnet_prefixes["Allocs"]["chat"] +
|
||||
triggers["stop onslaught"]
|
||||
),
|
||||
"callback": main_function
|
||||
},
|
||||
{
|
||||
"identifier": "start onslaught (BCM)",
|
||||
"regex": (
|
||||
telnet_prefixes["telnet_log"]["timestamp"] +
|
||||
telnet_prefixes["BCM"]["chat"] +
|
||||
triggers["start onslaught"]
|
||||
),
|
||||
"callback": main_function
|
||||
},
|
||||
{
|
||||
"identifier": "stop onslaught (BCM)",
|
||||
"regex": (
|
||||
telnet_prefixes["telnet_log"]["timestamp"] +
|
||||
telnet_prefixes["BCM"]["chat"] +
|
||||
triggers["stop onslaught"]
|
||||
),
|
||||
"callback": main_function
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
loaded_modules_dict["module_" + module_name].register_trigger(trigger_name, trigger_meta)
|
||||
64
bot/modules/locations/commands/take_me_to_my_grave.py
Normal file
64
bot/modules/locations/commands/take_me_to_my_grave.py
Normal file
@@ -0,0 +1,64 @@
|
||||
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):
|
||||
location_identifier = "PlaceofDeath"
|
||||
|
||||
active_dataset = module.dom.data.get("module_game_environment", {}).get("active_dataset", None)
|
||||
steamid = regex_result.group("player_steamid")
|
||||
|
||||
player_dict = module.dom.data.get("module_players", {}).get("elements", {}).get(active_dataset, {}).get(steamid, {})
|
||||
location_dict = (
|
||||
module.dom.data.get("module_locations", {})
|
||||
.get("elements", {})
|
||||
.get(active_dataset, {})
|
||||
.get(steamid, {})
|
||||
.get(location_identifier, {})
|
||||
)
|
||||
|
||||
if len(player_dict) >= 1 and len(location_dict) >= 1:
|
||||
event_data = ['teleport_to_coordinates', {
|
||||
'location_coordinates': {
|
||||
"x": location_dict["coordinates"]["x"],
|
||||
"y": location_dict["coordinates"]["y"],
|
||||
"z": location_dict["coordinates"]["z"]
|
||||
}
|
||||
}]
|
||||
module.trigger_action_hook(origin_module, event_data=event_data, dispatchers_steamid=steamid)
|
||||
|
||||
|
||||
triggers = {
|
||||
"take me to my grave": r"\'(?P<player_name>.*)\'\:\s(?P<command>\/take me to my grave)"
|
||||
}
|
||||
|
||||
trigger_meta = {
|
||||
"description": "sends the player to his final resting place, if available",
|
||||
"main_function": main_function,
|
||||
"triggers": [
|
||||
{
|
||||
"identifier": "take me to my grave (Allocs)",
|
||||
"regex": (
|
||||
telnet_prefixes["telnet_log"]["timestamp"] +
|
||||
telnet_prefixes["Allocs"]["chat"] +
|
||||
triggers["take me to my grave"]
|
||||
),
|
||||
"callback": main_function
|
||||
},
|
||||
{
|
||||
"identifier": "take me to my grave (BCM)",
|
||||
"regex": (
|
||||
telnet_prefixes["telnet_log"]["timestamp"] +
|
||||
telnet_prefixes["BCM"]["chat"] +
|
||||
triggers["take me to my grave"]
|
||||
),
|
||||
"callback": main_function
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
loaded_modules_dict["module_" + module_name].register_trigger(trigger_name, trigger_meta)
|
||||
100
bot/modules/locations/commands/where_am_i.py
Normal file
100
bot/modules/locations/commands/where_am_i.py
Normal file
@@ -0,0 +1,100 @@
|
||||
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 find_by_key(data, target):
|
||||
for key, value in data.items():
|
||||
if isinstance(value, dict):
|
||||
yield from find_by_key(value, target)
|
||||
elif key == target:
|
||||
yield value
|
||||
|
||||
|
||||
def main_function(origin_module, module, regex_result):
|
||||
player_steamid = regex_result.group("player_steamid")
|
||||
active_dataset = module.dom.data.get("module_game_environment", {}).get("active_dataset", None)
|
||||
|
||||
player_dict = (
|
||||
module.dom.data.get("module_players", {})
|
||||
.get("elements", {})
|
||||
.get(active_dataset, {})
|
||||
.get(player_steamid, {})
|
||||
)
|
||||
|
||||
all_locations_dict = (
|
||||
module.dom.data.get("module_locations", {})
|
||||
.get("elements", {})
|
||||
.get(active_dataset, {})
|
||||
)
|
||||
|
||||
occupied_locations = []
|
||||
for locations_by_owner in all_locations_dict:
|
||||
for location_identifier, location_dict in all_locations_dict[locations_by_owner].items():
|
||||
if origin_module.position_is_inside_boundary(player_dict, location_dict):
|
||||
occupied_locations.append(location_dict)
|
||||
|
||||
if len(occupied_locations) > 0:
|
||||
event_data = ['say_to_player', {
|
||||
'steamid': player_steamid,
|
||||
'message': '[FFFFFF]You are inside the following locations:[-]'
|
||||
}]
|
||||
module.trigger_action_hook(origin_module.players, event_data=event_data)
|
||||
|
||||
for location_dict in occupied_locations:
|
||||
location_owner_dict = (
|
||||
module.dom.data.get("module_players", {})
|
||||
.get("elements", {})
|
||||
.get(active_dataset, {})
|
||||
.get(location_dict.get("owner"), {})
|
||||
)
|
||||
|
||||
event_data = ['say_to_player', {
|
||||
'steamid': player_steamid,
|
||||
'message': '[FFFFFF]{name} [66FF66]({owner})[-]'.format(
|
||||
name=location_dict.get("name", "n/a"),
|
||||
owner=location_owner_dict.get("name", "n/a")
|
||||
)
|
||||
}]
|
||||
module.trigger_action_hook(origin_module.players, event_data=event_data)
|
||||
else:
|
||||
event_data = ['say_to_player', {
|
||||
'steamid': player_steamid,
|
||||
'message': '[FFFFFF]You do not seem to be in any designated location[-]'
|
||||
}]
|
||||
module.trigger_action_hook(origin_module.players, event_data=event_data)
|
||||
|
||||
|
||||
triggers = {
|
||||
"where am i": r"\'(?P<player_name>.*)\'\:\s(?P<command>\/where am i)"
|
||||
}
|
||||
|
||||
trigger_meta = {
|
||||
"description": "prints out a list of locations a player currently occupies",
|
||||
"main_function": main_function,
|
||||
"triggers": [
|
||||
{
|
||||
"identifier": "where am i (Allocs)",
|
||||
"regex": (
|
||||
telnet_prefixes["telnet_log"]["timestamp"] +
|
||||
telnet_prefixes["Allocs"]["chat"] +
|
||||
triggers["where am i"]
|
||||
),
|
||||
"callback": main_function
|
||||
},
|
||||
{
|
||||
"identifier": "where am i (BCM)",
|
||||
"regex": (
|
||||
telnet_prefixes["telnet_log"]["timestamp"] +
|
||||
telnet_prefixes["BCM"]["chat"] +
|
||||
triggers["where am i"]
|
||||
),
|
||||
"callback": main_function
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
loaded_modules_dict["module_" + module_name].register_trigger(trigger_name, trigger_meta)
|
||||
Reference in New Issue
Block a user