1- import { TextChannel } from 'discord.js'
1+ import { WebhookClient } from 'discord.js'
22import type { ArgsOf } from 'discordx'
33import { Discord , On } from 'discordx'
44import { injectable } from 'tsyringe'
@@ -31,19 +31,31 @@ interface ScheduledJobConfig {
3131@Discord ( )
3232@injectable ( )
3333export class AppDiscord {
34- PROD_ALARMS : string
3534 PROD_URL : string
3635 DEV_URL : string
36+ DEV_API_URL : string
3737 private scheduledJobs : schedule . Job [ ] = [ ]
38+ private webhooks : {
39+ devWiki : string
40+ devHiiq : string
41+ prodWiki : string
42+ prodAlarms : string
43+ }
3844
3945 constructor (
4046 private updates : Updates ,
4147 private revalidate : RevalidateService ,
4248 private wikiUpdates : WikiUpdates ,
4349 ) {
44- this . PROD_ALARMS = JSON . parse ( process . env . CHANNELS ) . ALARMS
4550 this . PROD_URL = process . env . PROD_URL
4651 this . DEV_URL = process . env . DEV_URL
52+ this . DEV_API_URL = process . env . DEV_API_URL
53+ this . webhooks = {
54+ devWiki : process . env . DEV_WIKI_WEBHOOK || '' ,
55+ devHiiq : process . env . DEV_HIIQ_WEBHOOK || '' ,
56+ prodWiki : process . env . PROD_WIKI_WEBHOOK || '' ,
57+ prodAlarms : process . env . PROD_ALARMS_WEBHOOK || '' ,
58+ }
4759 }
4860
4961 private async executeWithErrorHandling (
@@ -59,12 +71,7 @@ export class AppDiscord {
5971 }
6072 }
6173
62- private createScheduledJobs ( channels : any ) : ScheduledJobConfig [ ] {
63- const devWikiChannel = channels . devWikiChannel
64- const devHiiqChannel = channels . devHiiqChannel
65- const prodWikiChannel = channels . prodWikiChannel
66- const prodAlertChannel = channels . prodAlertChannel
67-
74+ private createScheduledJobs ( ) : ScheduledJobConfig [ ] {
6875 return [
6976 {
7077 name : 'Wiki Updates Check' ,
@@ -73,13 +80,13 @@ export class AppDiscord {
7380 task : async ( ) => {
7481 await Promise . all ( [
7582 this . updates . sendUpdates ( {
76- channelId : devWikiChannel ,
83+ webhookUrl : this . webhooks . devWiki ,
7784 channelType : ChannelTypes . DEV ,
7885 url : this . DEV_URL ,
7986 updateType : UpdateTypes . WIKI ,
8087 } ) ,
8188 this . updates . sendUpdates ( {
82- channelId : prodWikiChannel ,
89+ webhookUrl : this . webhooks . prodWiki ,
8390 channelType : ChannelTypes . PROD ,
8491 url : this . PROD_URL ,
8592 updateType : UpdateTypes . WIKI ,
@@ -93,7 +100,7 @@ export class AppDiscord {
93100 enabled : true ,
94101 task : async ( ) => {
95102 await this . updates . sendUpdates ( {
96- channelId : devHiiqChannel ,
103+ webhookUrl : this . webhooks . devHiiq ,
97104 channelType : ChannelTypes . DEV ,
98105 url : '' ,
99106 updateType : UpdateTypes . HIIQ ,
@@ -110,10 +117,10 @@ export class AppDiscord {
110117 this . PROD_URL ,
111118 `${ process . cwd ( ) } /build/utils/prodWikiLinks.js` ,
112119 ) ,
113- this . revalidate . revalidateRandomWiki (
114- this . DEV_URL ,
115- `${ process . cwd ( ) } /build/utils/devWikiLinks.js` ,
116- ) ,
120+ // this.revalidate.revalidateRandomWiki(
121+ // this.DEV_URL,
122+ // `${process.cwd()}/build/utils/devWikiLinks.js`,
123+ // ),
117124 ] )
118125 } ,
119126 } ,
@@ -127,9 +134,9 @@ export class AppDiscord {
127134 ...pages . map ( page =>
128135 this . revalidate . revalidateWikiPage ( this . PROD_URL , page ) ,
129136 ) ,
130- ...pages . map ( page =>
131- this . revalidate . revalidateWikiPage ( this . DEV_URL , page ) ,
132- ) ,
137+ // ...pages.map(page =>
138+ // this.revalidate.revalidateWikiPage(this.DEV_URL, page),
139+ // ),
133140 ] )
134141 } ,
135142 } ,
@@ -138,7 +145,7 @@ export class AppDiscord {
138145 schedule : '*/30 * * * *' ,
139146 enabled : true ,
140147 task : async ( ) => {
141- await this . checkWebpageStatus ( urls , prodAlertChannel )
148+ await this . checkWebpageStatus ( urls , this . webhooks . prodAlarms )
142149 } ,
143150 } ,
144151 {
@@ -156,26 +163,12 @@ export class AppDiscord {
156163 async isReady ( [ client ] : ArgsOf < 'clientReady' > ) {
157164 console . log ( '🤖 Bot is ready! Setting up scheduled tasks...' )
158165
159- const channelIds = JSON . parse ( process . env . CHANNELS )
160-
161- const channels = {
162- devWikiChannel : client . channels . cache . get (
163- channelIds . DEV . WIKI ,
164- ) as TextChannel ,
165- devHiiqChannel : client . channels . cache . get (
166- channelIds . DEV . HIIQ ,
167- ) as TextChannel ,
168- prodWikiChannel : client . channels . cache . get (
169- channelIds . PROD . WIKI ,
170- ) as TextChannel ,
171- prodAlertChannel : client . channels . cache . get (
172- channelIds . PROD . ALARMS ,
173- ) as TextChannel ,
174- }
175-
176- Object . entries ( channels ) . forEach ( ( [ name , channel ] ) => {
177- if ( ! channel ) {
178- console . error ( `❌ Channel ${ name } not found!` )
166+ // Validate webhook URLs
167+ Object . entries ( this . webhooks ) . forEach ( ( [ name , url ] ) => {
168+ if ( ! url ) {
169+ console . warn ( `⚠️ Webhook ${ name } not configured` )
170+ } else {
171+ console . log ( `✅ Webhook ${ name } configured` )
179172 }
180173 } )
181174
@@ -187,7 +180,7 @@ export class AppDiscord {
187180 this . wikiUpdates . startApiHealthMonitoring ( ) ,
188181 )
189182
190- const jobConfigs = this . createScheduledJobs ( channels )
183+ const jobConfigs = this . createScheduledJobs ( )
191184
192185 jobConfigs . forEach ( config => {
193186 if ( config . enabled ) {
@@ -213,7 +206,7 @@ export class AppDiscord {
213206
214207 const [ extractedProdLinks , extractedDevLinks ] = await Promise . all ( [
215208 this . revalidate . extractLinks ( this . PROD_URL ) ,
216- this . revalidate . extractLinks ( this . DEV_URL ) ,
209+ this . revalidate . extractLinks ( this . DEV_API_URL ) ,
217210 ] )
218211
219212 await Promise . all ( [
@@ -236,7 +229,7 @@ export class AppDiscord {
236229
237230 async checkWebpageStatus (
238231 urls : string [ ] ,
239- channel : TextChannel ,
232+ webhookUrl : string ,
240233 ) : Promise < void > {
241234 console . log ( `🔍 Checking status of ${ urls . length } websites...` )
242235
@@ -283,7 +276,7 @@ export class AppDiscord {
283276 if ( result ) {
284277 console . log ( ` - ${ result . url } : ${ result . status } ` )
285278 await this . updates . sendUpdates ( {
286- channelId : channel ,
279+ webhookUrl : webhookUrl ,
287280 channelType : ChannelTypes . PROD ,
288281 url : result . url ,
289282 updateType : UpdateTypes . DOWNTIME ,
0 commit comments