import { ClientUser , Constants , DQConstants , Guild , PresenceStatus , Snowflake , Util , } from 'discord.js' ; import { CustomStatus } from '../utilities/CustomStatus' ; type FriendsSources = { all : boolean ; mutualGuilds : boolean ; mutualFriends : boolean ; } ; /**
 * A wrapper around the ClientUser's settings.
 */ export class ClientUserSettings { public convertEmoticons : boolean = false ; public customStatus ? : CustomStatus ; public defaultGuildsRestricted : boolean = false ; public detectPlatformAccounts : boolean = false ; public developerMode : boolean = false ; public enableTTSCommand : boolean = false ; public explicitContentFilter : 'DISABLED' | 'NON_FRIENDS' | 'FRIENDS_AND_NON_FRIENDS' | string = 'DISABLED' ; public friendsSources : FriendsSources = { all : false , mutualFriends : false , mutualGuilds : false } ; public guildFolders : Snowflake [ ] = [ ] ; public guildPositions : Snowflake [ ] = [ ] ; public inlineAttachmentMedia : boolean = false ; public inlineEmbedMedia : boolean = false ; public locale : string = '' ; public messageDisplayCompact : boolean = false ; public renderReactions : boolean = false ; public restrictedGuilds : Snowflake [ ] = [ ] ; public showCurrentGame : boolean = false ; public status : PresenceStatus = 'offline' ; public theme : string = 'dark' ; private user : ClientUser ; constructor ( user , data ) { this . user = user ; this . _patch ( data ) ; } param { Object } data returns { void } private _patch ( data ) { for ( const [ key , value ] of Object . entries ( ( Constants as DQConstants ) . UserSettingsMap ) ) { if ( key in data && typeof value === 'function' ) { this [ value . name ] = value ( data [ key ] ) ; } else { this [ value ] = data [ key ] ; } } } param { string } name param { * } value returns { Promise < Object > } update ( name , value ) { return this . user . client . api . users ( '@me' ) . settings . patch ( { data : { [ name ] : value } } ) ; } param { Guild } guild param { number } position param { boolean } relative returns { Promise < Guild > } setGuildPosition ( guild , position , relative ) { const temp = Object . assign ( [ ] , this . guildPositions ) ; Util . moveElementInArray ( temp , guild . id , position , relative ) ; return this . update ( 'guild_positions' , temp ) . then ( ( ) => guild ) ; } param { Guild } guild returns { Promise < Guild > } addRestrictedGuild ( guild ) { const temp = Object . assign ( [ ] , this . restrictedGuilds ) ; if ( temp . includes ( guild . id ) ) { return Promise . reject ( new Error ( 'Guild is already restricted' ) ) ; } temp . push ( guild . id ) ; return this . update ( 'restricted_guilds' , temp ) . then ( ( ) => guild ) ; } param { Guild } guild returns { Promise < Guild > } removeRestrictedGuild ( guild ) { const temp = Object . assign ( [ ] , this . restrictedGuilds ) ; const index = temp . indexOf ( guild . id ) ; if ( index < 0 ) { return Promise . reject ( new Error ( 'Guild is not restricted' ) ) ; } temp . splice ( index , 1 ) ; return this . update ( 'restricted_guilds' , temp ) . then ( ( ) => guild ) ; } }