add ready and stop listener
implement activity service
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import { config } from "config";
|
||||
import { activityService } from "features/activity/activity.service";
|
||||
import { logChannelService } from "features/log-channel/log-channel.service";
|
||||
import client from "lib/client";
|
||||
|
||||
19
adapters/fluxer/src/features/activity/activity.schema.ts
Normal file
19
adapters/fluxer/src/features/activity/activity.schema.ts
Normal 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",
|
||||
};
|
||||
35
adapters/fluxer/src/features/activity/activity.service.ts
Normal file
35
adapters/fluxer/src/features/activity/activity.service.ts
Normal 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();
|
||||
@@ -1 +1 @@
|
||||
import "lib/client";
|
||||
import "listeners";
|
||||
|
||||
2
adapters/fluxer/src/listeners/index.ts
Normal file
2
adapters/fluxer/src/listeners/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
import "./ready.listener";
|
||||
import "./stop.listener";
|
||||
14
adapters/fluxer/src/listeners/ready.listener.ts
Normal file
14
adapters/fluxer/src/listeners/ready.listener.ts
Normal 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");
|
||||
});
|
||||
3
adapters/fluxer/src/listeners/stop.listener.ts
Normal file
3
adapters/fluxer/src/listeners/stop.listener.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { Events } from "@fluxerjs/core";
|
||||
import client from "lib/client";
|
||||
import { logger } from "lib/common-logger";
|
||||
Reference in New Issue
Block a user