@@ -19,38 +19,37 @@ import BlacklistManager from '#src/managers/BlacklistManager.js';
1919import HubManager from '#src/managers/HubManager.js' ;
2020import { HubService } from '#src/services/HubService.js' ;
2121import { type EmojiKeys , getEmoji } from '#src/utils/EmojiUtils.js' ;
22-
23- import { stripIndents } from 'common-tags' ;
24- import type {
25- ChatInputCommandInteraction ,
26- GuildTextBasedChannel ,
27- MessageComponentInteraction ,
28- } from 'discord.js' ;
22+ import Context from '#src/core/CommandContext/Context.js' ;
2923import type { TranslationKeys } from '#types/TranslationKeys.d.ts' ;
3024import { createConnection } from '#utils/ConnectedListUtils.js' ;
3125import db from '#utils/Db.js' ;
3226import { type supportedLocaleCodes , t } from '#utils/Locale.js' ;
33- import { check } from '#utils/ProfanityUtils.js' ;
3427import { getOrCreateWebhook , getReplyMethod } from '#utils/Utils.js' ;
3528import { logJoinToHub } from '#utils/hub/logger/JoinLeave.js' ;
3629import { sendToHub } from '#utils/hub/utils.js' ;
37- import Context from '#src/core/CommandContext/Context.js' ;
30+ import { stripIndents } from 'common-tags' ;
31+ import type {
32+ ChatInputCommandInteraction ,
33+ GuildTextBasedChannel ,
34+ MessageComponentInteraction ,
35+ } from 'discord.js' ;
3836// eslint-disable-next-line no-duplicate-imports
3937import type { CachedContextType } from '#src/core/CommandContext/Context.js' ;
38+ import { checkRule } from '#src/utils/network/antiSwearChecks.js' ;
4039
4140export class HubJoinService {
4241 private readonly interaction :
43- | ChatInputCommandInteraction < 'cached' >
44- | MessageComponentInteraction < 'cached' >
45- | Context < CachedContextType > ;
42+ | ChatInputCommandInteraction < 'cached' >
43+ | MessageComponentInteraction < 'cached' >
44+ | Context < CachedContextType > ;
4645 private readonly locale : supportedLocaleCodes ;
4746 private readonly hubService : HubService ;
4847
4948 constructor (
5049 interaction :
51- | ChatInputCommandInteraction < 'cached' >
52- | MessageComponentInteraction < 'cached' >
53- | Context < CachedContextType > ,
50+ | ChatInputCommandInteraction < 'cached' >
51+ | MessageComponentInteraction < 'cached' >
52+ | Context < CachedContextType > ,
5453 locale : supportedLocaleCodes ,
5554 hubService : HubService = new HubService ( ) ,
5655 ) {
@@ -74,19 +73,13 @@ export class HubJoinService {
7473 return await this . joinHub ( channel , randomHub . name ) ;
7574 }
7675
77- async joinHub (
78- channel : GuildTextBasedChannel ,
79- hubInviteOrName : string | undefined ,
80- ) {
76+ async joinHub ( channel : GuildTextBasedChannel , hubInviteOrName : string | undefined ) {
8177 if ( ! this . interaction . deferred ) {
8278 // eslint-disable-next-line @typescript-eslint/ban-ts-comment
8379 // @ts -expect-error
8480 await this . interaction . deferReply ( { flags : [ 'Ephemeral' ] } ) ;
8581 }
8682
87- const checksPassed = await this . runChecks ( channel ) ;
88- if ( ! checksPassed ) return false ;
89-
9083 const hub = await this . fetchHub ( hubInviteOrName ) ;
9184 if ( ! hub ) {
9285 await this . interaction . editReply ( {
@@ -97,10 +90,10 @@ export class HubJoinService {
9790 return false ;
9891 }
9992
100- if (
101- ( await this . isAlreadyInHub ( channel , hub . id ) ) ||
102- ( await this . isBlacklisted ( hub ) )
103- ) {
93+ const checksPassed = await this . runChecks ( channel , hub ) ;
94+ if ( ! checksPassed ) return false ;
95+
96+ if ( ( await this . isAlreadyInHub ( channel , hub . id ) ) || ( await this . isBlacklisted ( hub ) ) ) {
10497 return false ;
10598 }
10699
@@ -116,32 +109,27 @@ export class HubJoinService {
116109 hub : { connect : { id : hub . id } } ,
117110 connected : true ,
118111 compact : true ,
119- profFilter : true ,
120112 } ) ;
121113
122114 await this . sendSuccessMessages ( hub , channel ) ;
123115 return true ;
124116 }
125117
126- private async runChecks ( channel : GuildTextBasedChannel ) {
127- if (
128- ! channel
129- . permissionsFor ( this . interaction . member )
130- . has ( 'ManageMessages' , true )
131- ) {
118+ private async runChecks ( channel : GuildTextBasedChannel , hub : HubManager ) {
119+ if ( ! channel . permissionsFor ( this . interaction . member ) . has ( 'ManageMessages' , true ) ) {
132120 await this . replyError ( 'errors.missingPermissions' , {
133121 permissions : 'Manage Messages' ,
134122 emoji : this . getEmoji ( 'x_icon' ) ,
135123 } ) ;
136124 return false ;
137125 }
138126
139- const { hasSlurs , hasProfanity } = check ( this . interaction . guild . name ) ;
140- if ( hasSlurs || hasProfanity ) {
141- await this . replyError ( 'errors.serverNameInappropriate' , {
142- emoji : this . getEmoji ( 'x_icon' ) ,
143- } ) ;
144- return false ;
127+ for ( const rule of await hub . fetchAntiSwearRules ( ) ) {
128+ const match = checkRule ( channel . guild . name , rule ) ;
129+ if ( match ) {
130+ await this . replyError ( 'errors.serverNameInappropriate' , { emoji : this . getEmoji ( 'x_icon' ) } ) ;
131+ return false ;
132+ }
145133 }
146134
147135 return true ;
@@ -184,14 +172,8 @@ export class HubJoinService {
184172 }
185173
186174 private async isBlacklisted ( hub : HubManager ) {
187- const userBlManager = new BlacklistManager (
188- 'user' ,
189- this . interaction . user . id ,
190- ) ;
191- const serverBlManager = new BlacklistManager (
192- 'server' ,
193- this . interaction . guildId ,
194- ) ;
175+ const userBlManager = new BlacklistManager ( 'user' , this . interaction . user . id ) ;
176+ const serverBlManager = new BlacklistManager ( 'server' , this . interaction . guildId ) ;
195177
196178 const userBlacklist = await userBlManager . fetchBlacklist ( hub . id ) ;
197179 const serverBlacklist = await serverBlManager . fetchBlacklist ( hub . id ) ;
@@ -219,10 +201,7 @@ export class HubJoinService {
219201 return webhook ;
220202 }
221203
222- private async sendSuccessMessages (
223- hub : HubManager ,
224- channel : GuildTextBasedChannel ,
225- ) {
204+ private async sendSuccessMessages ( hub : HubManager , channel : GuildTextBasedChannel ) {
226205 const replyData = {
227206 content : t ( 'hub.join.success' , this . locale , {
228207 channel : `${ channel } ` ,
@@ -240,15 +219,15 @@ export class HubJoinService {
240219 await this . interaction [ replyMethod ] ( replyData ) ;
241220
242221 const totalConnections =
243- ( await hub . connections . fetch ( ) ) ?. reduce (
244- ( total , c ) => total + ( c . data . connected ? 1 : 0 ) ,
245- 0 ,
246- ) ?? 0 ;
222+ ( await hub . connections . fetch ( ) ) ?. reduce (
223+ ( total , c ) => total + ( c . data . connected ? 1 : 0 ) ,
224+ 0 ,
225+ ) ?? 0 ;
247226
248227 const serverCountMessage =
249- totalConnections === 0
250- ? 'There are no other servers connected to this hub yet. *cricket noises* 🦗'
251- : `We now have ${ totalConnections } servers in this hub! 🎉` ;
228+ totalConnections === 0
229+ ? 'There are no other servers connected to this hub yet. *cricket noises* 🦗'
230+ : `We now have ${ totalConnections } servers in this hub! 🎉` ;
252231
253232 // Announce to hub
254233 await sendToHub ( hub . id , {
0 commit comments