Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
feat: add timestamp filtering for stats (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
Naomi authored Apr 14, 2024
1 parent 96b4b96 commit 1c3f4e5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
31 changes: 29 additions & 2 deletions src/commands/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,21 @@ export const stats: Command = {
data: new SlashCommandBuilder()
.setName("stats")
.setDescription("Generate a report on help threads.")
.setDMPermission(false),
.setDMPermission(false)
.addNumberOption((o) =>
o
.setName("start")
.setDescription(
"Timestamp (in ms) of time you'd like to start tracking from."
)
)
.addNumberOption((o) =>
o
.setName("end")
.setDescription(
"Timestamp (in ms) of time you'd like to end tracking from."
)
),
run: async (bot, interaction) => {
try {
await interaction.deferReply({ ephemeral: true });
Expand All @@ -32,9 +46,22 @@ export const stats: Command = {
}

const threads = await fetchHelpThreads(bot);
const sorted = threads
let sorted = threads
.map((e) => e)
.sort((a, b) => (b.createdTimestamp ?? 0) - (a.createdTimestamp ?? 0));
const start = interaction.options.getNumber("start");
const end = interaction.options.getNumber("end");

if (start) {
sorted = sorted.filter(
(t) => t.createdTimestamp && t.createdTimestamp >= start
);
}
if (end) {
sorted = sorted.filter(
(t) => t.createdTimestamp && t.createdTimestamp <= end
);
}

const total = sorted.length;
const answeredArray = sorted.filter((thread) =>
Expand Down
4 changes: 3 additions & 1 deletion src/interfaces/Command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { ChatInputCommandInteraction, SlashCommandBuilder } from "discord.js";
import { ExtendedClient } from "./ExtendedClient";

export interface Command {
data: SlashCommandBuilder;
data:
| SlashCommandBuilder
| Omit<SlashCommandBuilder, "addSubcommand" | "addSubcommandGroup">;
run: (
bot: ExtendedClient,
interaction: ChatInputCommandInteraction
Expand Down

0 comments on commit 1c3f4e5

Please sign in to comment.