Add attachments support
This commit is contained in:
parent
11404358eb
commit
aeb3c70f91
|
@ -17,8 +17,8 @@
|
|||
*/
|
||||
|
||||
import {
|
||||
ActionRowBuilder,
|
||||
ButtonBuilder,
|
||||
ActionRowBuilder,
|
||||
ButtonBuilder,
|
||||
ButtonStyle,
|
||||
CommandInteraction,
|
||||
ComponentType,
|
||||
|
@ -43,6 +43,11 @@ export const data = new SlashCommandBuilder()
|
|||
.setName("message")
|
||||
.setRequired(true)
|
||||
.setDescription("What you want to confess")
|
||||
)
|
||||
.addStringOption(option =>
|
||||
option
|
||||
.setName("attachment")
|
||||
.setDescription("The link to an image to attach (optional)")
|
||||
);
|
||||
|
||||
export async function execute(interaction: CommandInteraction) {
|
||||
|
@ -69,7 +74,12 @@ export async function execute(interaction: CommandInteraction) {
|
|||
const adminChannel = dt.getGuildInfo(interaction.guild?.id!)?.settings
|
||||
.modChannel;
|
||||
// @ts-ignore
|
||||
const messageContent = interaction.options.getString("message");
|
||||
const messageContent: string = interaction.options.getString("message");
|
||||
// @ts-ignore
|
||||
const attachment: string = interaction.options.getString("attachment");
|
||||
|
||||
const isAttachment = (text: string) =>
|
||||
text && (text.startsWith("http://") || text.startsWith("https://"));
|
||||
|
||||
const color = getRandomColor();
|
||||
const messageId = StoreMan.genId();
|
||||
|
@ -79,6 +89,8 @@ export async function execute(interaction: CommandInteraction) {
|
|||
// @ts-ignore
|
||||
.setDescription(messageContent);
|
||||
|
||||
isAttachment(attachment) && userConfessionEmbed.setImage(attachment);
|
||||
|
||||
const adminConfessionEmbed = new EmbedBuilder()
|
||||
.setColor(color)
|
||||
.setTitle(`Anonymous Confession \`${messageId}\``)
|
||||
|
@ -95,13 +107,16 @@ export async function execute(interaction: CommandInteraction) {
|
|||
}
|
||||
);
|
||||
|
||||
isAttachment(attachment) && adminConfessionEmbed.setImage(attachment);
|
||||
|
||||
const submitConfessionButton = new ButtonBuilder()
|
||||
.setCustomId("submitConfession")
|
||||
.setLabel("Submit a Confession")
|
||||
.setStyle(ButtonStyle.Primary);
|
||||
|
||||
const actionRow = new ActionRowBuilder<ButtonBuilder>()
|
||||
.setComponents(submitConfessionButton);
|
||||
const actionRow = new ActionRowBuilder<ButtonBuilder>().setComponents(
|
||||
submitConfessionButton
|
||||
);
|
||||
|
||||
const message = await (
|
||||
BotClient.channels.cache.get(confessChannel!) as TextChannel
|
||||
|
@ -110,7 +125,9 @@ export async function execute(interaction: CommandInteraction) {
|
|||
components: [actionRow]
|
||||
});
|
||||
|
||||
const collector = message.createMessageComponentCollector({ componentType: ComponentType.Button });
|
||||
const collector = message.createMessageComponentCollector({
|
||||
componentType: ComponentType.Button
|
||||
});
|
||||
|
||||
collector.on("collect", i => {
|
||||
if (i.customId === "submitConfession") {
|
||||
|
@ -127,17 +144,25 @@ export async function execute(interaction: CommandInteraction) {
|
|||
messageId,
|
||||
interaction.user.displayName,
|
||||
interaction.user.id,
|
||||
messageContent
|
||||
messageContent,
|
||||
attachment
|
||||
);
|
||||
|
||||
const confessionsLength = dt.getGuildInfo(interaction.guild?.id!)?.confessions.length!;
|
||||
const confessionsLength = dt.getGuildInfo(interaction.guild?.id!)
|
||||
?.confessions.length!;
|
||||
|
||||
if (confessionsLength >= 2) {
|
||||
await (BotClient.channels.cache.get(confessChannel!) as TextChannel).messages.fetch(
|
||||
dt.getGuildInfo(interaction.guild?.id!)?.confessions[confessionsLength - 2].messageId!
|
||||
).then(message => {
|
||||
message.edit({ components: [] });
|
||||
});
|
||||
await (
|
||||
BotClient.channels.cache.get(confessChannel!) as TextChannel
|
||||
).messages
|
||||
.fetch(
|
||||
dt.getGuildInfo(interaction.guild?.id!)?.confessions[
|
||||
confessionsLength - 2
|
||||
].messageId!
|
||||
)
|
||||
.then(message => {
|
||||
message.edit({ components: [] });
|
||||
});
|
||||
}
|
||||
|
||||
return interaction.reply({
|
||||
|
|
|
@ -16,19 +16,25 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { CommandInteraction,PermissionFlagsBits,SlashCommandBuilder } from "discord.js";
|
||||
import {
|
||||
CommandInteraction,
|
||||
PermissionFlagsBits,
|
||||
SlashCommandBuilder
|
||||
} from "discord.js";
|
||||
import { dt } from "../main";
|
||||
import { BotClient } from "../bot";
|
||||
|
||||
export const data = new SlashCommandBuilder()
|
||||
.setName("confessbanlist")
|
||||
.setDescription("Get the current ban list")
|
||||
.setDefaultMemberPermissions(PermissionFlagsBits.ManageMessages)
|
||||
.setDefaultMemberPermissions(PermissionFlagsBits.ManageMessages);
|
||||
|
||||
export async function execute(interaction: CommandInteraction) {
|
||||
const bannedMembers = dt.getBans(interaction.guild?.id!);
|
||||
|
||||
let content = bannedMembers.length ? "Banned Members:\n" : "There are no banned members.";
|
||||
let content = bannedMembers.length
|
||||
? "Banned Members:\n"
|
||||
: "There are no banned members.";
|
||||
|
||||
for (const member of bannedMembers) {
|
||||
const identifiedMember = await BotClient.users.fetch(member.user);
|
||||
|
@ -39,5 +45,5 @@ export async function execute(interaction: CommandInteraction) {
|
|||
return interaction.reply({
|
||||
content: content,
|
||||
ephemeral: true
|
||||
})
|
||||
});
|
||||
}
|
||||
|
|
61
src/main.ts
61
src/main.ts
|
@ -16,7 +16,17 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, CacheType, ComponentType, EmbedBuilder, Events, Interaction, ModalSubmitInteraction, TextChannel, } from "discord.js";
|
||||
import {
|
||||
ActionRowBuilder,
|
||||
ButtonBuilder,
|
||||
ButtonStyle,
|
||||
ComponentType,
|
||||
EmbedBuilder,
|
||||
Events,
|
||||
Interaction,
|
||||
ModalSubmitInteraction,
|
||||
TextChannel
|
||||
} from "discord.js";
|
||||
import { BotClient, BOT_TOKEN, deployCommands } from "./bot";
|
||||
import { commands } from "./commands";
|
||||
import { StoreMan } from "./storeman";
|
||||
|
@ -60,9 +70,12 @@ BotClient.on(Events.InteractionCreate, async interaction => {
|
|||
}
|
||||
|
||||
if (interaction.customId === "submitConfession") {
|
||||
const messageContent: string = interaction.fields.getTextInputValue("confessionInput");
|
||||
// const attachment: string = interaction.getTextInputValue("confessionAttachment");
|
||||
|
||||
const messageContent: string =
|
||||
interaction.fields.getTextInputValue("confessionInput");
|
||||
const attachment: string = interaction.fields.getTextInputValue(
|
||||
"confessionAttachment"
|
||||
);
|
||||
|
||||
try {
|
||||
if (dt.isBanned(interaction.guild?.id!, interaction.user.id)) {
|
||||
return interaction.reply({
|
||||
|
@ -84,6 +97,9 @@ BotClient.on(Events.InteractionCreate, async interaction => {
|
|||
const adminChannel = dt.getGuildInfo(interaction.guild?.id!)?.settings
|
||||
.modChannel;
|
||||
|
||||
const isAttachment = (text: string) =>
|
||||
text && (text.startsWith("http://") || text.startsWith("https://"));
|
||||
|
||||
const color = getRandomColor();
|
||||
const messageId = StoreMan.genId();
|
||||
const userConfessionEmbed = new EmbedBuilder()
|
||||
|
@ -92,6 +108,8 @@ BotClient.on(Events.InteractionCreate, async interaction => {
|
|||
// @ts-ignore
|
||||
.setDescription(messageContent);
|
||||
|
||||
isAttachment(attachment) && userConfessionEmbed.setImage(attachment);
|
||||
|
||||
const adminConfessionEmbed = new EmbedBuilder()
|
||||
.setColor(color)
|
||||
.setTitle(`Anonymous Confession \`${messageId}\``)
|
||||
|
@ -108,13 +126,16 @@ BotClient.on(Events.InteractionCreate, async interaction => {
|
|||
}
|
||||
);
|
||||
|
||||
isAttachment(attachment) && adminConfessionEmbed.setImage(attachment);
|
||||
|
||||
const submitConfessionButton = new ButtonBuilder()
|
||||
.setCustomId("submitConfession")
|
||||
.setLabel("Submit a Confession")
|
||||
.setStyle(ButtonStyle.Primary);
|
||||
|
||||
const actionRow = new ActionRowBuilder<ButtonBuilder>()
|
||||
.setComponents(submitConfessionButton);
|
||||
const actionRow = new ActionRowBuilder<ButtonBuilder>().setComponents(
|
||||
submitConfessionButton
|
||||
);
|
||||
|
||||
const message = await (
|
||||
BotClient.channels.cache.get(confessChannel!) as TextChannel
|
||||
|
@ -123,7 +144,9 @@ BotClient.on(Events.InteractionCreate, async interaction => {
|
|||
components: [actionRow]
|
||||
});
|
||||
|
||||
const collector = message.createMessageComponentCollector({ componentType: ComponentType.Button });
|
||||
const collector = message.createMessageComponentCollector({
|
||||
componentType: ComponentType.Button
|
||||
});
|
||||
|
||||
collector.on("collect", i => {
|
||||
if (i.customId === "submitConfession") {
|
||||
|
@ -140,17 +163,25 @@ BotClient.on(Events.InteractionCreate, async interaction => {
|
|||
messageId,
|
||||
interaction.user.displayName,
|
||||
interaction.user.id,
|
||||
messageContent
|
||||
messageContent,
|
||||
attachment
|
||||
);
|
||||
|
||||
const confessionsLength = dt.getGuildInfo(interaction.guild?.id!)?.confessions.length!;
|
||||
const confessionsLength = dt.getGuildInfo(interaction.guild?.id!)
|
||||
?.confessions.length!;
|
||||
|
||||
if (confessionsLength >= 2) {
|
||||
await (BotClient.channels.cache.get(confessChannel!) as TextChannel).messages.fetch(
|
||||
dt.getGuildInfo(interaction.guild?.id!)?.confessions[confessionsLength - 2].messageId!
|
||||
).then(message => {
|
||||
message.edit({ components: [] });
|
||||
});
|
||||
await (
|
||||
BotClient.channels.cache.get(confessChannel!) as TextChannel
|
||||
).messages
|
||||
.fetch(
|
||||
dt.getGuildInfo(interaction.guild?.id!)?.confessions[
|
||||
confessionsLength - 2
|
||||
].messageId!
|
||||
)
|
||||
.then(message => {
|
||||
message.edit({ components: [] });
|
||||
});
|
||||
}
|
||||
|
||||
return interaction.reply({
|
||||
|
@ -161,6 +192,6 @@ BotClient.on(Events.InteractionCreate, async interaction => {
|
|||
logger.error("An error occured:", err);
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
BotClient.login(BOT_TOKEN);
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {
|
||||
import {
|
||||
ActionRowBuilder,
|
||||
ModalActionRowComponentBuilder,
|
||||
ModalBuilder,
|
||||
|
@ -26,27 +26,31 @@ import {
|
|||
|
||||
const submit = new ModalBuilder()
|
||||
.setCustomId("submitConfession")
|
||||
.setTitle("Submit Confession")
|
||||
.setTitle("Submit Confession");
|
||||
|
||||
const confessionInput = new TextInputBuilder()
|
||||
.setCustomId("confessionInput")
|
||||
.setLabel("Confession")
|
||||
.setRequired(true)
|
||||
.setMaxLength(2000)
|
||||
.setStyle(TextInputStyle.Paragraph)
|
||||
.setStyle(TextInputStyle.Paragraph);
|
||||
|
||||
// TODO: Add support for attachments
|
||||
//
|
||||
// const attachmentInput = new TextInputBuilder()
|
||||
// .setCustomId("confessionAttachment")
|
||||
// .setLabel("Attachment (optional)")
|
||||
// .setRequired(false)
|
||||
// .setStyle(TextInputStyle.Short)
|
||||
const attachmentInput = new TextInputBuilder()
|
||||
.setCustomId("confessionAttachment")
|
||||
.setLabel("Attachment (optional)")
|
||||
.setRequired(false)
|
||||
.setStyle(TextInputStyle.Short);
|
||||
|
||||
const actionRow = new ActionRowBuilder<ModalActionRowComponentBuilder>()
|
||||
.addComponents(confessionInput);
|
||||
// .addComponents(confessionInput, attachmentInput);
|
||||
const confessionRow =
|
||||
new ActionRowBuilder<ModalActionRowComponentBuilder>().addComponents(
|
||||
confessionInput
|
||||
);
|
||||
|
||||
submit.addComponents(actionRow);
|
||||
const attachmentRow =
|
||||
new ActionRowBuilder<ModalActionRowComponentBuilder>().addComponents(
|
||||
attachmentInput
|
||||
);
|
||||
|
||||
submit.addComponents(confessionRow, attachmentRow);
|
||||
|
||||
export { submit };
|
||||
|
|
|
@ -38,14 +38,16 @@ export class StoreMan {
|
|||
id: string,
|
||||
author: string,
|
||||
authorId: string,
|
||||
content: string
|
||||
content: string,
|
||||
attachment?: string
|
||||
): Confession {
|
||||
return {
|
||||
id: id,
|
||||
messageId: message.id,
|
||||
author: author,
|
||||
authorId: authorId,
|
||||
content: content
|
||||
content: content,
|
||||
attachment: attachment
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -122,7 +124,8 @@ export class StoreMan {
|
|||
id: string,
|
||||
author: string,
|
||||
authorId: string,
|
||||
content: string
|
||||
content: string,
|
||||
attachment?: string
|
||||
): boolean {
|
||||
const guildId = message.guild?.id;
|
||||
|
||||
|
@ -134,7 +137,14 @@ export class StoreMan {
|
|||
}
|
||||
|
||||
guild.confessions.push(
|
||||
StoreMan.toConfession(message, id, author, authorId, content)
|
||||
StoreMan.toConfession(
|
||||
message,
|
||||
id,
|
||||
author,
|
||||
authorId,
|
||||
content,
|
||||
attachment
|
||||
)
|
||||
);
|
||||
this.saveFile();
|
||||
return true;
|
||||
|
@ -243,7 +253,9 @@ export class StoreMan {
|
|||
if (guild.id === guildId) {
|
||||
if (this.getConfession(guildId, confessionId)) {
|
||||
guild.settings.bans = guild.settings.bans.filter(ban => {
|
||||
return ban.user !== this.getConfession(guildId, confessionId)?.authorId!;
|
||||
return (
|
||||
ban.user !== this.getConfession(guildId, confessionId)?.authorId!
|
||||
);
|
||||
});
|
||||
|
||||
this.saveFile();
|
||||
|
|
|
@ -22,6 +22,7 @@ export interface Confession {
|
|||
author: string;
|
||||
authorId: string;
|
||||
content: string;
|
||||
attachment?: string;
|
||||
}
|
||||
|
||||
export interface ConfessionBan {
|
||||
|
|
Loading…
Reference in a new issue