-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.ts
717 lines (665 loc) · 28.1 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
'use strict'
import {
nip19,
getPublicKey,
getEventHash,
signEvent
} from 'nostr-tools'
const suddendeath = require('suddendeath')
var eaw = require('eastasianwidth')
var runes = require('runes')
export interface Env {
NULLPOGA_GA_TOKEN: string
NULLPOGA_VA_TOKEN: string
NULLPOGA_LOGINBONUS_TOKEN: string
NULLPOGA_NSEC: string
}
const NULLPOGA_NPUB: string = '4e86cdbb1ed747ff40c65303d1fc463e10aecb113049b05fc4317c29e31ccaaf'
const page = `
<!doctype html>
<link href="//fonts.bunny.net/css?family=sigmar-one:400" rel="stylesheet" />
<meta charset="utf-8" />
<title>Cloudflare NullpoGa</title>
<style>
body {
font-size: 40px;
text-align: center;
}
h1,h2,h3 {
font-family: 'Sigmar One', serif;
font-style: normal;
text-shadow: none;
text-decoration: none;
text-transform: none;
letter-spacing: -0.05em;
word-spacing: 0em;
line-height: 1.15;
}
</style>
<body>
<h1>ぬるぽ・ガッ</h1>
2023 (C) <a href="http://mattn.kaoriya.net/">mattn</a>, code is <a href="https://github.com/mattn/cloudflare-nostr-nullpoga">here</a>
</body>
`
function notAuthenticated(_request: Request, _env: Env) {
return new Response(
'Not Authenticated',
{
status: 401,
headers: {
'content-type': 'text/plain; charset=UTF-8',
'accept-charset': 'utf-8',
},
},
)
}
function notFound(_request: Request, _env: Env) {
return new Response(`Not found`, {
status: 404,
})
}
function unsupportedMethod(_request: Request, _env: Env) {
return new Response(`Unsupported method`, {
status: 400,
})
}
function bearerAuthentication(request: Request, secret: string) {
if (!request.headers.has('authorization')) {
return false
}
const authorization = request.headers.get('Authorization')!
const [scheme, encoded] = authorization.split(' ')
return scheme === 'Bearer' && encoded === secret
}
function createLike(env: Env, mention: { [name: string]: any }): { [name: string]: any } {
const decoded = nip19.decode(env.NULLPOGA_NSEC)
const sk = decoded.data as string
const pk = getPublicKey(sk)
let event = {
id: '',
kind: 7,
pubkey: pk,
created_at: Math.floor(Date.now() / 1000),
tags: [['e', mention.id]],
content: '❤',
sig: '',
}
event.id = getEventHash(event)
event.sig = signEvent(event, sk)
return event
}
function createReplyWithTags(env: Env, mention: { [name: string]: any }, message: string, tags: string[][]): { [name: string]: any } {
const decoded = nip19.decode(env.NULLPOGA_NSEC)
const sk = decoded.data as string
const pk = getPublicKey(sk)
if (mention.pubkey == pk) throw new Error('Self reply not acceptable')
const tt = []
tt.push(['e', mention.id], ['p', mention.pubkey])
if (mention.kind == 42) {
for (let tag of mention.tags.filter((x: any[]) => x[0] === 'e')) {
tt.push(tag)
}
}
for (let tag of tags) {
tt.push(tag)
}
const created_at = mention.created_at + 1
let event = {
id: '',
kind: mention.kind,
pubkey: pk,
created_at: created_at, // Math.floor(Date.now() / 1000),
tags: tt,
content: message,
sig: '',
}
event.id = getEventHash(event)
event.sig = signEvent(event, sk)
return event
}
function createNoteWithTags(env: Env, mention: { [name: string]: any }, message: string, tags: string[][]): { [name: string]: any } {
const decoded = nip19.decode(env.NULLPOGA_NSEC)
const sk = decoded.data as string
const pk = getPublicKey(sk)
const tt = []
if (mention.kind == 42) {
for (let tag of mention.tags.filter((x: any[]) => x[0] === 'e')) {
tt.push(tag)
}
}
for (let tag of tags) {
tt.push(tag)
}
let event = {
id: '',
kind: mention.kind,
pubkey: pk,
created_at: Math.floor(Date.now() / 1000),
tags: tt,
content: message,
sig: '',
}
event.id = getEventHash(event)
event.sig = signEvent(event, sk)
return event
}
async function doPage(_request: Request, _env: Env): Promise<Response> {
return new Response(page, {
headers: {
'content-type': 'text/html; charset=UTF-8',
},
})
}
async function doNullpo(request: Request, env: Env): Promise<Response> {
if (!bearerAuthentication(request, env.NULLPOGA_GA_TOKEN)) {
return notAuthenticated(request, env)
}
const mention: { [name: string]: any } = await request.json()
return new Response(JSON.stringify(createNoteWithTags(env, mention, 'ぬるぽ', [])), {
headers: {
'content-type': 'application/json; charset=UTF-8',
},
})
}
async function doClock(_request: Request, env: Env): Promise<Response> {
const now = new Date(Date.now() + ((new Date().getTimezoneOffset() + (9 * 60)) * 60 * 1000))
const hour = now.getHours()
const message = 'ぬるぽが' + (hour < 12 ? '午前' : '午後') + (hour % 12) + '時をお伝えします'
return new Response(JSON.stringify(createNoteWithTags(env, { kind: 1, tags: [] }, message, [])), {
headers: {
'content-type': 'application/json; charset=UTF-8',
},
})
}
async function doOchinchinLandStatus(_request: Request, env: Env): Promise<Response> {
const status = (await env.ochinchinland.get('status')) as string
return new Response(JSON.stringify({ "status": status }), {
headers: {
'content-type': 'application/json; charset=UTF-8',
'access-control-allow-origin': '*',
},
})
}
async function doSuitou(request: Request, env: Env): Promise<Response> {
const mention: { [name: string]: any } = await request.json()
return new Response(JSON.stringify(createReplyWithTags(env, mention, 'えらい!', [])), {
headers: {
'content-type': 'application/json; charset=UTF-8',
},
})
}
async function doIgyo(request: Request, env: Env): Promise<Response> {
const mention: { [name: string]: any } = await request.json()
let tags = [['emoji', 'igyo', 'https://i.gyazo.com/6ca054b84392b4b1bd0038d305f72b64.png']]
return new Response(JSON.stringify(createReplyWithTags(env, mention, ':igyo:', tags)), {
headers: {
'content-type': 'application/json; charset=UTF-8',
},
})
}
async function doLetterpack(request: Request, env: Env): Promise<Response> {
const mention: { [name: string]: any } = await request.json()
return new Response(JSON.stringify(createReplyWithTags(env, mention, 'https://i.gyazo.com/d3d5ab0007253e060482e52e5734d402.png', [])), {
headers: {
'content-type': 'application/json; charset=UTF-8',
},
})
}
async function doUltrasoul(request: Request, env: Env): Promise<Response> {
const mention: { [name: string]: any } = await request.json()
return new Response(JSON.stringify(createReplyWithTags(env, mention, 'ウルトラソゥ!', [])), {
headers: {
'content-type': 'application/json; charset=UTF-8',
},
})
}
async function doHi(request: Request, env: Env): Promise<Response> {
const content = Math.floor(Math.random() * 1000) === 0 ? 'なんやねん' : '\ハーイ!🙌/'
const mention: { [name: string]: any } = await request.json()
return new Response(JSON.stringify(createNoteWithTags(env, mention, content, [])), {
headers: {
'content-type': 'application/json; charset=UTF-8',
},
})
}
export interface bookmark {
pattern: RegExp;
site: string;
}
const bookmarks: bookmark[] = [
{ pattern: /^おいくらsats$|^おいくらサッツ$/i, site: 'https://lokuyow.github.io/sats-rate/' },
{ pattern: /^ぶくまびぅあ$|ブックマーク/i, site: 'https://nostr-bookmark-viewer3.vercel.app/' },
{ pattern: /^nostrends$|トレンド/i, site: 'https://nostrends.vercel.app/' },
{ pattern: /^nostrbuzzs$|buzz/i, site: 'https://nostrbuzzs.deno.dev/' },
{ pattern: /^nosli$|^かまくらさんのアレ$|^鎌倉さんのアレ$|togetterみたいな/i, site: 'https://nosli.vercel.app/' },
{ pattern: /^のぞき窓$|^のぞきまど$/i, site: 'https://relay-jp.nostr.wirednet.jp/index.html' },
{ pattern: /^検索ポータル$/i, site: 'https://nostr.hoku.in/' },
{ pattern: /^検索$/i, site: 'https://nosey.vercel.app (鎌倉)\nhttps://search.yabu.me (いくらどん)\nhttps://showhyuga.pages.dev/utility/nos_search (ひゅうが)' },
{ pattern: /^nostrflu$|フォローリスト.*再送信/i, site: 'https://heguro.github.io/nostr-following-list-util/' },
{ pattern: /^nostter$|^のすったー$/i, site: 'https://nostter.vercel.app/' },
{ pattern: /^rabbit$/i, site: 'https://syusui-s.github.io/rabbit/' },
{ pattern: /^絵文字パック$|絵文字/i, site: 'https://emojis-iota.vercel.app/' },
{ pattern: /^イベントチェッカー$|チェッカー/i, site: 'https://koteitan.github.io/nostr-post-checker/' },
{ pattern: /^イベント削除$|削除/i, site: 'https://nostr-delete.vercel.app/' },
{ pattern: /^流速$|^観測所$|^野須田川観測所$|^野洲田川定点観測所$/i, site: 'https://nostr-hotter-site.vercel.app/' },
{ pattern: /^のさらい$|^おさらい$|^たいむましん$|^かすてらふぃさんのアレ$/i, site: 'https://nosaray.vercel.app/' },
]
async function doWhere(request: Request, env: Env): Promise<Response> {
const mention: { [name: string]: any } = await request.json()
let content = '' + mention.content.replace(/どこ[??]*$/, '').trim()
for (const b of bookmarks) {
if (content.match(b.pattern)) {
return new Response(JSON.stringify(createReplyWithTags(env, mention, b.site, [])), {
headers: {
'content-type': 'application/json; charset=UTF-8',
},
})
}
}
return new Response('')
}
async function doOnlyYou(request: Request, env: Env): Promise<Response> {
const mention: { [name: string]: any } = await request.json()
const tags = mention.tags.filter((x: any[]) => x[0] === 'emoji')
let content = mention.content.trim()
content = content
.replace(/^みんな(?:\s*)(.*)(?:\s*)てる[??!!.]*$/s, '$1てないのお前だけ')
.replace(/^みんな(?:\s*)(.*)(?:\s*)でる[??!!.]*$/s, '$1でないのお前だけ')
.replace(/^みんな(?:\s*)(.*)(?:\s*)いる[??!!.]*$/s, '$1いないのお前だけ')
.replace(/^みんな(?:\s*)(.*)(?:\s*)てない[??!!.]*$/s, '$1てるのお前だけ')
.replace(/^みんな(?:\s*)(.*)(?:\s*)でない[??!!.]*$/s, '$1でるのお前だけ')
.replace(/^みんな(?:\s*)(.*)(?:\s*)てへん[??!!.]*$/s, '$1てんのお前だけ')
.replace(/^みんな(?:\s*)(.*)(?:\s*)でへん[??!!.]*$/s, '$1でんのお前だけ')
return new Response(JSON.stringify(createReplyWithTags(env, mention, content, tags)), {
headers: {
'content-type': 'application/json; charset=UTF-8',
},
})
}
async function doNullpoGa(request: Request, env: Env): Promise<Response> {
if (!bearerAuthentication(request, env.NULLPOGA_GA_TOKEN)) {
return notAuthenticated(request, env)
}
const mention: { [name: string]: any } = await request.json()
let content = '' + mention.content
if (!content.match(/^ぬ[ぬるぽっー\n]+$/) || !content.match(/る/) || !content.match(/ぽ/)) {
return new Response('')
}
content = content.replaceAll('ぬ', 'ガ').replaceAll('る', 'ッ').replaceAll('ぽっ', 'ガッ').replaceAll('ーぽ', 'ーガッ').replaceAll('ー', 'ー').replaceAll('っ', 'ッ').replaceAll(/ッ+/g, 'ッ').replaceAll('ぽ', '')
return new Response(JSON.stringify(createReplyWithTags(env, mention, content, [])), {
headers: {
'content-type': 'application/json; charset=UTF-8',
},
})
}
async function doTsurupoVa(request: Request, env: Env): Promise<Response> {
if (!bearerAuthentication(request, env.NULLPOGA_VA_TOKEN)) {
return notAuthenticated(request, env)
}
const mention: { [name: string]: any } = await request.json()
let content = '' + mention.content
if (!content.match(/^つ[つるぽっー\n]+$/) || !content.match(/る/) || !content.match(/ぽ/)) {
return new Response('')
}
content = content.replaceAll('つ', 'ヴァ').replaceAll('る', 'ッ').replaceAll('ぽっ', 'ヴァッ').replaceAll('ーぽ', 'ーヴァッ').replaceAll('ー', 'ー').replaceAll('っ', 'ッ').replaceAll(/ッ+/g, 'ッ').replaceAll('ぽ', '')
return new Response(JSON.stringify(createReplyWithTags(env, mention, content, [])), {
headers: {
'content-type': 'application/json; charset=UTF-8',
},
})
}
async function doNattoruyarogai(request: Request, env: Env): Promise<Response> {
const mention: { [name: string]: any } = await request.json()
let content = '' + mention.content
if (!content.match(/そうはならんやろ/)) {
return new Response('')
}
return new Response(JSON.stringify(createReplyWithTags(env, mention, 'なっとるやろがい!!', [])), {
headers: {
'content-type': 'application/json; charset=UTF-8',
},
})
}
const pai = '🀀🀁🀂🀃🀄🀅🀆🀇🀈🀉🀊🀋🀌🀍🀎🀏🀐🀑🀒🀓🀔🀕🀖🀗🀘🀙🀚🀛🀜🀝🀞🀟🀠🀡'
//const pai = '東南西北白発中一二三四五六七八九123456789①②③④⑤⑥⑦⑧⑨'
async function doMahjongPai(request: Request, env: Env): Promise<Response> {
const mention: { [name: string]: any } = await request.json()
const content = Array.from(pai.repeat(4))
.map(v => ({ v, sort: Math.random() }))
.sort((a, b) => a.sort - b.sort).map(({ v }) => v)
.slice(0, 14).sort().join('')
return new Response(JSON.stringify(createReplyWithTags(env, mention, content, [])), {
headers: {
'content-type': 'application/json; charset=UTF-8',
},
})
};
async function doSuddendeanth(request: Request, env: Env): Promise<Response> {
const mention: { [name: string]: any } = await request.json()
const tags = mention.tags.filter((x: any[]) => x[0] === 'emoji')
return new Response(JSON.stringify(createReplyWithTags(env, mention, suddendeath(mention.content, true), tags)), {
headers: {
'content-type': 'application/json; charset=UTF-8',
},
})
};
async function doLoginbonus(request: Request, env: Env): Promise<Response> {
if (!bearerAuthentication(request, env.NULLPOGA_LOGINBONUS_TOKEN)) {
return notAuthenticated(request, env)
}
const mention: { [name: string]: any } = await request.json()
return new Response(JSON.stringify(createReplyWithTags(env, mention, 'ありません', [])), {
headers: {
'content-type': 'application/json; charset=UTF-8',
},
})
}
async function doNagashite(request: Request, env: Env): Promise<Response> {
const mention: { [name: string]: any } = await request.json()
const m = mention.content.match(/流して(\s+.*)$/)
const wave = m ? m[1].trim() : '🌊🌊🌊🌊🌊🌊🌊🌊'
const tags = mention.tags.filter((x: any[]) => x[0] === 'emoji')
return new Response(JSON.stringify(createNoteWithTags(env, mention, (wave + '\n').repeat(12), tags)), {
headers: {
'content-type': 'application/json; charset=UTF-8',
},
})
}
async function doLokuyow(request: Request, env: Env): Promise<Response> {
const icons = [
'hutu.png',
'hutu-2.png',
'hutu-up.png',
'huhe.png',
'nita.png',
'maji.png',
'bero.png',
'bero-ai.png',
'basu.png',
'kowa.png',
'kowa2.png',
'kowa2-ai.png',
'nita0.png',
'ike2.png',
'tiku.png',
'tiku2.png',
'mono.png',
'note13kmrhvkpnqk3tkg4z4x7527aqejqg90vk8hwe38khmd9hn29lcwsr5qxaj.jpg',
'note18aqm9p750934wyswmhfrdu93tnexrn6s62ser2fdlgs3xw7pc6csegutl2.jpg',
'note1x4sau4fqg7yg5l639x3d9yahhczmhvzgg6sc9adzttc2uqer4faqvx5p7q.jpg',
'note14x0c3vwz47ht4vnuvd0wxc5l8az2k09z4hx2hmw4zcgwz26nd9lsrr6f68.jpg',
'note10z20nh6k3cawg6d2alqdytqct5rud897l0eplv930zkzpt4k6zqs96lr8q.jpg',
'note1myxhqt5p3sc477h3fw7qfjgv37rx05cuj5yfj0y7u59yjszjjxgsczz76w.jpg',
'note1pju99k0jwhw3dftr4a2fk0kj5yaackklgaxx0tr9tstthnzkygwqyufrqg.jpg',
]
const item = '#ロクヨウ画像\n' + 'https://raw.githubusercontent.com/Lokuyow/Lokuyow.github.io/main/icon/' + icons[Math.floor(Math.random() * icons.length)]
const mention: { [name: string]: any } = await request.json()
const tags = [['t', 'ロクヨウ画像']]
return new Response(JSON.stringify(createReplyWithTags(env, mention, item, tags)), {
headers: {
'content-type': 'application/json; charset=UTF-8',
},
})
}
function levenshtein(a: string, b: string): number {
const an = a ? a.length : 0;
const bn = b ? b.length : 0;
if (an === 0) return bn;
if (bn === 0) return an;
const matrix = new Array<number[]>(bn + 1);
for (let i = 0; i <= bn; ++i) {
let row = matrix[i] = new Array<number>(an + 1);
row[0] = i;
}
const firstRow = matrix[0];
for (let j = 1; j <= an; ++j) {
firstRow[j] = j;
}
for (let i = 1; i <= bn; ++i) {
for (let j = 1; j <= an; ++j) {
if (b.charAt(i - 1) === a.charAt(j - 1)) {
matrix[i][j] = matrix[i - 1][j - 1];
} else {
matrix[i][j] = Math.min(
matrix[i - 1][j - 1],
matrix[i][j - 1],
matrix[i - 1][j]
) + 1;
}
}
}
return matrix[bn][an];
}
async function doDistance(request: Request, env: Env): Promise<Response> {
const mention: { [name: string]: any } = await request.json()
let content = '' + mention.content;
let m = content.match(/^"(\S+)"と"(\S+)"の文字列距離$/)
if (!m) m = content.match(/^「(\S+)」と「(\S+)」の文字列距離$/)
if (!m) m = content.match(/^(\S+)\s*と\s*(\S+)\s*の文字列距離$/)
if (!m) return new Response('')
return new Response(JSON.stringify(createReplyWithTags(env, mention, `${levenshtein(m[1], m[2])}です`, [])), {
headers: {
'content-type': 'application/json; charset=UTF-8',
},
})
}
async function doLike(request: Request, env: Env): Promise<Response> {
const mention: { [name: string]: any } = await request.json()
return new Response(JSON.stringify(createLike(env, mention)), {
headers: {
'content-type': 'application/json; charset=UTF-8',
},
})
}
async function doPe(request: Request, env: Env): Promise<Response> {
const mention: { [name: string]: any } = await request.json()
return new Response(JSON.stringify(createNoteWithTags(env, mention, 'ぺぇ〜', [])), {
headers: {
'content-type': 'application/json; charset=UTF-8',
},
})
}
async function doNya(request: Request, env: Env): Promise<Response> {
const mention: { [name: string]: any } = await request.json()
let content = [' A__A', '|・ㅅ・ |', '|っ c|', ''].join('\n')
let arr = mention.content.replace(/にゃ!$/, '').split(/(:[^:]+:)/g).map((x: string) => {
if (/^(:[^:]+:)$/.test(x)) return [x]
//return [...x.replace(/[A-Za-z0-9]/g, (s) => String.fromCharCode(s.charCodeAt(0) + 0xFEE0)).replace(/[ー〜]/g, '|')]
return runes(x.replace(/[A-Za-z0-9]/g, (s) => String.fromCharCode(s.charCodeAt(0) + 0xFEE0)).replace(/[ー〜]/g, '|'))
}).flat()
for (const c of arr) {
if (c == '' || c === '\n' || c === '\t' || c === ' ') continue
const isW = ['F', 'W', 'A', 'N'].includes(eaw.eastAsianWidth(c))
content += '| ' + (isW ? c : c + ' ') + ' |\n'
}
content += [' U ̄ ̄U'].join('\n')
const tags = mention.tags.filter((x: any[]) => x[0] === 'emoji')
return new Response(JSON.stringify(createReplyWithTags(env, mention, content, tags)), {
headers: {
'content-type': 'application/json; charset=UTF-8',
},
})
}
async function doOchinchinLand(request: Request, env: Env): Promise<Response> {
const mention: { [name: string]: any } = await request.json()
const tags = mention.tags.filter((x: any[]) => x[0] === 'emoji')
let content = ''
if (mention.content.match(/[??]$/)) {
const status = (await env.ochinchinland.get('status')) as string
content = status === 'open' ? '開園中' : '閉園中'
} else if (mention.content.match(/開閉[!!]*$/)) {
await env.ochinchinland.put('status', 'close')
content = 'https://cdn.nostr.build/i/f6103329b41603af2b36ec0131d27dd39d28ca1ddeb0041cd2839e5954563a92.jpg'
} else if (mention.content.match(/閉園[!!]*$/)) {
await env.ochinchinland.put('status', 'close')
content = 'https://cdn.nostr.build/i/4a7963a07bdac34b1408b871548d3a06527af359ad5a9f080d3c2031f6e582fe.jpg'
} else if (mention.content.match(/開園[!!]*$/)) {
await env.ochinchinland.put('status', 'open')
content = 'https://cdn.nostr.build/i/662dab3ac355c5b2e8682f10eef4102342599bf8f77b52e9c7a7a52153398bfd.jpg'
} else {
return new Response('')
}
return new Response(JSON.stringify(createReplyWithTags(env, mention, content, tags)), {
headers: {
'content-type': 'application/json; charset=UTF-8',
},
})
}
async function doWakaru(request: Request, env: Env): Promise<Response> {
const mention: { [name: string]: any } = await request.json()
const tags = mention.tags.filter((x: any[]) => x[0] === 'emoji')
const content = mention.content.match(/^[わ分]かる[!!]*$/) ?
'https://cdn.nostr.build/i/f795a1ba2802c5b397cb538d0068da2deb6e7510d8cfff877e5561a15d55199b.jpg' :
'https://cdn.nostr.build/i/fd99d078ba96f85b5e3f754e1aeef5f42dbf3312b5a345c5f3ea6405ce2980a7.jpg'
return new Response(JSON.stringify(createReplyWithTags(env, mention, content, tags)), {
headers: {
'content-type': 'application/json; charset=UTF-8',
},
})
}
const hakatano = new Map([
['裸に', 'しろ'],
['はだかに', 'しろ'],
['たかなわ', 'ゲートウェイ'],
['たかだの', 'ばば'],
['さかたと', 'しお'],
['かけいと', 'しお'],
['もりもと', 'れお'],
['とみーず', 'まさ'],
['おかもと', 'まよ'],
['まつもと', 'いよ'],
['みわあき', 'ひろ'],
['あたたた', 'たた'],
['はやしら', 'いす'],
['あるかの', 'いど'],
['はがたを', 'みろ'],
['はかたの', 'しお'],
])
async function doHakatano(request: Request, env: Env): Promise<Response> {
const mention: { [name: string]: any } = await request.json()
const tags = mention.tags.filter((x: any[]) => x[0] === 'emoji')
const content = mention.content.replace(/っ/g, '').replace(/[!!]/g, '').trim()
for (const [k, v] of hakatano) {
if (content === k) {
return new Response(JSON.stringify(createReplyWithTags(env, mention, v, tags)), {
headers: {
'content-type': 'application/json; charset=UTF-8',
},
})
}
}
return new Response('')
}
async function doSUUMO(request: Request, env: Env): Promise<Response> {
const mention: { [name: string]: any } = await request.json()
const content = '🌚ダン💥ダン💥ダン💥シャーン🎶ぽわ🌝ぽわ🌚ぽわ🌝ぽわ🌚ぽわ🌝ぽわ🌚ぽ〜〜〜わ⤴ぽわ🌚ぽわ🌝ぽわ🌚ぽわ🌝ぽわ🌚ぽわ🌝ぽ~~~わ⤵🌞'
return new Response(JSON.stringify(createNoteWithTags(env, mention, content, [])), {
headers: {
'content-type': 'application/json; charset=UTF-8',
},
})
}
async function doCAT(request: Request, env: Env): Promise<Response> {
const mention: { [name: string]: any } = await request.json()
if (mention.pubkey === NULLPOGA_NPUB) return new Response('')
let res = await fetch('https://api.thecatapi.com/v1/images/search')
const images: { [name: string]: any } = await res.json()
const tags = [['t', 'ぬっこ画像']]
return new Response(JSON.stringify(createReplyWithTags(env, mention, `#ぬっこ画像\n${images[0].url}`, tags)), {
headers: {
'content-type': 'application/json; charset=UTF-8',
},
})
}
async function doDOG(request: Request, env: Env): Promise<Response> {
const mention: { [name: string]: any } = await request.json()
if (mention.pubkey === NULLPOGA_NPUB) return new Response('')
let res = await fetch('https://api.thedogapi.com/v1/images/search')
const images: { [name: string]: any } = await res.json()
const tags = [['t', 'いっぬ画像']]
return new Response(JSON.stringify(createReplyWithTags(env, mention, `#いっぬ画像\n${images[0].url}`, tags)), {
headers: {
'content-type': 'application/json; charset=UTF-8',
},
})
}
export default {
async fetch(
request: Request,
env: Env): Promise<Response> {
const { protocol, pathname } = new URL(request.url)
if ('https:' !== protocol || 'https' !== request.headers.get('x-forwarded-proto')) {
throw new Error('Please use a HTTPS connection.')
}
console.log(`${request.method}: ${request.url}`)
if (request.method === 'GET') {
switch (pathname) {
case '/nullpo':
return doNullpo(request, env)
case '/ochinchinland':
return doOchinchinLandStatus(request, env)
case '/clock':
return doClock(request, env)
case '/':
return doPage(request, env)
}
return notFound(request, env)
}
if (request.method === 'POST') {
switch (pathname) {
case '/loginbonus':
return doLoginbonus(request, env)
case '/lokuyow':
return doLokuyow(request, env)
case '/tsurupo':
return doTsurupoVa(request, env)
case '/nagashite':
return doNagashite(request, env)
case '/nattoruyarogai':
return doNattoruyarogai(request, env)
case '/suddendeath':
return doSuddendeanth(request, env)
case '/mahjongpai':
return doMahjongPai(request, env)
case '/onlyyou':
return doOnlyYou(request, env)
case '/suitou':
return doSuitou(request, env)
case '/igyo':
return doIgyo(request, env)
case '/letterpack':
return doLetterpack(request, env)
case '/ultrasoul':
return doUltrasoul(request, env)
case '/hi':
return doHi(request, env)
case '/where':
return doWhere(request, env)
case '/distance':
return doDistance(request, env)
case '/like':
return doLike(request, env)
case '/pe':
return doPe(request, env)
case '/nya':
return doNya(request, env)
case '/ochinchinland':
return doOchinchinLand(request, env)
case '/wakaru':
return doWakaru(request, env)
case '/hakatano':
return doHakatano(request, env)
case '/suumo':
return doSUUMO(request, env)
case '/cat':
return doCAT(request, env)
case '/dog':
return doDOG(request, env)
case '/':
return doNullpoGa(request, env)
}
return notFound(request, env)
}
return unsupportedMethod(request, env)
},
}