@@ -11,8 +11,12 @@ import type {
11
11
import type {
12
12
CategoryChannel ,
13
13
ChannelLogsQueryOptions ,
14
+ ChannelType ,
14
15
Collection ,
15
16
Guild ,
17
+ GuildFeature ,
18
+ GuildDefaultMessageNotifications ,
19
+ GuildSystemChannelFlags ,
16
20
GuildChannelCreateOptions ,
17
21
Message ,
18
22
OverwriteData ,
@@ -28,10 +32,10 @@ import type {
28
32
import nodeFetch from 'node-fetch' ;
29
33
30
34
const MaxBitratePerTier : Record < PremiumTier , number > = {
31
- NONE : 64000 ,
32
- TIER_1 : 128000 ,
33
- TIER_2 : 256000 ,
34
- TIER_3 : 384000
35
+ None : 64000 ,
36
+ Tier1 : 128000 ,
37
+ Tier2 : 256000 ,
38
+ Tier3 : 384000
35
39
} ;
36
40
37
41
/**
@@ -61,7 +65,7 @@ export function fetchChannelPermissions(channel: TextChannel | VoiceChannel | Ca
61
65
export async function fetchVoiceChannelData ( channel : VoiceChannel ) {
62
66
return new Promise < VoiceChannelData > ( async ( resolve ) => {
63
67
const channelData : VoiceChannelData = {
64
- type : 'GUILD_VOICE' ,
68
+ type : ChannelType . GuildVoice ,
65
69
name : channel . name ,
66
70
bitrate : channel . bitrate ,
67
71
userLimit : channel . userLimit ,
@@ -129,12 +133,12 @@ export async function fetchTextChannelData(channel: TextChannel | NewsChannel, o
129
133
type : channel . type ,
130
134
name : channel . name ,
131
135
nsfw : channel . nsfw ,
132
- rateLimitPerUser : channel . type === 'GUILD_TEXT' ? channel . rateLimitPerUser : undefined ,
136
+ rateLimitPerUser : channel . type === ChannelType . GuildText ? channel . rateLimitPerUser : undefined ,
133
137
parent : channel . parent ? channel . parent . name : null ,
134
138
topic : channel . topic ,
135
139
permissions : fetchChannelPermissions ( channel ) ,
136
140
messages : [ ] ,
137
- isNews : channel . type === 'GUILD_NEWS' ,
141
+ isNews : channel . type === ChannelType . GuildNews ,
138
142
threads : [ ]
139
143
} ;
140
144
/* Fetch channel threads */
@@ -176,7 +180,7 @@ export async function fetchTextChannelData(channel: TextChannel | NewsChannel, o
176
180
export async function loadCategory ( categoryData : CategoryData , guild : Guild ) {
177
181
return new Promise < CategoryChannel > ( ( resolve ) => {
178
182
guild . channels . create ( categoryData . name , {
179
- type : 'GUILD_CATEGORY'
183
+ type : ChannelType . GuildCategory
180
184
} ) . then ( async ( category ) => {
181
185
// When the category is created
182
186
const finalPermissions : OverwriteData [ ] = [ ] ;
@@ -209,7 +213,8 @@ export async function loadChannel(
209
213
210
214
const loadMessages = ( channel : TextChannel | ThreadChannel , messages : MessageData [ ] , previousWebhook ?: Webhook ) : Promise < Webhook | void > => {
211
215
return new Promise ( async ( resolve ) => {
212
- const webhook = previousWebhook || await ( channel as TextChannel ) . createWebhook ( 'MessagesBackup' , {
216
+ const webhook = previousWebhook || await ( channel as TextChannel ) . createWebhook ( {
217
+ name : 'MessagesBackup' ,
213
218
avatar : channel . client . user . displayAvatarURL ( )
214
219
} ) . catch ( ( ) => { } ) ;
215
220
if ( ! webhook ) return resolve ( ) ;
@@ -238,16 +243,17 @@ export async function loadChannel(
238
243
}
239
244
240
245
const createOptions : GuildChannelCreateOptions = {
246
+ name : channelData . name ,
241
247
type : null ,
242
248
parent : category
243
249
} ;
244
- if ( channelData . type === 'GUILD_TEXT' || channelData . type === 'GUILD_NEWS' ) {
250
+ if ( channelData . type === ChannelType . GuildText || channelData . type === ChannelType . GuildNews ) {
245
251
createOptions . topic = ( channelData as TextChannelData ) . topic ;
246
252
createOptions . nsfw = ( channelData as TextChannelData ) . nsfw ;
247
253
createOptions . rateLimitPerUser = ( channelData as TextChannelData ) . rateLimitPerUser ;
248
254
createOptions . type =
249
- ( channelData as TextChannelData ) . isNews && guild . features . includes ( 'NEWS' ) ? 'GUILD_NEWS' : 'GUILD_TEXT' ;
250
- } else if ( channelData . type === 'GUILD_VOICE' ) {
255
+ ( channelData as TextChannelData ) . isNews && guild . features . includes ( GuildFeature . News ) ? ChannelType . GuildNews : ChannelType . GuildText ;
256
+ } else if ( channelData . type === ChannelType . GuildVoice ) {
251
257
// Downgrade bitrate
252
258
let bitrate = ( channelData as VoiceChannelData ) . bitrate ;
253
259
const bitrates = Object . values ( MaxBitratePerTier ) ;
@@ -256,9 +262,9 @@ export async function loadChannel(
256
262
}
257
263
createOptions . bitrate = bitrate ;
258
264
createOptions . userLimit = ( channelData as VoiceChannelData ) . userLimit ;
259
- createOptions . type = 'GUILD_VOICE' ;
265
+ createOptions . type = ChannelType . GuildVoice ;
260
266
}
261
- guild . channels . create ( channelData . name , createOptions ) . then ( async ( channel ) => {
267
+ guild . channels . create ( createOptions ) . then ( async ( channel ) => {
262
268
/* Update channel permissions */
263
269
const finalPermissions : OverwriteData [ ] = [ ] ;
264
270
channelData . permissions . forEach ( ( perm ) => {
@@ -272,7 +278,7 @@ export async function loadChannel(
272
278
}
273
279
} ) ;
274
280
await channel . permissionOverwrites . set ( finalPermissions ) ;
275
- if ( channelData . type === 'GUILD_TEXT' ) {
281
+ if ( channelData . type === ChannelType . GuildText ) {
276
282
/* Load messages */
277
283
let webhook : Webhook | void ;
278
284
if ( ( channelData as TextChannelData ) . messages . length > 0 ) {
@@ -282,8 +288,8 @@ export async function loadChannel(
282
288
if ( ( channelData as TextChannelData ) . threads . length > 0 ) { //&& guild.features.includes('THREADS_ENABLED')) {
283
289
await Promise . all ( ( channelData as TextChannelData ) . threads . map ( async ( threadData ) => {
284
290
let autoArchiveDuration = threadData . autoArchiveDuration ;
285
- if ( ! guild . features . includes ( 'SEVEN_DAY_THREAD_ARCHIVE' ) && autoArchiveDuration === 10080 ) autoArchiveDuration = 4320 ;
286
- if ( ! guild . features . includes ( 'THREE_DAY_THREAD_ARCHIVE' ) && autoArchiveDuration === 4320 ) autoArchiveDuration = 1440 ;
291
+ // if (!guild.features.includes('SEVEN_DAY_THREAD_ARCHIVE') && autoArchiveDuration === 10080) autoArchiveDuration = 4320;
292
+ // if (!guild.features.includes('THREE_DAY_THREAD_ARCHIVE') && autoArchiveDuration === 4320) autoArchiveDuration = 1440;
287
293
return ( channel as TextChannel ) . threads . create ( {
288
294
name : threadData . name ,
289
295
autoArchiveDuration
@@ -329,16 +335,16 @@ export async function clearGuild(guild: Guild) {
329
335
guild . setIcon ( null ) ;
330
336
guild . setBanner ( null ) . catch ( ( ) => { } ) ;
331
337
guild . setSplash ( null ) . catch ( ( ) => { } ) ;
332
- guild . setDefaultMessageNotifications ( 'ONLY_MENTIONS' ) ;
338
+ guild . setDefaultMessageNotifications ( GuildDefaultMessageNotifications . OnlyMentions ) ;
333
339
guild . setWidgetSettings ( {
334
340
enabled : false ,
335
341
channel : null
336
342
} ) ;
337
- if ( ! guild . features . includes ( 'COMMUNITY' ) ) {
338
- guild . setExplicitContentFilter ( 'DISABLED' ) ;
339
- guild . setVerificationLevel ( 'NONE' ) ;
343
+ if ( ! guild . features . includes ( GuildFeature . Community ) ) {
344
+ guild . setExplicitContentFilter ( GuildExplicitContentFilter . Disabled ) ;
345
+ guild . setVerificationLevel ( GuildVerificationLevel . None ) ;
340
346
}
341
347
guild . setSystemChannel ( null ) ;
342
- guild . setSystemChannelFlags ( [ 'SUPPRESS_GUILD_REMINDER_NOTIFICATIONS' , 'SUPPRESS_JOIN_NOTIFICATIONS' , 'SUPPRESS_PREMIUM_SUBSCRIPTIONS' ] ) ;
348
+ guild . setSystemChannelFlags ( [ GuildSystemChannelFlags . SuppressGuildReminderNotifications , GuildSystemChannelFlags . SuppressJoinNotifications , GuildSystemChannelFlags . SuppressPremiumSubscriptions ] ) ;
343
349
return ;
344
350
}
0 commit comments