1
0
mirror of https://github.com/toast-ts/Daggerbot-TS.git synced 2024-09-29 12:30:58 -04:00

Improve load time

This commit is contained in:
AnxietyisReal 2023-01-09 23:02:21 +11:00
parent ad76dfa17e
commit 6be7c7780b

View File

@ -6,12 +6,11 @@ import { version } from 'typescript';
import { VERSION } from 'ts-node'; import { VERSION } from 'ts-node';
export default { export default {
async run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){ async run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){
await interaction.deferReply();
const columns = ['Command name', 'Count']; const columns = ['Command name', 'Count'];
const includedCommands = client.commands.filter(x=>x.uses).sort((a,b)=>b.uses - a.uses); const includedCommands = client.commands.filter(x=>x.uses).sort((a,b)=>b.uses - a.uses);
if (includedCommands.size == 0) return interaction.reply(`No commands have been used yet.\nUptime: ${client.formatTime(client.uptime as number, 2, {longNames: true, commas: true})}`); if (includedCommands.size == 0) return interaction.reply(`No commands have been used yet.\nUptime: ${client.formatTime(client.uptime as number, 2, {longNames: true, commas: true})}`);
const nameLength = Math.max(...includedCommands.map(x=>x.default.data.name.length), columns[0].length) + 2; const nameLength = Math.max(...includedCommands.map(x=>x.default.data.name.length), columns[0].length) + 2;
const amountLength = Math.max(...includedCommands.map(x=>x.uses.toLocaleString().length), columns[1].length) + 1; const amountLength = Math.max(...includedCommands.map(x=>x.uses.toString().length), columns[1].length) + 1;
const rows = [`${columns[0] + ' '.repeat(nameLength - columns[0].length)}|${' '.repeat(amountLength - columns[1].length) + columns[1]}\n`, '-'.repeat(nameLength) + '-'.repeat(amountLength) + '\n']; const rows = [`${columns[0] + ' '.repeat(nameLength - columns[0].length)}|${' '.repeat(amountLength - columns[1].length) + columns[1]}\n`, '-'.repeat(nameLength) + '-'.repeat(amountLength) + '\n'];
includedCommands.forEach(command=>{ includedCommands.forEach(command=>{
const name = command.default.data.name; const name = command.default.data.name;
@ -39,7 +38,7 @@ export default {
}; };
// Bytes conversion // Bytes conversion
function formatBytes(bytes, decimals = 2) { function formatBytes(bytes:number, decimals:number = 2) {
if (bytes === 0) return '0 Bytes'; if (bytes === 0) return '0 Bytes';
const k = 1024; const k = 1024;
const dm = decimals < 0 ? 0 : decimals; const dm = decimals < 0 ? 0 : decimals;
@ -67,7 +66,7 @@ export default {
`**Uptime:**\nHost: ${client.formatTime((os.uptime()*1000), 2, {longNames: true, commas: true})}\nBot: ${client.formatTime(client.uptime as number, 2, {commas: true, longNames: true})}` `**Uptime:**\nHost: ${client.formatTime((os.uptime()*1000), 2, {longNames: true, commas: true})}\nBot: ${client.formatTime(client.uptime as number, 2, {commas: true, longNames: true})}`
].join('\n')) ].join('\n'))
.setFooter({text: `Load time: ${client.formatTime(Date.now() - interaction.createdTimestamp, 2, {longNames: true, commas: true})}`}); .setFooter({text: `Load time: ${client.formatTime(Date.now() - interaction.createdTimestamp, 2, {longNames: true, commas: true})}`});
interaction.editReply({embeds: [embed, embed1]}); interaction.reply({embeds: [embed, embed1]})
}, },
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
.setName('statistics') .setName('statistics')