@@ -15,11 +15,12 @@ import { badArgument, generateToken, todoControllers } from '../../utils/tools.j
1515import { getVerificationGuildMessage } from '../../discord/utils/messages.js' ;
1616import moment from 'moment' ;
1717import { getUserDataGRPD } from '../../models/v3/gdrp.js' ;
18- import { getMainClient } from '../../discord/index.js' ;
18+ import { getGuildClient , getMainClient } from '../../discord/index.js' ;
1919import redis from '../../services/redis/index.js' ;
2020import prisma from '../../services/prisma/index.js' ;
2121import { NextFunction , Request , Response } from 'express' ;
2222import { getLogsByServer , getTotalLogsByServer } from '../../database/gm_server_logs.js' ;
23+ import { Guild } from '../../classes/v3/Guild.js' ;
2324
2425export async function getProfile ( req : Request , res : Response ) {
2526 const { steamID64, discordID } = req . query ;
@@ -137,6 +138,9 @@ export async function oauthLogin(req: Request, res: Response) {
137138 } ) ;
138139 }
139140
141+ const guildIDMatch = typeof req . query . state === 'string' ? req . query . state . match ( / g u i l d I D = ( [ 0 - 9 ] + ) / ) : null ;
142+ const guildID = guildIDMatch ? guildIDMatch [ 1 ] : null ;
143+
140144 discordUserToken . expirationDate = new Date ( Date . now ( ) + discordUserToken . expires_in * 1000 ) ;
141145 discordUserToken . creationDate = new Date ( ) ;
142146
@@ -147,14 +151,30 @@ export async function oauthLogin(req: Request, res: Response) {
147151 } ) ;
148152 }
149153
150- // I remove the auto join guild feature if uncomment also update perm here: getUserTokenFromCode
151- await addUserToGuild ( ConfigDiscord . guildID , discordUser . id , discordUserToken . access_token )
152- . then ( ( ) => {
153- console . log ( 'User added to guild' ) ;
154- } )
155- . catch ( ( error ) => {
156- console . error ( error ) ;
157- } ) ;
154+ let skipGuidJoin = false ;
155+
156+ if ( guildID ) {
157+ const dscClient = await getGuildClient ( guildID ) ;
158+ if ( ! dscClient ) return ;
159+
160+ const dscGuild = dscClient . guilds . cache . get ( guildID ) ;
161+ if ( ! dscGuild ) return ;
162+
163+ const guild = new Guild ( dscGuild ) ;
164+ if ( ! guild ) return ;
165+
166+ skipGuidJoin = await guild . getSetting ( 'verification_dont_join_support' ) ;
167+ }
168+
169+ if ( ! skipGuidJoin ) {
170+ await addUserToGuild ( ConfigDiscord . guildID , discordUser . id , discordUserToken . access_token )
171+ . then ( ( ) => {
172+ console . log ( 'User added to guild' ) ;
173+ } )
174+ . catch ( ( error ) => {
175+ console . error ( error ) ;
176+ } ) ;
177+ }
158178
159179 const userIP = req . headers [ 'x-forwarded-for' ] || req . connection . remoteAddress ;
160180 const userCountry = req . headers [ 'cf-ipcountry' ] || 'XX' ;
@@ -905,7 +925,7 @@ export async function createVerificationMessage(req: Request, res: Response) {
905925 }
906926
907927 // send msg
908- const msg = await getVerificationGuildMessage ( dscGuild . preferredLocale ) ;
928+ const msg = await getVerificationGuildMessage ( dscGuild . preferredLocale , dscGuild . id ) ;
909929 const sentMsg = await channel . send ( msg ) ;
910930
911931 // save msg
0 commit comments