add window
This commit is contained in:
parent
2b9cdeb329
commit
7aea375db3
3 changed files with 258 additions and 0 deletions
157
deno.lock
157
deno.lock
|
@ -1,5 +1,162 @@
|
|||
{
|
||||
"version": "3",
|
||||
"packages": {
|
||||
"specifiers": {
|
||||
"npm:discord.js": "npm:discord.js@14.13.0"
|
||||
},
|
||||
"npm": {
|
||||
"@discordjs/builders@1.6.5": {
|
||||
"integrity": "sha512-SdweyCs/+mHj+PNhGLLle7RrRFX9ZAhzynHahMCLqp5Zeq7np7XC6/mgzHc79QoVlQ1zZtOkTTiJpOZu5V8Ufg==",
|
||||
"dependencies": {
|
||||
"@discordjs/formatters": "@discordjs/formatters@0.3.2",
|
||||
"@discordjs/util": "@discordjs/util@1.0.1",
|
||||
"@sapphire/shapeshift": "@sapphire/shapeshift@3.9.2",
|
||||
"discord-api-types": "discord-api-types@0.37.50",
|
||||
"fast-deep-equal": "fast-deep-equal@3.1.3",
|
||||
"ts-mixer": "ts-mixer@6.0.3",
|
||||
"tslib": "tslib@2.6.2"
|
||||
}
|
||||
},
|
||||
"@discordjs/collection@1.5.3": {
|
||||
"integrity": "sha512-SVb428OMd3WO1paV3rm6tSjM4wC+Kecaa1EUGX7vc6/fddvw/6lg90z4QtCqm21zvVe92vMMDt9+DkIvjXImQQ==",
|
||||
"dependencies": {}
|
||||
},
|
||||
"@discordjs/formatters@0.3.2": {
|
||||
"integrity": "sha512-lE++JZK8LSSDRM5nLjhuvWhGuKiXqu+JZ/DsOR89DVVia3z9fdCJVcHF2W/1Zxgq0re7kCzmAJlCMMX3tetKpA==",
|
||||
"dependencies": {
|
||||
"discord-api-types": "discord-api-types@0.37.50"
|
||||
}
|
||||
},
|
||||
"@discordjs/rest@2.0.1": {
|
||||
"integrity": "sha512-/eWAdDRvwX/rIE2tuQUmKaxmWeHmGealttIzGzlYfI4+a7y9b6ZoMp8BG/jaohs8D8iEnCNYaZiOFLVFLQb8Zg==",
|
||||
"dependencies": {
|
||||
"@discordjs/collection": "@discordjs/collection@1.5.3",
|
||||
"@discordjs/util": "@discordjs/util@1.0.1",
|
||||
"@sapphire/async-queue": "@sapphire/async-queue@1.5.0",
|
||||
"@sapphire/snowflake": "@sapphire/snowflake@3.5.1",
|
||||
"@vladfrangu/async_event_emitter": "@vladfrangu/async_event_emitter@2.2.2",
|
||||
"discord-api-types": "discord-api-types@0.37.50",
|
||||
"magic-bytes.js": "magic-bytes.js@1.0.19",
|
||||
"tslib": "tslib@2.6.2",
|
||||
"undici": "undici@5.22.1"
|
||||
}
|
||||
},
|
||||
"@discordjs/util@1.0.1": {
|
||||
"integrity": "sha512-d0N2yCxB8r4bn00/hvFZwM7goDcUhtViC5un4hPj73Ba4yrChLSJD8fy7Ps5jpTLg1fE9n4K0xBLc1y9WGwSsA==",
|
||||
"dependencies": {}
|
||||
},
|
||||
"@discordjs/ws@1.0.1": {
|
||||
"integrity": "sha512-avvAolBqN3yrSvdBPcJ/0j2g42ABzrv3PEL76e3YTp2WYMGH7cuspkjfSyNWaqYl1J+669dlLp+YFMxSVQyS5g==",
|
||||
"dependencies": {
|
||||
"@discordjs/collection": "@discordjs/collection@1.5.3",
|
||||
"@discordjs/rest": "@discordjs/rest@2.0.1",
|
||||
"@discordjs/util": "@discordjs/util@1.0.1",
|
||||
"@sapphire/async-queue": "@sapphire/async-queue@1.5.0",
|
||||
"@types/ws": "@types/ws@8.5.6",
|
||||
"@vladfrangu/async_event_emitter": "@vladfrangu/async_event_emitter@2.2.2",
|
||||
"discord-api-types": "discord-api-types@0.37.50",
|
||||
"tslib": "tslib@2.6.2",
|
||||
"ws": "ws@8.14.2"
|
||||
}
|
||||
},
|
||||
"@sapphire/async-queue@1.5.0": {
|
||||
"integrity": "sha512-JkLdIsP8fPAdh9ZZjrbHWR/+mZj0wvKS5ICibcLrRI1j84UmLMshx5n9QmL8b95d4onJ2xxiyugTgSAX7AalmA==",
|
||||
"dependencies": {}
|
||||
},
|
||||
"@sapphire/shapeshift@3.9.2": {
|
||||
"integrity": "sha512-YRbCXWy969oGIdqR/wha62eX8GNHsvyYi0Rfd4rNW6tSVVa8p0ELiMEuOH/k8rgtvRoM+EMV7Csqz77YdwiDpA==",
|
||||
"dependencies": {
|
||||
"fast-deep-equal": "fast-deep-equal@3.1.3",
|
||||
"lodash": "lodash@4.17.21"
|
||||
}
|
||||
},
|
||||
"@sapphire/snowflake@3.5.1": {
|
||||
"integrity": "sha512-BxcYGzgEsdlG0dKAyOm0ehLGm2CafIrfQTZGWgkfKYbj+pNNsorZ7EotuZukc2MT70E0UbppVbtpBrqpzVzjNA==",
|
||||
"dependencies": {}
|
||||
},
|
||||
"@types/node@18.16.19": {
|
||||
"integrity": "sha512-IXl7o+R9iti9eBW4Wg2hx1xQDig183jj7YLn8F7udNceyfkbn1ZxmzZXuak20gR40D7pIkIY1kYGx5VIGbaHKA==",
|
||||
"dependencies": {}
|
||||
},
|
||||
"@types/ws@8.5.6": {
|
||||
"integrity": "sha512-8B5EO9jLVCy+B58PLHvLDuOD8DRVMgQzq8d55SjLCOn9kqGyqOvy27exVaTio1q1nX5zLu8/6N0n2ThSxOM6tg==",
|
||||
"dependencies": {
|
||||
"@types/node": "@types/node@18.16.19"
|
||||
}
|
||||
},
|
||||
"@vladfrangu/async_event_emitter@2.2.2": {
|
||||
"integrity": "sha512-HIzRG7sy88UZjBJamssEczH5q7t5+axva19UbZLO6u0ySbYPrwzWiXBcC0WuHyhKKoeCyneH+FvYzKQq/zTtkQ==",
|
||||
"dependencies": {}
|
||||
},
|
||||
"busboy@1.6.0": {
|
||||
"integrity": "sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==",
|
||||
"dependencies": {
|
||||
"streamsearch": "streamsearch@1.1.0"
|
||||
}
|
||||
},
|
||||
"discord-api-types@0.37.50": {
|
||||
"integrity": "sha512-X4CDiMnDbA3s3RaUXWXmgAIbY1uxab3fqe3qwzg5XutR3wjqi7M3IkgQbsIBzpqBN2YWr/Qdv7JrFRqSgb4TFg==",
|
||||
"dependencies": {}
|
||||
},
|
||||
"discord.js@14.13.0": {
|
||||
"integrity": "sha512-Kufdvg7fpyTEwANGy9x7i4od4yu5c6gVddGi5CKm4Y5a6sF0VBODObI3o0Bh7TGCj0LfNT8Qp8z04wnLFzgnbA==",
|
||||
"dependencies": {
|
||||
"@discordjs/builders": "@discordjs/builders@1.6.5",
|
||||
"@discordjs/collection": "@discordjs/collection@1.5.3",
|
||||
"@discordjs/formatters": "@discordjs/formatters@0.3.2",
|
||||
"@discordjs/rest": "@discordjs/rest@2.0.1",
|
||||
"@discordjs/util": "@discordjs/util@1.0.1",
|
||||
"@discordjs/ws": "@discordjs/ws@1.0.1",
|
||||
"@sapphire/snowflake": "@sapphire/snowflake@3.5.1",
|
||||
"@types/ws": "@types/ws@8.5.6",
|
||||
"discord-api-types": "discord-api-types@0.37.50",
|
||||
"fast-deep-equal": "fast-deep-equal@3.1.3",
|
||||
"lodash.snakecase": "lodash.snakecase@4.1.1",
|
||||
"tslib": "tslib@2.6.2",
|
||||
"undici": "undici@5.22.1",
|
||||
"ws": "ws@8.14.2"
|
||||
}
|
||||
},
|
||||
"fast-deep-equal@3.1.3": {
|
||||
"integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==",
|
||||
"dependencies": {}
|
||||
},
|
||||
"lodash.snakecase@4.1.1": {
|
||||
"integrity": "sha512-QZ1d4xoBHYUeuouhEq3lk3Uq7ldgyFXGBhg04+oRLnIz8o9T65Eh+8YdroUwn846zchkA9yDsDl5CVVaV2nqYw==",
|
||||
"dependencies": {}
|
||||
},
|
||||
"lodash@4.17.21": {
|
||||
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
|
||||
"dependencies": {}
|
||||
},
|
||||
"magic-bytes.js@1.0.19": {
|
||||
"integrity": "sha512-/088hrf0svd5aDFLXuWStA447/ZXv21sS/1uaaPELohYL8+QzcO3mD8JkEFe0DSAsU5ex+O2+12Zmiz7wIdA1Q==",
|
||||
"dependencies": {}
|
||||
},
|
||||
"streamsearch@1.1.0": {
|
||||
"integrity": "sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==",
|
||||
"dependencies": {}
|
||||
},
|
||||
"ts-mixer@6.0.3": {
|
||||
"integrity": "sha512-k43M7uCG1AkTyxgnmI5MPwKoUvS/bRvLvUb7+Pgpdlmok8AoqmUaZxUUw8zKM5B1lqZrt41GjYgnvAi0fppqgQ==",
|
||||
"dependencies": {}
|
||||
},
|
||||
"tslib@2.6.2": {
|
||||
"integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==",
|
||||
"dependencies": {}
|
||||
},
|
||||
"undici@5.22.1": {
|
||||
"integrity": "sha512-Ji2IJhFXZY0x/0tVBXeQwgPlLWw13GVzpsWPQ3rV50IFMMof2I55PZZxtm4P6iNq+L5znYN9nSTAq0ZyE6lSJw==",
|
||||
"dependencies": {
|
||||
"busboy": "busboy@1.6.0"
|
||||
}
|
||||
},
|
||||
"ws@8.14.2": {
|
||||
"integrity": "sha512-wEBG1ftX4jcglPxgFCMJmZ2PLtSbJ2Peg6TmpJFTbe9GZYOQCDPdMYu/Tm0/bGZkw8paZnJY45J4K2PZrLYq8g==",
|
||||
"dependencies": {}
|
||||
}
|
||||
}
|
||||
},
|
||||
"redirects": {
|
||||
"https://deno.land/x/canvas/mod.ts": "https://deno.land/x/canvas@v1.4.1/mod.ts",
|
||||
"https://deno.land/x/emit/mod.ts": "https://deno.land/x/emit@0.28.0/mod.ts"
|
||||
|
|
5
serverside/window/.vscode/settings.json
vendored
Normal file
5
serverside/window/.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"deno.enable": true,
|
||||
"deno.lint": true,
|
||||
"deno.unstable": true
|
||||
}
|
96
serverside/window/main.ts
Normal file
96
serverside/window/main.ts
Normal file
|
@ -0,0 +1,96 @@
|
|||
// server and discord in one
|
||||
|
||||
import { Client, Events, GatewayIntentBits } from "npm:discord.js";
|
||||
import { createCanvas } from "https://deno.land/x/canvas/mod.ts";
|
||||
import { contentType } from "https://deno.land/std@0.202.0/media_types/mod.ts";
|
||||
|
||||
import config from "./config.json" with { type: "json" };
|
||||
|
||||
type Message = { author: string; content: string; id: string };
|
||||
|
||||
const kv = await Deno.openKv();
|
||||
|
||||
let messages = (await kv.get<Message[]>(["messages"])).value ?? [];
|
||||
|
||||
const client = new Client({
|
||||
intents: [
|
||||
GatewayIntentBits.Guilds,
|
||||
GatewayIntentBits.GuildMessages,
|
||||
GatewayIntentBits.MessageContent,
|
||||
],
|
||||
});
|
||||
|
||||
client.once(Events.ClientReady, (c) => {
|
||||
console.log(`logged in as ${c.user.tag}`);
|
||||
});
|
||||
|
||||
client.login(config.token);
|
||||
|
||||
// we don't need to await!
|
||||
function update_messages() {
|
||||
kv.set(["messages"], messages);
|
||||
}
|
||||
|
||||
function add_message(msg: Message) {
|
||||
messages.push(msg);
|
||||
update_messages();
|
||||
}
|
||||
|
||||
function delete_message(id: string) {
|
||||
messages = messages.filter((m) => m.id != id);
|
||||
update_messages();
|
||||
}
|
||||
|
||||
client.on(Events.MessageCreate, (message) => {
|
||||
add_message({
|
||||
author: message.author.username,
|
||||
content: message.content,
|
||||
id: message.id,
|
||||
});
|
||||
console.log("added", messages);
|
||||
});
|
||||
|
||||
client.on(Events.MessageDelete, (message) => {
|
||||
delete_message(message.id);
|
||||
console.log("deleted", message.id, messages);
|
||||
});
|
||||
|
||||
const canvas = createCanvas(1025, 612);
|
||||
const ctx = canvas.getContext("2d");
|
||||
|
||||
const default_fill = "#3B0920";
|
||||
const bg_fill = "#FFE8D4";
|
||||
const border_stroke = "#83254F";
|
||||
|
||||
function clear_canvas() {
|
||||
ctx.fillStyle = bg_fill;
|
||||
ctx.strokeStyle = border_stroke;
|
||||
ctx.lineWidth = 10;
|
||||
ctx.fillRect(0, 0, 1025, 612);
|
||||
ctx.strokeRect(0, 0, 1025, 612);
|
||||
}
|
||||
|
||||
function draw_message(x: number, y: number, message: Message) {
|
||||
ctx.fillStyle = "#FFAB5C";
|
||||
ctx.fillText(message.author, x, y);
|
||||
ctx.fillStyle = default_fill;
|
||||
ctx.fillText(
|
||||
message.content,
|
||||
x + ctx.measureText(message.author).width + 5,
|
||||
y,
|
||||
);
|
||||
}
|
||||
|
||||
Deno.serve({ port: 61263 }, () => {
|
||||
const most_recent = messages.slice(-40);
|
||||
|
||||
clear_canvas();
|
||||
|
||||
most_recent.forEach((msg, i) => {
|
||||
draw_message(13, 17 + i * 15, msg);
|
||||
});
|
||||
|
||||
return new Response(canvas.toBuffer(), {
|
||||
headers: { "Content-Type": contentType("png") },
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue