Changed to use init function instead

This commit is contained in:
2022-02-02 21:17:51 +07:00
parent 20bb133e6b
commit 12704f9471
2 changed files with 57 additions and 66 deletions
+15 -25
View File
@@ -14,31 +14,7 @@ enum MeasureType {
DiscordWebsocket = "discordwebsocket"
}
let measureList = [
{
type: MeasureType.Ping,
title: "☁️Internet | ",
host: "1.1.1.1"
},
{
type: MeasureType.DiscordWebsocket,
title: "🚀 Discord Websocket | "
},
{
type: MeasureType.DiscordHTTPPing,
title: "🏓 Discord HTTP | "
}
];
if(fs.existsSync(path.join(process.cwd(), 'configs/Ping.json'))) {
try {
const rawData = fs.readFileSync(path.join(process.cwd(), 'configs/Ping.json'));
const jsonData = JSON.parse(rawData.toString());
measureList = jsonData;
} catch (err) {
Logger.error("Unable to load custom Ping config: " + err);
}
}
let measureList: any = [];
const EMBEDS = {
PING_INFO: (data: Message | Interaction, description: string) => {
@@ -53,6 +29,20 @@ const EMBEDS = {
export default class Ping {
async init() {
if (fs.existsSync(path.join(process.cwd(), 'configs/Ping.json'))) {
try {
const rawData = fs.readFileSync(path.join(process.cwd(), 'configs/Ping.json'));
const jsonData = JSON.parse(rawData.toString());
measureList = jsonData;
} catch (err) {
Logger.error("Unable to load custom Ping config: " + err);
}
}
}
async onCommand(command: string, args: any, message: Message) {
if (command.toLowerCase() !== 'ping') return;
await this.process(message, args);
+4 -3
View File
@@ -124,6 +124,9 @@ let Announcements = {
}
}
export default class InteractionManager {
async init() {
if (fs.existsSync(path.join(process.cwd(), 'configs/ServiceAnnouncement.json'))) {
try {
@@ -133,11 +136,9 @@ if (fs.existsSync(path.join(process.cwd(), 'configs/ServiceAnnouncement.json')))
} catch (err) {
Logger.error("Unable to load custom ServiceAnnouncement config: " + err);
}
} else {
fs.writeFileSync(path.join(process.cwd(), 'configs/ServiceAnnouncement.json'), JSON.stringify(Announcements, null, 4), 'utf8');
}
}
export default class InteractionManager {
async onCommand(command: string, args: any, message: Message) {
if (command.toLowerCase() !== 'serviceannouncement') return;
await this.process(message, args);