1 |
import DiscordClient from "../client/Client"; |
import { MessageEmbed, WebhookClient } from "discord.js"; |
|
import { Guild } from "discord.js"; |
|
2 |
import { appendFile } from "fs/promises"; |
import { appendFile } from "fs/promises"; |
3 |
import Service from "../utils/structures/Service"; |
import Service from "../utils/structures/Service"; |
4 |
|
import { splitMessage } from "../utils/util"; |
5 |
|
|
6 |
export enum LogLevel { |
export enum LogLevel { |
7 |
LOG = 'log', |
LOG = 'log', |
26 |
async log(stream: string, level: LogLevel, message: string) { |
async log(stream: string, level: LogLevel, message: string) { |
27 |
await appendFile(stream, `[${new Date().toISOString()}] [${level}] ${message}\n`); |
await appendFile(stream, `[${new Date().toISOString()}] [${level}] ${message}\n`); |
28 |
} |
} |
29 |
|
|
30 |
|
async logToHomeServer(message: string, logLevel: LogLevel = LogLevel.ERROR) { |
31 |
|
if (!process.env.DEBUG_WEKHOOK_URL) |
32 |
|
return; |
33 |
|
|
34 |
|
const webhookClient = new WebhookClient({ url: process.env.DEBUG_WEKHOOK_URL! }); |
35 |
|
const splitted = splitMessage(message); |
36 |
|
const embed = new MessageEmbed({ |
37 |
|
color: logLevel === LogLevel.WARN ? 'GOLD' : 0xf14a60, |
38 |
|
title: logLevel === LogLevel.WARN ? 'Core Warning' : 'Fatal Error', |
39 |
|
description: splitted.shift(), |
40 |
|
}); |
41 |
|
|
42 |
|
if (splitted.length === 0) { |
43 |
|
embed.setTimestamp(); |
44 |
|
} |
45 |
|
|
46 |
|
try { |
47 |
|
await webhookClient.send({ |
48 |
|
embeds: [ |
49 |
|
embed |
50 |
|
] |
51 |
|
}); |
52 |
|
|
53 |
|
for (const index in splitted) { |
54 |
|
const embed = new MessageEmbed({ |
55 |
|
color: logLevel === LogLevel.WARN ? 'GOLD' : 0xf14a60, |
56 |
|
description: splitted[index], |
57 |
|
}); |
58 |
|
|
59 |
|
if (parseInt(index) === (splitted.length - 1)) { |
60 |
|
embed.setTimestamp(); |
61 |
|
} |
62 |
|
|
63 |
|
await webhookClient.send({ |
64 |
|
embeds: [ |
65 |
|
embed |
66 |
|
] |
67 |
|
}); |
68 |
|
} |
69 |
|
} |
70 |
|
catch (e) { |
71 |
|
console.log(e); |
72 |
|
} |
73 |
|
} |
74 |
} |
} |