mirror of
https://github.com/kirameki-cafe/Yumi.git
synced 2026-09-14 03:09:59 +00:00
Optimized speed and use new configuration
This commit is contained in:
+7
-22
@@ -2,11 +2,11 @@ import { CommandInteraction, Message, Interaction } from "discord.js";
|
||||
import { makeSuccessEmbed, makeProcessingEmbed, sendMessageOrInteractionResponse } from "../utils/DiscordMessage";
|
||||
import DiscordProvider from "../providers/Discord";
|
||||
import NodePing from "ping";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import { Promise, reject } from "bluebird";
|
||||
import os from "os";
|
||||
import Logger from "../libs/Logger";
|
||||
import Environment from "../providers/Environment";
|
||||
import Configuration from "../providers/Configuration";
|
||||
|
||||
enum MeasureType {
|
||||
Ping = "ping",
|
||||
@@ -14,7 +14,6 @@ enum MeasureType {
|
||||
DiscordWebsocket = "discordwebsocket"
|
||||
}
|
||||
|
||||
let measureList: any = [];
|
||||
|
||||
const EMBEDS = {
|
||||
PING_INFO: (data: Message | Interaction, description: string) => {
|
||||
@@ -29,20 +28,6 @@ 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);
|
||||
@@ -77,10 +62,8 @@ export default class Ping {
|
||||
|
||||
let desString = [];
|
||||
|
||||
// TODO: Optimize speed of this
|
||||
|
||||
for (let entry of measureList) {
|
||||
|
||||
await Promise.map(Configuration.getConfig("Ping"), (entry: any) => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let stringCurrent = `${entry.title}`;
|
||||
|
||||
if (entry.type === MeasureType.Ping) {
|
||||
@@ -106,7 +89,9 @@ export default class Ping {
|
||||
desString.push(stringCurrent);
|
||||
}
|
||||
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
}, { concurrency: 5 });
|
||||
|
||||
desString.push("");
|
||||
desString.push("💻 Running on " + `${os.hostname()}${Environment.get().NODE_ENV === "development" ? ' / Development Environment' : ''}`);
|
||||
|
||||
Reference in New Issue
Block a user