-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogging.ts
106 lines (101 loc) · 3.59 KB
/
logging.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import env from './env.js';
import { EmbedBuilder, Client, ActionRowBuilder, GuildMember, ColorResolvable, TextChannel } from 'discord.js';
interface LoggerColors {
info: string;
warn: string;
error: string;
success: string;
verbose: string;
}
type EmbedModifier = (embed: EmbedBuilder) => void;
type ActionRowConstructor = () => ActionRowBuilder<any> | undefined;
class Logger {
private client: Client;
private channel: string;
public colour: LoggerColors;
constructor(client: Client) {
this.client = client;
this.channel = env.LOGGING_CHANNEL_ID;
this.colour = {
info: '#9dcbf7',
warn: '#eea766',
error: '#ff7d92',
success: '#7ce87c',
verbose: '#bbbbbb',
};
}
public log(
colour: string,
member: GuildMember | null,
title: string,
description: string,
embedModifier: EmbedModifier = () => {},
actionRowConstructor: ActionRowConstructor = () => undefined
): void {
const embed = new EmbedBuilder()
.setTitle(title)
.setDescription(description)
.setColor(colour as ColorResolvable)
.setTimestamp();
if (member) {
try {
embed.setAuthor({ name: member.user.tag, iconURL: member.user.displayAvatarURL(), url: `https://discord.com/users/${member.id}` });
embed.setFooter({ text: `ID: ${member.id}` });
} catch (e) { }
}
try { embedModifier(embed);} catch (e) { }
const actionRow = actionRowConstructor();
const textChannel = this.client.channels.cache.get(this.channel) as TextChannel;
if (actionRow) {
textChannel?.send({ embeds: [embed], components: [actionRow] });
} else {
textChannel?.send({ embeds: [embed] });
}
}
public info(
member: GuildMember | null,
title: string,
description: string,
embedModifier: EmbedModifier = () => {},
actionRowConstructor: ActionRowConstructor = () => undefined
): void {
this.log(this.colour.info, member, title, description, embedModifier, actionRowConstructor);
}
public warn(
member: GuildMember | null,
title: string,
description: string,
embedModifier: EmbedModifier = () => {},
actionRowConstructor: ActionRowConstructor = () => undefined
): void {
this.log(this.colour.warn, member, title, description, embedModifier, actionRowConstructor);
}
public error(
member: GuildMember | null,
title: string,
description: string,
embedModifier: EmbedModifier = () => {},
actionRowConstructor: ActionRowConstructor = () => undefined
): void {
this.log(this.colour.error, member, title, description, embedModifier, actionRowConstructor);
}
public success(
member: GuildMember | null,
title: string,
description: string,
embedModifier: EmbedModifier = () => {},
actionRowConstructor: ActionRowConstructor = () => undefined
): void {
this.log(this.colour.success, member, title, description, embedModifier, actionRowConstructor);
}
public verbose(
member: GuildMember | null,
title: string,
description: string,
embedModifier: EmbedModifier = () => {},
actionRowConstructor: ActionRowConstructor = () => undefined
): void {
this.log(this.colour.verbose, member, title, description, embedModifier, actionRowConstructor);
}
}
export default Logger;