mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-11-12 07:54:52 +09:00
Framework: - Intervals are gone. Update periods are hardcoded on_nth_tick values again, since nobody has needed to change them. - apply is a single loop over the declared fields and logs a warning when an override is invalid. receive_update also warns about unknown keys. - Nested tables are addressed as "section.key". Lists of strings can be overridden. Features.optional declares a value with no default. - Features.on_apply rebuilds values derived from the config, such as lookup sets. It also runs during on_load. exp_roles is assumed to be present: - AFK Kick picks a role (active_role_id) instead of a custom check function. - Chat Auto Reply, Protection, and Nuke Protection no longer take a permission as a setting. New features, each chosen for an edge case: - Discord Alerts: conditional handlers, and a command map that becomes a list. - Entity Protection: lists turned into sets at load, and bookkeeping that must keep running while disabled. - Nuke Protection: config keyed by defines, flattened to a banned items list. - Popups: one config shared by two control files. - Spawn Area: nested sections, and settings that only apply when the map is created. Page: now laid out like the role page. It has a search across every setting, one long list with a sticky sidebar to jump between sections, and the enabled switch separated at the front of each header with Reset to defaults on the right. Changed rows are highlighted, and a bottom bar offers Revert and Apply. Role settings use a role picker and lists use a tag select. 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 not Roles.player_has_permission(player, "exp_scenario.chat.commands") 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,
|
|
},
|
|
})
|