From 4e3364bda767ec59fe1af88b3d49c701b85813d3 Mon Sep 17 00:00:00 2001 From: "Kalle (Sendou)" <38327916+Sendouc@users.noreply.github.com> Date: Wed, 23 Dec 2020 13:07:48 +0200 Subject: [PATCH] not EPHEMERAL because no embeds --- discord/commands/info.ts | 7 ++----- discord/index.ts | 4 ++-- discord/utils.ts | 2 ++ pages/api/discord.ts | 10 +++------- 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/discord/commands/info.ts b/discord/commands/info.ts index e3c730140..20557922f 100644 --- a/discord/commands/info.ts +++ b/discord/commands/info.ts @@ -1,12 +1,9 @@ import getEmbed from "discord/embed"; import { weaponsToEmoji } from "discord/emoji"; -import { RespondData } from "discord/utils"; +import { RespondFuction } from "discord/utils"; import { getUserByIdentifier } from "prisma/queries/getUserByIdentifier"; -const infoCommand = async ( - respond: (result: RespondData) => void, - discordId: string -) => { +const infoCommand = async (respond: RespondFuction, discordId: string) => { const user = await getUserByIdentifier(discordId); if (!user) { diff --git a/discord/index.ts b/discord/index.ts index 8ff0ea940..271395a01 100644 --- a/discord/index.ts +++ b/discord/index.ts @@ -1,9 +1,9 @@ import infoCommand from "./commands/info"; -import { InteractionInfo, InvocationCommon, RespondData } from "./utils"; +import { InteractionInfo, InvocationCommon, RespondFuction } from "./utils"; const handleCommand = async ( interaction: InvocationCommon & InteractionInfo, - respond: (result: RespondData) => void + respond: RespondFuction ) => { switch (interaction.data.name) { case "ping": diff --git a/discord/utils.ts b/discord/utils.ts index a85b97c86..b987e0de9 100644 --- a/discord/utils.ts +++ b/discord/utils.ts @@ -27,3 +27,5 @@ export type RespondData = { content?: string; embeds?: Embed[]; }; + +export type RespondFuction = (result: RespondData) => void; diff --git a/pages/api/discord.ts b/pages/api/discord.ts index 2355d7b7f..b12e29066 100644 --- a/pages/api/discord.ts +++ b/pages/api/discord.ts @@ -1,9 +1,5 @@ import handleCommand from "discord"; -import { - InteractionResponseFlags, - InteractionResponseType, - InteractionType, -} from "discord-interactions"; +import { InteractionResponseType, InteractionType } from "discord-interactions"; import { RespondData } from "discord/utils"; import { NextApiRequest, NextApiResponse } from "next"; import getRawBody from "raw-body"; @@ -43,7 +39,7 @@ const discordCommandHandler = async ( if (interaction && interaction.type === InteractionType.COMMAND) { handleCommand(interaction, (data) => res.status(200).json({ - type: InteractionResponseType.CHANNEL_MESSAGE, + type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE, data: getCompleteData(data), }) ); @@ -59,7 +55,7 @@ function getCompleteData(result: RespondData) { ...result, // add zero-width space because empty content isn't allowed even with embeds content: result.content ? result.content : "\u200b", - flags: InteractionResponseFlags.EPHEMERAL, + //flags: InteractionResponseFlags.EPHEMERAL, }; }