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

feat: first batch of emojis 🎉

This commit is contained in:
Lily Bergonzat 2024-02-14 09:17:11 +01:00
parent dfb0e2c19d
commit a4c4b17a14
91 changed files with 3659 additions and 2032 deletions

View file

@ -1,4 +1,5 @@
import {
ChatInputCommandInteraction,
Client,
Message,
MessageCreateOptions,
@ -9,6 +10,7 @@ import {
TextBasedChannel,
User,
} from "discord.js";
import { sendContextResponse } from "../pluginUtils";
import { MINUTES, noop } from "../utils";
import { Awaitable } from "./typeUtils";
import Timeout = NodeJS.Timeout;
@ -27,14 +29,14 @@ const defaultOpts: PaginateMessageOpts = {
export async function createPaginatedMessage(
client: Client,
channel: TextBasedChannel | User,
context: TextBasedChannel | User | ChatInputCommandInteraction,
totalPages: number,
loadPageFn: LoadPageFn,
opts: Partial<PaginateMessageOpts> = {},
): Promise<Message> {
const fullOpts = { ...defaultOpts, ...opts } as PaginateMessageOpts;
const firstPageContent = await loadPageFn(1);
const message = await channel.send(firstPageContent);
const message = await sendContextResponse(context, firstPageContent);
let page = 1;
let pageLoadId = 0; // Used to avoid race conditions when rapidly switching pages

View file

@ -0,0 +1,20 @@
import { AttachmentSlashCommandOption, slashOptions } from "knub";
type AttachmentSlashOptions = Omit<AttachmentSlashCommandOption, "type" | "resolveValue" | "getExtraAPIProps">;
export function generateAttachmentSlashOptions(amount: number, options: AttachmentSlashOptions) {
return new Array(amount).fill(0).map((_, i) => {
return slashOptions.attachment({
name: amount > 1 ? `${options.name}${i + 1}` : options.name,
description: options.description,
required: options.required ?? false,
});
});
}
export function retrieveMultipleOptions(amount: number, options: any, name: string) {
return new Array(amount)
.fill(0)
.map((_, i) => options[amount > 1 ? `${name}${i + 1}` : name])
.filter((a) => a);
}

View file

@ -2,22 +2,26 @@ import {
ActionRowBuilder,
ButtonBuilder,
ButtonStyle,
GuildTextBasedChannel,
ChatInputCommandInteraction,
MessageActionRowComponentBuilder,
MessageComponentInteraction,
MessageCreateOptions,
TextBasedChannel,
User,
} from "discord.js";
import moment from "moment";
import { v4 as uuidv4 } from "uuid";
import { isContextInteraction } from "../pluginUtils";
import { noop } from "../utils";
export async function waitForButtonConfirm(
channel: GuildTextBasedChannel,
context: TextBasedChannel | User | ChatInputCommandInteraction,
toPost: MessageCreateOptions,
options?: WaitForOptions,
): Promise<boolean> {
return new Promise(async (resolve) => {
const idMod = `${channel.guild.id}-${moment.utc().valueOf()}`;
const contextIsInteraction = isContextInteraction(context);
const idMod = `${context.id}-${moment.utc().valueOf()}`;
const row = new ActionRowBuilder<MessageActionRowComponentBuilder>().addComponents([
new ButtonBuilder()
.setStyle(ButtonStyle.Success)
@ -29,7 +33,9 @@ export async function waitForButtonConfirm(
.setLabel(options?.cancelText || "Cancel")
.setCustomId(`cancelButton:${idMod}:${uuidv4()}`),
]);
const message = await channel.send({ ...toPost, components: [row] });
const sendMethod = contextIsInteraction ? (context.replied ? "followUp" : "reply") : "send";
const extraParameters = contextIsInteraction ? { fetchReply: true } : {};
const message = await context[sendMethod]({ ...toPost, components: [row], ...extraParameters });
const collector = message.createMessageComponentCollector({ time: 10000 });