feat(verification): add information on user in text channel

This commit is contained in:
Anthony
2022-09-01 03:37:28 +01:00
parent a893e13d57
commit 0829e7c996
3 changed files with 101 additions and 8 deletions

View File

@@ -34,9 +34,11 @@ import {
MessageButton,
MessageEmbed,
} from 'discord.js';
import { time } from '@discordjs/builders';
import { maxVCs, questionInfo, serverFind } from '../../utils/verificationConfig';
import { joinVerification, startVerification, finishVerification } from '../../utils/database/verification';
import { userExists, addExistingUser } from '../../utils/database/dbExistingUser';
import { rolesToString } from '../../utils/formatter';
import IDs from '../../utils/ids';
class VerificationJoinVCListener extends Listener {
@@ -79,6 +81,8 @@ class VerificationJoinVCListener extends Listener {
const currentChannel = currentChannelGuild as VoiceChannel;
const category = categoryGuild as CategoryChannel;
const roles = rolesToString(member.roles.cache.map((r) => r.id));
// Checks if a verifier has joined
if (channel.members.size === 2) {
await newState.channel!.permissionOverwrites.set([
@@ -156,8 +160,12 @@ class VerificationJoinVCListener extends Listener {
});
// Send a message that someone wants to be verified
await verificationText.send(`${member.user} wants to be verified in ${channel}
\n<@&${IDs.roles.staff.verifier}> <@&${IDs.roles.staff.trialVerifier}>`);
const userInfoEmbed = await this.getUserInfo(member, roles);
await verificationText.send({
content: `${member.user} wants to be verified in ${channel}
\n<@&${IDs.roles.staff.verifier}> <@&${IDs.roles.staff.trialVerifier}>`,
embeds: [userInfoEmbed],
});
await this.verificationProcess(verificationText, channel.id, member, guild);
}
@@ -180,10 +188,19 @@ class VerificationJoinVCListener extends Listener {
deny: ['VIEW_CHANNEL', 'CONNECT', 'SEND_MESSAGES'],
},
{
id: IDs.roles.verifyingAsVegan,
id: IDs.roles.nonvegan.nonvegan,
allow: ['VIEW_CHANNEL'],
deny: ['CONNECT'],
},
{
id: IDs.roles.vegan.vegan,
allow: ['VIEW_CHANNEL'],
deny: ['CONNECT'],
},
{
id: IDs.roles.vegan.activist,
deny: ['VIEW_CHANNEL', 'CONNECT'],
},
{
id: IDs.roles.staff.verifier,
allow: ['SEND_MESSAGES', 'VIEW_CHANNEL'],
@@ -205,9 +222,17 @@ class VerificationJoinVCListener extends Listener {
deny: ['VIEW_CHANNEL', 'CONNECT', 'SEND_MESSAGES'],
},
{
id: IDs.roles.verifyingAsVegan,
id: IDs.roles.nonvegan.nonvegan,
allow: ['VIEW_CHANNEL'],
},
{
id: IDs.roles.vegan.vegan,
allow: ['VIEW_CHANNEL'],
},
{
id: IDs.roles.vegan.activist,
deny: ['VIEW_CHANNEL', 'CONNECT'],
},
{
id: IDs.roles.staff.verifier,
allow: ['SEND_MESSAGES', 'VIEW_CHANNEL'],
@@ -223,7 +248,11 @@ class VerificationJoinVCListener extends Listener {
deny: ['SEND_MESSAGES', 'VIEW_CHANNEL'],
},
{
id: IDs.roles.verifyingAsVegan,
id: IDs.roles.nonvegan.nonvegan,
deny: ['VIEW_CHANNEL'],
},
{
id: IDs.roles.vegan.vegan,
deny: ['VIEW_CHANNEL'],
},
{
@@ -234,6 +263,24 @@ class VerificationJoinVCListener extends Listener {
await currentChannel.setUserLimit(0);
}
// Creates an embed for information about the user
private async getUserInfo(user: GuildMember, roles: string) {
const joinTime = time(user.joinedAt!);
const registerTime = time(user.user.createdAt);
const embed = new MessageEmbed()
.setColor(user.displayHexColor)
.setTitle(`Information on ${user.user.username}`)
.setThumbnail(user.user.avatarURL()!)
.addFields(
{ name: 'Joined:', value: `${joinTime}`, inline: true },
{ name: 'Created:', value: `${registerTime}`, inline: true },
{ name: 'Roles:', value: roles },
);
return embed;
}
private async verificationProcess(
channel: TextChannel,
verId: string,
@@ -419,7 +466,7 @@ class VerificationJoinVCListener extends Listener {
embed = new MessageEmbed()
.setColor('#34c000')
.setTitle(`Successfully verified ${user.displayName}!`)
.setThumbnail(user.avatarURL()!)
.setThumbnail(user.user.avatarURL()!)
.addFields(
{ name: 'Roles:', value: this.getTextRoles(info.roles) },
);

View File

@@ -141,9 +141,17 @@ class VerificationLeaveVCListener extends Listener {
deny: ['VIEW_CHANNEL', 'CONNECT', 'SEND_MESSAGES'],
},
{
id: IDs.roles.verifyingAsVegan,
id: IDs.roles.nonvegan.nonvegan,
allow: ['VIEW_CHANNEL'],
},
{
id: IDs.roles.vegan.vegan,
allow: ['VIEW_CHANNEL'],
},
{
id: IDs.roles.vegan.activist,
deny: ['VIEW_CHANNEL', 'CONNECT'],
},
{
id: IDs.roles.staff.verifier,
allow: ['SEND_MESSAGES', 'VIEW_CHANNEL'],
@@ -161,7 +169,11 @@ class VerificationLeaveVCListener extends Listener {
await verification!.permissionOverwrites.set([
{
id: IDs.roles.verifyingAsVegan,
id: IDs.roles.nonvegan.nonvegan,
allow: ['VIEW_CHANNEL'],
},
{
id: IDs.roles.vegan.vegan,
allow: ['VIEW_CHANNEL'],
},
]);

34
src/utils/formatter.ts Normal file
View File

@@ -0,0 +1,34 @@
// 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 <https://www.gnu.org/licenses/>.
*/
import type { Snowflake } from 'discord-api-types/globals';
export function rolesToString(roles: Snowflake[]) {
let output = '';
roles.forEach((role) => {
output += `<@&${role}>`;
});
if (output.length === 0) {
output = 'None';
}
return output;
}