mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 03:25:23 +09:00
Setup exp_scenario for commands
This commit is contained in:
19
exp_scenario/module/commands/authorities.lua
Normal file
19
exp_scenario/module/commands/authorities.lua
Normal file
@@ -0,0 +1,19 @@
|
||||
|
||||
local Commands = require("modules/exp_commands")
|
||||
local add, allow, deny = Commands.add_permission_authority, Commands.status.success, Commands.status.unauthorised
|
||||
|
||||
local Roles = require("modules/exp_legacy/expcore/roles")
|
||||
|
||||
local authorities = {}
|
||||
|
||||
--- If a command has the flag "character_only" then the command can only be used outside of remote view
|
||||
authorities.exp_permission =
|
||||
add(function(player, command)
|
||||
if not Roles.player_allowed(player, command.flags.exp_permission or ("command/" .. command)) then
|
||||
return deny{ "exp-commands-authorities_role.deny" }
|
||||
else
|
||||
return allow()
|
||||
end
|
||||
end)
|
||||
|
||||
return authorities
|
||||
97
exp_scenario/module/commands/types.lua
Normal file
97
exp_scenario/module/commands/types.lua
Normal file
@@ -0,0 +1,97 @@
|
||||
|
||||
--[[-- Command Types - Roles
|
||||
The data types that are used with exp_roles
|
||||
|
||||
Adds parsers for:
|
||||
role
|
||||
lower_role
|
||||
lower_role_player
|
||||
lower_role_player_online
|
||||
lower_role_player_alive
|
||||
]]
|
||||
|
||||
local Commands = require("modules/exp_commands")
|
||||
local add, parse = Commands.add_data_type, Commands.parse_input
|
||||
local valid, invalid = Commands.status.success, Commands.status.invalid_input
|
||||
|
||||
local Roles = require("modules.exp_legacy.expcore.roles")
|
||||
local highest_role = Roles.get_player_highest_role
|
||||
local key_of_roles = Commands.types.key_of(Roles.config.roles)
|
||||
|
||||
local types = {}
|
||||
|
||||
--- A role defined by exp roles
|
||||
--- @type Commands.InputParser
|
||||
types.role =
|
||||
add("role", function(input, player)
|
||||
local _, status, rtn = parse(input, player, key_of_roles)
|
||||
return status, rtn
|
||||
end)
|
||||
|
||||
--- A role which is lower than the players highest role
|
||||
--- @type Commands.InputParser
|
||||
types.lower_role =
|
||||
add("lower_role", function(input, player)
|
||||
local success, status, result = parse(input, player, types.role)
|
||||
if not success then return status, result end
|
||||
--- @cast result any TODO role is not a defined type
|
||||
|
||||
local player_highest = highest_role(player)
|
||||
if player_highest.index >= result.index then
|
||||
return invalid{ "exp-commands-parse_role.lower-role" }
|
||||
else
|
||||
return valid(result)
|
||||
end
|
||||
end)
|
||||
|
||||
--- A player who is of a lower role than the executing player
|
||||
--- @type Commands.InputParser
|
||||
types.lower_role_player =
|
||||
add("lower_role_player", function(input, player)
|
||||
local success, status, result = parse(input, player, Commands.types.player)
|
||||
if not success then return status, result end
|
||||
--- @cast result LuaPlayer
|
||||
|
||||
local other_highest = highest_role(result)
|
||||
local player_highest = highest_role(player)
|
||||
if player_highest.index < other_highest.index then
|
||||
return invalid{ "exp-commands-parse_role.lower-role-player" }
|
||||
else
|
||||
return valid(result)
|
||||
end
|
||||
end)
|
||||
|
||||
--- A player who is of a lower role than the executing player
|
||||
--- @type Commands.InputParser
|
||||
types.lower_role_player_online =
|
||||
add("lower_role_player", function(input, player)
|
||||
local success, status, result = parse(input, player, Commands.types.player_online)
|
||||
if not success then return status, result end
|
||||
--- @cast result LuaPlayer
|
||||
|
||||
local other_highest = highest_role(result)
|
||||
local player_highest = highest_role(player)
|
||||
if player_highest.index < other_highest.index then
|
||||
return invalid{ "exp-commands-parse_role.lower-role-player" }
|
||||
else
|
||||
return valid(result)
|
||||
end
|
||||
end)
|
||||
|
||||
--- A player who is of a lower role than the executing player
|
||||
types.lower_role_player_alive =
|
||||
add("lower_role_player", function(input, player)
|
||||
local success, status, result = parse(input, player, Commands.types.player_alive)
|
||||
if not success then return status, result end
|
||||
--- @cast result LuaPlayer
|
||||
|
||||
local other_highest = highest_role(result)
|
||||
local player_highest = highest_role(player)
|
||||
if player_highest.index < other_highest.index then
|
||||
return invalid{ "exp-commands-parse_role.lower-role-player" }
|
||||
else
|
||||
return valid(result)
|
||||
end
|
||||
end)
|
||||
|
||||
return types
|
||||
9
exp_scenario/module/control.lua
Normal file
9
exp_scenario/module/control.lua
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
--- Command Extensions
|
||||
require("modules.exp_scenario/commands/types")
|
||||
require("modules.exp_scenario/commands/authorities")
|
||||
|
||||
--- Commands
|
||||
require("modules/exp_scenario/commands/admin_chat")
|
||||
require("modules/exp_scenario/commands/bot_queues")
|
||||
require("modules/exp_scenario/commands/cheat")
|
||||
6
exp_scenario/module/locale/en.cfg
Normal file
6
exp_scenario/module/locale/en.cfg
Normal file
@@ -0,0 +1,6 @@
|
||||
[exp-commands-authorities_role]
|
||||
deny=Unauthorized, Access is denied due to missing permissions
|
||||
|
||||
[exp-commands-parse_role]
|
||||
lower-role=Role is higher than your highest.
|
||||
lower-role-player=Player has a higher role.
|
||||
13
exp_scenario/module/module.json
Normal file
13
exp_scenario/module/module.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"name": "exp_scenario",
|
||||
"load": [
|
||||
],
|
||||
"require": [
|
||||
"control.lua"
|
||||
],
|
||||
"dependencies": {
|
||||
"clusterio": "*",
|
||||
"exp_util": "*",
|
||||
"exp_commands": "*"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user