Skip to content

Commit

Permalink
feat: Add !stats command
Browse files Browse the repository at this point in the history
  • Loading branch information
3urobeat committed Feb 13, 2025
1 parent 25a041f commit 4f60fbb
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
49 changes: 48 additions & 1 deletion src/commands/core/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Created Date: 2021-07-09 16:26:00
* Author: 3urobeat
*
* Last Modified: 2025-02-12 22:07:40
* Last Modified: 2025-02-13 21:52:15
* Modified By: 3urobeat
*
* Copyright (c) 2021 - 2025 3urobeat <https://github.com/3urobeat>
Expand Down Expand Up @@ -133,6 +133,53 @@ module.exports.info = {
};


module.exports.stats = {
names: ["stats", "statistics"],
description: "Returns statistics about the amount of fulfilled requests",
args: [],
ownersOnly: false,

/**
* The stats command
* @param {CommandHandler} commandHandler The commandHandler object
* @param {Array} args Array of arguments that will be passed to the command
* @param {function(object, object, string): void} respondModule Function that will be called to respond to the user's request. Passes context, resInfo and txt as parameters.
* @param {object} context The context (this.) of the object calling this command. Will be passed to respondModule() as first parameter.
* @param {CommandHandler.resInfo} resInfo Object containing additional information your respondModule might need to process the response (for example the userID who executed the command).
*/
run: async (commandHandler, args, respondModule, context, resInfo) => {
const respond = ((txt) => respondModule(context, resInfo, txt)); // Shorten each call

const info = commandHandler.controller.info;
const stats = await commandHandler.data.statsDB.findAsync({});
const statsStart = (new Date(stats.find((e) => e.requestType == "startedTrackingTimestamp").timestamp)).toISOString().split("T", 1)[0];

const totalComments = stats.find((e) => e.requestType == "comment");
const totalFavs = stats.find((e) => e.requestType == "favorite");
const totalFollows = stats.find((e) => e.requestType == "follow");
const totalVotes = stats.find((e) => e.requestType == "vote");

/* eslint-disable no-irregular-whitespace */
respond(`
-----------------------------------~~~~~------------------------------------
>   During the last ${Number(Math.round(((new Date() - commandHandler.controller.info.bootStartTimestamp) / 3600000)+"e"+2)+"e-"+2)} hours of uptime, I have...
>   - sent ${info.commentCounter} comments
>   - sent ${info.favCounter} un-/favorites
>   - sent ${info.followCounter} un-/follows
>   - sent ${info.voteCounter} votes
|
>   Since ${statsStart}, I have...
>   - sent ${totalComments ? totalComments.amount : 0} comments
>   - sent ${totalFavs ? totalFavs.amount : 0} un-/favorites
>   - sent ${totalFollows ? totalFollows.amount : 0} un-/follows
>   - sent ${totalVotes ? totalVotes.amount : 0} votes
-----------------------------------~~~~~------------------------------------
`.replace(/^( {4})+/gm, "")); // Remove all the whitespaces that are added by the proper code indentation here
/* eslint-enable no-irregular-whitespace */
}
};


module.exports.ping = {
names: ["ping", "pong"],
description: "Returns ping in ms to Steam's servers. Can be used to check if the bot is responsive",
Expand Down
2 changes: 1 addition & 1 deletion src/data/fileStructure.json
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@
{
"path": "src/commands/core/general.js",
"url": "https://raw.githubusercontent.com/3urobeat/steam-comment-service-bot/beta-testing/src/commands/core/general.js",
"checksum": "eff7522cbc2b49aa903770a4ea2893a8"
"checksum": "2118c865f415a8a7be9f2a53276d590a"
},
{
"path": "src/commands/core/group.js",
Expand Down

0 comments on commit 4f60fbb

Please sign in to comment.