Improved logging system

master
Tymon 1 year ago
parent 0067905feb
commit f8220a93bb

@ -1,3 +1,3 @@
# 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 { AIs, checkAI } from "../ai/index.ts";
import { db } from "../database.ts";
import { sendInteractionLog } from "../socket.ts";
export default {
name: "change",
@ -37,6 +38,15 @@ export default {
history: [],
});
sendInteractionLog(
interaction.user.username,
"change",
`${newName ? newName : "[name not changed]"}, ${
newDesc ? "[check description in panel]" : "[description not changed]"
}`,
channelId,
);
await sendInteractionResponse(bot, interaction, {
content: `Name: ${newName ?? "[unchanged]"}\nDescription: ${newDesc ?? "[unchanged]"}`,
});

@ -3,7 +3,7 @@ import { BotEmitter } from "@wackford/mod.ts";
import { AIs } from "../ai/index.ts";
import config from "../config.ts";
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;
@ -36,8 +36,8 @@ export default function init() {
history,
});
sendSocketMessage(user.username, message.content, message.channelId.toString());
sendSocketMessage(
sendMessageLog(user.username, message.content, message.channelId.toString());
sendMessageLog(
AIs[message.channelId.toString()].name,
res,
message.channelId.toString(),

@ -60,25 +60,46 @@ function reqHandler(req: Request) {
}
export default function initialize(hostname: string, port: number) {
serve(reqHandler, { hostname: hostname, port: port });
serve(reqHandler, { hostname, port });
}
export function sendSocketMessage(
name: string,
message: string,
channel: string,
description = "",
) {
function sendLog(type: string, data: Record<string, unknown>) {
Object.keys(connected).forEach((val) => {
if (connected[val]) {
connected[val].ws.send(
JSON.stringify({
name,
description,
message,
channel,
type,
...data,
}),
);
}
});
}
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