add more listeners

add activity service
add log channel service
This commit is contained in:
2026-02-17 23:07:17 +01:00
parent 071fe2f891
commit aa88d30244
14 changed files with 159 additions and 37 deletions

View File

@@ -0,0 +1,19 @@
import z from "zod";
export const Activities = z.enum([
"playing",
"streaming",
"listening",
"watching",
"competing",
"invisible",
]);
export const ActivityLocales: Record<z.infer<typeof Activities>, string> = {
playing: "spielt sudoku",
streaming: "streamt sudoku",
listening: "hört sudoku",
watching: "schaut sudoku",
competing: "wettstreitet sudoku",
invisible: "versteckt sudoku",
};

View File

@@ -0,0 +1,27 @@
import client from "lib/client";
import type z from "zod";
import { type Activities, ActivityLocales } from "./activity.schema";
/**
* Set the activity of the bot. This can be used to show that the bot is playing a game, listening to music, etc.
*/
export class ActivityService {
async set(activity: z.output<typeof Activities>) {
if (activity === "invisible") {
client.user?.setPresence({
status: "invisible",
});
client.user?.setActivity(" ", { type: 0 });
return;
}
client.user?.setActivity(ActivityLocales[activity], {
type: 0,
});
client.user?.setPresence({
status: "online",
});
}
}
export const activityService = new ActivityService();

View File

@@ -0,0 +1,26 @@
import { config } from "config";
import client from "lib/client";
import { logger } from "lib/common-logger";
export class LogChannelService {
private logChannelId = config.channelMapping.text.bot;
async getLogChannel() {
const logChannel = await client.channels.fetch(this.logChannelId);
if (logChannel?.isTextBased() && logChannel.isSendable()) {
return logChannel;
} else {
logger.fatal("Log channel not found or is not text-based.");
throw new Error("Log channel not found or is not text-based");
}
}
async sendLogMessage(message: string) {
const logChannel = await this.getLogChannel();
await logChannel.send(message);
}
}
export const logChannelService = new LogChannelService();