@@ -3,10 +3,12 @@ import {
33 GuildMember ,
44 Role ,
55 ColorResolvable ,
6- PermissionFlagsBits ,
76} from "discord.js" ;
87import { Config } from "../libs/loadVariables.js" ;
9- import { setCustomRole , getBooster , BoosterRecord } from "./boosterService.js" ;
8+ import {
9+ setCustomRole ,
10+ getCustomRole ,
11+ } from "./boosterService.js" ;
1012
1113export interface BoostLevelRole {
1214 minBoosts : number ;
@@ -24,10 +26,8 @@ export async function assignBoosterRole(
2426 config : Config
2527) : Promise < void > {
2628 if ( member . roles . cache . has ( config . boosterRoleId ) ) return ;
27-
2829 const role = member . guild . roles . cache . get ( config . boosterRoleId ) ;
2930 if ( ! role ) return ;
30-
3131 await member . roles . add ( role ) ;
3232}
3333
@@ -36,10 +36,8 @@ export async function removeBoosterRole(
3636 config : Config
3737) : Promise < void > {
3838 if ( ! member . roles . cache . has ( config . boosterRoleId ) ) return ;
39-
4039 const role = member . guild . roles . cache . get ( config . boosterRoleId ) ;
4140 if ( ! role ) return ;
42-
4341 await member . roles . remove ( role ) ;
4442}
4543
@@ -49,13 +47,13 @@ export async function assignLevelRoles(
4947) : Promise < void > {
5048 if ( BOOST_LEVEL_ROLES . length === 0 ) return ;
5149
52- const eligibleRoleIds = BOOST_LEVEL_ROLES . filter (
53- ( lr ) => boostCount >= lr . minBoosts
54- ) . map ( ( lr ) => lr . roleId ) ;
50+ const eligibleRoleIds = BOOST_LEVEL_ROLES
51+ . filter ( ( lr ) => boostCount >= lr . minBoosts )
52+ . map ( ( lr ) => lr . roleId ) ;
5553
56- const ineligibleRoleIds = BOOST_LEVEL_ROLES . filter (
57- ( lr ) => boostCount < lr . minBoosts
58- ) . map ( ( lr ) => lr . roleId ) ;
54+ const ineligibleRoleIds = BOOST_LEVEL_ROLES
55+ . filter ( ( lr ) => boostCount < lr . minBoosts )
56+ . map ( ( lr ) => lr . roleId ) ;
5957
6058 for ( const roleId of eligibleRoleIds ) {
6159 if ( ! member . roles . cache . has ( roleId ) ) {
@@ -101,23 +99,22 @@ export async function createCustomRole(
10199 } ) ;
102100
103101 await member . roles . add ( role ) ;
104- setCustomRole ( member . id , role . id ) ;
102+ await setCustomRole ( member . id , guild . id , role . id ) ;
103+
105104 return role ;
106105}
107106
108107export async function deleteCustomRole (
109108 guild : Guild ,
110109 userId : string
111110) : Promise < void > {
112- const record : BoosterRecord | null = getBooster ( userId ) ;
113- if ( ! record ?. customRoleId ) return ;
111+ const customRole = await getCustomRole ( userId , guild . id ) ;
112+ if ( ! customRole ) return ;
114113
115- const role = guild . roles . cache . get ( record . customRoleId ) ;
116- if ( role ) {
117- await role . delete ( ) ;
118- }
114+ const role = guild . roles . cache . get ( customRole . discordRoleId ) ;
115+ if ( role ) await role . delete ( ) ;
119116
120- setCustomRole ( userId , null ) ;
117+ await setCustomRole ( userId , guild . id , null ) ;
121118}
122119
123120export async function updateCustomRole (
@@ -126,10 +123,10 @@ export async function updateCustomRole(
126123 name ?: string ,
127124 color ?: ColorResolvable
128125) : Promise < Role | null > {
129- const record : BoosterRecord | null = getBooster ( userId ) ;
130- if ( ! record ?. customRoleId ) return null ;
126+ const customRole = await getCustomRole ( userId , guild . id ) ;
127+ if ( ! customRole ) return null ;
131128
132- const role = guild . roles . cache . get ( record . customRoleId ) ;
129+ const role = guild . roles . cache . get ( customRole . discordRoleId ) ;
133130 if ( ! role ) return null ;
134131
135132 await role . edit ( {
0 commit comments