add more listeners
add activity service add log channel service
This commit is contained in:
19
adapters/discord/src/features/activity/activity.schema.ts
Normal file
19
adapters/discord/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",
|
||||
};
|
||||
27
adapters/discord/src/features/activity/activity.service.ts
Normal file
27
adapters/discord/src/features/activity/activity.service.ts
Normal 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();
|
||||
@@ -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();
|
||||
Reference in New Issue
Block a user