@@ -12,7 +12,6 @@ import {
12
12
import { DatabaseService } from "./database/index.js" ;
13
13
import { I18n , I18nArgs } from "@hammerhq/localization" ;
14
14
import { resolve } from "path" ;
15
- import { ConfigDataService } from "./services/ConfigDataService.js" ;
16
15
import { LoggerService } from "./services/LoggerService.js" ;
17
16
import { ClusterClient , getInfo } from "discord-hybrid-sharding" ;
18
17
import { join , dirname } from "path" ;
@@ -37,62 +36,53 @@ import { RainlinkPlayer } from "./rainlink/main.js";
37
36
import { IconType } from "./@types/Emoji.js" ;
38
37
import { TopggService } from "./services/TopggService.js" ;
39
38
config ( ) ;
40
- const __dirname = dirname ( fileURLToPath ( import . meta. url ) ) ;
41
- const configData = new ConfigDataService ( ) . data ;
42
- const REGEX = [
43
- / (?: h t t p s ? : \/ \/ ) ? (?: w w w \. ) ? y o u t u (?: \. b e \/ | b e .c o m \/ \S * (?: w a t c h | e m b e d ) (?: (?: (? = \/ [ - a - z A - Z 0 - 9 _ ] { 11 , } (? ! \S ) ) \/ ) | (?: \S * v = | v \/ ) ) ) ( [ - a - z A - Z 0 - 9 _ ] { 11 , } ) / ,
44
- / ^ .* ( y o u t u .b e \/ | l i s t = ) ( [ ^ # \& \? ] * ) .* / ,
45
- / ^ (?: s p o t i f y : | h t t p s : \/ \/ [ a - z ] + \. s p o t i f y \. c o m \/ ( t r a c k \/ | u s e r \/ ( .* ) \/ p l a y l i s t \/ | p l a y l i s t \/ ) ) ( .* ) $ / ,
46
- / ^ h t t p s ? : \/ \/ (?: w w w \. ) ? d e e z e r \. c o m \/ [ a - z ] + \/ ( t r a c k | a l b u m | p l a y l i s t ) \/ ( \d + ) $ / ,
47
- / ^ (?: ( h t t p s ? ) : \/ \/ ) ? (?: (?: w w w | m ) \. ) ? ( s o u n d c l o u d \. c o m | s n d \. s c ) \/ ( .* ) $ / ,
48
- / (?: h t t p s : \/ \/ m u s i c \. a p p l e \. c o m \/ ) (?: .+ ) ? ( a r t i s t | a l b u m | m u s i c - v i d e o | p l a y l i s t ) \/ ( [ \w \- \. ] + ( \/ ) + [ \w \- \. ] + | [ ^ & ] + ) \/ ( [ \w \- \. ] + ( \/ ) + [ \w \- \. ] + | [ ^ & ] + ) / ,
49
- / ^ h t t p s ? : \/ \/ (?: w w w \. | s e c u r e \. | s p \. ) ? n i c o v i d e o \. j p \/ w a t c h \/ ( [ a - z ] { 2 } [ 0 - 9 ] + ) / ,
50
- / (?: h t t p s : \/ \/ s p o t i f y \. l i n k ) \/ ( [ A - Z a - z 0 - 9 ] + ) / ,
51
- / ^ h t t p s : \/ \/ d e e z e r \. p a g e \. l i n k \/ [ a - z A - Z 0 - 9 ] { 12 } $ / ,
52
- ] ;
53
39
54
40
export class Manager extends Client {
55
- metadata : Metadata ;
56
- config : Config ;
57
- logger : LoggerService ;
58
- db ! : DatabaseTable ;
59
- owner : string ;
60
- color : ColorResolvable ;
61
- i18n : I18n ;
62
- prefix : string ;
63
- isDatabaseConnected : boolean ;
64
- shardStatus : boolean ;
65
- lavalinkList : LavalinkDataType [ ] ;
66
- lavalinkUsing : LavalinkUsingDataType [ ] ;
67
- lavalinkUsed : LavalinkUsingDataType [ ] ;
68
- rainlink : Rainlink ;
69
- commands : Collection < string , Command > ;
70
- interval : Collection < string , NodeJS . Timer > ;
71
- sentQueue : Collection < string , boolean > ;
72
- nplayingMsg : Collection < string , { coll : InteractionCollector < ButtonInteraction < "cached" > > ; msg : Message } > ;
73
- aliases : Collection < string , string > ;
74
- plButton : Collection < string , PlayerButton > ;
75
- leaveDelay : Collection < string , NodeJS . Timeout > ;
76
- nowPlaying : Collection < string , { interval : NodeJS . Timeout ; msg : GlobalMsg } > ;
77
- wsl : Collection < string , { send : ( data : Record < string , unknown > ) => void } > ;
78
- UpdateMusic ! : ( player : RainlinkPlayer ) => Promise < void | Message < true > > ;
79
- UpdateQueueMsg ! : ( player : RainlinkPlayer ) => Promise < void | Message < true > > ;
80
- enSwitch ! : ActionRowBuilder < ButtonBuilder > ;
81
- diSwitch ! : ActionRowBuilder < ButtonBuilder > ;
82
- enSwitchMod ! : ActionRowBuilder < ButtonBuilder > ;
83
- topgg ?: TopggService ;
84
- icons : IconType ;
85
- cluster ?: ClusterClient < Client > ;
86
- REGEX : RegExp [ ] ;
87
- constructor ( ) {
41
+ public metadata : Metadata ;
42
+ public logger : LoggerService ;
43
+ public db ! : DatabaseTable ;
44
+ public owner : string ;
45
+ public color : ColorResolvable ;
46
+ public i18n : I18n ;
47
+ public prefix : string ;
48
+ public isDatabaseConnected : boolean ;
49
+ public shardStatus : boolean ;
50
+ public lavalinkList : LavalinkDataType [ ] ;
51
+ public lavalinkUsing : LavalinkUsingDataType [ ] ;
52
+ public lavalinkUsed : LavalinkUsingDataType [ ] ;
53
+ public rainlink : Rainlink ;
54
+ public commands : Collection < string , Command > ;
55
+ public interval : Collection < string , NodeJS . Timer > ;
56
+ public sentQueue : Collection < string , boolean > ;
57
+ public nplayingMsg : Collection < string , { coll : InteractionCollector < ButtonInteraction < "cached" > > ; msg : Message } > ;
58
+ public aliases : Collection < string , string > ;
59
+ public plButton : Collection < string , PlayerButton > ;
60
+ public leaveDelay : Collection < string , NodeJS . Timeout > ;
61
+ public nowPlaying : Collection < string , { interval : NodeJS . Timeout ; msg : GlobalMsg } > ;
62
+ public wsl : Collection < string , { send : ( data : Record < string , unknown > ) => void } > ;
63
+ public UpdateMusic ! : ( player : RainlinkPlayer ) => Promise < void | Message < true > > ;
64
+ public UpdateQueueMsg ! : ( player : RainlinkPlayer ) => Promise < void | Message < true > > ;
65
+ public enSwitch ! : ActionRowBuilder < ButtonBuilder > ;
66
+ public diSwitch ! : ActionRowBuilder < ButtonBuilder > ;
67
+ public enSwitchMod ! : ActionRowBuilder < ButtonBuilder > ;
68
+ public topgg ?: TopggService ;
69
+ public icons : IconType ;
70
+ public cluster ?: ClusterClient < Client > ;
71
+ public REGEX : RegExp [ ] ;
72
+
73
+ constructor (
74
+ public config : Config ,
75
+ public clientIndex : number ,
76
+ isMsgEnable : boolean
77
+ ) {
88
78
super ( {
89
79
shards : process . env . IS_SHARING == "true" ? getInfo ( ) . SHARD_LIST : "auto" ,
90
80
shardCount : process . env . IS_SHARING == "true" ? getInfo ( ) . TOTAL_SHARDS : 1 ,
91
81
allowedMentions : {
92
82
parse : [ "roles" , "users" , "everyone" ] ,
93
83
repliedUser : false ,
94
84
} ,
95
- intents : configData . features . MESSAGE_CONTENT . enable
85
+ intents : isMsgEnable
96
86
? [
97
87
GatewayIntentBits . Guilds ,
98
88
GatewayIntentBits . GuildVoiceStates ,
@@ -103,10 +93,9 @@ export class Manager extends Client {
103
93
} ) ;
104
94
105
95
// Initial basic bot config
106
- // process.argv[1].replace(/^.*[\\\/]/, "") + " " +
107
- this . logger = new LoggerService ( this ) ;
96
+ const __dirname = dirname ( fileURLToPath ( import . meta . url ) ) ;
97
+ this . logger = new LoggerService ( this , clientIndex ) ;
108
98
this . logger . info ( "ClientManager" , "Booting client..." ) ;
109
- this . config = configData ;
110
99
this . metadata = new ManifestService ( ) . data . metadata . bot ;
111
100
this . owner = this . config . bot . OWNER_ID ;
112
101
this . color = ( this . config . bot . EMBED_COLOR || "#2b2d31" ) as ColorResolvable ;
@@ -116,7 +105,17 @@ export class Manager extends Client {
116
105
} ) ;
117
106
this . prefix = this . config . features . MESSAGE_CONTENT . commands . prefix || "d!" ;
118
107
this . shardStatus = false ;
119
- this . REGEX = REGEX ;
108
+ this . REGEX = [
109
+ / (?: h t t p s ? : \/ \/ ) ? (?: w w w \. ) ? y o u t u (?: \. b e \/ | b e .c o m \/ \S * (?: w a t c h | e m b e d ) (?: (?: (? = \/ [ - a - z A - Z 0 - 9 _ ] { 11 , } (? ! \S ) ) \/ ) | (?: \S * v = | v \/ ) ) ) ( [ - a - z A - Z 0 - 9 _ ] { 11 , } ) / ,
110
+ / ^ .* ( y o u t u .b e \/ | l i s t = ) ( [ ^ # \& \? ] * ) .* / ,
111
+ / ^ (?: s p o t i f y : | h t t p s : \/ \/ [ a - z ] + \. s p o t i f y \. c o m \/ ( t r a c k \/ | u s e r \/ ( .* ) \/ p l a y l i s t \/ | p l a y l i s t \/ ) ) ( .* ) $ / ,
112
+ / ^ h t t p s ? : \/ \/ (?: w w w \. ) ? d e e z e r \. c o m \/ [ a - z ] + \/ ( t r a c k | a l b u m | p l a y l i s t ) \/ ( \d + ) $ / ,
113
+ / ^ (?: ( h t t p s ? ) : \/ \/ ) ? (?: (?: w w w | m ) \. ) ? ( s o u n d c l o u d \. c o m | s n d \. s c ) \/ ( .* ) $ / ,
114
+ / (?: h t t p s : \/ \/ m u s i c \. a p p l e \. c o m \/ ) (?: .+ ) ? ( a r t i s t | a l b u m | m u s i c - v i d e o | p l a y l i s t ) \/ ( [ \w \- \. ] + ( \/ ) + [ \w \- \. ] + | [ ^ & ] + ) \/ ( [ \w \- \. ] + ( \/ ) + [ \w \- \. ] + | [ ^ & ] + ) / ,
115
+ / ^ h t t p s ? : \/ \/ (?: w w w \. | s e c u r e \. | s p \. ) ? n i c o v i d e o \. j p \/ w a t c h \/ ( [ a - z ] { 2 } [ 0 - 9 ] + ) / ,
116
+ / (?: h t t p s : \/ \/ s p o t i f y \. l i n k ) \/ ( [ A - Z a - z 0 - 9 ] + ) / ,
117
+ / ^ h t t p s : \/ \/ d e e z e r \. p a g e \. l i n k \/ [ a - z A - Z 0 - 9 ] { 12 } $ / ,
118
+ ] ;
120
119
121
120
if ( ! this . config . lavalink . AVOID_SUSPEND )
122
121
this . logger . warn (
@@ -160,18 +159,17 @@ export class Manager extends Client {
160
159
new DeployService ( this ) ;
161
160
new initHandler ( this ) ;
162
161
new DatabaseService ( this ) ;
163
- super . login ( this . config . bot . TOKEN ) ;
164
162
}
165
163
166
- configVolCheck ( vol : number = this . config . lavalink . DEFAULT_VOLUME ) {
164
+ protected configVolCheck ( vol : number = this . config . lavalink . DEFAULT_VOLUME ) {
167
165
if ( ! vol || isNaN ( vol ) || vol > 100 || vol < 1 ) {
168
166
this . config . lavalink . DEFAULT_VOLUME = 100 ;
169
167
return false ;
170
168
}
171
169
return true ;
172
170
}
173
171
174
- configSearchCheck ( data : string [ ] = this . config . lavalink . AUTOCOMPLETE_SEARCH ) {
172
+ protected configSearchCheck ( data : string [ ] = this . config . lavalink . AUTOCOMPLETE_SEARCH ) {
175
173
const defaultSearch = [ "yorushika" , "yoasobi" , "tuyu" , "hinkik" ] ;
176
174
if ( ! data || data . length == 0 ) {
177
175
this . config . lavalink . AUTOCOMPLETE_SEARCH = defaultSearch ;
@@ -186,12 +184,12 @@ export class Manager extends Client {
186
184
return true ;
187
185
}
188
186
189
- stringCheck ( data : unknown ) {
187
+ protected stringCheck ( data : unknown ) {
190
188
if ( typeof data === "string" || data instanceof String ) return true ;
191
189
return false ;
192
190
}
193
191
194
- getString ( locale : string , section : string , key : string , args ?: I18nArgs | undefined ) {
192
+ public getString ( locale : string , section : string , key : string , args ?: I18nArgs | undefined ) {
195
193
const currentString = this . i18n . get ( locale , section , key , args ) ;
196
194
const locateErr = `Locale '${ locale } ' not found.` ;
197
195
const sectionErr = `Section '${ section } ' not found in locale '${ locale } '` ;
0 commit comments