mirror of
https://github.com/xHyroM/roles-bot.git
synced 2024-12-21 21:31:05 +01:00
feat: add make a choice into dropdown
This commit is contained in:
parent
ee32db2f4d
commit
c62cfa2438
6 changed files with 38 additions and 15 deletions
|
@ -41,6 +41,16 @@ new Component({
|
|||
: // support for legacy select menus
|
||||
ctx.interaction.data.custom_id;
|
||||
|
||||
if (roleId === "nothing") {
|
||||
return ctx.respond({
|
||||
type: InteractionResponseType.ChannelMessageWithSource,
|
||||
data: {
|
||||
content: "No role selected.",
|
||||
flags: MessageFlags.Ephemeral,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const content = !ctx.interaction.member?.roles.includes(roleId)
|
||||
? `Gave the <@&${roleId}> role!`
|
||||
: `Removed the <@&${roleId}> role!`;
|
||||
|
|
|
@ -82,7 +82,7 @@ new Component({
|
|||
},
|
||||
});
|
||||
|
||||
const rawData = await REDIS.get(
|
||||
const rawData: string | null = await REDIS.get(
|
||||
`roles-bot-setup:${ctx.interaction.guild_id}`,
|
||||
);
|
||||
if (!rawData)
|
||||
|
@ -141,7 +141,7 @@ new Component({
|
|||
const interaction =
|
||||
ctx.interaction as APIMessageComponentSelectMenuInteraction;
|
||||
|
||||
const rawData = await REDIS.get(
|
||||
const rawData: string | null = await REDIS.get(
|
||||
`roles-bot-setup:${ctx.interaction.guild_id}`,
|
||||
);
|
||||
if (!rawData)
|
||||
|
@ -233,7 +233,9 @@ new Component({
|
|||
},
|
||||
});
|
||||
|
||||
const rawData = await REDIS.get(`roles-bot-setup:${ctx.guildId}`);
|
||||
const rawData: string | null = await REDIS.get(
|
||||
`roles-bot-setup:${ctx.guildId}`,
|
||||
);
|
||||
if (!rawData)
|
||||
return ctx.respond({
|
||||
type: InteractionResponseType.ChannelMessageWithSource,
|
||||
|
|
|
@ -18,7 +18,7 @@ new Modal({
|
|||
id: "setup:part-roles-lpe",
|
||||
acknowledge: false,
|
||||
run: async (ctx) => {
|
||||
const rawData = await REDIS.get(
|
||||
const rawData: string | null = await REDIS.get(
|
||||
`roles-bot-setup:${ctx.interaction.guild_id}`,
|
||||
);
|
||||
if (!rawData)
|
||||
|
@ -95,7 +95,7 @@ new Modal({
|
|||
id: "setup:part-messageContent",
|
||||
acknowledge: false,
|
||||
run: async (ctx) => {
|
||||
const rawData = await REDIS.get(
|
||||
const rawData: string | null = await REDIS.get(
|
||||
`roles-bot-setup:${ctx.interaction.guild_id}`,
|
||||
);
|
||||
if (!rawData)
|
||||
|
@ -168,7 +168,7 @@ new Modal({
|
|||
id: "setup:part-webhook",
|
||||
acknowledge: false,
|
||||
run: async (ctx) => {
|
||||
const rawData = await REDIS.get(
|
||||
const rawData: string | null = await REDIS.get(
|
||||
`roles-bot-setup:${ctx.interaction.guild_id}`,
|
||||
);
|
||||
if (!rawData)
|
||||
|
|
|
@ -11,7 +11,9 @@ import { decodeFromString } from "serialize";
|
|||
import { BasicData } from "../types";
|
||||
|
||||
export default async function (data: BasicData, ctx: Context, rawRole: string) {
|
||||
const rolesRaw = await REDIS.get(`roles-bot-setup-roles:${ctx.guildId}`);
|
||||
const rolesRaw: string | null = await REDIS.get(
|
||||
`roles-bot-setup-roles:${ctx.guildId}`,
|
||||
);
|
||||
if (!rolesRaw)
|
||||
return ctx.respond({
|
||||
type: InteractionResponseType.ChannelMessageWithSource,
|
||||
|
|
|
@ -2,7 +2,6 @@ import {
|
|||
APIActionRowComponent,
|
||||
APIEmbed,
|
||||
APIMessageActionRowComponent,
|
||||
ButtonStyle,
|
||||
InteractionResponseType,
|
||||
MessageFlags,
|
||||
RouteBases,
|
||||
|
@ -65,11 +64,18 @@ export default async function (ctx: Context, data: Data) {
|
|||
}
|
||||
|
||||
const components: APIActionRowComponent<APIMessageActionRowComponent>[] = [];
|
||||
const array = splitArray(data.roleIds, data.selecting === "buttons" ? 5 : 25);
|
||||
const array = splitArray(data.roleIds, data.selecting === "buttons" ? 5 : 24);
|
||||
for (const items of array) {
|
||||
const actionRow = new ActionRowBuilder();
|
||||
|
||||
const selectMenu = new StringSelectMenuBuilder().setCustomId("select:role");
|
||||
const selectMenuNaiveOption = new StringSelectMenuOptionBuilder()
|
||||
.setLabel("Make a choice")
|
||||
.setValue("nothing")
|
||||
.setDefault(true);
|
||||
|
||||
const selectMenu = new StringSelectMenuBuilder()
|
||||
.setCustomId("select:role")
|
||||
.addOptions(selectMenuNaiveOption);
|
||||
|
||||
for (const item of items) {
|
||||
switch (data.selecting) {
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
// from https://gist.github.com/devsnek/77275f6e3f810a9545440931ed314dc1
|
||||
|
||||
"use strict";
|
||||
|
||||
import type { Env } from "../types";
|
||||
|
||||
function hex2bin(hex: string) {
|
||||
|
@ -14,13 +12,18 @@ function hex2bin(hex: string) {
|
|||
|
||||
const encoder = new TextEncoder();
|
||||
|
||||
export function getAlgorithm() {
|
||||
// @ts-expect-error
|
||||
return typeof MINIFLARE !== "undefined" ? "Ed25519" : "NODE-ED25519";
|
||||
}
|
||||
|
||||
export async function verify(request: Request, env: Env) {
|
||||
const subtle = await crypto.subtle.importKey(
|
||||
"raw",
|
||||
hex2bin(env.publicKey),
|
||||
{
|
||||
name: typeof MINIFLARE !== "undefined" ? "Ed25519" : "NODE-ED25519",
|
||||
namedCurve: typeof MINIFLARE !== "undefined" ? "Ed25519" : "NODE-ED25519",
|
||||
name: getAlgorithm(),
|
||||
namedCurve: getAlgorithm(),
|
||||
},
|
||||
true,
|
||||
["verify"],
|
||||
|
@ -32,7 +35,7 @@ export async function verify(request: Request, env: Env) {
|
|||
const unknown = await request.clone().text();
|
||||
|
||||
return await crypto.subtle.verify(
|
||||
typeof MINIFLARE !== "undefined" ? "Ed25519" : "NODE-ED25519",
|
||||
getAlgorithm(),
|
||||
subtle,
|
||||
signature,
|
||||
encoder.encode(timestamp + unknown),
|
||||
|
|
Loading…
Reference in a new issue