diff --git a/src/interaction-handlers/welcome.ts b/src/interaction-handlers/welcome.ts new file mode 100644 index 0000000..9be98ac --- /dev/null +++ b/src/interaction-handlers/welcome.ts @@ -0,0 +1,79 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +/* + Animal Rights Advocates Discord Bot + Copyright (C) 2022 Anthony Berg + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +import { InteractionHandler, InteractionHandlerTypes, PieceContext } from '@sapphire/framework'; +import type { ButtonInteraction, GuildMember, TextChannel } from 'discord.js'; +import IDs from '../utils/ids'; + +class WelcomeButtonHandler extends InteractionHandler { + public constructor(ctx: PieceContext, options: InteractionHandler.Options) { + super(ctx, { + ...options, + interactionHandlerType: InteractionHandlerTypes.Button, + }); + } + + public override parse(interaction: ButtonInteraction) { + if (interaction.customId !== 'welcomeJoin') return this.none(); + + return this.some(); + } + + public async run(interaction: ButtonInteraction) { + let { member } = interaction; + const general = this.container.client.channels.cache.get(IDs.channels.nonVegan.general) as TextChannel | undefined; + if (general === undefined) { + return; + } + + if (member === null) { + await interaction.reply({ + content: 'There was an error giving you the role, please try again later or contact ModMail to be let into this server.', + ephemeral: true, + }); + return; + } + + try { + member = member as GuildMember; + + // Give non-vegan role + if (!member.voice.channel) { + await member.roles.add(IDs.roles.nonvegan.nonvegan); + + await general.send(`Welcome ${member} to ARA :D. Please check <#${IDs.channels.information.roles}> ` + + `and remember to follow the <#${IDs.channels.information.conduct}> and to respect ongoing discussion and debates.` + + '\n\nIf you would like to be verified as a vegan, join the \'Verification\' voice channel.'); + return; + } + + await interaction.reply({ + content: 'You\'re currently in a verification, you\'ll have to leave the verification or get verified before being able to access the server again.', + ephemeral: true, + }); + } catch (error) { + await interaction.reply({ + content: 'There was an error giving you the role, please try again later or contact ModMail to be let into this server.', + ephemeral: true, + }); + } + } +} + +export default WelcomeButtonHandler; diff --git a/src/listeners/verification/welcome.ts b/src/listeners/verification/welcome.ts new file mode 100644 index 0000000..1d35c2e --- /dev/null +++ b/src/listeners/verification/welcome.ts @@ -0,0 +1,82 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +/* + Animal Rights Advocates Discord Bot + Copyright (C) 2022 Anthony Berg + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +import { Listener } from '@sapphire/framework'; +import { Constants, MessageActionRow, MessageButton } from 'discord.js'; + +import type { + Client, + TextChannel, +} from 'discord.js'; +import IDs from '../../utils/ids'; + +class VerificationReady extends Listener { + public constructor(context: Listener.Context, options: Listener.Options) { + super(context, { + ...options, + once: true, + event: 'ready', + }); + } + + public async run(client: Client) { + // Get verification category + let welcome = client.channels.cache.get(IDs.channels.welcome) as TextChannel | undefined; + if (welcome === undefined) { + welcome = await client.channels.fetch(IDs.categories.verification) as TextChannel | undefined; + if (welcome === undefined) { + console.error('verifyStart: Welcome not found'); + return; + } + } + + const botId = this.container.client.id; + const messages = await welcome.messages.fetch(); + const message = messages.first(); + + const content = '**To continue and unlock more channels, please click \'Join\':**' + + '\n\n**Important:** If you want to get the vegan role, you will need to pass voice verification. ' + + 'You can do this by joining the \'Verification\' voice channel after clicking the button below. ' + + 'You\'ll chat with one of our verifiers who will just ask you a few questions before approving your Vegan role. ' + + 'Vegans have access to more channels. Voice discussions may be recorded.'; + + const button = new MessageActionRow() + .addComponents( + new MessageButton() + .setCustomId('welcomeJoin') + .setLabel('Join') + .setStyle(Constants.MessageButtonStyles.SUCCESS), + ); + + if (message?.author.id !== botId) { + await welcome.send({ + content, + components: [button], + }); + } else if (message?.author.id === botId && message?.components.length < 1) { + await message.delete(); + await welcome.send({ + content, + components: [button], + }); + } + } +} + +export default VerificationReady;