Aethel Bot OSS repository!
aethel.xyz
bot
fun
ai
discord
discord-bot
aethel
1import logger from './logger';
2import { CommandInteraction } from 'discord.js';
3
4export interface CommandLogOptions {
5 commandName: string;
6 additionalInfo?: string;
7 isGuild?: boolean;
8 isDM?: boolean;
9}
10
11export function logUserAction(options: CommandLogOptions): void {
12 const { commandName, isGuild, isDM, additionalInfo } = options;
13
14 let logMessage = `User executed ${commandName} command`;
15
16 if (isGuild) {
17 logMessage += ` in guild`;
18 } else if (isDM) {
19 logMessage += ` in DM`;
20 }
21
22 if (additionalInfo) {
23 logMessage += ` with ${additionalInfo}`;
24 }
25
26 logger.info(logMessage);
27}
28
29export function logUserActionFromInteraction(
30 interaction: CommandInteraction,
31 commandName: string,
32 additionalInfo?: string,
33): void {
34 logUserAction({
35 commandName,
36 isGuild: !!interaction.guildId,
37 isDM: !interaction.guildId,
38 additionalInfo,
39 });
40}
41
42export function createCommandLogger(commandName: string) {
43 return {
44 logAction: (options: Omit<CommandLogOptions, 'commandName'>) => {
45 logUserAction({ ...options, commandName });
46 },
47 logFromInteraction: (interaction: CommandInteraction, additionalInfo?: string) => {
48 logUserActionFromInteraction(interaction, commandName, additionalInfo);
49 },
50 };
51}