add docs, protocol, plugins, README, CHANGELOG
This commit is contained in:
parent
1d2209bfac
commit
f262da222b
44 changed files with 9269 additions and 0 deletions
43
plugins/examples/modbot/index.ts
Normal file
43
plugins/examples/modbot/index.ts
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
// VNOX example plugin — moderation bot
|
||||
// Runtime: Deno
|
||||
// See docs/community/plugins.md for full API reference
|
||||
|
||||
const BANNED_WORDS = ["badword", "spam"];
|
||||
|
||||
const ws = new WebSocket("ws://localhost:7800/plugins");
|
||||
|
||||
ws.addEventListener("open", () => {
|
||||
console.log("[modbot] connected to VNOX gateway");
|
||||
});
|
||||
|
||||
ws.addEventListener("message", async (event) => {
|
||||
const e = JSON.parse(event.data);
|
||||
|
||||
if (e.event === "message.created") {
|
||||
const { message_id, channel_id, content } = e.data;
|
||||
const lower = content.toLowerCase();
|
||||
|
||||
if (BANNED_WORDS.some((word) => lower.includes(word))) {
|
||||
await rpc("message.delete", { message_id, channel_id });
|
||||
console.log(`[modbot] deleted message ${message_id}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
ws.addEventListener("close", () => {
|
||||
console.log("[modbot] disconnected");
|
||||
});
|
||||
|
||||
function rpc(method: string, params: object): Promise<unknown> {
|
||||
return new Promise((resolve) => {
|
||||
const id = crypto.randomUUID();
|
||||
ws.send(JSON.stringify({ id, method, params }));
|
||||
ws.addEventListener("message", function handler(e) {
|
||||
const res = JSON.parse((e as MessageEvent).data);
|
||||
if (res.id === id) {
|
||||
ws.removeEventListener("message", handler);
|
||||
resolve(res.result);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
11
plugins/examples/modbot/plugin.json
Normal file
11
plugins/examples/modbot/plugin.json
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"name": "modbot",
|
||||
"version": "0.1.0",
|
||||
"author": "vnox",
|
||||
"description": "Example moderation bot — deletes messages with banned words",
|
||||
"main": "index.ts",
|
||||
"permissions": [
|
||||
"channel.read",
|
||||
"message.delete"
|
||||
]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue