mirror of
https://github.com/Mr-X-GTA/YimMenu.git
synced 2025-06-23 01:02:23 +08:00
feat(lua): Allow lua scripts to flag modders with a custom reason if needed. (#2248)
This commit is contained in:
@ -18,6 +18,7 @@ class DocKind(Enum):
|
||||
Constructor = "constructor"
|
||||
Function = "function"
|
||||
Tabs = "tabs"
|
||||
Infraction = "infraction"
|
||||
|
||||
|
||||
class Table:
|
||||
@ -324,7 +325,10 @@ def parse_lua_api_doc(folder_path):
|
||||
.lower()
|
||||
)
|
||||
|
||||
if doc_kind is not DocKind.Tabs:
|
||||
if (
|
||||
doc_kind is not DocKind.Tabs
|
||||
and doc_kind is not DocKind.Infraction
|
||||
):
|
||||
continue
|
||||
|
||||
if doc_kind is not None and "//" in line:
|
||||
@ -367,7 +371,10 @@ def parse_lua_api_doc(folder_path):
|
||||
line,
|
||||
line_lower,
|
||||
)
|
||||
case DocKind.Tabs: parse_tabs_doc(file)
|
||||
case DocKind.Tabs:
|
||||
parse_tabs_doc(file)
|
||||
case DocKind.Infraction:
|
||||
parse_infraction_doc(file)
|
||||
case _:
|
||||
# print("unsupported doc kind: " + str(doc_kind))
|
||||
pass
|
||||
@ -386,6 +393,7 @@ def parse_table_doc(cur_table, line, line_lower):
|
||||
|
||||
return cur_table
|
||||
|
||||
|
||||
def parse_class_doc(cur_class, line, line_lower):
|
||||
if is_lua_doc_comment_startswith(line_lower, "name"):
|
||||
class_name = line.split(lua_api_comment_separator, 1)[1].strip()
|
||||
@ -402,28 +410,43 @@ def parse_class_doc(cur_class, line, line_lower):
|
||||
|
||||
|
||||
def parse_function_doc(cur_function, cur_table, cur_class, line, line_lower):
|
||||
if is_lua_doc_comment_startswith(line_lower, "table") and lua_api_comment_separator in line_lower:
|
||||
if (
|
||||
is_lua_doc_comment_startswith(line_lower, "table")
|
||||
and lua_api_comment_separator in line_lower
|
||||
):
|
||||
table_name = line.split(lua_api_comment_separator, 1)[1].strip()
|
||||
cur_table = make_table(table_name)
|
||||
|
||||
cur_function = Function("Didnt get name yet", cur_table, [], None, "", "")
|
||||
cur_table.functions.append(cur_function)
|
||||
elif is_lua_doc_comment_startswith(line_lower, "class") and lua_api_comment_separator in line_lower:
|
||||
elif (
|
||||
is_lua_doc_comment_startswith(line_lower, "class")
|
||||
and lua_api_comment_separator in line_lower
|
||||
):
|
||||
class_name = line.split(lua_api_comment_separator, 1)[1].strip()
|
||||
cur_class = make_class(class_name)
|
||||
|
||||
cur_function = Function("Didnt get name yet", cur_class, [], None, "", "")
|
||||
cur_class.functions.append(cur_function)
|
||||
elif is_lua_doc_comment_startswith(line_lower, "name") and lua_api_comment_separator in line_lower:
|
||||
elif (
|
||||
is_lua_doc_comment_startswith(line_lower, "name")
|
||||
and lua_api_comment_separator in line_lower
|
||||
):
|
||||
function_name = line.split(lua_api_comment_separator, 1)[1].strip()
|
||||
cur_function.name = function_name
|
||||
|
||||
if function_name not in functions:
|
||||
functions[function_name] = cur_function
|
||||
elif is_lua_doc_comment_startswith(line_lower, "param") and lua_api_comment_separator in line_lower:
|
||||
elif (
|
||||
is_lua_doc_comment_startswith(line_lower, "param")
|
||||
and lua_api_comment_separator in line_lower
|
||||
):
|
||||
parameter = make_parameter_from_doc_line(line)
|
||||
cur_function.parameters.append(parameter)
|
||||
elif is_lua_doc_comment_startswith(line_lower, "return") and lua_api_comment_separator in line_lower:
|
||||
elif (
|
||||
is_lua_doc_comment_startswith(line_lower, "return")
|
||||
and lua_api_comment_separator in line_lower
|
||||
):
|
||||
return_info = line.split(lua_api_comment_separator, 2)
|
||||
try:
|
||||
cur_function.return_type = return_info[1].strip()
|
||||
@ -439,19 +462,28 @@ def parse_function_doc(cur_function, cur_table, cur_class, line, line_lower):
|
||||
|
||||
|
||||
def parse_field_doc(cur_field, cur_table, cur_class, line, line_lower):
|
||||
if is_lua_doc_comment_startswith(line_lower, "table") and lua_api_comment_separator in line_lower:
|
||||
if (
|
||||
is_lua_doc_comment_startswith(line_lower, "table")
|
||||
and lua_api_comment_separator in line_lower
|
||||
):
|
||||
table_name = line.split(lua_api_comment_separator, 1)[1].strip()
|
||||
cur_table = make_table(table_name)
|
||||
|
||||
cur_field = Field("Didnt get name yet", "", "")
|
||||
cur_table.fields.append(cur_field)
|
||||
elif is_lua_doc_comment_startswith(line_lower, "class") and lua_api_comment_separator in line_lower:
|
||||
elif (
|
||||
is_lua_doc_comment_startswith(line_lower, "class")
|
||||
and lua_api_comment_separator in line_lower
|
||||
):
|
||||
class_name = line.split(lua_api_comment_separator, 1)[1].strip()
|
||||
cur_class = make_class(class_name)
|
||||
|
||||
cur_field = Field("Didnt get name yet", "", "")
|
||||
cur_class.fields.append(cur_field)
|
||||
elif is_lua_doc_comment_startswith(line_lower, "field") and lua_api_comment_separator in line_lower:
|
||||
elif (
|
||||
is_lua_doc_comment_startswith(line_lower, "field")
|
||||
and lua_api_comment_separator in line_lower
|
||||
):
|
||||
field_info = line.split(lua_api_comment_separator, 2)
|
||||
cur_field.name = field_info[1].strip()
|
||||
cur_field.type_ = field_info[2].strip()
|
||||
@ -467,13 +499,19 @@ def parse_field_doc(cur_field, cur_table, cur_class, line, line_lower):
|
||||
|
||||
|
||||
def parse_constructor_doc(cur_constructor, cur_class, line, line_lower):
|
||||
if is_lua_doc_comment_startswith(line_lower, "class") and lua_api_comment_separator in line_lower:
|
||||
if (
|
||||
is_lua_doc_comment_startswith(line_lower, "class")
|
||||
and lua_api_comment_separator in line_lower
|
||||
):
|
||||
class_name = line.split(lua_api_comment_separator, 1)[1].strip()
|
||||
cur_class = make_class(class_name)
|
||||
|
||||
cur_constructor = Constructor(cur_class, [], "")
|
||||
cur_class.constructors.append(cur_constructor)
|
||||
elif is_lua_doc_comment_startswith(line_lower, "param") and lua_api_comment_separator in line_lower:
|
||||
elif (
|
||||
is_lua_doc_comment_startswith(line_lower, "param")
|
||||
and lua_api_comment_separator in line_lower
|
||||
):
|
||||
parameter = make_parameter_from_doc_line(line)
|
||||
cur_constructor.parameters.append(parameter)
|
||||
else:
|
||||
@ -485,6 +523,8 @@ def parse_constructor_doc(cur_constructor, cur_class, line, line_lower):
|
||||
|
||||
|
||||
tabs_enum = []
|
||||
|
||||
|
||||
def parse_tabs_doc(file):
|
||||
start_parsing = False
|
||||
for line in file:
|
||||
@ -503,7 +543,29 @@ def parse_tabs_doc(file):
|
||||
continue
|
||||
else:
|
||||
tabs_enum.append(line.replace(",", "").strip())
|
||||
|
||||
|
||||
|
||||
infraction_enum = []
|
||||
|
||||
|
||||
def parse_infraction_doc(file):
|
||||
start_parsing = False
|
||||
for line in file:
|
||||
if "enum class" in line.lower():
|
||||
start_parsing = True
|
||||
continue
|
||||
|
||||
if start_parsing:
|
||||
if "};" in line.lower():
|
||||
return
|
||||
if "{" == line.lower().strip():
|
||||
continue
|
||||
if "//" in line.lower():
|
||||
continue
|
||||
if "" == line.lower().strip():
|
||||
continue
|
||||
else:
|
||||
infraction_enum.append(line.replace(",", "").strip())
|
||||
|
||||
|
||||
def make_parameter_from_doc_line(line):
|
||||
@ -519,13 +581,15 @@ def make_parameter_from_doc_line(line):
|
||||
|
||||
return Parameter(param_name, param_type, param_desc)
|
||||
|
||||
|
||||
def sanitize_description(line):
|
||||
if line.startswith("// ") and line[3] != ' ':
|
||||
if line.startswith("// ") and line[3] != " ":
|
||||
line = line[3:]
|
||||
if line.startswith("//"):
|
||||
line = line[2:]
|
||||
return line.rstrip()
|
||||
|
||||
|
||||
def is_lua_doc_comment_startswith(line_lower, starts_with_text):
|
||||
return line_lower.replace("//", "").strip().startswith(starts_with_text)
|
||||
|
||||
@ -550,7 +614,8 @@ if os.path.exists(tabs_file_name):
|
||||
os.remove(tabs_file_name)
|
||||
f = open(tabs_file_name, "a")
|
||||
|
||||
f.write("""# Tabs
|
||||
f.write(
|
||||
"""# Tabs
|
||||
|
||||
All the tabs from the menu are listed below, used as parameter for adding gui elements to them.
|
||||
|
||||
@ -565,16 +630,42 @@ end)
|
||||
|
||||
For a complete list of available gui functions, please refer to the tab class documentation and the gui table documentation.
|
||||
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
f.write(f"## Tab Count: {len(tabs_enum)}\n\n")
|
||||
|
||||
# Minus the first, because it's the `NONE` tab, minus the last one because it's for runtime defined tabs.
|
||||
for i in range(1, len(tabs_enum) - 1 ):
|
||||
for i in range(1, len(tabs_enum) - 1):
|
||||
f.write("### `GUI_TAB_" + tabs_enum[i] + "`\n")
|
||||
|
||||
f.close()
|
||||
|
||||
infraction_file_name = f"../lua/infraction.md"
|
||||
if os.path.exists(infraction_file_name):
|
||||
os.remove(infraction_file_name)
|
||||
f = open(infraction_file_name, "a")
|
||||
|
||||
f.write(
|
||||
"""# Infraction
|
||||
|
||||
All the infraction from the menu are listed below, used as parameter for adding an infraction to a given player, for flagging them as modder.
|
||||
|
||||
**Example Usage:**
|
||||
```lua
|
||||
network.flag_player_as_modder(player_index, infraction.CUSTOM_REASON, "My custom reason on why the player is flagged as a modder")
|
||||
```
|
||||
|
||||
"""
|
||||
)
|
||||
|
||||
f.write(f"## Infraction Count: {len(infraction_enum)}\n\n")
|
||||
|
||||
for i in range(0, len(infraction_enum)):
|
||||
f.write("### `" + infraction_enum[i] + "`\n")
|
||||
|
||||
f.close()
|
||||
|
||||
try:
|
||||
os.makedirs("./classes/")
|
||||
except:
|
||||
@ -589,13 +680,13 @@ for class_name, class_ in classes.items():
|
||||
f.close()
|
||||
|
||||
|
||||
|
||||
commands_file_name = f"./commands.md"
|
||||
if os.path.exists(commands_file_name):
|
||||
os.remove(commands_file_name)
|
||||
f = open(commands_file_name, "a")
|
||||
|
||||
f.write("""# Commands
|
||||
f.write(
|
||||
"""# Commands
|
||||
|
||||
All the current commands from the menu are listed below.
|
||||
|
||||
@ -608,7 +699,8 @@ command.call_player(somePlayerIndex, "spawn", {joaat("adder")})
|
||||
|
||||
For a complete list of available command functions, please refer to the command table documentation.
|
||||
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
commands = []
|
||||
@ -629,4 +721,4 @@ for cmd in commands:
|
||||
f.write(f"Arg Count: {arg_count}\n")
|
||||
f.write("\n")
|
||||
|
||||
f.close()
|
||||
f.close()
|
||||
|
23
docs/lua/infraction.md
Normal file
23
docs/lua/infraction.md
Normal file
@ -0,0 +1,23 @@
|
||||
# Infraction
|
||||
|
||||
All the infraction from the menu are listed below, used as parameter for adding an infraction to a given player, for flagging them as modder.
|
||||
|
||||
**Example Usage:**
|
||||
```lua
|
||||
network.flag_player_as_modder(player_index, infraction.CUSTOM_REASON, "My custom reason on why the player is flagged as a modder")
|
||||
```
|
||||
|
||||
## Infraction Count: 12
|
||||
|
||||
### `TRIGGERED_ANTICHEAT`
|
||||
### `TRIED_CRASH_PLAYER`
|
||||
### `TRIED_KICK_PLAYER`
|
||||
### `ATTACKING_WITH_GODMODE`
|
||||
### `ATTACKING_WITH_INVISIBILITY`
|
||||
### `ATTACKING_WHEN_HIDDEN_FROM_PLAYER_LIST`
|
||||
### `SPOOFED_DATA`
|
||||
### `SPOOFED_HOST_TOKEN`
|
||||
### `INVALID_PLAYER_MODEL`
|
||||
### `SUPER_JUMP`
|
||||
### `UNDEAD_OTR`
|
||||
### `CUSTOM_REASON`
|
@ -2,7 +2,7 @@
|
||||
|
||||
Table containing helper functions for network related features.
|
||||
|
||||
## Functions (10)
|
||||
## Functions (11)
|
||||
|
||||
### `trigger_script_event(bitset, _args)`
|
||||
|
||||
@ -79,16 +79,18 @@ integer = network.get_selected_player()
|
||||
integer = network.get_selected_database_player_rockstar_id()
|
||||
```
|
||||
|
||||
### `flag_player_as_modder(player_idx)`
|
||||
### `flag_player_as_modder(player_idx, reason, custom_reason)`
|
||||
|
||||
Flags the given player as a modder in our local database.
|
||||
|
||||
- **Parameters:**
|
||||
- `player_idx` (integer): Index of the player.
|
||||
- `reason` (Infraction): Reason why the player is flagged as a modder, if the infraction is CUSTOM_REASON, then the custom_reason string is added in the local database. For a full list of the possible infraction reasons to use, please check the infraction page.
|
||||
- `custom_reason` (string): Optional, required only when the infraction is CUSTOM_REASON. The custom reason why the player is flagged as a modder.
|
||||
|
||||
**Example Usage:**
|
||||
```lua
|
||||
network.flag_player_as_modder(player_idx)
|
||||
network.flag_player_as_modder(player_idx, reason, custom_reason)
|
||||
```
|
||||
|
||||
### `is_player_flagged_as_modder(player_idx)`
|
||||
@ -104,6 +106,19 @@ network.flag_player_as_modder(player_idx)
|
||||
boolean = network.is_player_flagged_as_modder(player_idx)
|
||||
```
|
||||
|
||||
### `get_flagged_modder_reason(player_idx)`
|
||||
|
||||
- **Parameters:**
|
||||
- `player_idx` (integer): Index of the player.
|
||||
|
||||
- **Returns:**
|
||||
- `string`: Returns a string which contains the reason(s) why the player is flagged as a modder.
|
||||
|
||||
**Example Usage:**
|
||||
```lua
|
||||
string = network.get_flagged_modder_reason(player_idx)
|
||||
```
|
||||
|
||||
### `force_script_host(script_name)`
|
||||
|
||||
Try to force ourself to be host for the given GTA Script.
|
||||
|
Reference in New Issue
Block a user