行会公告全靠会长手动发布:深夜活动公告忘发、重复发同一公告、公告文案被误改——公告管理缺乏排期与审批流程。定时发布封装:公告预设发布时间与内容,到点自动推送,发布前走内容过滤(敏感词检查),支持定时撤销。
定时发布与内容过滤:排期队列、敏感词检查、自动推送。示例代码如下:
local publishQueue = {}
local function scheduleNotice(guildName, text, publishTs)
local filtered = contentFilter(text)
if filtered == nil then
sendmsg(getplayerbyname(guildName), 1, "公告含敏感内容,请修改。")
return false
end
publishQueue[#publishQueue + 1] =
{ guild = guildName, text = filtered, ts = publishTs }
return true
end
local function contentFilter(text)
local BAD = { "代充", "外挂", "线下交易" }
for _, w in ipairs(BAD) do
if string.find(text, w, 1, true) then
return nil
end
end
return text
end
local function processQueue()
local now = os.time()
local remaining = {}
for _, item in ipairs(publishQueue) do
if now >= item.ts then
sendmsg(nil, 1, "[" .. item.guild .. "] " .. item.text)
else
remaining[#remaining + 1] = item
end
end
publishQueue = remaining
end
撤销已排期的公告示例代码如下:
local function cancelNotice(guildName)
local remaining = {}
for _, item in ipairs(publishQueue) do
if item.guild ~= guildName then
remaining[#remaining + 1] = item
end
end
publishQueue = remaining
end
schedulePress 的 contentFilter 在入队前过滤敏感词(代充、外挂、线下交易),命中的公告不入队。processQueue 每分钟由定时器调用,到期的公告推送至世界频道后从队列移除。cancelNotice 按行会名清除该行会全部待发公告。
公告排期踩过三个坑:一是同一行会重复排期导致同一公告发多次,排期前查重(同行会同时段去重);二是进程重启后内存队列丢失,排期数据需落库并在启动时恢复;三是敏感词库只过滤了精确匹配,变体(加空格、拆字)绕过检测——复用聊天频道的变体归一逻辑。
全站技术干货持续更新:996 引擎 / Lua 实战帖,语法、参数与示例一篇讲透。进入文章地图 · 查看全部 →
【游戏】 一、一行代码拆解:score = 3000 - used 10 —— 副本评分的全部骨架:基础分减去用时惩罚,分数…
【语法】 一、隐蔽陷阱:Lua 没有四舍五入函数,math.floor(2.5) 得 2 恒向负无穷取整——正数的四舍五入要…
【游戏】 一、业务场景:攻城战开打,会长世界喊话等人集合耽误 8 分钟,守军早已布防;集结令上线——会长发起,在线成员一键传…
【语法】 一、抛坑提问:乱序编号 {100, 4, 200, 1, 3, 2} 里最长连续段是 1 到 4 长度 4——排序…
【语法】 一、抛坑提问:统计第 1 到第 10 项,写 for i = 1, t - 1 少算一个,写 for i = 1,…
【游戏】 一、一行代码拆解:if old and old = actor then kick(old) end —— 顶号的…