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

Made cases commands ephemeral by default

This commit is contained in:
Lily Bergonzat 2024-02-17 23:57:01 +01:00
parent b428e18fc7
commit ba65ecb48f
8 changed files with 52 additions and 15 deletions

View file

@ -5,6 +5,7 @@
import { import {
ChatInputCommandInteraction, ChatInputCommandInteraction,
GuildMember, GuildMember,
InteractionReplyOptions,
Message, Message,
MessageCreateOptions, MessageCreateOptions,
PermissionsBitField, PermissionsBitField,
@ -80,17 +81,19 @@ export async function getContextChannel(
export async function sendContextResponse( export async function sendContextResponse(
context: TextBasedChannel | Message | User | ChatInputCommandInteraction, context: TextBasedChannel | Message | User | ChatInputCommandInteraction,
response: string | Omit<MessageCreateOptions, "flags">, response: string | Omit<MessageCreateOptions, "flags"> | InteractionReplyOptions,
): Promise<Message> { ): Promise<Message> {
if (isContextInteraction(context)) { if (isContextInteraction(context)) {
const options = { ...(typeof response === "string" ? { content: response } : response), fetchReply: true }; const options = { ...(typeof response === "string" ? { content: response } : response), fetchReply: true };
return (context.replied ? context.followUp(options) : context.reply(options)) as Promise<Message>; return (context.replied ? context.followUp(options) : context.reply(options)) as Promise<Message>;
} else if ("send" in context) {
return context.send(response);
} else {
return (await getContextChannel(context)).send(response);
} }
if (typeof response !== "string" && "ephemeral" in response) {
delete response.ephemeral;
}
return (await getContextChannel(context)).send(response as string | Omit<MessageCreateOptions, "flags">);
} }
export function getBaseUrl(pluginData: AnyPluginData<any>) { export function getBaseUrl(pluginData: AnyPluginData<any>) {

View file

@ -2,6 +2,10 @@ import { commandTypeHelpers as ct } from "../../../../commandTypes";
import { actualCaseCmd } from "../../functions/actualCommands/actualCaseCmd"; import { actualCaseCmd } from "../../functions/actualCommands/actualCaseCmd";
import { modActionsMsgCmd } from "../../types"; import { modActionsMsgCmd } from "../../types";
const opts = {
show: ct.switchOption({ def: false, shortcut: "sh" }),
};
export const CaseMsgCmd = modActionsMsgCmd({ export const CaseMsgCmd = modActionsMsgCmd({
trigger: "case", trigger: "case",
permission: "can_view", permission: "can_view",
@ -10,10 +14,12 @@ export const CaseMsgCmd = modActionsMsgCmd({
signature: [ signature: [
{ {
caseNumber: ct.number(), caseNumber: ct.number(),
...opts,
}, },
], ],
async run({ pluginData, message: msg, args }) { async run({ pluginData, message: msg, args }) {
actualCaseCmd(pluginData, msg, msg.author.id, args.caseNumber); actualCaseCmd(pluginData, msg, msg.author.id, args.caseNumber, args.show);
}, },
}); });

View file

@ -1,6 +1,10 @@
import { slashOptions } from "knub"; import { slashOptions } from "knub";
import { actualCaseCmd } from "../../functions/actualCommands/actualCaseCmd"; import { actualCaseCmd } from "../../functions/actualCommands/actualCaseCmd";
const opts = [
slashOptions.boolean({ name: "show", description: "To make the result visible to everyone", required: false }),
];
export const CaseSlashCmd = { export const CaseSlashCmd = {
name: "case", name: "case",
configPermission: "can_view", configPermission: "can_view",
@ -9,9 +13,11 @@ export const CaseSlashCmd = {
signature: [ signature: [
slashOptions.number({ name: "case-number", description: "The number of the case to show", required: true }), slashOptions.number({ name: "case-number", description: "The number of the case to show", required: true }),
...opts,
], ],
async run({ interaction, options, pluginData }) { async run({ interaction, options, pluginData }) {
actualCaseCmd(pluginData, interaction, interaction.user.id, options["case-number"]); actualCaseCmd(pluginData, interaction, interaction.user.id, options["case-number"], options.show);
}, },
}; };

View file

@ -13,6 +13,7 @@ const opts = {
unmutes: ct.switchOption({ def: false, shortcut: "um" }), unmutes: ct.switchOption({ def: false, shortcut: "um" }),
bans: ct.switchOption({ def: false, shortcut: "b" }), bans: ct.switchOption({ def: false, shortcut: "b" }),
unbans: ct.switchOption({ def: false, shortcut: "ub" }), unbans: ct.switchOption({ def: false, shortcut: "ub" }),
show: ct.switchOption({ def: false, shortcut: "sh" }),
}; };
export const CasesModMsgCmd = modActionsMsgCmd({ export const CasesModMsgCmd = modActionsMsgCmd({
@ -42,6 +43,7 @@ export const CasesModMsgCmd = modActionsMsgCmd({
args.reverseFilters, args.reverseFilters,
args.hidden, args.hidden,
args.expand, args.expand,
args.show,
); );
}, },
}); });

View file

@ -17,6 +17,7 @@ const opts = [
slashOptions.boolean({ name: "unmutes", description: "To filter unmutes", required: false }), slashOptions.boolean({ name: "unmutes", description: "To filter unmutes", required: false }),
slashOptions.boolean({ name: "bans", description: "To filter bans", required: false }), slashOptions.boolean({ name: "bans", description: "To filter bans", required: false }),
slashOptions.boolean({ name: "unbans", description: "To filter unbans", required: false }), slashOptions.boolean({ name: "unbans", description: "To filter unbans", required: false }),
slashOptions.boolean({ name: "show", description: "To make the result visible to everyone", required: false }),
]; ];
export const CasesSlashCmd = { export const CasesSlashCmd = {
@ -43,6 +44,7 @@ export const CasesSlashCmd = {
options["reverse-filters"], options["reverse-filters"],
options.hidden, options.hidden,
options.expand, options.expand,
options.show,
); );
}, },
}; };

View file

@ -15,6 +15,7 @@ const opts = {
unmutes: ct.switchOption({ def: false, shortcut: "um" }), unmutes: ct.switchOption({ def: false, shortcut: "um" }),
bans: ct.switchOption({ def: false, shortcut: "b" }), bans: ct.switchOption({ def: false, shortcut: "b" }),
unbans: ct.switchOption({ def: false, shortcut: "ub" }), unbans: ct.switchOption({ def: false, shortcut: "ub" }),
show: ct.switchOption({ def: false, shortcut: "sh" }),
}; };
export const CasesUserMsgCmd = modActionsMsgCmd({ export const CasesUserMsgCmd = modActionsMsgCmd({
@ -55,6 +56,7 @@ export const CasesUserMsgCmd = modActionsMsgCmd({
args.reverseFilters, args.reverseFilters,
args.hidden, args.hidden,
args.expand, args.expand,
args.show,
); );
}, },
}); });

