2022-06-06 14:59:53 +07:00
import App from '..' ;
import {
GuildChannel ,
GuildMember ,
Message ,
Permissions ,
TextChannel ,
MessageActionRow ,
MessageButton ,
Interaction ,
CommandInteraction ,
Role ,
ThreadChannel ,
ButtonInteraction
} from 'discord.js' ;
2022-03-03 20:56:49 +07:00
2022-06-06 14:59:53 +07:00
import DiscordProvider from '../providers/Discord' ;
import Prisma from '../providers/Prisma' ;
import {
makeSuccessEmbed ,
makeInfoEmbed ,
makeErrorEmbed ,
sendHybridInteractionMessageResponse ,
sendMessage
} from '../utils/DiscordMessage' ;
import DiscordModule , { HybridInteractionMessage } from '../utils/DiscordModule' ;
2021-09-17 11:14:54 -07:00
const EMBEDS = {
NO_PERMISSION : ( data : Message | Interaction ) => {
2022-03-03 20:56:49 +07:00
return makeErrorEmbed ({
2021-09-17 11:14:54 -07:00
title : 'You need ``ADMINISTRATOR`` permission on this guild!' ,
2022-06-06 14:59:53 +07:00
user : data instanceof Interaction ? data.user : data.author
2021-09-17 11:14:54 -07:00
});
},
NO_PARAMETER : ( data : Message | Interaction ) => {
2022-03-03 20:56:49 +07:00
return makeErrorEmbed ({
2021-09-17 11:14:54 -07:00
title : 'Missing parameter' ,
description : `You must define membership screening channel and role to enable this feature` ,
2022-06-06 14:59:53 +07:00
user : data instanceof Interaction ? data.user : data.author
2021-09-17 11:14:54 -07:00
});
},
NO_ROLE_MENTIONED : ( data : Message | Interaction ) => {
2022-03-03 20:56:49 +07:00
return makeErrorEmbed ({
2021-09-17 11:14:54 -07:00
title : 'No role mentioned' ,
2022-06-06 14:59:53 +07:00
user : data instanceof Interaction ? data.user : data.author
2021-09-17 11:14:54 -07:00
});
},
NO_ROLE_FOUND : ( data : Message | Interaction ) => {
2022-03-03 20:56:49 +07:00
return makeErrorEmbed ({
2021-09-17 11:14:54 -07:00
title : 'Cannot find that role' ,
2022-06-06 14:59:53 +07:00
user : data instanceof Interaction ? data.user : data.author
2021-09-17 11:14:54 -07:00
});
},
NO_CHANNEL_MENTIONED : ( data : Message | Interaction ) => {
2022-03-03 20:56:49 +07:00
return makeErrorEmbed ({
2021-09-17 11:14:54 -07:00
title : 'No channel mentioned' ,
2022-06-06 14:59:53 +07:00
user : data instanceof Interaction ? data.user : data.author
2021-09-17 11:14:54 -07:00
});
},
NO_CHANNEL_FOUND : ( data : Message | Interaction ) => {
2022-03-03 20:56:49 +07:00
return makeErrorEmbed ({
2021-09-17 11:14:54 -07:00
title : 'Cannot find that channel' ,
2022-06-06 14:59:53 +07:00
user : data instanceof Interaction ? data.user : data.author
2021-09-17 11:14:54 -07:00
});
},
2022-03-03 20:56:49 +07:00
MSINFO : ( data : Message | Interaction ) => {
return makeInfoEmbed ({
2021-09-17 11:14:54 -07:00
title : 'Membership Screening' ,
description : `Membership Screening is a feature to prevent unwanted people to join your guild, similar to whitelist feature. Moderators can approve or deny join request` ,
fields : [
{
name : 'Available arguments' ,
value : '``setRole`` ``setChannel`` ``createMessage``'
}
],
2022-06-06 14:59:53 +07:00
user : data instanceof Interaction ? data.user : data.author
2021-09-17 11:14:54 -07:00
});
},
ALREADY_ENABLED : ( data : Message | Interaction ) => {
2022-03-03 20:56:49 +07:00
return makeInfoEmbed ({
2021-09-17 11:14:54 -07:00
title : 'Membership Screening is already enabled' ,
2022-06-06 14:59:53 +07:00
user : data instanceof Interaction ? data.user : data.author
2021-09-17 11:14:54 -07:00
});
},
2022-03-03 20:56:49 +07:00
MESSAGE_CREATED : ( data : Message | Interaction ) => {
return makeSuccessEmbed ({
title : 'Membership Screening message created' ,
2022-06-06 14:59:53 +07:00
user : data instanceof Interaction ? data.user : data.author
2022-03-03 20:56:49 +07:00
});
},
2021-09-17 11:14:54 -07:00
ALREADY_DISABLED : ( data : Message | Interaction ) => {
2022-03-03 20:56:49 +07:00
return makeInfoEmbed ({
2021-09-17 11:14:54 -07:00
title : 'Membership Screening is already disabled' ,
2022-06-06 14:59:53 +07:00
user : data instanceof Interaction ? data.user : data.author
2021-09-17 11:14:54 -07:00
});
},
ENABLED : ( data : Message | Interaction ) => {
2022-03-03 20:56:49 +07:00
return makeSuccessEmbed ({
2021-09-17 11:14:54 -07:00
title : 'Enabled Membership Screening' ,
description : `All new member join request will be sent in your defined channel` ,
2022-06-06 14:59:53 +07:00
user : data instanceof Interaction ? data.user : data.author
2021-09-17 11:14:54 -07:00
});
},
DISABLED : ( data : Message | Interaction ) => {
2022-03-03 20:56:49 +07:00
return makeSuccessEmbed ({
2021-09-17 11:14:54 -07:00
title : 'Disabled Membership Screening' ,
description : `No longer accepting request, all new member can join directly` ,
2022-06-06 14:59:53 +07:00
user : data instanceof Interaction ? data.user : data.author
});
2021-09-17 11:14:54 -07:00
},
MANAGED_ROLE : ( data : Message | Interaction , role : Role ) => {
2022-03-03 20:56:49 +07:00
return makeErrorEmbed ({
2021-09-17 11:14:54 -07:00
title : 'You cannot use this role' ,
2022-06-06 14:59:53 +07:00
description :
'``' + role . name + '``' + ' is managed by external service and cannot be used' ,
user : data instanceof Interaction ? data.user : data.author
2021-09-17 11:14:54 -07:00
});
},
CONFIGURED_ROLE : ( data : Message | Interaction , role : Role ) => {
2022-03-03 20:56:49 +07:00
return makeSuccessEmbed ({
2021-09-17 11:14:54 -07:00
title : 'Configured Membership Screening Role' ,
2022-06-06 14:59:53 +07:00
description :
'New member will be given a ' + '``' + role . name + '``' + ' role after approval' ,
user : data instanceof Interaction ? data.user : data.author
2021-09-17 11:14:54 -07:00
});
},
CONFIGURED_CHANNEL : ( data : Message | Interaction , channel : GuildChannel ) => {
2022-03-03 20:56:49 +07:00
return makeSuccessEmbed ({
2022-01-27 14:29:50 +07:00
title : 'Configured Membership Screening Channel' ,
2022-06-06 14:59:53 +07:00
description :
'Anyone with ``VIEW_CHANNEL`` permission in ' +
'``' +
channel . name +
'``' +
' can approve or deny request' ,
user : data instanceof Interaction ? data.user : data.author
2021-09-17 11:14:54 -07:00
});
},
INVALID_CHANNEL : ( data : Message | Interaction , channel : GuildChannel ) => {
2022-03-03 20:56:49 +07:00
return makeErrorEmbed ({
2021-09-17 11:14:54 -07:00
title : 'Invalid channel type, only TextChannel is supported' ,
2022-03-03 20:56:49 +07:00
description : '``' + channel . name + '``' + ' is not a text channel' ,
2022-06-06 14:59:53 +07:00
user : data instanceof Interaction ? data.user : data.author
2021-09-17 11:14:54 -07:00
});
},
2022-06-06 14:59:53 +07:00
INVALID_CHANNEL_THREAD : (
data : Message | Interaction ,
channel : GuildChannel | ThreadChannel
) => {
2022-03-03 20:56:49 +07:00
return makeErrorEmbed ({
2021-09-17 11:14:54 -07:00
title : 'Thread channel is not supported' ,
2022-06-06 14:59:53 +07:00
description :
'``' +
channel . name +
'``' +
' is a thread channel. Please use a regular text channel' ,
user : data instanceof Interaction ? data.user : data.author
2021-09-17 11:14:54 -07:00
});
},
BOT_NO_PERMISSION : ( data : Message | Interaction , channel : GuildChannel ) => {
2022-03-03 20:56:49 +07:00
return makeErrorEmbed ({
2021-09-17 11:14:54 -07:00
title : `I don't have permission` ,
2022-03-03 20:56:49 +07:00
description : 'I cannot access/send message in ' + '``' + channel . name + '``' ,
2022-06-06 14:59:53 +07:00
user : data instanceof Interaction ? data.user : data.author
2021-09-17 11:14:54 -07:00
});
},
NO_LONGER_VALID_ROLE : ( data : Message | Interaction ) => {
2022-03-03 20:56:49 +07:00
return makeErrorEmbed ({
2021-09-17 11:14:54 -07:00
title : 'The configured role is no longer valid. Please update the role in configuration' ,
2022-06-06 14:59:53 +07:00
user : data instanceof Interaction ? data.user : data.author
});
2021-09-17 11:14:54 -07:00
},
CANNOT_PERFORM_ASSIGN_ROLE : ( data : Message | Interaction ) => {
2022-03-03 20:56:49 +07:00
return makeErrorEmbed ({
2021-09-17 11:14:54 -07:00
title : 'Cannot grant the role to user, make sure I have permission to do that' ,
2022-06-06 14:59:53 +07:00
user : data instanceof Interaction ? data.user : data.author
2021-09-17 11:14:54 -07:00
});
},
CANNOT_PERFORM_ASSIGN_KICK : ( data : Message | Interaction ) => {
2022-03-03 20:56:49 +07:00
return makeErrorEmbed ({
2021-09-17 11:14:54 -07:00
title : 'Cannot kick the user, make sure I have permission to do that' ,
2022-06-06 14:59:53 +07:00
user : data instanceof Interaction ? data.user : data.author
});
2021-09-17 11:14:54 -07:00
},
CANNOT_PERFORM_ASSIGN_BAN : ( data : Message | Interaction ) => {
2022-03-03 20:56:49 +07:00
return makeErrorEmbed ({
2021-09-17 11:14:54 -07:00
title : 'Cannot ban the user, make sure I have permission to do that' ,
2022-06-06 14:59:53 +07:00
user : data instanceof Interaction ? data.user : data.author
});
2021-09-17 11:14:54 -07:00
},
CREATE_MESSAGE : () => {
2022-03-03 20:56:49 +07:00
return makeInfoEmbed ({
2021-09-17 11:14:54 -07:00
icon : '👋' ,
title : 'Welcome to this server!' ,
description : `This server have membership screening enabled, **you'll have access to the server when the moderators let you in**. \ n \ nAlso please make sure that you acknowledged the common rules that everyone should be doing no matter where, Discord ToS (https://discordapp.com/terms)` ,
user : DiscordProvider.client.user
2022-06-06 14:59:53 +07:00
});
2021-09-17 11:14:54 -07:00
}
2022-06-06 14:59:53 +07:00
};
2021-09-15 04:11:28 -07:00
2022-03-03 20:56:49 +07:00
export default class MembershipScreening extends DiscordModule {
2022-06-06 14:59:53 +07:00
public id = 'Discord_MembershipScreening' ;
public commands = [ 'membershipscreening' , 'ms' ];
public commandInteractionName = 'membershipscreening' ;
2022-03-03 20:56:49 +07:00
async GuildOnModuleCommand ( args : any , message : Message ) {
await this . run ( new HybridInteractionMessage ( message ), args );
2021-09-17 11:14:54 -07:00
}
2021-09-15 04:11:28 -07:00
2022-03-03 20:56:49 +07:00
async GuildModuleCommandInteractionCreate ( interaction : CommandInteraction ) {
await this . run ( new HybridInteractionMessage ( interaction ), interaction . options );
}
2021-09-15 04:11:28 -07:00
2022-03-03 20:56:49 +07:00
async GuildButtonInteractionCreate ( interaction : ButtonInteraction ) {
const hybridData = new HybridInteractionMessage ( interaction );
const guild = hybridData . getGuild ();
const user = hybridData . getUser ();
const channel = hybridData . getChannel ();
2022-06-06 14:59:53 +07:00
if ( ! guild || ! user || ! channel ) return ;
2022-03-03 20:56:49 +07:00
if ( ! this . isJsonValid ( interaction . customId )) return ;
const payload = JSON . parse ( interaction . customId );
2022-06-06 14:59:53 +07:00
if (
typeof payload . m === 'undefined' ||
2022-03-03 20:56:49 +07:00
typeof payload . a === 'undefined' ||
2022-06-06 14:59:53 +07:00
payload . m !== 'MembershipScreening'
)
return ;
2022-03-03 20:56:49 +07:00
const message = await channel . messages . fetch ( interaction . message . id );
if ( ! message ) return ;
const embed = message . embeds ;
if ( ! embed || embed . length === 0 ) return ;
const PrismaGuild = await Prisma . client . guild . findFirst ({ where : { id : guild.id } });
if ( ! PrismaGuild ) return ;
2022-06-06 14:59:53 +07:00
if (
! PrismaGuild . MembershipScreening_Enabled ||
2022-03-03 20:56:49 +07:00
PrismaGuild . MembershipScreening_ApprovalChannel === null ||
2022-06-06 14:59:53 +07:00
PrismaGuild . MembershipScreening_GivenRole === null
)
return ;
2022-03-03 20:56:49 +07:00
embed [ 0 ]. footer = {
text : ` ${ interaction . user . username } | v ${ App . version } ` ,
2022-06-06 13:00:38 +07:00
iconURL : ` ${ interaction . user . displayAvatarURL () } ?size=4096`
2022-06-06 14:59:53 +07:00
};
2022-03-03 20:56:49 +07:00
if ([ 'approve' , 'deny' , 'ban' ]. includes ( payload . a )) {
if ( ! payload . d . requester ) return ;
2022-06-06 14:59:53 +07:00
const role = ( await guild . roles . fetch ()). find (
( role ) => role . id === PrismaGuild . MembershipScreening_GivenRole
);
const requesterMember = ( await guild . members . fetch ()). find (
( member ) => member . id === payload . d . requester
);
2022-03-03 20:56:49 +07:00
if ( ! role )
2022-06-06 14:59:53 +07:00
return await interaction . reply ({
ephemeral : true ,
embeds : [ EMBEDS . NO_LONGER_VALID_ROLE ( interaction )]
});
2022-03-03 20:56:49 +07:00
if ( ! requesterMember ) {
2022-06-06 14:59:53 +07:00
embed [ 0 ]. addField ( '❌ Invalid' , `Unable to find the user. User left already?` );
2022-03-03 20:56:49 +07:00
return await message . edit ({ components : [], embeds : embed });
}
if ( requesterMember . roles . cache . has ( PrismaGuild . MembershipScreening_GivenRole )) {
2022-06-06 14:59:53 +07:00
embed [ 0 ]. addField (
'✅ Approved' ,
`By: Unknown (User already obtained the role by other means)`
);
2022-03-03 20:56:49 +07:00
return await message . edit ({ components : [], embeds : embed });
}
if ( payload . a === 'approve' ) {
try {
await requesterMember . roles . add ( role );
2022-06-06 14:59:53 +07:00
embed [ 0 ]. addField (
'✅ Approved' ,
`By: ${ interaction . user . username } # ${ interaction . user . discriminator } ( ${ interaction . user . id } )`
);
2022-03-03 20:56:49 +07:00
await message . edit ({ components : [], embeds : embed });
2022-06-06 14:59:53 +07:00
} catch ( err ) {
return interaction . reply ({
ephemeral : true ,
embeds : [ EMBEDS . CANNOT_PERFORM_ASSIGN_ROLE ( message )]
});
2022-03-03 20:56:49 +07:00
}
2022-06-06 14:59:53 +07:00
} else if ( payload . a === 'deny' ) {
2022-03-03 20:56:49 +07:00
try {
await requesterMember . kick ();
2022-06-06 14:59:53 +07:00
embed [ 0 ]. addField (
'❌ Denied' ,
`By: ${ interaction . user . username } # ${ interaction . user . discriminator } ( ${ interaction . user . id } )`
);
2022-03-03 20:56:49 +07:00
await message . edit ({ components : [], embeds : embed });
2022-06-06 14:59:53 +07:00
} catch ( err ) {
return interaction . reply ({
ephemeral : true ,
embeds : [ EMBEDS . CANNOT_PERFORM_ASSIGN_KICK ( message )]
});
2022-03-03 20:56:49 +07:00
}
2022-06-06 14:59:53 +07:00
} else if ( payload . a === 'ban' ) {
2022-03-03 20:56:49 +07:00
try {
await requesterMember . ban ({
reason : `Membership Screening, action issued by ${ interaction . user . username } # ${ interaction . user . discriminator } ( ${ interaction . user . id } )`
});
2022-06-06 14:59:53 +07:00
embed [ 0 ]. addField (
'🔪 Banned' ,
`By: ${ interaction . user . username } # ${ interaction . user . discriminator } ( ${ interaction . user . id } )`
);
2022-03-03 20:56:49 +07:00
await message . edit ({ components : [], embeds : embed });
2022-06-06 14:59:53 +07:00
} catch ( err ) {
return interaction . reply ({
ephemeral : true ,
embeds : [ EMBEDS . CANNOT_PERFORM_ASSIGN_BAN ( message )]
});
2022-03-03 20:56:49 +07:00
}
}
}
}
async run ( data : HybridInteractionMessage , args : any ) {
const guild = data . getGuild ();
const user = data . getUser ();
const member = data . getMember ();
const channel = data . getChannel ();
if ( ! guild || ! user || ! member || ! channel ) return ;
2022-06-06 14:59:53 +07:00
const PrismaGuild = await Prisma . client . guild . findFirst ({ where : { id : guild.id } });
2022-03-03 20:56:49 +07:00
if ( ! PrismaGuild ) return ;
2022-01-27 14:29:50 +07:00
2021-09-17 11:14:54 -07:00
const funct = {
2022-03-03 20:56:49 +07:00
enable : async ( data : HybridInteractionMessage ) => {
if ( ! PrismaGuild . MembershipScreening_Enabled ) {
2022-06-06 14:59:53 +07:00
if (
PrismaGuild . MembershipScreening_GivenRole === null ||
PrismaGuild . MembershipScreening_ApprovalChannel == null
)
return await sendHybridInteractionMessageResponse ( data , {
embeds : [ EMBEDS . NO_PARAMETER ( data . getRaw ())]
});
2021-09-17 11:14:54 -07:00
2022-06-06 14:59:53 +07:00
await Prisma . client . guild . update ({
where : { id : guild.id },
data : { MembershipScreening_Enabled : true }
});
2022-03-03 20:56:49 +07:00
2022-06-06 14:59:53 +07:00
return await sendHybridInteractionMessageResponse ( data , {
embeds : [ EMBEDS . ENABLED ( data . getRaw ())]
});
} else
return await sendHybridInteractionMessageResponse ( data , {
embeds : [ EMBEDS . ALREADY_ENABLED ( data . getRaw ())]
});
2021-09-17 11:14:54 -07:00
},
2022-03-03 20:56:49 +07:00
disable : async ( data : HybridInteractionMessage ) => {
if ( PrismaGuild . MembershipScreening_Enabled ) {
await Prisma . client . guild . update ({
where : { id : guild.id },
data : { MembershipScreening_Enabled : false }
2021-09-15 04:11:28 -07:00
});
2022-03-03 20:56:49 +07:00
2022-06-06 14:59:53 +07:00
return await sendHybridInteractionMessageResponse ( data , {
embeds : [ EMBEDS . DISABLED ( data . getRaw ())]
});
} else
return await sendHybridInteractionMessageResponse ( data , {
embeds : [ EMBEDS . ALREADY_DISABLED ( data . getRaw ())]
});
2021-09-17 11:14:54 -07:00
},
2022-03-03 20:56:49 +07:00
setRole : async ( data : HybridInteractionMessage ) => {
2021-09-17 11:14:54 -07:00
let role : Role | undefined ;
2021-09-15 04:11:28 -07:00
2022-03-03 20:56:49 +07:00
if ( data . isMessage ()) {
2021-09-17 11:14:54 -07:00
let _name : string ;
2022-03-03 20:56:49 +07:00
if ( typeof args [ 1 ] === 'undefined' )
2022-06-06 14:59:53 +07:00
return await sendHybridInteractionMessageResponse ( data , {
embeds : [ EMBEDS . NO_ROLE_MENTIONED ( data . getRaw ())]
});
2021-09-15 04:11:28 -07:00
2021-09-17 11:14:54 -07:00
let __name = args ;
__name . shift ();
2022-06-06 14:59:53 +07:00
_name = __name . join ( ' ' );
2022-03-03 20:56:49 +07:00
2022-06-06 14:59:53 +07:00
role =
data . getMessage (). mentions . roles . first () ||
guild . roles . cache . find (( role ) => role . name === _name );
} else if ( data . isSlashCommand ())
role = guild . roles . cache . find (
( role ) => role . id === data . getSlashCommand (). options . getRole ( 'role' ) ? . id
);
2021-09-15 04:11:28 -07:00
2022-03-03 20:56:49 +07:00
if ( ! role )
2022-06-06 14:59:53 +07:00
return await sendHybridInteractionMessageResponse ( data , {
embeds : [ EMBEDS . NO_ROLE_FOUND ( data . getRaw ())]
});
2021-09-17 11:14:54 -07:00
2022-03-03 20:56:49 +07:00
if ( role . managed )
2022-06-06 14:59:53 +07:00
return await sendHybridInteractionMessageResponse ( data , {
embeds : [ EMBEDS . MANAGED_ROLE ( data . getRaw (), role )]
});
2021-09-15 04:11:28 -07:00
2022-06-06 14:59:53 +07:00
await Prisma . client . guild . update ({
where : { id : guild.id },
data : { MembershipScreening_GivenRole : role.id }
});
2021-09-15 04:11:28 -07:00
2022-06-06 14:59:53 +07:00
return await sendHybridInteractionMessageResponse ( data , {
embeds : [ EMBEDS . CONFIGURED_ROLE ( data . getRaw (), role )]
});
2021-09-17 11:14:54 -07:00
},
2022-03-03 20:56:49 +07:00
setChannel : async ( data : HybridInteractionMessage ) => {
let mentionChannel ;
if ( data . isMessage ()) {
if ( ! args [ 1 ])
2022-06-06 14:59:53 +07:00
return await sendHybridInteractionMessageResponse ( data , {
embeds : [ EMBEDS . NO_CHANNEL_MENTIONED ( data . getRaw ())]
});
2022-03-03 20:56:49 +07:00
mentionChannel = data . getMessage (). mentions . channels . first ();
2022-06-06 14:59:53 +07:00
} else if ( data . isSlashCommand ())
2022-03-03 20:56:49 +07:00
mentionChannel = data . getSlashCommand (). options . getChannel ( 'channel' );
2021-09-15 04:11:28 -07:00
2022-03-03 20:56:49 +07:00
if ( ! mentionChannel )
2022-06-06 14:59:53 +07:00
return await sendHybridInteractionMessageResponse ( data , {
embeds : [ EMBEDS . NO_CHANNEL_FOUND ( data . getRaw ())]
});
2021-09-15 04:11:28 -07:00
2022-03-03 20:56:49 +07:00
let TargetChannel = guild . channels . cache . get ( mentionChannel . id );
if ( ! TargetChannel ) return ;
2021-09-15 04:11:28 -07:00
2022-03-03 20:56:49 +07:00
if ( TargetChannel instanceof ThreadChannel || TargetChannel . isThread ())
2022-06-06 14:59:53 +07:00
return await sendHybridInteractionMessageResponse ( data , {
embeds : [ EMBEDS . INVALID_CHANNEL_THREAD ( data . getRaw (), TargetChannel )]
});
2021-09-15 04:11:28 -07:00
2022-03-03 20:56:49 +07:00
if ( ! TargetChannel . isText ())
2022-06-06 14:59:53 +07:00
return await sendHybridInteractionMessageResponse ( data , {
embeds : [ EMBEDS . INVALID_CHANNEL ( data . getRaw (), TargetChannel )]
});
2021-09-15 04:11:28 -07:00
2022-06-06 14:59:53 +07:00
if (
! guild
. me ! . permissionsIn ( TargetChannel )
. has ([ Permissions . FLAGS . SEND_MESSAGES , Permissions . FLAGS . VIEW_CHANNEL ])
)
return await sendHybridInteractionMessageResponse ( data , {
embeds : [ EMBEDS . BOT_NO_PERMISSION ( data . getRaw (), TargetChannel )]
});
2022-03-03 20:56:49 +07:00
2022-06-06 14:59:53 +07:00
await Prisma . client . guild . update ({
where : { id : guild.id },
data : { MembershipScreening_ApprovalChannel : mentionChannel.id }
});
return await sendHybridInteractionMessageResponse ( data , {
embeds : [ EMBEDS . CONFIGURED_CHANNEL ( data . getRaw (), TargetChannel )]
});
2021-09-17 11:14:54 -07:00
},
2022-03-03 20:56:49 +07:00
createMessage : async ( data : HybridInteractionMessage ) => {
2022-06-06 14:59:53 +07:00
if ( data . isMessage ())
return await sendMessage ( channel , undefined , {
embeds : [ EMBEDS . CREATE_MESSAGE ()]
});
else if ( data . isSlashCommand ()) {
await sendHybridInteractionMessageResponse ( data , {
embeds : [ EMBEDS . MESSAGE_CREATED ( data . getRaw ())]
});
return await sendMessage ( channel , undefined , {
embeds : [ EMBEDS . CREATE_MESSAGE ()]
});
2022-03-03 20:56:49 +07:00
}
2021-09-15 04:11:28 -07:00
}
2022-06-06 14:59:53 +07:00
};
2021-09-17 11:14:54 -07:00
let query ;
2022-03-03 20:56:49 +07:00
if ( ! member . permissions . has ([ Permissions . FLAGS . ADMINISTRATOR ]))
2022-06-06 14:59:53 +07:00
return await sendHybridInteractionMessageResponse ( data , {
embeds : [ EMBEDS . NO_PERMISSION ( data . getRaw ())]
});
2021-09-17 11:14:54 -07:00
2022-03-03 20:56:49 +07:00
if ( data . isMessage ()) {
if ( args . length === 0 )
2022-06-06 14:59:53 +07:00
return await sendHybridInteractionMessageResponse ( data , {
embeds : [ EMBEDS . MSINFO ( data . getRaw ())]
});
2021-09-17 11:14:54 -07:00
query = args [ 0 ]. toLowerCase ();
2022-06-06 14:59:53 +07:00
} else if ( data . isSlashCommand ()) query = args . getSubcommand ();
2021-09-17 11:14:54 -07:00
2022-03-03 20:56:49 +07:00
switch ( query ) {
2022-06-06 14:59:53 +07:00
case 'enable' :
case 'on' :
2021-09-17 11:14:54 -07:00
return await funct . enable ( data );
2022-06-06 14:59:53 +07:00
case 'disable' :
case 'off' :
2021-09-17 11:14:54 -07:00
return await funct . disable ( data );
2022-06-06 14:59:53 +07:00
case 'setrole' :
2021-09-17 11:14:54 -07:00
return await funct . setRole ( data );
2022-06-06 14:59:53 +07:00
case 'setchannel' :
2022-03-03 20:56:49 +07:00
return await funct . setChannel ( data );
2022-06-06 14:59:53 +07:00
case 'createmessage' :
2022-03-03 20:56:49 +07:00
return await funct . createMessage ( data );
2021-09-15 04:11:28 -07:00
}
}
2022-03-03 20:56:49 +07:00
async GuildMemberAdd ( member : GuildMember ) {
if ( member . user . bot ) return ;
2021-09-15 04:11:28 -07:00
const Guild = await Prisma . client . guild . findFirst ({ where : { id : member.guild.id } });
2022-03-03 20:56:49 +07:00
if ( ! Guild ) return ;
2021-09-15 04:11:28 -07:00
2022-03-03 20:56:49 +07:00
if ( ! Guild . MembershipScreening_Enabled ) return ;
if ( Guild . MembershipScreening_ApprovalChannel === null ) return ;
if ( Guild . MembershipScreening_GivenRole === null ) return ;
2021-09-15 04:11:28 -07:00
2022-01-27 18:01:04 +07:00
let channel = undefined ;
try {
2022-06-06 14:59:53 +07:00
channel = ( await DiscordProvider . client . channels . fetch (
Guild . MembershipScreening_ApprovalChannel
)) as TextChannel ;
2022-01-27 18:01:04 +07:00
} catch ( err ) {
// TODO: Handle channel not found error
return ;
}
2022-03-03 20:56:49 +07:00
if ( ! channel ) return ;
2021-09-15 04:11:28 -07:00
2022-03-03 20:56:49 +07:00
const embed = makeInfoEmbed ({
2021-09-15 04:11:28 -07:00
title : 'New member joined!' ,
description : ` ${ member . user . username } # ${ member . user . discriminator } ( ${ member . user . id } )` ,
fields : [
{
2022-06-06 14:59:53 +07:00
name : 'Account Information' ,
value : `Account age: <t: ${ Math . round (
member . user . createdAt . getTime () / 1000
) } :R>`
2021-09-15 04:11:28 -07:00
}
]
});
2022-06-06 13:00:38 +07:00
embed . setThumbnail ( ` ${ member . user . displayAvatarURL () } ?size=4096` );
2022-03-03 20:56:49 +07:00
2021-09-15 04:11:28 -07:00
const row = new MessageActionRow ()
. addComponents (
new MessageButton ()
2022-06-06 14:59:53 +07:00
. setCustomId (
JSON . stringify ({
m : 'MembershipScreening' ,
a : 'approve' ,
d : {
requester : member.id
}
})
)
2021-09-15 04:11:28 -07:00
. setEmoji ( '✅' )
. setLabel ( ' Approve' )
2022-06-06 14:59:53 +07:00
. setStyle ( 'SUCCESS' )
2021-09-15 04:11:28 -07:00
)
. addComponents (
new MessageButton ()
2022-06-06 14:59:53 +07:00
. setCustomId (
JSON . stringify ({
m : 'MembershipScreening' ,
a : 'deny' ,
d : {
requester : member.id
}
})
)
2021-09-17 11:14:54 -07:00
. setEmoji ( '⛔' )
. setLabel ( ' Deny and kick' )
2022-06-06 14:59:53 +07:00
. setStyle ( 'DANGER' )
2021-09-15 04:11:28 -07:00
)
. addComponents (
new MessageButton ()
2022-06-06 14:59:53 +07:00
. setCustomId (
JSON . stringify ({
m : 'MembershipScreening' ,
a : 'ban' ,
d : {
requester : member.id
}
})
)
2021-09-15 04:11:28 -07:00
. setEmoji ( '🔪' )
2021-09-17 11:14:54 -07:00
. setLabel ( ' Vision Hunt Decree (Ban)' )
2022-06-06 14:59:53 +07:00
. setStyle ( 'DANGER' )
);
2021-09-15 04:11:28 -07:00
await channel . send ({ content : '\u200b' , embeds : [ embed ], components : [ row ] });
}
2021-09-17 11:14:54 -07:00
2022-03-03 20:56:49 +07:00
private isJsonValid ( jsonString : string ) {
2021-09-15 04:11:28 -07:00
try {
let o = JSON . parse ( jsonString );
2022-06-06 14:59:53 +07:00
if ( o && typeof o === 'object' ) {
2021-09-15 04:11:28 -07:00
return true ;
//return o;
}
2022-06-06 14:59:53 +07:00
} catch ( e ) {}
2022-03-03 20:56:49 +07:00
2021-09-15 04:11:28 -07:00
return false ;
2021-09-17 11:14:54 -07:00
}
2022-06-06 14:59:53 +07:00
}