|
Some checks are pending
CI / test (push) Waiting to run
Only config.yaml was bind-mounted into the container, so phrases_file's default "./phrases.yaml" had nothing to resolve to at runtime and the bot crash-looped on startup. phrases.yaml is repo-tracked source, not a secret, so it belongs in the image like the binary itself. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> |
||
|---|---|---|
| .forgejo/workflows | ||
| cmd/yaju-is-always-watching-you | ||
| internal | ||
| .gitignore | ||
| config.example.yaml | ||
| Dockerfile | ||
| go.mod | ||
| go.sum | ||
| LICENSE | ||
| phrases.yaml | ||
| README.md | ||
yaju-is-always-watching-you (語録警察)
Forgejo用の言葉遣い是正bot。淫夢語録その他のネタ言葉遣いをissue/PRコメントやpushされたファイルから検知し、
- コメント/PRへの投稿 → 投稿者に
@mentionして警告リプライ - push → 該当箇所を伏字にした修正ブランチを自動で切り、是正PRをオープン(原文の
git pushやコミット履歴は一切書き換えない)
を行う、クソ真面目にクソどうでもいい機能を実装したbotです。野獣はいつもお前を見ている。
仕組み
Forgejoのwebhook(issue_comment / push)を受け取るだけの単純なHTTPサーバーです。リポジトリごとに何かを仕込む必要はなく、Organization/インスタンス全体のwebhookとして1箇所に登録するだけで全リポジトリに効きます。
Forgejo --webhook--> yaju-keisatsu --Forgejo API--> コメント投稿 / 是正PR作成
セットアップ
1. bot用アカウントとトークンを作る
Forgejo上にbot専用アカウント(例: yaju-keisatsu-bot)を作り、そのアカウントで Settings > Applications からAPIトークンを発行する。対象リポジトリへの読み書き・issue・pull request権限があれば十分。
2. 設定ファイルを用意
cp config.example.yaml config.yaml
config.yaml を編集し、forgejo.base_url / forgejo.token / webhook_secret / bot.username を埋める。
語録リストは phrases.yaml にコミュニティ管理のものが同梱されており、config.yaml の phrases_file: ./phrases.yaml で読み込む(デフォルトで設定済み)。追加・削除の提案はPRで歓迎。自分の運用だけで使いたい追加語録があれば、それとは別に config.yaml の phrases: に書けば phrases_file の内容とマージされる。
config.yaml は秘密情報を含むため絶対にコミットしないこと(.gitignore 済み)。
3. 起動
go run ./cmd/yaju-is-always-watching-you -config config.yaml
または Docker で:
docker build -t yaju-keisatsu .
docker run -p 8080:8080 -v $(pwd)/config.yaml:/etc/yaju-keisatsu/config.yaml yaju-keisatsu
4. Forgejoにwebhookを登録
インスタンス管理画面(サイト全体)、または Organization / リポジトリ単位の Settings > Webhooks から新規Webhookを追加:
- Target URL:
https://<yaju-keisatsuを立てたホスト>/webhook - HTTP Method:
POST - Trigger On:
Issue Comment,Push - Secret:
config.yamlのwebhook_secretと同じ値
動作の安全設計
- 削除や強制pushは一切行わない。 コメントは削除せず警告リプライのみ、pushされたコミット履歴も書き換えず、常に新規ブランチ+PRという提案どまりの形にしている。
- 自己ループ防止。
bot.usernameに設定したアカウント自身のコメント/pushには反応しない。これがないとbotの警告リプライ自体に語録が含まれて無限に自己反応してしまう。
ライセンス
MIT License。LICENSE 参照。Issue・PR歓迎。