mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 03:25:23 +09:00
Migrate all commands to new lib
This commit is contained in:
@@ -8,44 +8,6 @@ return {
|
||||
"modules.factorio-control", -- base factorio free play scenario
|
||||
"expcore.player_data", -- must be loaded first to register event handlers
|
||||
|
||||
--- Game Commands
|
||||
"modules.commands.debug",
|
||||
"modules.commands.me",
|
||||
"modules.commands.kill",
|
||||
"modules.commands.admin-chat",
|
||||
"modules.commands.admin-markers",
|
||||
"modules.commands.teleport",
|
||||
"modules.commands.cheat-mode",
|
||||
"modules.commands.ratio",
|
||||
"modules.commands.interface",
|
||||
"modules.commands.help",
|
||||
"modules.commands.roles",
|
||||
"modules.commands.rainbow",
|
||||
"modules.commands.clear-inventory",
|
||||
"modules.commands.jail",
|
||||
"modules.commands.repair",
|
||||
"modules.commands.reports",
|
||||
"modules.commands.spawn",
|
||||
"modules.commands.warnings",
|
||||
"modules.commands.find",
|
||||
"modules.commands.home",
|
||||
"modules.commands.connect",
|
||||
"modules.commands.last-location",
|
||||
"modules.commands.protection",
|
||||
"modules.commands.spectate",
|
||||
"modules.commands.search",
|
||||
"modules.commands.bot-queue",
|
||||
"modules.commands.speed",
|
||||
"modules.commands.pollution",
|
||||
"modules.commands.train",
|
||||
"modules.commands.friendly-fire",
|
||||
"modules.commands.research",
|
||||
"modules.commands.vlayer",
|
||||
"modules.commands.enemy",
|
||||
"modules.commands.waterfill",
|
||||
"modules.commands.artillery",
|
||||
"modules.commands.surface-clearing",
|
||||
|
||||
--- Addons
|
||||
"modules.addons.chat-popups",
|
||||
"modules.addons.damage-popups",
|
||||
@@ -104,9 +66,6 @@ return {
|
||||
"modules.gui.toolbar", -- must be loaded last to register toolbar handlers
|
||||
|
||||
--- Config Files
|
||||
"config.expcore.command_auth_admin", -- commands tagged with admin_only are blocked for non admins
|
||||
"config.expcore.command_auth_roles", -- commands must be allowed via the role config
|
||||
"config.expcore.command_runtime_disable", -- allows commands to be enabled and disabled during runtime
|
||||
"config.expcore.permission_groups", -- loads some predefined permission groups
|
||||
"config.expcore.roles", -- loads some predefined roles
|
||||
}
|
||||
|
||||
@@ -80,8 +80,8 @@ return {
|
||||
local options = { "?", ".", "!", "!!!" }
|
||||
return { "chat-bot.hodor", table.get_random(options) }
|
||||
end,
|
||||
["evolution"] = function(_player, _is_command)
|
||||
return { "chat-bot.current-evolution", string.format("%.2f", game.forces["enemy"].evolution_factor) }
|
||||
["evolution"] = function(player, _is_command)
|
||||
return { "chat-bot.current-evolution", string.format("%.2f", game.forces["enemy"].get_evolution_factor(player.surface)) }
|
||||
end,
|
||||
["makepopcorn"] = function(player, _is_command)
|
||||
local timeout = math.floor(180 * (math.random() + 0.5))
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
--- This is a very simple config file which adds a admin only auth function;
|
||||
-- not much to change here its more so it can be enabled and disabled from ./config/file_loader.lua;
|
||||
-- either way you can change the requirements to be "admin" if you wanted to
|
||||
-- @config Commands-Auth-Admin
|
||||
|
||||
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
|
||||
|
||||
-- luacheck:ignore 212/command
|
||||
Commands.add_authenticator(function(player, command, tags, reject)
|
||||
if tags.admin_only then
|
||||
if player.admin then
|
||||
return true
|
||||
else
|
||||
return reject{ "command-auth.admin-only" }
|
||||
end
|
||||
else
|
||||
return true
|
||||
end
|
||||
end)
|
||||
@@ -1,14 +0,0 @@
|
||||
--- This will make commands only work if the role has been allowed it in the role config
|
||||
-- @config Commands-Auth-Roles
|
||||
|
||||
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
|
||||
local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles
|
||||
|
||||
-- luacheck:ignore 212/tags
|
||||
Commands.add_authenticator(function(player, command, tags, reject)
|
||||
if Roles.player_allowed(player, "command/" .. command) then
|
||||
return true
|
||||
else
|
||||
return reject()
|
||||
end
|
||||
end)
|
||||
@@ -1,15 +0,0 @@
|
||||
--- This will make commands only work when a valid color from the presets has been selected
|
||||
-- @config Commands-Color-Parse
|
||||
|
||||
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
|
||||
local Colours = require("modules/exp_util/include/color")
|
||||
|
||||
Commands.add_parse("color", function(input, _, reject)
|
||||
if not input then return end
|
||||
local color = Colours[input]
|
||||
if not color then
|
||||
return reject{ "expcore-commands.reject-color" }
|
||||
else
|
||||
return input
|
||||
end
|
||||
end)
|
||||
@@ -1,143 +0,0 @@
|
||||
--[[-- This file contains some common command param parse functions;
|
||||
this file is less of a config and more of a requirement but you may wish to change how some behave;
|
||||
as such you need to be confident with lua but you edit this config file;
|
||||
use Commands.add_parse('name',function(input, player, reject) end) to add a parse;
|
||||
see ./expcore/commands.lua for more details
|
||||
@config Commands-Parse
|
||||
@usage Adds Parses:
|
||||
boolean
|
||||
string-options - options: array
|
||||
string-max-length - max_length: number
|
||||
number
|
||||
integer
|
||||
number-range - range_min: number, range_max: number
|
||||
integer-range - range_min: number, range_max: number
|
||||
player
|
||||
player-online
|
||||
player-alive
|
||||
force
|
||||
surface
|
||||
]]
|
||||
|
||||
local ExpUtil = require("modules/exp_util")
|
||||
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
|
||||
|
||||
-- luacheck:ignore 212/player
|
||||
Commands.add_parse("boolean", function(input, player)
|
||||
if not input then return end -- nil check
|
||||
input = input:lower()
|
||||
if input == "yes"
|
||||
or input == "y"
|
||||
or input == "true"
|
||||
or input == "1" then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end)
|
||||
|
||||
Commands.add_parse("string-options", function(input, player, reject, options)
|
||||
if not input then return end -- nil check
|
||||
local option = ExpUtil.auto_complete(options, input)
|
||||
return option or reject{ "expcore-commands.reject-string-options", table.concat(options, ", ") }
|
||||
end)
|
||||
|
||||
Commands.add_parse("string-max-length", function(input, player, reject, max_length)
|
||||
if not input then return end -- nil check
|
||||
local length = input:len()
|
||||
if length > max_length then
|
||||
return reject{ "expcore-commands.reject-string-max-length", max_length }
|
||||
else
|
||||
return input
|
||||
end
|
||||
end)
|
||||
|
||||
Commands.add_parse("number", function(input, player, reject)
|
||||
if not input then return end -- nil check
|
||||
local number = tonumber(input)
|
||||
if not number then
|
||||
return reject{ "expcore-commands.reject-number" }
|
||||
else
|
||||
return number
|
||||
end
|
||||
end)
|
||||
|
||||
Commands.add_parse("integer", function(input, player, reject)
|
||||
if not input then return end -- nil check
|
||||
local number = tonumber(input)
|
||||
if not number then
|
||||
return reject{ "expcore-commands.reject-number" }
|
||||
else
|
||||
return math.floor(number)
|
||||
end
|
||||
end)
|
||||
|
||||
Commands.add_parse("number-range", function(input, player, reject, range_min, range_max)
|
||||
local number = Commands.parse("number", input, player, reject)
|
||||
if not number then return end -- nil check
|
||||
if number < range_min or number > range_max then
|
||||
return reject{ "expcore-commands.reject-number-range", range_min, range_max }
|
||||
else
|
||||
return number
|
||||
end
|
||||
end)
|
||||
|
||||
Commands.add_parse("integer-range", function(input, player, reject, range_min, range_max)
|
||||
local number = Commands.parse("integer", input, player, reject)
|
||||
if not number then return end -- nil check
|
||||
if number < range_min or number > range_max then
|
||||
return reject{ "expcore-commands.reject-number-range", range_min, range_max }
|
||||
else
|
||||
return number
|
||||
end
|
||||
end)
|
||||
|
||||
Commands.add_parse("player", function(input, player, reject)
|
||||
if not input then return end -- nil check
|
||||
local input_player = game.players[input]
|
||||
if not input_player then
|
||||
return reject{ "expcore-commands.reject-player", input }
|
||||
else
|
||||
return input_player
|
||||
end
|
||||
end)
|
||||
|
||||
Commands.add_parse("player-online", function(input, player, reject)
|
||||
local input_player = Commands.parse("player", input, player, reject)
|
||||
if not input_player then return end -- nil check
|
||||
if not input_player.connected then
|
||||
return reject{ "expcore-commands.reject-player-online" }
|
||||
else
|
||||
return input_player
|
||||
end
|
||||
end)
|
||||
|
||||
Commands.add_parse("player-alive", function(input, player, reject)
|
||||
local input_player = Commands.parse("player-online", input, player, reject)
|
||||
if not input_player then return end -- nil check
|
||||
if not input_player.character or not input_player.character.health or input_player.character.health <= 0 then
|
||||
return reject{ "expcore-commands.reject-player-alive" }
|
||||
else
|
||||
return input_player
|
||||
end
|
||||
end)
|
||||
|
||||
Commands.add_parse("force", function(input, player, reject)
|
||||
if not input then return end -- nil check
|
||||
local force = game.forces[input]
|
||||
if not force then
|
||||
return reject{ "expcore-commands.reject-force" }
|
||||
else
|
||||
return force
|
||||
end
|
||||
end)
|
||||
|
||||
Commands.add_parse("surface", function(input, player, reject)
|
||||
if not input then return end
|
||||
local surface = game.surfaces[input]
|
||||
if not surface then
|
||||
return reject{ "expcore-commands.reject-surface" }
|
||||
else
|
||||
return surface
|
||||
end
|
||||
end)
|
||||
@@ -1,56 +0,0 @@
|
||||
--[[-- Adds some parse functions that can be used with the role system
|
||||
@config Commands-Parse-Roles
|
||||
@usage Adds Parses:
|
||||
role
|
||||
player-role
|
||||
player-role-online
|
||||
player-role-alive
|
||||
]]
|
||||
|
||||
local ExpUtil = require("modules/exp_util")
|
||||
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
|
||||
local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles
|
||||
local auto_complete = ExpUtil.auto_complete --- @dep expcore.common
|
||||
require("modules.exp_legacy.config.expcore.command_general_parse")
|
||||
|
||||
-- luacheck:ignore 212/player
|
||||
Commands.add_parse("role", function(input, player, reject)
|
||||
if not input then return end
|
||||
local roles = Roles.config.order
|
||||
local rev_roles = {}
|
||||
for i = #roles, 1, -1 do
|
||||
table.insert(rev_roles, roles[i])
|
||||
end
|
||||
|
||||
local role = auto_complete(rev_roles, input)
|
||||
role = Roles.get_role_by_name(role)
|
||||
if not role then
|
||||
return reject{ "expcore-role.reject-role" }
|
||||
else
|
||||
return role
|
||||
end
|
||||
end)
|
||||
|
||||
Commands.add_parse("player-role", function(input, player, reject)
|
||||
local input_player = Commands.parse("player", input, player, reject)
|
||||
if not input_player then return end -- nil check
|
||||
local player_highest = Roles.get_player_highest_role(player)
|
||||
local input_player_highest = Roles.get_player_highest_role(input_player)
|
||||
if player_highest.index < input_player_highest.index then
|
||||
return input_player
|
||||
else
|
||||
return reject{ "expcore-roles.reject-player-role" }
|
||||
end
|
||||
end)
|
||||
|
||||
Commands.add_parse("player-role-online", function(input, player, reject)
|
||||
local input_player = Commands.parse("player-role", input, player, reject)
|
||||
if not input_player then return end -- nil check
|
||||
return Commands.parse("player-online", input_player.name, player, reject)
|
||||
end)
|
||||
|
||||
Commands.add_parse("player-role-alive", function(input, player, reject)
|
||||
local input_player = Commands.parse("player-role", input, player, reject)
|
||||
if not input_player then return end -- nil check
|
||||
return Commands.parse("player-alive", input_player.name, player, reject)
|
||||
end)
|
||||
@@ -1,32 +0,0 @@
|
||||
--- This config for command auth allows commands to be globally enabled and disabled during runtime;
|
||||
-- this config adds Commands.disable and Commands.enable to enable and disable commands for all users
|
||||
-- @config Commands-Auth-Runtime-Disable
|
||||
|
||||
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
|
||||
local Storage = require("modules/exp_util/storage")
|
||||
|
||||
local disabled_commands = {}
|
||||
Storage.register(disabled_commands, function(tbl)
|
||||
disabled_commands = tbl
|
||||
end)
|
||||
|
||||
--- Stops a command from be used by any one
|
||||
-- @tparam string command_name the name of the command to disable
|
||||
function Commands.disable(command_name)
|
||||
disabled_commands[command_name] = true
|
||||
end
|
||||
|
||||
--- Allows a command to be used again after disable was used
|
||||
-- @tparam string command_name the name of the command to enable
|
||||
function Commands.enable(command_name)
|
||||
disabled_commands[command_name] = nil
|
||||
end
|
||||
|
||||
-- luacheck:ignore 212/player 212/tags
|
||||
Commands.add_authenticator(function(player, command, tags, reject)
|
||||
if disabled_commands[command] then
|
||||
return reject{ "command-auth.command-disabled" }
|
||||
else
|
||||
return true
|
||||
end
|
||||
end)
|
||||
Reference in New Issue
Block a user