diff --git a/README.md b/README.md index 50c2a8a..bdbb270 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/commands/change.ts b/src/commands/change.ts index e863f94..995a0ab 100644 --- a/src/commands/change.ts +++ b/src/commands/change.ts @@ -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]"}`, }); diff --git a/src/events/onMessage.ts b/src/events/onMessage.ts index 56a0ee2..5a88779 100644 --- a/src/events/onMessage.ts +++ b/src/events/onMessage.ts @@ -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(), diff --git a/src/socket.ts b/src/socket.ts index 0344fe7..00833f1 100644 --- a/src/socket.ts +++ b/src/socket.ts @@ -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) { 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, + }); +}