mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-11-14 08:14:52 +09:00
Features can now be enabled, disabled, and configured from the web UI while the game is running, without editing Lua files. The first five features covered are AFK Kick, Chat Auto Reply, Death Markers, Mine Depletion, and Station Auto Name. Lua side: module/features.lua holds each feature's defaults, keeps the overrides from the controller in storage, and patches them onto the config table in place. Features.guard skips a feature's handlers while it is disabled. The five config files move from exp_legacy into exp_scenario/module/config and their control files now read config at runtime instead of deciding at load which handlers to register. AFK Kick times are now in minutes. Controller side: features.ts lists the editable settings and their defaults. Overrides that differ from the default are stored in exp_scenario/features.json and guarded by the existing exp_scenario.config.view/edit permissions. The instance plugin sends them over rcon on start, on every change, and again after the controller restarts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
65 lines
2.2 KiB
Lua
65 lines
2.2 KiB
Lua
--[[-- Control - Chat Auto Reply
|
|
Adds auto replies to chat messages, as well as chat commands
|
|
]]
|
|
|
|
local Features = require("modules/exp_scenario/features")
|
|
local Roles = require("modules/exp_roles")
|
|
local config = require("modules/exp_scenario/config/chat_auto_reply")
|
|
|
|
local find = string.find
|
|
local sub = string.sub
|
|
|
|
--- Check if a message has any trigger words
|
|
--- @param event EventData.on_console_chat
|
|
local function on_console_chat(event)
|
|
if not event.player_index then return end
|
|
local player = assert(game.get_player(event.player_index))
|
|
local message = event.message:lower():gsub("%s+", "")
|
|
local prefix = config.command_prefix
|
|
local prefix_len = string.len(prefix)
|
|
|
|
-- Check if the player can chat commands
|
|
local commands_allowed = true
|
|
if config.command_admin_only and not player.admin then commands_allowed = false end
|
|
if config.command_permission and not Roles.player_has_permission(player, config.command_permission) then commands_allowed = false end
|
|
|
|
-- Check if a key word appears in the message
|
|
for key_word, reply in pairs(config.messages) do
|
|
local start_pos = find(message, key_word)
|
|
if start_pos then
|
|
local is_command = sub(message, start_pos - prefix_len - 1, start_pos - 1) == prefix
|
|
if type(reply) == "function" then
|
|
reply = reply(player, is_command)
|
|
end
|
|
|
|
if is_command and commands_allowed then
|
|
game.print{ "exp_chat-auto-reply.chat-reply", reply }
|
|
elseif is_command then
|
|
player.print{ "exp_chat-auto-reply.chat-disallowed" }
|
|
elseif not commands_allowed then
|
|
player.print{ "exp_chat-auto-reply.chat-reply", reply }
|
|
end
|
|
end
|
|
end
|
|
|
|
if not commands_allowed then return end
|
|
|
|
-- Check if a command appears in the message
|
|
for key_word, reply in pairs(config.commands) do
|
|
if find(message, prefix .. key_word) then
|
|
if type(reply) == "function" then
|
|
reply = reply(player, true)
|
|
end
|
|
game.print{ "exp_chat-auto-reply.chat-reply", reply }
|
|
end
|
|
end
|
|
end
|
|
|
|
local e = defines.events
|
|
|
|
return Features.guard(config, {
|
|
events = {
|
|
[e.on_console_chat] = on_console_chat,
|
|
},
|
|
})
|