mrmBot-Matrix/commands/general/count.js

36 lines
1.3 KiB
JavaScript
Raw Permalink Normal View History

2023-03-15 14:09:09 +00:00
import database from "../../utils/database.js";
import Command from "../../classes/command.js";
import * as collections from "../../utils/collections.js";
import { htmlescape } from "../../utils/misc.js";
2023-03-15 14:09:09 +00:00
class CountCommand extends Command {
async run() {
const counts = await database.getCounts();
if (this.args.length !== 0) {
if (collections.commands.has(this.args[0].toLowerCase())) {
let html;
const command = collections.aliases.get(this.args[0].toLowerCase()) ?? this.args[0].toLowerCase();
// TODO: room-specific prefix
const prefix = htmlescape(process.env.PREFIX);
let amount = counts[command]
if (amount == 1) {
amount = `<b>${amount}</b> time!`
} else {
amount = `<b>${amount}</b> times!`
}
html = `The command <code>${prefix}${command}</code> has been used ${amount}`
return { html: html }
}
return "You need to specify a valid command to see its usage amount!"
2023-03-15 14:09:09 +00:00
}
return "You need to specify a command to see its usage amount!"
2023-03-15 14:09:09 +00:00
}
2023-03-22 08:49:03 +00:00
static category = "general"
static description = "Gets how many times a command was used";
2023-03-15 14:09:09 +00:00
static arguments = ["{mention/id}"];
static aliases = ["counts"];
static dbRequired = true;
}
export default CountCommand;