mirror of
https://github.com/kirameki-cafe/Yumi.git
synced 2026-09-14 03:09:59 +00:00
Changed to use init function instead
This commit is contained in:
+33
-43
@@ -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,15 +29,29 @@ 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;
|
||||
if (command.toLowerCase() !== 'ping') return;
|
||||
await this.process(message, args);
|
||||
}
|
||||
|
||||
async interactionCreate(interaction: CommandInteraction) {
|
||||
if(interaction.isCommand()) {
|
||||
if(typeof interaction.commandName === 'undefined') return;
|
||||
if((interaction.commandName).toLowerCase() !== 'ping') return;
|
||||
async interactionCreate(interaction: CommandInteraction) {
|
||||
if (interaction.isCommand()) {
|
||||
if (typeof interaction.commandName === 'undefined') return;
|
||||
if ((interaction.commandName).toLowerCase() !== 'ping') return;
|
||||
await this.process(interaction, interaction.options);
|
||||
}
|
||||
}
|
||||
@@ -70,7 +60,7 @@ export default class Ping {
|
||||
const isSlashCommand = data instanceof CommandInteraction && data.isCommand();
|
||||
const isMessage = data instanceof Message;
|
||||
|
||||
if(!isSlashCommand && !isMessage) return;
|
||||
if (!isSlashCommand && !isMessage) return;
|
||||
|
||||
let placeholder;
|
||||
|
||||
@@ -81,7 +71,7 @@ export default class Ping {
|
||||
});
|
||||
|
||||
let beforeEditDate = Date.now();
|
||||
placeholder = await sendMessageOrInteractionResponse(data, { embeds:[loadingEmbed]} );
|
||||
placeholder = await sendMessageOrInteractionResponse(data, { embeds: [loadingEmbed] });
|
||||
let afterEditDate = Date.now();
|
||||
|
||||
|
||||
@@ -89,23 +79,23 @@ export default class Ping {
|
||||
|
||||
// TODO: Optimize speed of this
|
||||
|
||||
for(let entry of measureList) {
|
||||
for (let entry of measureList) {
|
||||
|
||||
let stringCurrent = `${entry.title}`;
|
||||
|
||||
if(entry.type === MeasureType.Ping) {
|
||||
if (entry.type === MeasureType.Ping) {
|
||||
const res = await NodePing.promise.probe(entry.host!, { min_reply: 4 });
|
||||
|
||||
if(!res.alive) {
|
||||
|
||||
if (!res.alive) {
|
||||
stringCurrent += "Failed";
|
||||
return desString.push(stringCurrent);
|
||||
}
|
||||
|
||||
if(res.avg === 'unknown' || res.min === 'unknown' || res.max === 'unknown') {
|
||||
|
||||
if (res.avg === 'unknown' || res.min === 'unknown' || res.max === 'unknown') {
|
||||
stringCurrent += "Failed";
|
||||
return desString.push(stringCurrent);
|
||||
}
|
||||
|
||||
|
||||
stringCurrent += `${parseFloat(res.avg).toFixed(1)}ms (${parseFloat(res.min).toFixed(1)}ms - ${parseFloat(res.max).toFixed(1)}ms)`;
|
||||
desString.push(stringCurrent);
|
||||
} else if (entry.type === MeasureType.DiscordWebsocket) {
|
||||
@@ -114,15 +104,15 @@ export default class Ping {
|
||||
} else if (entry.type === MeasureType.DiscordHTTPPing) {
|
||||
stringCurrent += `${Math.abs(afterEditDate - beforeEditDate).toFixed(1)}ms`;
|
||||
desString.push(stringCurrent);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
desString.push("");
|
||||
desString.push("💻 Running on " + `${os.hostname()}${Environment.get().NODE_ENV === "development" ? ' / Development Environment' : ''}`);
|
||||
|
||||
if(isSlashCommand) return await data.editReply({ embeds: [EMBEDS.PING_INFO(data, desString.join('\n'))] });
|
||||
else if(typeof placeholder !== "undefined" && isMessage && placeholder instanceof Message) return await placeholder.edit({ embeds: [EMBEDS.PING_INFO(data, desString.join('\n'))] });
|
||||
if (isSlashCommand) return await data.editReply({ embeds: [EMBEDS.PING_INFO(data, desString.join('\n'))] });
|
||||
else if (typeof placeholder !== "undefined" && isMessage && placeholder instanceof Message) return await placeholder.edit({ embeds: [EMBEDS.PING_INFO(data, desString.join('\n'))] });
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user