11const Discord = require ( "discord.js" ) ;
2- const { searchOneDB , getFactorioRoles } = require ( "../../functions" ) ;
2+ const { getFactorioRoles } = require ( "../../functions" ) ;
33const { LinkingCache } = require ( "../../functions" ) ;
44const { ErrorManager } = require ( "../../utils/error-manager" ) ;
55const lodash = require ( "lodash" ) ;
6- let { linkConfirmation } = require ( "../../config/messages.json" )
6+ let { linkConfirmation } = require ( "../../config/messages.json" ) ;
7+ const { DatabaseConnection } = require ( "../../utils/database-manager" ) ;
78
89module . exports = {
910 config : {
@@ -28,31 +29,35 @@ module.exports = {
2829 return message . channel . send ( "Give a Factorio name/Discord ping!" )
2930 let user ;
3031 if ( message . mentions . users . first ( ) ) {
31- let res = await searchOneDB ( "otherData" , "linkedPlayers" , {
32+ let res = await DatabaseConnection . findOneDB ( "otherData" , "linkedPlayers" , {
3233 discordID : ( message . mentions . users . first ( ) ) . id ,
3334 } )
34- if ( res == undefined )
35- return message . channel . send ( "User not linked!" ) ;
35+ if ( res === undefined || res === null ) return message . channel . send ( "User not linked, therefore has no roles!" ) ;
3636 user = res . factorioName ;
3737 } else {
38- user = args [ 0 ] ;
38+ let res = await DatabaseConnection . findOneDB ( "otherData" , "linkedPlayers" , {
39+ factorioName : args [ 0 ] ,
40+ } )
41+ if ( res === undefined || res === null ) return message . channel . send ( "User not linked, therefore has no roles!" ) ;
42+ user = res . factorioName ;
3943 }
4044
4145 let rolesEmbed = new Discord . MessageEmbed ( )
42- . setTitle ( "Roles of a Factorio player" )
43- . setDescription ( "Roles of a Factorio player" )
44- . setColor ( "GREEN" )
45- . setAuthor (
46- `${ message . guild . me . displayName } Help` ,
47- message . guild . iconURL
48- )
49- . setThumbnail ( client . user . displayAvatarURL ( ) )
50- . setFooter (
51- `© ${ message . guild . me . displayName } | Developed by DistroByte & oof2win2 | Total Commands: ${ client . commands . size } ` ,
52- client . user . displayAvatarURL ( )
53- ) ;
54- const roles = ( await getFactorioRoles ( user ) ) . roles ;
55- rolesEmbed . addField ( "\u200B" , roles . join ( ", " ) ) ;
46+ . setTitle ( "Roles of a Factorio player" )
47+ . setDescription ( "Roles of a Factorio player" )
48+ . setColor ( "GREEN" )
49+ . setAuthor (
50+ `${ message . guild . me . displayName } Help` ,
51+ message . guild . iconURL
52+ )
53+ . setThumbnail ( client . user . displayAvatarURL ( ) )
54+ . setFooter (
55+ `© ${ message . guild . me . displayName } | Developed by DistroByte & oof2win2 | Total Commands: ${ client . commands . size } ` ,
56+ client . user . displayAvatarURL ( )
57+ ) ;
58+ const roles = ( await getFactorioRoles ( user ) ) ;
59+ if ( roles === null || roles === undefined ) return message . channel . send ( 'No roles!' ) ;
60+ rolesEmbed . addField ( "\u200B" , roles . roles . join ( ", " ) ) ;
5661 return message . channel . send ( rolesEmbed ) ;
5762 } ,
5863} ;
0 commit comments