Improved logging system

master
Tymon 2 years ago
parent 0067905feb
commit f8220a93bb

@ -1,3 +1,3 @@
# ai_bot # ai_bot
this code should not be used by any sane person, ever.
useless README change to test something this code should not be used by any sane person, ever.

@ -2,6 +2,7 @@ import { sendInteractionResponse, SlashCommandOptions } from "@wackford/mod.ts";
import { ApplicationCommandOptionTypes } from "@wackford/discordeno.ts"; import { ApplicationCommandOptionTypes } from "@wackford/discordeno.ts";
import { AIs, checkAI } from "../ai/index.ts"; import { AIs, checkAI } from "../ai/index.ts";
import { db } from "../database.ts"; import { db } from "../database.ts";
import { sendInteractionLog } from "../socket.ts";
export default { export default {
name: "change", name: "change",
@ -37,6 +38,15 @@ export default {
history: [], history: [],
}); });
sendInteractionLog(
interaction.user.username,
"change",
`${newName ? newName : "[name not changed]"}, ${
newDesc ? "[check description in panel]" : "[description not changed]"
}`,
channelId,
);
await sendInteractionResponse(bot, interaction, { await sendInteractionResponse(bot, interaction, {
content: `Name: ${newName ?? "[unchanged]"}\nDescription: ${newDesc ?? "[unchanged]"}`, content: `Name: ${newName ?? "[unchanged]"}\nDescription: ${newDesc ?? "[unchanged]"}`,
}); });

@ -3,7 +3,7 @@ import { BotEmitter } from "@wackford/mod.ts";
import { AIs } from "../ai/index.ts"; import { AIs } from "../ai/index.ts";
import config from "../config.ts"; import config from "../config.ts";
import blacklist from "../../blacklist.json" assert { type: "json" }; import blacklist from "../../blacklist.json" assert { type: "json" };
import { sendSocketMessage } from "../socket.ts"; import { sendMessageLog } from "../socket.ts";
//const dirname = new URL(".", import.meta.url).pathname; //const dirname = new URL(".", import.meta.url).pathname;
@ -36,8 +36,8 @@ export default function init() {
history, history,
}); });
sendSocketMessage(user.username, message.content, message.channelId.toString()); sendMessageLog(user.username, message.content, message.channelId.toString());
sendSocketMessage( sendMessageLog(
AIs[message.channelId.toString()].name, AIs[message.channelId.toString()].name,
res, res,
message.channelId.toString(), message.channelId.toString(),

@ -60,25 +60,46 @@ function reqHandler(req: Request) {
} }
export default function initialize(hostname: string, port: number) { export default function initialize(hostname: string, port: number) {
serve(reqHandler, { hostname: hostname, port: port }); serve(reqHandler, { hostname, port });
} }
export function sendSocketMessage( function sendLog(type: string, data: Record<string, unknown>) {
name: string,
message: string,
channel: string,
description = "",
) {
Object.keys(connected).forEach((val) => { Object.keys(connected).forEach((val) => {
if (connected[val]) { if (connected[val]) {
connected[val].ws.send( connected[val].ws.send(
JSON.stringify({ JSON.stringify({
name, type,
description, ...data,
message,
channel,
}), }),
); );
} }
}); });
} }
export function sendMessageLog(
name: string,
message: string,
channel: string,
description = "",
) {
sendLog("MessageLog", {
name,
description,
message,
channel,
});
}
export function sendInteractionLog(
name: string,
command: string,
args: string, // funny javascript moment
channel: string,
) {
sendLog("InteractionLog", {
name,
command,
arguments: args,
channel,
});
}

Loading…
Cancel
Save