@@ -38,11 +38,11 @@ export default class TelegramBot extends TelegramApi {
38
38
// bot command: /code
39
39
code = async ( update : TelegramUpdate ) : Promise < Response > =>
40
40
( ( url ) =>
41
- ( update . inline_query &&
42
- this . answerInlineQuery ( update . inline_query . id , [
43
- new TelegramInlineQueryResultArticle ( url ) ,
44
- ] ) ) ??
45
- this . sendMessage ( update . message ?. chat . id ?? 0 , url ) ) (
41
+ update . inline_query
42
+ ? this . answerInlineQuery ( update . inline_query . id , [
43
+ new TelegramInlineQueryResultArticle ( url ) ,
44
+ ] )
45
+ : this . sendMessage ( update . message ?. chat . id ?? 0 , url ) ) (
46
46
"https://github.com/codebam/cf-workers-telegram-bot"
47
47
) ;
48
48
@@ -137,11 +137,11 @@ export default class TelegramBot extends TelegramApi {
137
137
. then ( ( response ) => responseToJSON ( response ) )
138
138
. then ( ( json ) =>
139
139
( ( message ) =>
140
- ( update . inline_query &&
141
- this . answerInlineQuery ( update . inline_query . id , [
142
- new TelegramInlineQueryResultArticle ( message ) ,
143
- ] ) ) ||
144
- this . sendMessage ( update . message ?. chat . id ?? 0 , message ) ) (
140
+ update . inline_query
141
+ ? this . answerInlineQuery ( update . inline_query . id , [
142
+ new TelegramInlineQueryResultArticle ( message ) ,
143
+ ] )
144
+ : this . sendMessage ( update . message ?. chat . id ?? 0 , message ) ) (
145
145
`Kanye says... ${ json . quote } `
146
146
)
147
147
)
@@ -154,19 +154,19 @@ export default class TelegramBot extends TelegramApi {
154
154
. then ( ( joke ) => joke as Joke )
155
155
. then ( ( joke_response ) =>
156
156
( ( message ) =>
157
- ( update . inline_query &&
158
- this . answerInlineQuery (
159
- update . inline_query . id ,
160
- [
161
- new TelegramInlineQueryResultArticle (
162
- message ,
163
- joke_response . joke ?? joke_response . setup ,
164
- "HTML"
165
- ) ,
166
- ] ,
167
- 0
168
- ) ) ??
169
- this . sendMessage ( update . message ?. chat . id ?? 0 , message , "HTML" ) ) (
157
+ update . inline_query
158
+ ? this . answerInlineQuery (
159
+ update . inline_query . id ,
160
+ [
161
+ new TelegramInlineQueryResultArticle (
162
+ message ,
163
+ joke_response . joke ?? joke_response . setup ,
164
+ "HTML"
165
+ ) ,
166
+ ] ,
167
+ 0
168
+ )
169
+ : this . sendMessage ( update . message ?. chat . id ?? 0 , message , "HTML" ) ) (
170
170
joke_response . joke ??
171
171
`${ joke_response . setup } \n\n<tg-spoiler>${ joke_response . delivery } </tg-spoiler>`
172
172
)
@@ -177,62 +177,59 @@ export default class TelegramBot extends TelegramApi {
177
177
fetch ( "https://shibe.online/api/shibes" )
178
178
. then ( ( response ) => response . json ( ) )
179
179
. then ( ( json ) => json as [ string ] )
180
- . then (
181
- ( shibe_response ) =>
182
- ( update . inline_query &&
183
- this . answerInlineQuery (
180
+ . then ( ( shibe_response ) =>
181
+ update . inline_query
182
+ ? this . answerInlineQuery (
184
183
update . inline_query . id ,
185
184
[ new TelegramInlineQueryResultPhoto ( shibe_response [ 0 ] ) ] ,
186
185
0
187
- ) ) ??
188
- this . sendPhoto ( update . message ?. chat . id ?? 0 , shibe_response [ 0 ] )
186
+ )
187
+ : this . sendPhoto ( update . message ?. chat . id ?? 0 , shibe_response [ 0 ] )
189
188
) ;
190
189
191
190
// bot command: /cat
192
191
cat = async ( update : TelegramUpdate ) : Promise < Response > =>
193
192
fetch ( "https://meow.senither.com/v1/random" )
194
193
. then ( ( response ) => response . json ( ) )
195
194
. then ( ( json ) => json as { data : { url : string } } )
196
- . then (
197
- ( json ) =>
198
- ( update . inline_query &&
199
- this . answerInlineQuery (
195
+ . then ( ( json ) =>
196
+ update . inline_query
197
+ ? this . answerInlineQuery (
200
198
update . inline_query . id ,
201
199
[ new TelegramInlineQueryResultPhoto ( json . data . url ) ] ,
202
200
0
203
- ) ) ??
204
- this . sendPhoto ( update . message ?. chat . id ?? 0 , json . data . url )
201
+ )
202
+ : this . sendPhoto ( update . message ?. chat . id ?? 0 , json . data . url )
205
203
) ;
206
204
207
205
// bot command: /bored
208
206
bored = async ( update : TelegramUpdate ) : Promise < Response > =>
209
207
fetch ( "https://boredapi.com/api/activity/" )
210
208
. then ( ( response ) => responseToJSON ( response ) )
211
209
. then ( ( json ) => json as Bored )
212
- . then (
213
- ( bored_response ) =>
214
- ( update . inline_query &&
215
- this . answerInlineQuery (
210
+ . then ( ( bored_response ) =>
211
+ update . inline_query
212
+ ? this . answerInlineQuery (
216
213
update . inline_query . id ,
217
214
[ new TelegramInlineQueryResultArticle ( bored_response . activity ) ] ,
218
215
0
219
- ) ) ??
220
- this . sendMessage (
221
- update . message ?. chat . id ?? 0 ,
222
- bored_response . activity
223
- )
216
+ )
217
+ : this . sendMessage (
218
+ update . message ?. chat . id ?? 0 ,
219
+ bored_response . activity
220
+ )
224
221
) ;
225
222
226
223
// bot command: /epoch
227
224
epoch = async ( update : TelegramUpdate ) : Promise < Response > =>
228
225
( ( seconds ) =>
229
- ( update . inline_query &&
230
- this . answerInlineQuery (
231
- update . inline_query . id ,
232
- [ new TelegramInlineQueryResultArticle ( seconds ) ] ,
233
- 0
234
- ) ) ??
235
- this . sendMessage ( update . message ?. chat . id ?? 0 , seconds ) ) (
226
+ update . inline_query
227
+ ? this . answerInlineQuery (
228
+ update . inline_query . id ,
229
+ [ new TelegramInlineQueryResultArticle ( seconds ) ] ,
230
+ 0
231
+ )
232
+ : this . sendMessage ( update . message ?. chat . id ?? 0 , seconds ) ) (
236
233
Math . floor ( Date . now ( ) / 1000 ) . toString ( )
237
234
) ;
238
235
@@ -241,15 +238,14 @@ export default class TelegramBot extends TelegramApi {
241
238
( ( key ) =>
242
239
this . get_set
243
240
. get ( key )
244
- . then (
245
- ( value ) =>
246
- ( update . inline_query &&
247
- this . answerInlineQuery (
241
+ . then ( ( value ) =>
242
+ update . inline_query
243
+ ? this . answerInlineQuery (
248
244
update . inline_query . id ,
249
245
[ new TelegramInlineQueryResultArticle ( value ?? "" ) ] ,
250
246
0
251
- ) ) ??
252
- this . sendMessage ( update . message ?. chat . id ?? 0 , value ?? "" )
247
+ )
248
+ : this . sendMessage ( update . message ?. chat . id ?? 0 , value ?? "" )
253
249
) ) ( args [ 1 ] ) ;
254
250
255
251
// bot command: /set
@@ -299,24 +295,24 @@ export default class TelegramBot extends TelegramApi {
299
295
// bot command: /roll
300
296
roll = async ( update : TelegramUpdate , args : string [ ] ) : Promise < Response > =>
301
297
( ( outcome , message ) =>
302
- ( update . inline_query &&
303
- this . answerInlineQuery ( update . inline_query . id , [
304
- new TelegramInlineQueryResultArticle (
298
+ update . inline_query
299
+ ? this . answerInlineQuery ( update . inline_query . id , [
300
+ new TelegramInlineQueryResultArticle (
301
+ message (
302
+ update . inline_query . from . username ,
303
+ update . inline_query . from . first_name ,
304
+ outcome
305
+ )
306
+ ) ,
307
+ ] )
308
+ : this . sendMessage (
309
+ update . message ?. chat . id ?? 0 ,
305
310
message (
306
- update . inline_query . from . username ,
307
- update . inline_query . from . first_name ,
311
+ update . message ? .from . username ?? "" ,
312
+ update . message ? .from . first_name ?? "" ,
308
313
outcome
309
314
)
310
- ) ,
311
- ] ) ) ??
312
- this . sendMessage (
313
- update . message ?. chat . id ?? 0 ,
314
- message (
315
- update . message ?. from . username ?? "" ,
316
- update . message ?. from . first_name ?? "" ,
317
- outcome
318
- )
319
- ) ) (
315
+ ) ) (
320
316
Math . floor ( Math . random ( ) * ( parseInt ( args [ 1 ] ) || 6 - 1 + 1 ) + 1 ) ,
321
317
( username : string , first_name : string , outcome : number ) =>
322
318
`${ first_name ?? username } rolled a ${
0 commit comments