创建: 2026/07/02 19:41:27 America/Chicago
作者: admin

auto-topic.lua 脚本以设定的时间间隔将配置的中心通知发布到 Verlihub 主聊天。将其用于规则提醒、维护说明、支持链接、命令提示和简短的社区消息,不需要单独的外部机器人。

保持这个脚本很小。它应该发送简短的配置消息,然后将控制权返回给 Verlihub。不要向此脚本添加长时间运行的作业、数据库查询、外部 HTTP 请求、文件扫描或阻塞等待。

该脚本的作用

该脚本从配置的机器人名称或集线器身份发送自动主聊天消息。

常见用途包括:

  • 发帖中心规则提醒。
  • 发布网站或支持链接。
  • 宣布定期维护。
  • 提醒用户可用的命令。
  • 共享社区链接。
  • 显示轮流通知。
  • 发布当天时间消息。

主聊天通知示例:

<HubNotice> Please review the hub rules with !rules before sharing or chatting.

要求

该脚本需要:

  • Verlihub 已安装并正在运行。
  • 已安装 Verlihub Lua 插件。
  • Lua 插件在 Verlihub 中启用。
  • 加载和卸载 Lua 脚本的权限。
  • Verlihub Lua 个文件的可写脚本目录。

在加载脚本之前,请确认 Lua 插件处于活动状态:

!pluglist

如果未列出 Lua 插件,请首先从父级 Lua 设置文章中加载或启用它。

使用专用脚本目录:

mkdir -p /PATH/TO/HUB/scripts

将脚本放置在:

/PATH/TO/HUB/scripts/auto-topic.lua

对于生产系统,该目录只能由受信任的管理员或 Verlihub 服务用户写入。不要使该目录成为全局可写的。

加载和卸载命令

加载脚本:

!luaload /PATH/TO/HUB/scripts/auto-topic.lua

卸载脚本:

!luaunload /PATH/TO/HUB/scripts/auto-topic.lua

如果您编辑脚本,请将其卸载并再次加载:

!luaunload /PATH/TO/HUB/scripts/auto-topic.lua
!luaload /PATH/TO/HUB/scripts/auto-topic.lua

使用完整的绝对路径,除非您的 Verlihub Lua 插件配置支持相对路径。

脚本代码

-- Script: auto-topic.lua
-- Purpose: Sends rotating automatic notices to Verlihub main chat.
-- Scope: Lightweight hub notices only.
-- Notes: Keep interval reasonable to avoid chat spam.

botname = "HubNotice"
interval = 900
counter = 0
notice_index = 1

notices = {
    "Welcome to the hub. Please read the rules with !rules.",
    "Need help? Use !help or contact an operator.",
    "Visit our website for updates, guides, and hub information.",
    "Keep main chat respectful and avoid spam or repeated messages."
}

function SendNotice()
    if notices[notice_index] == nil then
        notice_index = 1
    end

    VH:SendToAll("<" .. botname .. "> " .. notices[notice_index])
    notice_index = notice_index + 1

    if notice_index > table.getn(notices) then
        notice_index = 1
    end
end

function OnTimer()
    counter = counter + 1

    if counter >= interval then
        counter = 0
        SendNotice()
    end
end

配置选项

botname

botname = "HubNotice"

自动通知之前显示的名称。选择一个清晰的名称,以便用户了解该消息是自动中心信息。

示例:

botname = "HubNotice"
botname = "RulesBot"
botname = "InfoBot"
botname = "Maintenance"

interval

interval = 900

控制脚本发送通知的频率。预期值通常为秒,具体取决于您的环境中 Verlihub Lua 计时器的配置方式。

推荐值:

价值意义
300每 5 分钟一次。
600每 10 分钟一班。
900每 15 分钟一班。
1800每 30 分钟一班。
3600每 60 分钟一班。

对于生产中心来说,900 或者 1800 通常比短间隔更安全。避免使集线器产生噪音的值:

interval = 10

对于正常的主聊天来说,每 10 秒发布一次通知太过激进。

counter

counter = 0

脚本使用的内部计数器。除非您要修改脚本逻辑,否则请勿更改此设置。

notice_index

notice_index = 1

跟踪接下来应该发送哪个通知。将此保留在 1 除非您希望脚本从不同的消息开始。

notices

notices = {
    "Welcome to the hub. Please read the rules with !rules.",
    "Need help? Use !help or contact an operator.",
    "Visit our website for updates, guides, and hub information.",
    "Keep main chat respectful and avoid spam or repeated messages."
}

在主聊天中轮流显示的消息列表。每条通知都应该简短、有用且不会造成干扰。

好的通知示例:

notices = {
    "Use !rules to view hub rules.",
    "Use !help to see available commands.",
    "Operators are marked in the user list if you need assistance.",
    "Please keep main chat friendly and on topic."
}

