Skip to content

Discord Logging

Discord 日志

BUPA Chat 拥有两个独立的 Discord 功能。本页介绍出站 Webhook 日志(聊天 → Discord)。入站频道桥接(Discord → 聊天)在 shared/config/discord.lua 中进行配置,是一个独立的功能,将在末尾说明。

Webhook 日志(聊天 → Discord)

Webhook URL 存储在 server/webhook.lua 中 —— 这是一个你可以直接编辑的 escrow_ignore 文件。其中定义了三个键:

server/webhook.lua
local webhooks = {
    chatMessage  = "https://.../webhook-proxy/....",
    emoteCommand = "https://.../webhook-proxy/....",
    pmMessage    = "https://.../webhook-proxy/....",
}

请将占位符代理 URL 替换为你自己的 Discord Webhook URL。如果某个键的 URL 为空,则不会为其发送任何内容。

消息如何映射到 Webhook

配置条目通过 webhookKey 引用对应 Webhook 的

  • 分类 —— 每个分类都可以设置 webhookKey(参见 聊天分类)。
  • 私聊消息 —— config.pm.webhookKey(默认为 chatMessage)。
  • 动作/表情 —— 每个动作命令都可以设置 webhookKey/me/do 使用 emoteCommand)。

每条普通的聊天消息都会被记录到 chatMessage Webhook 中。当某个分类同时定义了它自己的 webhookKey 时,该分类的消息将同时记录到分类 WebhookchatMessage Webhook 中。

日志记录由 sendDiscordLog(webhookKey, message, src) 处理,它会向映射的 URL 发送独立的 JSON 有效负载 —— 无需外部的 Discord 资源:

server/webhook.lua
function sendDiscordLog(webhook, msg, src)
    local url = webhooks[webhook]
    if not url or url == "" then return end
    local payload = type(msg) == "table" and { embeds = { msg } } or { content = tostring(msg) }
    PerformHttpRequest(url, function() end, "POST", json.encode(payload),
        { ["Content-Type"] = "application/json" })
end

要添加新的日志目标,只需在 webhooks 表中添加一个键,并通过 webhookKey 从分类、私聊或动作中引用它。

频道桥接(Discord → 聊天)

另外,shared/config/discord.lua (config.discord) 可以轮询 Discord 频道并将其消息转发到游戏聊天中。该功能默认处于禁用状态。

shared/config/discord.lua
config.discord = {
    active = false,
    pollInterval = 15000,   -- 两次轮询之间的毫秒数
    channels = {
        {
            channelId = "",   -- 要读取的 Discord 频道
            -- permissions = { "admin" },   -- 可选:谁可以看到这些消息
            -- jobs  = { police = true },
            -- gangs = { whiteGang = true },
            tags = { { tag = "Discord", textColor = { 51, 51, 51 }, bgColor = { 88, 101, 242 } } },
            color = { 200, 200, 200 },
        },
        -- 更多频道:包含 Discord 管理员 / PD / EMS / 帮派示例
    },
}

每个频道条目都可以通过 permissionsjobsgangs 进行权限限制,因此频道的消息只会显示给符合条件的玩家。该桥接通过 Discord Bot API 读取消息,并且需要 Bot Token + Guild ID —— 可以直接在 config.discord 中提供,或者从 general.luaconfig.adminChatName.discord 中复用。由 Bot 发送的消息将被忽略。