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

Merge master

This commit is contained in:
Dragory 2024-01-27 14:45:35 +02:00
commit e72abb05b2
No known key found for this signature in database
2 changed files with 50 additions and 43 deletions

View file

@ -1,4 +1,4 @@
import { APIEmbed } from "discord.js";
import { APIEmbed, User } from "discord.js";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { CaseTypes } from "../../../data/CaseTypes";
import { sendErrorMessage } from "../../../pluginUtils";
@ -10,10 +10,9 @@ import {
renderUsername,
resolveMember,
resolveUser,
trimLines,
} from "../../../utils";
import { asyncMap } from "../../../utils/async";
import { getChunkedEmbedFields } from "../../../utils/getChunkedEmbedFields";
import { createPaginatedMessage } from "../../../utils/createPaginatedMessage.js";
import { getGuildPrefix } from "../../../utils/getGuildPrefix";
import { modActionsCmd } from "../types";
@ -29,6 +28,8 @@ const opts = {
unbans: ct.switchOption({ def: false, shortcut: "ub" }),
};
const casesPerPage = 10;
export const CasesUserCmd = modActionsCmd({
trigger: ["cases", "modlogs"],
permission: "can_view",
@ -100,49 +101,55 @@ export const CasesUserCmd = modActionsCmd({
} else {
// Compact view (= regular message with a preview of each case)
const casesPlugin = pluginData.getPlugin(CasesPlugin);
const lines = await asyncMap(casesToDisplay, (c) => casesPlugin.getCaseSummary(c, true, msg.author.id));
const totalPages = Math.max(Math.ceil(cases.length / casesPerPage), 1);
const prefix = getGuildPrefix(pluginData);
const linesPerChunk = 10;
const lineChunks = chunkArray(lines, linesPerChunk);
const footerField = {
name: emptyEmbedValue,
value: trimLines(`
Use \`${prefix}case <num>\` to see more information about an individual case
`),
};
createPaginatedMessage(
pluginData.client,
msg.channel,
totalPages,
async (page) => {
const chunkedCases = chunkArray(cases, casesPerPage)[page - 1];
const lines = await asyncMap(chunkedCases, (c) => casesPlugin.getCaseSummary(c, true, msg.author.id));
for (const [i, linesInChunk] of lineChunks.entries()) {
const isLastChunk = i === lineChunks.length - 1;
const isLastPage = page === totalPages;
const firstCaseNum = (page - 1) * casesPerPage + 1;
const lastCaseNum = isLastPage ? cases.length : page * casesPerPage;
const title =
totalPages === 1
? `Cases for ${userName} (${lines.length} total)`
: `Most recent cases ${firstCaseNum}-${lastCaseNum} of ${cases.length} for ${userName}`;
if (isLastChunk && !args.hidden && hiddenCases.length) {
if (hiddenCases.length === 1) {
linesInChunk.push(`*+${hiddenCases.length} hidden case, use "-hidden" to show it*`);
} else {
linesInChunk.push(`*+${hiddenCases.length} hidden cases, use "-hidden" to show them*`);
}
}
const embed = {
author: {
name: title,
icon_url: user instanceof User ? user.displayAvatarURL() : undefined,
},
description: lines.join("\n"),
fields: [
{
name: emptyEmbedValue,
value: `Use \`${prefix}case <num>\` to see more information about an individual case`,
},
],
} satisfies APIEmbed;
const chunkStart = i * linesPerChunk + 1;
const chunkEnd = Math.min((i + 1) * linesPerChunk, lines.length);
if (isLastPage && !args.hidden && hiddenCases.length)
embed.fields.push({
name: emptyEmbedValue,
value:
hiddenCases.length === 1
? `*+${hiddenCases.length} hidden case, use "-hidden" to show it*`
: `*+${hiddenCases.length} hidden cases, use "-hidden" to show them*`,
});
const embed = {
author: {
name:
lineChunks.length === 1
? `Cases for ${userName} (${lines.length} total)`
: `Cases ${chunkStart}${chunkEnd} of ${lines.length} for ${userName}`,
icon_url: user.displayAvatarURL(),
},
fields: [
...getChunkedEmbedFields(emptyEmbedValue, linesInChunk.join("\n")),
...(isLastChunk ? [footerField] : []),
],
} satisfies APIEmbed;
msg.channel.send({ embeds: [embed] });
}
return { embeds: [embed] };
},
{
limitToUserId: msg.author.id,
},
);
}
}
},