@@ -16,7 +16,7 @@ import {
16
16
function url_to_label (
17
17
url : string ,
18
18
alternative : string ,
19
- smart_label : boolean ,
19
+ smart_label : boolean
20
20
) : string {
21
21
// Reduce URLs to a representative label,
22
22
// as Discord at most allows 80 characters in their labels
@@ -59,7 +59,7 @@ export default class DiscordBot {
59
59
command : string = "hey" ,
60
60
slashCommandsDescription : string = "Say hey to the bot" ,
61
61
showSources : boolean | string = false ,
62
- smartLabel : boolean | string = false ,
62
+ smartLabel : boolean | string = false
63
63
) {
64
64
try {
65
65
if ( this . _clients . has ( identifier ) ) {
@@ -81,7 +81,7 @@ export default class DiscordBot {
81
81
token ,
82
82
clientId ,
83
83
slashCommands . replace ( / [ ^ a - z A - Z 0 - 9 ] / g, "" ) ,
84
- slashCommandsDescription ,
84
+ slashCommandsDescription
85
85
) ;
86
86
}
87
87
} ) ;
@@ -114,7 +114,7 @@ export default class DiscordBot {
114
114
const bot_response = await discordBotHandler (
115
115
identifier ,
116
116
message . toString ( ) ,
117
- chat_id ,
117
+ chat_id
118
118
) ;
119
119
120
120
const unique_button_sources : Array < string > = Array . from (
@@ -123,9 +123,9 @@ export default class DiscordBot {
123
123
new Set (
124
124
bot_response ?. sourceDocuments ?. map (
125
125
( d : { metadata : { source : string } } ) : string =>
126
- d . metadata . source ,
127
- ) ,
128
- ) ,
126
+ d . metadata . source
127
+ )
128
+ )
129
129
) ;
130
130
131
131
await interaction
@@ -137,24 +137,27 @@ export default class DiscordBot {
137
137
description : bot_response ?. text ,
138
138
} ) ,
139
139
] ,
140
- components : showSources
141
- ? [
142
- new ActionRowBuilder < ButtonBuilder > ( {
143
- components : unique_button_sources . map (
144
- ( url : string , i : number ) : ButtonBuilder =>
145
- new ButtonBuilder ( {
146
- style : ButtonStyle . Link ,
147
- label : url_to_label (
148
- url ,
149
- `Source ${ ( i + 1 ) . toString ( ) } ` ,
150
- smartLabelBool ,
151
- ) ,
152
- url : url ,
153
- } ) ,
154
- ) ,
155
- } ) ,
156
- ]
157
- : [ ] ,
140
+ components :
141
+ unique_button_sources . length > 0
142
+ ? showSources
143
+ ? [
144
+ new ActionRowBuilder < ButtonBuilder > ( {
145
+ components : unique_button_sources . map (
146
+ ( url : string , i : number ) : ButtonBuilder =>
147
+ new ButtonBuilder ( {
148
+ style : ButtonStyle . Link ,
149
+ label : url_to_label (
150
+ url ,
151
+ `Source ${ ( i + 1 ) . toString ( ) } ` ,
152
+ smartLabelBool
153
+ ) ,
154
+ url : url ,
155
+ } )
156
+ ) ,
157
+ } ) ,
158
+ ]
159
+ : [ ]
160
+ : [ ] ,
158
161
} )
159
162
. catch ( ( err : any ) => console . log ( err ) ) ;
160
163
}
@@ -176,7 +179,7 @@ export default class DiscordBot {
176
179
177
180
const bot_response = await clearDiscordChatHistory (
178
181
identifier ,
179
- chat_id ,
182
+ chat_id
180
183
) ;
181
184
182
185
await reply . edit ( bot_response ) ;
@@ -212,7 +215,7 @@ export default class DiscordBot {
212
215
token : string ,
213
216
clientId : string ,
214
217
slashCommands : string = "hey" ,
215
- slashCommandsDescription : string = "Say hey to the bot" ,
218
+ slashCommandsDescription : string = "Say hey to the bot"
216
219
) {
217
220
try {
218
221
const rest = new REST ( { version : "10" } ) . setToken ( token ) ;
0 commit comments