2020-07-24 02:25:33 +02:00
|
|
|
import { modActionsCommand } from "../types";
|
|
|
|
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
|
|
|
import { sendErrorMessage } from "../../../pluginUtils";
|
2020-08-10 03:18:34 +03:00
|
|
|
import { trimLines, createChunkedMessage, emptyEmbedValue } from "src/utils";
|
|
|
|
import { CasesPlugin } from "../../Cases/CasesPlugin";
|
|
|
|
import { asyncMap } from "../../../utils/async";
|
|
|
|
import { EmbedOptions } from "eris";
|
|
|
|
import { getChunkedEmbedFields } from "../../../utils/getChunkedEmbedFields";
|
|
|
|
import { getDefaultPrefix } from "knub/dist/commands/commandUtils";
|
|
|
|
import { getGuildPrefix } from "../../../utils/getGuildPrefix";
|
2020-07-24 02:25:33 +02:00
|
|
|
|
|
|
|
const opts = {
|
|
|
|
mod: ct.member({ option: true }),
|
|
|
|
};
|
|
|
|
|
|
|
|
export const CasesModCmd = modActionsCommand({
|
|
|
|
trigger: "cases",
|
|
|
|
permission: "can_view",
|
|
|
|
description: "Show the most recent 5 cases by the specified -mod",
|
|
|
|
|
|
|
|
signature: [
|
|
|
|
{
|
|
|
|
...opts,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
|
|
|
|
async run({ pluginData, message: msg, args }) {
|
|
|
|
const modId = args.mod ? args.mod.id : msg.author.id;
|
|
|
|
const recentCases = await pluginData.state.cases.with("notes").getRecentByModId(modId, 5);
|
|
|
|
|
|
|
|
const mod = pluginData.client.users.get(modId);
|
|
|
|
const modName = mod ? `${mod.username}#${mod.discriminator}` : modId;
|
|
|
|
|
|
|
|
if (recentCases.length === 0) {
|
|
|
|
sendErrorMessage(pluginData, msg.channel, `No cases by **${modName}**`);
|
|
|
|
} else {
|
2020-08-10 03:18:34 +03:00
|
|
|
const casesPlugin = pluginData.getPlugin(CasesPlugin);
|
|
|
|
const lines = await asyncMap(recentCases, c => casesPlugin.getCaseSummary(c, true));
|
|
|
|
const prefix = getGuildPrefix(pluginData);
|
|
|
|
const embed: EmbedOptions = {
|
|
|
|
author: {
|
|
|
|
name: `Most recent 5 cases by ${modName}`,
|
|
|
|
icon_url: mod ? mod.avatarURL || mod.defaultAvatarURL : undefined,
|
|
|
|
},
|
|
|
|
fields: [
|
|
|
|
...getChunkedEmbedFields(emptyEmbedValue, lines.join("\n")),
|
|
|
|
{
|
|
|
|
name: emptyEmbedValue,
|
|
|
|
value: trimLines(`
|
|
|
|
Use \`${prefix}case <num>\` to see more information about an individual case
|
|
|
|
Use \`${prefix}cases <user>\` to see a specific user's cases
|
|
|
|
`),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
msg.channel.createMessage({ embed });
|
2020-07-24 02:25:33 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|