@@ -11,16 +11,32 @@ import Manager from "../../api/manager";
1111export default class VerificationManager extends Manager {
1212 private readonly verificationChannelID : string ;
1313 private readonly memberRoleID : string ;
14+ private verified : Map < string , string > ;
1415
1516 constructor ( bot : Bot ) {
1617 super ( bot ) ;
1718 this . verificationChannelID = bot . settings . channels . verification ;
1819 this . memberRoleID = bot . settings . roles . member ;
20+ this . verified = new Map ( ) ;
1921
2022 this . bot = bot ;
2123 }
2224
2325 public async init ( ) {
26+ // Fetch verified list from firestore
27+ const document = await this . bot . managers . firestore . firestore
28+ ?. collection ( "discord" )
29+ . doc ( "snowflake_to_name" )
30+ . get ( ) ;
31+
32+ if ( document ?. exists ) {
33+ this . verified = new Map ( Object . entries ( document . data ( ) ! ) ) ;
34+ } else {
35+ this . bot . logger . error (
36+ "Unable to fetch snowflake to name mapping for verification. Verified users will be able to re-verify."
37+ ) ;
38+ }
39+
2440 // Ensure the verification channel's last message has a verification button to the bot
2541 const guild = await this . bot . guilds . fetch ( this . bot . settings . guild ) ;
2642 const verificationChannel = await guild . channels . fetch (
@@ -56,7 +72,24 @@ export default class VerificationManager extends Manager {
5672 }
5773 }
5874
75+ public async handleMemberJoin ( member : GuildMember ) {
76+ // Set nickname and return verified role
77+ if ( this . verified . has ( member . id ) ) {
78+ await member . setNickname ( this . verified . get ( member . id ) ! ) ;
79+ await member . roles . add ( this . memberRoleID ) ;
80+ }
81+ }
82+
5983 public async handleVerificationRequest ( interaction : ButtonInteraction ) {
84+ // Do not allow verified users to reverify
85+ if ( this . verified . has ( interaction . user . id ) ) {
86+ await interaction . reply ( {
87+ content : "You've already been verified!" ,
88+ ephemeral : true ,
89+ } ) ;
90+ return ;
91+ }
92+
6093 // Prompt for real name using modal
6194 const nameInput = new TextInputComponent ( {
6295 customId : "name" ,
@@ -94,6 +127,10 @@ export default class VerificationManager extends Manager {
94127 ?. collection ( "discord" )
95128 . doc ( "snowflake_to_name" )
96129 . set ( map , { merge : true } ) ;
130+
131+ // Add to local verified list
132+ this . verified . set ( member . id , name ) ;
133+
97134
98135 // Reply
99136 await interaction . reply ( {
0 commit comments