避免冗长、重复或攻击性的通知。当自动消息出现过于频繁时,用户更有可能忽略它们。

配置示例

基本规则提醒

botname = "RulesBot"
interval = 1800
notices = {
    "Please read the hub rules with !rules.",
    "Do not spam main chat or repeat the same message.",
    "Respect other users and follow operator instructions."
}

网站和支持通知

botname = "InfoBot"
interval = 3600
notices = {
    "Visit the website for hub guides, updates, and support.",
    "Need help? Use !help or contact an operator.",
    "Check the articles section for Verlihub setup notes and Lua scripts."
}

维护通知

botname = "Maintenance"
interval = 900
notices = {
    "Scheduled maintenance may occur during low-traffic hours.",
    "If the hub disconnects during maintenance, reconnect after a few minutes.",
    "Check the website for maintenance updates."
}

社区公告

botname = "Community"
interval = 1800
notices = {
    "Welcome to the hub. Keep chat friendly and helpful.",
    "Use main chat for general discussion. Contact operators for support issues.",
    "Invite trusted users and help keep the hub useful."
}

对于大多数中心,使用 15 分钟或 30 分钟的间隔:

botname = "HubNotice"
interval = 1800
notices = {
    "Welcome to the hub. Use !rules to review the hub rules.",
    "Need help? Use !help or contact an operator.",
    "Keep main chat respectful and avoid spam."
}

这可以使通知保持可见,而不会淹没聊天。对于繁忙的集线器,请使用:

interval = 3600

对于安静的集线器,请使用:

interval = 1800

主要的聊天自动化应该支持社区,而不是打断它。

测试脚本

加载脚本后,确认:

  • 脚本加载时没有错误。
  • 该通知出现在主聊天中。
  • 通知按预期顺序轮换。
  • 间隔不太激进。
  • 机器人名称很清楚。
  • 该脚本卸载干净。
  • 重新加载脚本不会创建重复的计时器或重复的通知。

先用短间隔进行测试,然后改为生产间隔。

测试设置示例:

interval = 30

测试后,改回来:

interval = 1800

然后重新加载脚本。

故障排除

脚本无法加载

检查 Lua 插件是否处于活动状态:

!pluglist

检查文件路径是否正确:

!luaload /PATH/TO/HUB/scripts/auto-topic.lua

如果相对路径不起作用,请使用绝对路径。

通知不出现

查看:

  • Lua 插件已加载。
  • 脚本路径正确。
  • 您的 Verlihub Lua 插件版本支持计时器功能。
  • 测试时间隔不要太高。
  • notices 表至少包含一条消息。

暂时使用:

interval = 30

然后重新加载脚本并等待下一次通知。

通知出现得太频繁

增加间隔。

interval = 1800

或者:

interval = 3600

避免在生产环境使用过短的间隔。

出现重复通知

这通常意味着脚本被加载多次或旧实例未正确卸载。

卸载脚本:

!luaunload /PATH/TO/HUB/scripts/auto-topic.lua

然后再次加载:

!luaload /PATH/TO/HUB/scripts/auto-topic.lua

如果重复出现,请在维护时段重新启动 Lua 插件或 Verlihub 服务。

编辑通知后出现脚本错误

检查 Lua 语法。每个通知行都应以逗号结尾,最后一行除外,最后一行可能会省略它。

正确的:

notices = {
    "First notice.",
    "Second notice.",
    "Third notice."
}

错误:

notices = {
    "First notice."
    "Second notice."
}

错误的示例是在第一条消息后缺少逗号。

安全注意事项

该脚本应该保持轻量级。不要添加:

  • 外部 HTTP 请求。
  • 数据库查询。
  • 文件扫描。
  • 长循环。
  • 阻止睡眠呼叫。
  • 每个用户的繁重处理。

该脚本应该只轮换配置的通知并以合理的时间间隔发送它们。

保养注意事项

更改脚本之前保留备份:

cp /PATH/TO/HUB/scripts/auto-topic.lua /PATH/TO/HUB/scripts/auto-topic.lua.bak

如果使用 Git:

cd /PATH/TO/HUB/scripts
git add auto-topic.lua
git commit -m "Update auto-topic.lua notices"

仅更改机器人名称、通知或间隔时,不需要更改逻辑。

建议的通知写作规则

好的通知简短而有用。

受到推崇的:

  • 每份通知一个想法。
  • 措辞清晰。
  • 没有重复的标点符号。
  • 没有全部大写的消息。
  • 没有过于频繁的发帖。
  • 主聊天中没有长段落。

避免:

  • 每隔几秒发布一次。
  • 重复发布同一条消息。
  • 仅将通知用作广告。
  • 将大型规则块发送到主聊天。
  • 经常打断正在进行的对话。

父页面