-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
225 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import { ms } from '@naval-base/ms'; | ||
import { PrismaClient } from '@prisma/client'; | ||
import type { Embed, MessageContextMenuCommandInteraction, ModalActionRowComponentBuilder } from 'discord.js'; | ||
import { | ||
ActionRowBuilder, | ||
ApplicationCommandType, | ||
EmbedBuilder, | ||
ModalBuilder, | ||
TextInputBuilder, | ||
TextInputStyle, | ||
} from 'discord.js'; | ||
import { nanoid } from 'nanoid'; | ||
import { singleton } from 'tsyringe'; | ||
import type { Command, CommandBody } from '../struct/Command.js'; | ||
import { Colors } from '../util/colors.js'; | ||
|
||
@singleton() | ||
export default class implements Command<ApplicationCommandType.Message> { | ||
public readonly interactionOptions: CommandBody<ApplicationCommandType.Message> = { | ||
name: 'Add Answer', | ||
type: ApplicationCommandType.Message, | ||
default_member_permissions: '0', | ||
dm_permission: false, | ||
}; | ||
|
||
public constructor(private readonly prisma: PrismaClient) {} | ||
|
||
public async handle(interaction: MessageContextMenuCommandInteraction<'cached'>) { | ||
const question = await this.prisma.amaQuestion.findFirst({ | ||
where: { | ||
answerMessageId: interaction.targetId, | ||
}, | ||
}); | ||
|
||
if (!question) { | ||
return interaction.reply({ | ||
content: 'This message is not an AMA question.', | ||
ephemeral: true, | ||
}); | ||
} | ||
|
||
const id = nanoid(); | ||
|
||
const modal = new ModalBuilder() | ||
.setTitle('Add an answer') | ||
.setCustomId(id) | ||
.addComponents( | ||
new ActionRowBuilder<ModalActionRowComponentBuilder>().addComponents( | ||
new TextInputBuilder() | ||
.setCustomId('answer') | ||
.setLabel('Answer to the question') | ||
.setPlaceholder('Yes! I love ramen!') | ||
.setMinLength(2) | ||
.setMaxLength(4_000) | ||
.setStyle(TextInputStyle.Paragraph) | ||
.setRequired(true), | ||
), | ||
new ActionRowBuilder<ModalActionRowComponentBuilder>().addComponents( | ||
new TextInputBuilder() | ||
.setCustomId('image-url') | ||
.setLabel('(Optional) Image URL to use') | ||
.setStyle(TextInputStyle.Short) | ||
.setRequired(false), | ||
), | ||
); | ||
|
||
await interaction.showModal(modal); | ||
const modalInteraction = await interaction | ||
.awaitModalSubmit({ time: ms('5m'), filter: (interaction) => interaction.customId === id }) | ||
.catch(() => null); | ||
|
||
if (!modalInteraction) { | ||
return; | ||
} | ||
|
||
const text = modalInteraction.fields.getTextInputValue('answer'); | ||
const imageUrl = modalInteraction.fields.getTextInputValue('image-url'); | ||
|
||
const embeds: (Embed | EmbedBuilder)[] = interaction.targetMessage.embeds; | ||
const answerEmbed = new EmbedBuilder() | ||
.setDescription(text) | ||
.setImage(imageUrl.length ? imageUrl : null) | ||
.setAuthor({ | ||
name: `${interaction.user.tag} (${interaction.user.id})`, | ||
iconURL: interaction.user.displayAvatarURL(), | ||
}) | ||
.setColor(Colors.Blurple); | ||
|
||
if (embeds.length >= 2) { | ||
embeds.splice(1, 1, answerEmbed); | ||
} else { | ||
embeds.push(answerEmbed); | ||
} | ||
|
||
await interaction.targetMessage.edit({ | ||
embeds, | ||
}); | ||
|
||
await modalInteraction.reply({ | ||
content: 'Answer added!', | ||
ephemeral: true, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { ms } from '@naval-base/ms'; | ||
import { PrismaClient } from '@prisma/client'; | ||
import type { MessageContextMenuCommandInteraction, ModalActionRowComponentBuilder } from 'discord.js'; | ||
import { | ||
ActionRowBuilder, | ||
ApplicationCommandType, | ||
Embed, | ||
EmbedBuilder, | ||
ModalBuilder, | ||
TextInputBuilder, | ||
TextInputStyle, | ||
} from 'discord.js'; | ||
import { nanoid } from 'nanoid'; | ||
import { singleton } from 'tsyringe'; | ||
import type { Command, CommandBody } from '../struct/Command'; | ||
|
||
@singleton() | ||
export default class implements Command<ApplicationCommandType.Message> { | ||
public readonly interactionOptions: CommandBody<ApplicationCommandType.Message> = { | ||
name: 'Add Timestamp', | ||
type: ApplicationCommandType.Message, | ||
default_member_permissions: '0', | ||
dm_permission: false, | ||
}; | ||
|
||
public constructor(private readonly prisma: PrismaClient) {} | ||
|
||
public async handle(interaction: MessageContextMenuCommandInteraction<'cached'>) { | ||
const question = await this.prisma.amaQuestion.findFirst({ | ||
where: { | ||
answerMessageId: interaction.targetId, | ||
}, | ||
}); | ||
|
||
if (!question) { | ||
return interaction.reply({ | ||
content: 'This message is not an AMA question.', | ||
ephemeral: true, | ||
}); | ||
} | ||
|
||
const id = nanoid(); | ||
|
||
const modal = new ModalBuilder() | ||
.setTitle('Indicate when the question was answered') | ||
.setCustomId(id) | ||
.addComponents( | ||
new ActionRowBuilder<ModalActionRowComponentBuilder>().addComponents( | ||
new TextInputBuilder() | ||
.setCustomId('text') | ||
.setLabel('(Text) Visual representation of the timestamp') | ||
.setPlaceholder('e.g. 1:23:45') | ||
.setMinLength(1) | ||
.setMaxLength(20) | ||
.setStyle(TextInputStyle.Short) | ||
.setRequired(true), | ||
), | ||
new ActionRowBuilder<ModalActionRowComponentBuilder>().addComponents( | ||
new TextInputBuilder() | ||
.setCustomId('url') | ||
.setLabel('(Optional) Link for the timestamp') | ||
.setPlaceholder('e.g. https://youtu.be/Siqi_yunMV0') | ||
.setStyle(TextInputStyle.Short) | ||
.setRequired(false), | ||
), | ||
); | ||
|
||
await interaction.showModal(modal); | ||
const modalInteraction = await interaction | ||
.awaitModalSubmit({ time: ms('5m'), filter: (interaction) => interaction.customId === id }) | ||
.catch(() => null); | ||
|
||
if (!modalInteraction) { | ||
return; | ||
} | ||
|
||
const text = modalInteraction.fields.getTextInputValue('text'); | ||
const url = modalInteraction.fields.getTextInputValue('url'); | ||
|
||
const final = url.length ? `[${text}](${url})` : text; | ||
|
||
const [toUpdate, ...rest] = interaction.targetMessage.embeds; | ||
const updated = new EmbedBuilder(toUpdate!.toJSON()).setFields([{ name: 'Answered at', value: final }]); | ||
|
||
await interaction.targetMessage.edit({ | ||
embeds: [updated, ...rest], | ||
}); | ||
|
||
await modalInteraction.reply({ | ||
content: 'Timestamp added!', | ||
ephemeral: true, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
prisma/migrations/20231010161637_remove_stages_add_context/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
-- AlterTable | ||
ALTER TABLE "Ama" ALTER COLUMN "stageOnly" SET DEFAULT false; | ||
|
||
-- AlterTable | ||
ALTER TABLE "AmaQuestion" ADD COLUMN "answerMessageId" TEXT; |
2 changes: 2 additions & 0 deletions
2
prisma/migrations/20231010163926_add_created_at/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "Ama" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters