Skip to content

Commit

Permalink
Merge pull request #35 from reinhello/patch
Browse files Browse the repository at this point in the history
Code cleanup
  • Loading branch information
reinacchi authored Aug 4, 2022
2 parents e1c0991 + 1c221e4 commit c5f54c2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 25 deletions.
1 change: 1 addition & 0 deletions bot/src/Reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ReaderClient } from "reader-framework";
import * as Config from "../../config/config.json";

const client = new ReaderClient(Config.BOT.TOKEN, {
defaultImageFormat: "png",
intents: [
"guilds",
"guildMessages",
Expand Down
42 changes: 22 additions & 20 deletions framework/lib/Commands/Modules/StatsCommand.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
import { ReaderClient } from "../../Client";
import { CommandInteraction, Constants, TextableChannel, VERSION } from "eris";
import { CommandInteraction, TextableChannel, VERSION } from "eris";
import { Utils } from "givies-framework";
import { Util } from "../../Utils";
import osUtils from "os-utils";

export async function statsCommand(client: ReaderClient, interaction: CommandInteraction<TextableChannel>) {
const memory: number = process.memoryUsage().rss
const totalMemory: string = `${Util.bytesToSize(memory).value}${Util.bytesToSize(memory).unit} / ${Util.bytesToSize(require("os").totalmem()).value}${Util.bytesToSize(require("os").totalmem()).unit}`;
/* @ts-ignore */
const totalMem = Util.bytesToSize(require("os").totalmem()).value * 1000;
const memory: number = process.memoryUsage().rss;

/* eslint-disable-next-line */
const totalMemory = `${Util.bytesToSize(memory).value}${Util.bytesToSize(memory).unit} / ${Util.bytesToSize(require("os").totalmem()).value}${Util.bytesToSize(require("os").totalmem()).unit}`;

/* eslint-disable-next-line */
const totalMem = Util.bytesToSize(require("os").totalmem()).value * 1000 ;
const used: number = process.memoryUsage().rss / totalMem / totalMem;

osUtils.cpuUsage((percentage) => {
const embed = new Utils.RichEmbed()
.setColor(client.config.BOT.COLOUR)
.setFooter(client.user.username, client.user.avatarURL)
.setThumbnail(client.user.avatarURL)
.setTimestamp()
.setTitle(client.translate("general.stats.title").replace("{bot}", client.user.username))
.addField(client.translate("general.stats.memory"), `${totalMemory} \n (${Math.round(used * 100) / 100}%)`, true)
.addField(client.translate("general.stats.cpu"), `${Util.round(percentage, 2)}%`, true)
.addField(client.translate("general.stats.uptime"), `${Util.time(client.uptime)}`, true)
.addField("NodeJS", `${process.versions.node}`, true)
.addField("Eris", `${VERSION}`, true)
.addField(client.translate("general.stats.platform"), `${process.platform.charAt(0).toUpperCase() + process.platform.slice(1)}`, true);
.setColor(client.config.BOT.COLOUR)
.setFooter(client.user.username, client.user.avatarURL)
.setThumbnail(client.user.avatarURL)
.setTimestamp()
.setTitle(client.translate("general.stats.title").replace("{bot}", client.user.username))
.addField(client.translate("general.stats.memory"), `${totalMemory} \n (${Math.round(used * 100) / 100}%)`, true)
.addField(client.translate("general.stats.cpu"), `${Util.round(percentage, 2)}%`, true)
.addField(client.translate("general.stats.uptime"), `${Util.time(client.uptime)}`, true)
.addField("NodeJS", `${process.versions.node}`, true)
.addField("Eris", `${VERSION}`, true)
.addField(client.translate("general.stats.platform"), `${process.platform.charAt(0).toUpperCase() + process.platform.slice(1)}`, true);

return interaction.createMessage({
embeds: [embed],
flags: Constants.MessageFlags.EPHEMERAL
});
return interaction.createMessage({
embeds: [embed]
});
});
}
2 changes: 1 addition & 1 deletion framework/lib/Events/Modules/GuildCreateEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function guildCreateEvent(client: ReaderClient, guild: Guild) {
settings: ({
locale: "en"
} as IGuildSchemaSettings)
})
});
}

commands.forEach((command) => {
Expand Down
2 changes: 0 additions & 2 deletions framework/lib/Events/Modules/InteractionCreateEvent.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ReaderClient } from "../../Client";
import { CommandInteraction, Constants, TextChannel } from "eris";
import { ICommandRunPayload } from "../../Interfaces";
import { t } from "i18next";
import { GuildModel, UserModel } from "../../Models";
import { Utils } from "givies-framework";
Expand All @@ -12,7 +11,6 @@ export async function interactionCreateEvent(client: ReaderClient, interaction:
if (interaction.member.bot) return;

const command = client.commands.get(interaction.data.name);
const payload: ICommandRunPayload = { client, interaction };
const guildData = await GuildModel.findOne({ id: interaction.guildID });
const userData = await UserModel.findOne({ id: interaction.member.id });

Expand Down
4 changes: 2 additions & 2 deletions framework/lib/Utils/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Utils } from "givies-framework";
import byteSize from "byte-size";

interface IByteSize {
value: string;
value: number;
unit: string;
}

Expand All @@ -18,7 +18,7 @@ export class Util {
* @returns {IByteSize}
*/
public static bytesToSize(bytes: number): IByteSize {
return byteSize(bytes);
return byteSize(bytes) as any;
}

/**
Expand Down

0 comments on commit c5f54c2

Please sign in to comment.