diff --git a/src/listeners/verification/trusted.ts b/src/listeners/verification/trusted.ts new file mode 100644 index 0000000..c4bd398 --- /dev/null +++ b/src/listeners/verification/trusted.ts @@ -0,0 +1,87 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +/* + Animal Rights Advocates Discord Bot + Copyright (C) 2024 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 { GuildMember } from 'discord.js'; +import IDs from '#utils/ids'; +import { noModHistory, userPreviouslyHadRole } from '#utils/database/memberMod'; + +/** + * Gives the trusted role to users who have levelled up to level 5 + * and has not gotten any other warnings/restrictions prior. + */ +export class TrustedListener extends Listener { + public constructor( + context: Listener.LoaderContext, + options: Listener.Options, + ) { + super(context, { + ...options, + event: 'xpLevelUp', + }); + } + + public async run(member: GuildMember, level: number) { + // Checks if the member has gotten level 5 + if (level !== 5) { + return; + } + + // Checks if the user has been previously moderated + const noModerationHistory = await noModHistory(member.id); + if (!noModerationHistory) { + return; + } + + const { guild } = member; + const trusted = guild.roles.cache.get(IDs.roles.trusted); + + if (trusted === undefined) { + this.container.logger.error( + 'TrustedXP Listener: the Trusted role could not be found in the guild.', + ); + return; + } + + // Checks if the member has previously had the trusted role given/removed + const previouslyHadRole = await userPreviouslyHadRole( + member.id, + trusted.id, + ); + if (previouslyHadRole) { + return; + } + + // Checks if the user already has the trusted role + if (member.roles.cache.has(trusted.id)) { + return; + } + + // Gives the trusted role to the member + await member.roles.add(trusted); + + // Send a DM to inform the member that they have been given the trusted role + await member.user.send( + `Hi, you have been given the ${trusted.name} as you have been interacting in ARA for a long enough time!` + + '\n\nThis role allows you to post attachments to the server and stream in VCs.' + + "\nMake sure that you follow the rules, and don't post anything NSFW, anything objectifying animals and follow Discord's ToS." + + `\nNot following these rules can result in the removal of the ${trusted.name} role.`, + ); + } +}