3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-20 00:05:04 +00:00

Allow filtering to cases only after a specific time

This commit is contained in:
Dark 2020-08-29 18:59:46 +02:00
parent 1c1885c49b
commit 5746ab36a0
2 changed files with 22 additions and 5 deletions

View file

@ -5,6 +5,7 @@ import { sendErrorMessage } from "src/pluginUtils";
import { EmbedOptions } from "eris"; import { EmbedOptions } from "eris";
import { CaseTypes } from "src/data/CaseTypes"; import { CaseTypes } from "src/data/CaseTypes";
import moment from "moment-timezone"; import moment from "moment-timezone";
import humanizeDuration from "humanize-duration";
export const ModStatsCmd = casesCommand({ export const ModStatsCmd = casesCommand({
trigger: "modstats", trigger: "modstats",
@ -14,6 +15,7 @@ export const ModStatsCmd = casesCommand({
signature: [ signature: [
{ {
moderator: ct.resolvedUser(), moderator: ct.resolvedUser(),
within: ct.delay({ required: false }),
}, },
], ],
@ -25,7 +27,8 @@ export const ModStatsCmd = casesCommand({
} }
const latestCase = await pluginData.state.cases.findLatestByModId(args.moderator.id); const latestCase = await pluginData.state.cases.findLatestByModId(args.moderator.id);
const allAmounts = await getAllCaseTypeAmountsForUserId(pluginData, args.moderator.id); const within = args.within ? moment().subtract(args.within) : null;
const allAmounts = await getAllCaseTypeAmountsForUserId(pluginData, args.moderator.id, within);
const embed: EmbedOptions = { const embed: EmbedOptions = {
fields: [], fields: [],
@ -36,7 +39,8 @@ export const ModStatsCmd = casesCommand({
icon_url: args.moderator.avatarURL, icon_url: args.moderator.avatarURL,
}; };
let embedDesc = `**The user created ${allAmounts.total} cases:**\n`; let embedDesc = "";
embedDesc += `**The user created ${allAmounts.total} cases:**\n`;
for (const type in CaseTypes) { for (const type in CaseTypes) {
if (!isNaN(Number(type))) { if (!isNaN(Number(type))) {
const typeAmount = allAmounts.typeAmounts.get(Number(type)).amount; const typeAmount = allAmounts.typeAmounts.get(Number(type)).amount;
@ -45,8 +49,17 @@ export const ModStatsCmd = casesCommand({
embedDesc += `\n**${CaseTypes[type]}:** ${typeAmount}`; embedDesc += `\n**${CaseTypes[type]}:** ${typeAmount}`;
} }
} }
embedDesc += `\n\n**First case on:** ${moment(firstCase.created_at).format("LL")}`;
embedDesc += `\n**Latest case on:** ${moment(latestCase.created_at).format("LL")}`; if (within == null) {
embedDesc += `\n\n**First case on:** ${moment(firstCase.created_at)
.utc()
.format("LL HH:mm UTC")}`;
embedDesc += `\n**Latest case on:** ${moment(latestCase.created_at)
.utc()
.format("LL HH:mm UTC")}`;
} else {
embedDesc += `\n\n**Only cases after:** ${within.utc().format("LL HH:mm UTC")}\n`;
}
embed.description = embedDesc; embed.description = embedDesc;
msg.channel.createMessage({ embed }); msg.channel.createMessage({ embed });

View file

@ -1,10 +1,12 @@
import { PluginData } from "knub"; import { PluginData } from "knub";
import { CasesPluginType } from "../types"; import { CasesPluginType } from "../types";
import { CaseTypes } from "../../../data/CaseTypes"; import { CaseTypes } from "../../../data/CaseTypes";
import moment from "moment-timezone";
export async function getAllCaseTypeAmountsForUserId( export async function getAllCaseTypeAmountsForUserId(
pluginData: PluginData<CasesPluginType>, pluginData: PluginData<CasesPluginType>,
userID: string, userID: string,
within: moment.Moment,
): Promise<AllTypeAmounts> { ): Promise<AllTypeAmounts> {
const allAmounts = new Map<CaseTypes, { amount: number }>(); const allAmounts = new Map<CaseTypes, { amount: number }>();
for (const type in CaseTypes) { for (const type in CaseTypes) {
@ -13,7 +15,9 @@ export async function getAllCaseTypeAmountsForUserId(
let total = 0; let total = 0;
const cases = (await pluginData.state.cases.getByModId(userID)).filter(c => !c.is_hidden); const cases = (await pluginData.state.cases.getByModId(userID)).filter(
c => !c.is_hidden && moment(c.created_at) >= within,
);
if (cases.length > 0) { if (cases.length > 0) {
cases.forEach(singleCase => { cases.forEach(singleCase => {