import { Role } from "discord.js" ; import { DisharmonyGuild , DisharmonyGuildMember } from "disharmony" ; export default class Guild extends DisharmonyGuild { private _users : Map < string , Date > ; public get inactiveThresholdDays ( ) : number { return this . record . inactiveThresholdDays || 7 ; } public set inactiveThresholdDays ( value ) { this . record . inactiveThresholdDays = value ; } public get activeRoleId ( ) : string { return this . record . activeRoleId || "" ; } public set activeRoleId ( value ) { this . record . activeRoleId = value ; } public get activeRole ( ) { return this . djs . roles . get ( this . activeRoleId ) ; } public get inactiveRole ( ) { return this . djs . roles . get ( this . inactiveRoleId ) ; } public get inactiveRoleId ( ) : string { return this . record . inactiveRoleId || "" ; } public set inactiveRoleId ( value ) { this . record . inactiveRoleId = value ; } public get allowRoleAddition ( ) : boolean { return this . record . allowRoleAddition ; } public set allowRoleAddition ( value ) { this . record . allowRoleAddition = value ; } public get users ( ) : Map < string , Date > { if ( ! this . _users ) this . _users = new Map ( this . record . users || [ ] ) ; return this . _users ; } public ignoredUserIds : string [ ] ; public ignoredRoleIds : string [ ] ; public getConfigJson ( ) { const blacklist = [ "id" , "_id" , "users" ] ; return JSON . stringify ( this . toRecord ( ) , ( k , v ) => blacklist . indexOf ( k ) < 0 ? v : undefined , "\t" ) ; } public isMemberIgnored ( member ) { const isIgnoredIndividually = this . ignoredUserIds . indexOf ( member . id ) >= 0 ; const hasIgnoredRole = this . ignoredRoleIds . some ( roleId => member . djs . roles . has ( roleId ) ) ; return isIgnoredIndividually || hasIgnoredRole ; } public canBotManageRole ( targetRole ) { return ! ! this . me . djs . roles . find ( role => role . position > targetRole . position && role . hasPermission ( "MANAGE_ROLES" ) ) ; } /** True if the supplied snowflake is configured */ public isRoleConfigured ( snowflake ) { return ( snowflake && snowflake !== "disabled" && snowflake . length > 0 && this . djs . roles . has ( snowflake ) ) ; } /** True if the supplied snowflake is configured, but badly */ public isRoleBadlyConfigured ( snowflake ) { return this . isRoleConfigured ( snowflake ) && ! this . canBotManageRole ( this . djs . roles . get ( snowflake ) ! ) ; } /** True if the supplied snowflake is configured, and not configured badly */ public isRoleWellConfigured ( snowflake ) { return this . isRoleConfigured ( snowflake ) && ! this . isRoleBadlyConfigured ( snowflake ) ; } public loadRecord ( record ) { this . ignoredUserIds = record . ignoredUserIds || [ ] ; this . ignoredRoleIds = record . ignoredRoleIds || [ ] ; return super . loadRecord ( record ) ; } public toRecord ( ) { this . record . ignoredUserIds = this . ignoredUserIds ; this . record . ignoredRoleIds = this . ignoredRoleIds ; if ( this . _users ) this . record . users = [ ... this . _users . entries ( ) ] ; return super . toRecord ( ) ; } }