View file

@ -10,6 +10,7 @@ export async function actualCaseCmd(
context: Message | ChatInputCommandInteraction, context: Message | ChatInputCommandInteraction,
authorId: string, authorId: string,
caseNumber: number, caseNumber: number,
show: boolean | null,
) { ) {
const theCase = await pluginData.state.cases.findByCaseNumber(caseNumber); const theCase = await pluginData.state.cases.findByCaseNumber(caseNumber);
@ -21,5 +22,5 @@ export async function actualCaseCmd(
const casesPlugin = pluginData.getPlugin(CasesPlugin); const casesPlugin = pluginData.getPlugin(CasesPlugin);
const embed = await casesPlugin.getCaseEmbed(theCase.id, authorId); const embed = await casesPlugin.getCaseEmbed(theCase.id, authorId);
sendContextResponse(context, embed); sendContextResponse(context, { ...embed, ephemeral: show !== true });
} }

View file

@ -29,6 +29,7 @@ async function sendExpandedCases(
context: Message | ChatInputCommandInteraction, context: Message | ChatInputCommandInteraction,
casesCount: number, casesCount: number,
cases: Case[], cases: Case[],
show: boolean | null,
) { ) {
if (casesCount > maxExpandedCases) { if (casesCount > maxExpandedCases) {
await sendContextResponse(context, "Too many cases for expanded view. Please use compact view instead."); await sendContextResponse(context, "Too many cases for expanded view. Please use compact view instead.");
@ -40,7 +41,7 @@ async function sendExpandedCases(
for (const theCase of cases) { for (const theCase of cases) {
const embed = await casesPlugin.getCaseEmbed(theCase.id); const embed = await casesPlugin.getCaseEmbed(theCase.id);
await sendContextResponse(context, embed); await sendContextResponse(context, { ...embed, ephemeral: !show });
} }
} }
@ -54,6 +55,7 @@ async function casesUserCmd(
typesToShow: CaseTypes[], typesToShow: CaseTypes[],
hidden: boolean | null, hidden: boolean | null,
expand: boolean | null, expand: boolean | null,
show: boolean | null,
) { ) {
const casesPlugin = pluginData.getPlugin(CasesPlugin); const casesPlugin = pluginData.getPlugin(CasesPlugin);
const casesFilters: Omit<FindOptionsWhere<Case>, "guild_id" | "user_id"> = { type: In(typesToShow) }; const casesFilters: Omit<FindOptionsWhere<Case>, "guild_id" | "user_id"> = { type: In(typesToShow) };
@ -86,7 +88,7 @@ async function casesUserCmd(
} }
if (expand) { if (expand) {
sendExpandedCases(pluginData, context, casesToDisplay.length, casesToDisplay); sendExpandedCases(pluginData, context, casesToDisplay.length, casesToDisplay, show);
return; return;
} }
@ -129,7 +131,7 @@ async function casesUserCmd(
fields: [...(isLastChunk ? [footerField] : [])], fields: [...(isLastChunk ? [footerField] : [])],
} satisfies APIEmbed; } satisfies APIEmbed;
sendContextResponse(context, { embeds: [embed] }); sendContextResponse(context, { embeds: [embed], ephemeral: !show });
} }
} }
@ -143,6 +145,7 @@ async function casesModCmd(
typesToShow: CaseTypes[], typesToShow: CaseTypes[],
hidden: boolean | null, hidden: boolean | null,
expand: boolean | null, expand: boolean | null,
show: boolean | null,
) { ) {
const casesPlugin = pluginData.getPlugin(CasesPlugin); const casesPlugin = pluginData.getPlugin(CasesPlugin);
const casesFilters = { type: In(typesToShow), is_hidden: !!hidden }; const casesFilters = { type: In(typesToShow), is_hidden: !!hidden };
@ -161,7 +164,7 @@ async function casesModCmd(
// Expanded view (= individual case embeds) // Expanded view (= individual case embeds)
const cases = totalCases > 8 ? [] : await casesPlugin.getRecentCasesByMod(modId ?? author.id, 8, 0, casesFilters); const cases = totalCases > 8 ? [] : await casesPlugin.getRecentCasesByMod(modId ?? author.id, 8, 0, casesFilters);
sendExpandedCases(pluginData, context, totalCases, cases); sendExpandedCases(pluginData, context, totalCases, cases, show);
return; return;
} }
@ -199,7 +202,7 @@ async function casesModCmd(
], ],
} satisfies APIEmbed; } satisfies APIEmbed;
return { embeds: [embed] }; return { embeds: [embed], ephemeral: !show };
}, },
{ {
limitToUserId: author.id, limitToUserId: author.id,
@ -222,6 +225,7 @@ export async function actualCasesCmd(
reverseFilters: boolean | null, reverseFilters: boolean | null,
hidden: boolean | null, hidden: boolean | null,
expand: boolean | null, expand: boolean | null,
show: boolean | null,
) { ) {
const mod = modId const mod = modId
? (await resolveMember(pluginData.client, pluginData.guild, modId)) || (await resolveUser(pluginData.client, modId)) ? (await resolveMember(pluginData.client, pluginData.guild, modId)) || (await resolveUser(pluginData.client, modId))
@ -253,6 +257,17 @@ export async function actualCasesCmd(
} }
user user
? casesUserCmd(pluginData, context, author.user, modId!, user, modName, typesToShow, hidden, expand) ? casesUserCmd(pluginData, context, author.user, modId!, user, modName, typesToShow, hidden, expand, show === true)
: casesModCmd(pluginData, context, author.user, modId!, mod ?? author, modName, typesToShow, hidden, expand); : casesModCmd(
pluginData,
context,
author.user,
modId!,
mod ?? author,
modName,
typesToShow,
hidden,
expand,
show === true,
);
} }