add ready and stop listener

implement activity service
This commit is contained in:
2026-02-18 16:51:09 +01:00
parent 7678c1a722
commit 84b851f60f
7 changed files with 74 additions and 2 deletions

View File

@@ -1,4 +1,3 @@
import { config } from "config";
import { activityService } from "features/activity/activity.service"; import { activityService } from "features/activity/activity.service";
import { logChannelService } from "features/log-channel/log-channel.service"; import { logChannelService } from "features/log-channel/log-channel.service";
import client from "lib/client"; import client from "lib/client";

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,35 @@
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.options.presence = {
status: "invisible",
activities: [],
afk: false,
...client.options.presence,
};
return;
}
client.options.presence = {
status: "online",
activities: [
{
name: ActivityLocales[activity],
type: 0,
},
],
afk: false,
...client.options.presence,
};
}
}
export const activityService = new ActivityService();

View File

@@ -1 +1 @@
import "lib/client"; import "listeners";

View File

@@ -0,0 +1,2 @@
import "./ready.listener";
import "./stop.listener";

View File

@@ -0,0 +1,14 @@
import { Events } from "@fluxerjs/core";
import { activityService } from "features/activity/activity.service";
import { logChannelService } from "features/log-channel/log-channel.service";
import client from "lib/client";
import { logger } from "lib/common-logger";
client.on(Events.Ready, async () => {
await logChannelService.sendLogMessage("wieder online!!!");
logger.info("bot is online");
await activityService.set("competing");
logger.info("finished ready procedure");
});

View File

@@ -0,0 +1,3 @@
import { Events } from "@fluxerjs/core";
import client from "lib/client";
import { logger } from "lib/common-logger";