# 数据库架构

机器人使用两个本地 SQLite 文件，它们会在首次运行时自动创建。

***

## warnings.db

存储所有口头警告记录。

### verbal\_warnings

| 列              | 类型            | 描述                       |
| -------------- | ------------- | ------------------------ |
| `id`           | INTEGER 主键 自增 | 唯一警告 ID                  |
| `createdAt`    | TEXT          | 时间戳（UTC，插入时自动设置）         |
| `userId`       | INTEGER       | 被警告者的 Discord 用户 ID      |
| `reason`       | TEXT          | 警告原因                     |
| `evidenceLink` | TEXT          | 作为证据使用的 Discord 消息链接     |
| `modId`        | INTEGER       | 执行管理的工作人员的 Discord 用户 ID |

**索引：** `idx_vw_userId` 在 `userId` 用于快速按用户查找。

```sql
CREATE TABLE verbal_warnings (
    id           INTEGER PRIMARY KEY AUTOINCREMENT,
    createdAt    TEXT    NOT NULL DEFAULT (datetime('now')),
    userId       INTEGER NOT NULL,
    reason       TEXT    NOT NULL,
    evidenceLink TEXT    NOT NULL,
    modId        INTEGER NOT NULL
);

CREATE INDEX idx_vw_userId ON verbal_warnings (userId);
```

***

## staffpolls.db

存储投票、其选项以及投票者记录。

### staffpoll\_polls

| 列              | 类型         | 描述                  |
| -------------- | ---------- | ------------------- |
| `id`           | INTEGER 主键 | 唯一投票 ID             |
| `title`        | TEXT       | 投票标题                |
| `description`  | TEXT       | 投票描述（默认：空）          |
| `created_at`   | TEXT       | 创建时间戳（UTC）          |
| `created_by`   | INTEGER    | 创建者的 Discord 用户 ID  |
| `channel_id`   | INTEGER    | 发布投票的频道             |
| `message_id`   | INTEGER    | 投票嵌入消息的消息 ID        |
| `is_active`    | INTEGER    | 1 = 开启，0 = 关闭       |
| `is_anonymous` | INTEGER    | 1 = 隐藏投票者身份         |
| `max_votes`    | INTEGER    | 每位投票者最多可选项数（0 = 不限） |

### staffpoll\_options

| 列               | 类型         | 描述                             |
| --------------- | ---------- | ------------------------------ |
| `id`            | INTEGER 主键 | 唯一选项 ID                        |
| `poll_id`       | INTEGER 外键 | 引用 `staffpoll_polls.id` （级联删除） |
| `label`         | TEXT       | 按钮上显示的选项文本                     |
| `display_order` | INTEGER    | 按钮排序（升序）                       |

***

## Supabase（Auttaja 集成）

Auttaja 组件会从外部 Supabase 表读取并写入数据。此表不由机器人管理——假定它已在之前的 Auttaja 部署中存在。

### public.punishments

| 列                | 描述                                                        |
| ---------------- | --------------------------------------------------------- |
| `id`             | 记录 ID                                                     |
| `guild_id`       | Discord 服务器 ID                                            |
| `offender`       | 被处罚成员的 Discord 用户 ID                                      |
| `punisher`       | 工作人员的 Discord 用户 ID                                       |
| `reason`         | 处罚原因                                                      |
| `action`         | 操作类型： `ban`, `tempban`, `softban`, `mute`, `kick`, `warn` |
| `timestamp`      | 处罚发出时间                                                    |
| `duration`       | 时长（用于临时封禁/禁言）                                             |
| `deleted`        | 软删除标记                                                     |
| `removed_by`     | 移除该处罚的人                                                   |
| `removed_reason` | 移除处罚的原因                                                   |
| `resolve`        | 解决备注                                                      |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.vigila.augystudios.com/zh/can-kao/database-schema.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
