/
JCbot.py
818 lines (782 loc) · 38.8 KB
/
JCbot.py
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
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
from mastodon import *
import time, re, sys, os, json, random
import threading, requests, pprint, codecs
from time import sleep
from datetime import datetime
from pytz import timezone
import warnings, traceback
def LTL(status): # から受け取ったtootに対してどうするか追加してね(*'∀'人)
# 以下bot機能の一覧
bot.check01(status)
bot.fav01(status)
bot.res01(status)
bot.res02(status)
bot.res03(status)
bot.check00(status)
bot.check02(status)
game.poem(status)
game.senryu(status)
game.cinema(status)
# ここまで
def HTL(status): # ホームから受け取ったtootに対してどうするか追加してね(*'∀'人)
account = status["account"]
ct = account["statuses_count"]
if account["acct"] == "JC":
path = 'thank\\' + account["acct"] + '.txt'
if os.path.exists(path):
f = open(path, 'r')
x = f.read()
f.close()
ct += 1
if re.match('^\d+000$', str(ct)):
toot_now = "°˖✧◝(⁰▿⁰)◜✧˖" + str(ct) + 'toot達成ーーーー♪♪'
g_vis = "public"
bot.rets(4, toot_now, g_vis)
else:
bot.check03(status)
def MEN(status): # メンション通知に対してどうするか追加してね(*'∀'人)
status = notification["status"]
account = status["account"]
mentions = status["mentions"]
content = unesc(Re1.text(status["content"]))
try:
print("===通知が来ました===")
non_bmp_map = dict.fromkeys(range(0x10000, sys.maxunicode + 1), 0xfffd)
if notification["type"] == "mention":
status = notification["status"]
account = status["account"]
mentions = status["mentions"]
content = unesc(Re1.text(status["content"]))
log = threading.Thread(Log(status).read())
log.run()
bot.thank(account, 64)
if mentions:
if re.compile("おは|おあひょ").search(content):
toot_now = "@" + str(account["acct"]) + " " + "(*'∀'人)おあひょーーーー♪"
g_vis = status["visibility"]
bot.rets(8, toot_now, g_vis, status['id'])
elif re.compile("こんに").search(content):
toot_now = "@" + str(account["acct"]) + " " + "(*'∀'人)こんにちはーーーー♪"
g_vis = status["visibility"]
bot.rets(8, toot_now, g_vis, status['id'])
elif re.compile("こんば").search(content):
toot_now = "@" + str(account["acct"]) + " " + "(*'∀'人)こんばんはーーーー♪"
g_vis = status["visibility"]
bot.rets(8, toot_now, g_vis, status['id'])
elif re.compile("\d+[dD]\d+").search(content):
inp = (re.sub("<span class(.+)</span></a></span>|<p>|</p>", "",
str(status['content']).translate(non_bmp_map)))
result = game.dice(inp)
g_vis = status["visibility"]
toot_now = ":@" + str(account["acct"]) + ": @" + account["acct"] + "\n" + result
bot.rets(5, toot_now, g_vis, status['id'])
elif re.compile("(アラーム|[Aa][Rr][Aa][Mm])(\d+)").search(content):
non_bmp_map = dict.fromkeys(range(0x10000, sys.maxunicode + 1), 0xfffd)
content = str(status['content']).translate(non_bmp_map)
account = status['account']
com = re.search("(アラーム|[Aa][Rr][Aa][Mm])(\d+)([秒分]?)", content)
sec = int(com.group(2))
clo = com.group(3)
if clo == "分":
sec = sec * 60
else:
pass
print(str(sec))
if re.compile("(アラーム|[Aa][Rr][Aa][Mm])(.*)「(.*)」").search(content):
mes = re.search("「(.*)」", content)
toot_now = ("@" + account["acct"] + " " + "(*'∀'人)時間だよーー♪♪\n"
"「" + mes.group(1) + "」")
else:
toot_now = "@" + account["acct"] + " " + "(*'∀'人)時間だよーー♪♪"
g_vis = status["visibility"]
in_reply_to_id = status["id"]
t = threading.Timer(sec, bot.toot, [toot_now, g_vis, status['id']])
t.start()
#bot.rets(sec,toot_now, g_vis,status['id'] )
elif re.compile(
"(フォロー|follow)(して|く[うぅー]*ださ[あぁー]*い|お願[あぁー]*い|"
"おねが[あぁー]*い|頼[むみ]|たの[むみ]|ぷりーず|プリーズ|please)").search(
content):
mastodon.account_follow(account["id"])
toot_now = "@" + account["acct"] + " " + "(*'∀'人)フォローしました♪♪"
g_vis = status["visibility"]
in_reply_to_id = status["id"]
bot.rets(8, toot_now, g_vis, status['id'])
elif re.compile("(こそこそ)<br />(.+)").search(content): # 悪用されないように変えてます
if status["visibility"] == "direct":
print("○受け取りました")
com = re.search("(こそこそ).*<br />(.+)", str(content))
messe = com.group(2)
toot_now = messe
g_vis = "public"
bot.rets(1, toot_now, g_vis)
elif re.compile("連想ゲーム開始").search(content):
if rensou_time:
toot_now = ("@" + account["acct"] + " "
+ "(*'∀'人)ごめんね、今開催中なの♪♪")
g_vis = status["visibility"]
in_reply_to_id = status["id"]
bot.rets(5, toot_now, g_vis, status['id'])
else:
t = threading.Timer(0, game.rensou)
t.start()
rensou_time = True
elif account["acct"] == "twotwo":
if re.compile("").search(content):
pass
else:
pass
v = threading.Timer(5, bot.fav_now,[status["id"]])
v.start()
elif notification["type"] == "favourite":
account = notification["account"]
print(str(account["display_name"]).translate(non_bmp_map) + "@" + str(
account["acct"]) + "からニコってくれたよ₍₍ ◝(●˙꒳˙●)◜ ₎₎")
print()
bot.thank(account, 32)
print("---")
elif notification["type"] == "reblog":
account = notification["account"]
print(str(account["display_name"]).translate(non_bmp_map) + "@" + str(
account["acct"]) + "がブーストしてくれたよ(๑˃́ꇴ˂̀๑)")
print()
bot.thank(account, 32)
print("---")
pass
except Exception as e:
print("エラー情報【USER】\n" + traceback.format_exc())
with open('error.log', 'a') as f:
traceback.print_exc(file=f)
pass
class bot():
def _init_(self):
self.n_sta = None
def res(sec):
count.end = count.end - sec
if count.end < 0:
count.end = 0
def rets(sec, toot_now, g_vis, rep=None, spo=None):
now = time.time()
delay = now - count.CT
loss = count.end - int(delay)
if loss < 0:
loss = 0
sec = sec + loss
t = threading.Timer(sec, bot.toot, [toot_now, g_vis, rep, spo])
t.start()
print("【次までのロスタイム:" + str(count.end + sec) + "】")
s = threading.Timer(sec, bot.res, [sec])
s.start()
count.CT = time.time()
count.end = count.end + sec
def toot(toot_now, g_vis, rep=None, spo=None):
mastodon.status_post(status=toot_now, visibility=g_vis, in_reply_to_id=rep, spoiler_text=spo)
print("【次までのロスタイム:" + str(count.end) + "】")
"""visibility これで公開範囲を指定できるよ!: public, unlisted, private, direct"""
def standby():
print("「(๑•̀ㅁ•́๑)✧<tootステンバーイ」")
def block01(status):
f = codecs.open("NG\sekuhara.txt", 'r', 'utf-8')
l = []
for x in f:
l.append(x.rstrip("\r\n"))
f.close()
m = len(l)
for x in range(m):
if re.compile(str(l[x])).search(re.sub("<p>|</p>", "", str(status))):
j = True
print(str(l[x]))
# bot.thank(account, -64)
break
else:
j = False
return j
def res07(status):
account = status["account"]
if account['acct'] != "kiri_bot01":
if account["acct"] != "JC":
if re.compile("ももな(.*)[1-5][dD]\d+").search(status['content']):
print("○hitしました♪")
non_bmp_map = dict.fromkeys(range(0x10000, sys.maxunicode + 1), 0xfffd)
coro = (re.sub("<p>|</p>", "", str(status['content']).translate(non_bmp_map)))
toot_now = ":@" + account["acct"] + ": @" + account["acct"] + "\n" + game.dice(coro)
g_vis = status["visibility"]
bot.rets(5, toot_now, g_vis)
elif re.compile("ももな(.*)([6-9]|\d{2})[dD](\d*)").search(status['content']):
toot_now = "6回以上の回数は畳む内容だからメンションの方で送ってーー!!"
g_vis = status["visibility"]
bot.rets(6, toot_now, g_vis)
def check00(status):
account = status["account"]
ct = account["statuses_count"]
path = 'thank\\' + account["acct"] + '.txt'
if os.path.exists(path):
f = open(path, 'r')
x = f.read()
f.close()
if int(x) >= -10:
if account["acct"] == "JC":
ct += 1
if re.match('^\d+000$', str(ct)):
toot_now = "°˖✧◝(⁰▿⁰)◜✧˖" + str(ct) + 'toot達成ーーーー♪♪'
g_vis = "public"
bot.rets(4, toot_now, g_vis)
else:
if re.match('^\d+0000$', str(ct)):
toot_now = " :@" + account['acct'] + ": @" + account['acct'] + "\n°˖✧◝(⁰▿⁰)◜✧˖" + str(
ct) + 'tootおめでとーーーー♪♪'
g_vis = "public"
bot.rets(4, toot_now, g_vis)
elif re.match('^\d000$', str(ct)):
toot_now = " :@" + account['acct'] + ": @" + account['acct'] + "\n(*'∀'人)" + str(ct) + 'tootおめでとーー♪'
g_vis = "public"
bot.rets(4, toot_now, g_vis)
if account["acct"] == "lamazeP": # ラマーズP監視隊
ct += 5
if re.match('^\d+000$', str(ct)):
toot_now = "@lamazeP (๑•̀ㅁ•́๑)" + str(ct) + 'tootまであと5だよ!!!!'
g_vis = "direct"
bot.rets(4, toot_now, g_vis)
else:
pass
def check03(status):
account = status["account"]
ct = account["statuses_count"]
if account["acct"] == "Knzk": # 神崎おにいさん監視隊
ct += 5
if re.match('^\d+000$', str(ct)):
toot_now = "@yzhsn (๑•̀ㅁ•́๑)神崎おにいさん!!\n" + str(ct) + 'tootまであと5だよ!!!!'
g_vis = "direct"
bot.rets(4, toot_now, g_vis)
if account["acct"] == "5": # やなちゃん監視隊
ct += 5
if re.match('^\d+000$', str(ct)):
toot_now = "@5 (๑•̀ㅁ•́๑)やなちゃん!!\n" + str(ct) + 'tootまであと5だよ!!!!'
g_vis = "direct"
bot.rets(4, toot_now, g_vis)
if account["acct"] == "yzhsn": # 裾野監視隊
ct += 5
if re.match('^\d+000$', str(ct)):
toot_now = "@yzhsn (๑•̀ㅁ•́๑)おい裾野!!\n" + str(ct) + 'tootまであと5だよ!!!!'
g_vis = "direct"
bot.rets(4, toot_now, g_vis)
if account["acct"] == "lamazeP": # ラマーズP監視隊
ct += 5
if re.match('^\d+000$', str(ct)):
toot_now = "@lamazeP (๑•̀ㅁ•́๑)" + str(ct) + 'tootまであと5だよ!!!!'
g_vis = "direct"
bot.rets(4, toot_now, g_vis)
else: # テスト
ct += 5
if re.match('^\d+000$', str(ct)):
toot_now = "@" + account["acct"] + " (๑•̀ㅁ•́๑)ただいまフォローしてる方にテスト中!\n" + str(
ct) + 'tootまであと5だよ!!!!'
g_vis = "direct"
bot.rets(4, toot_now, g_vis)
def res01(status):
account = status["account"]
content = re.sub("<p>|</p>", "", str(status['content']))
path = 'thank\\' + account["acct"] + '.txt'
if os.path.exists(path):
f = open(path, 'r')
x = f.read()
f.close()
if int(x) >= -10:
if account["acct"] != "JC":
if count.timer_hello == 0:
if re.compile("ももな(.*)おは|ももな(.*)おあひょ").search(content):
print("○hitしました♪")
print("○あいさつします(*'∀'人)")
toot_now = "(๑•̀ㅁ•́๑)✧おはありでーーーーす♪"
g_vis = "public"
bot.rets(20, toot_now, g_vis)
count.timer_hello = 1
else:
if re.compile("[寝ね](ます|る|マス)(.*)[ぽお]や[すし]|ももな(.*)[ぽお]や[すし]").search(content):
if not re.compile("[寝ね]る(人|ひと)").search(status['content']):
print("○hitしました♪")
print("○おやすみします(*'∀'人)")
if account['acct'] == "5": # やなちゃん専用挨拶
print("○やなちゃんだ!!(*'∀'人)")
toot_now = ":@" + account[
'acct'] + ":" + "やなちゃん!!!!!!" + "\n" + '(。>﹏<。)あとで一緒に寝るーーーー!!!!'
else:
toot_now = ":@" + account['acct'] + ":" + account[
'display_name'] + "\n" + '(ृ ु *`ω、)ु ⋆゜おやすみーーーー♪'
g_vis = "public"
bot.rets(5, toot_now, g_vis)
elif re.compile(
"[いイ行逝]って(くる|きます|[きキ]マストドン)|出かけて(くる|きま[あぁー]*す|[きキ]マストドン)|おでかけ(する|しま[あぁー]*す|[しシ]マストドン)|(出勤|離脱|しゅっきん|りだつ)(する|しま[あぁー]*す|[しシ]マストドン)|^(出勤|離脱)$|(.+)して(くる|きま[あぁー]*す|[きキ]マストドン)([ー~!。よぞね]|$)").search(
content):
print("○hitしました♪")
print("○見送ります(*'∀'人)")
if account['acct'] == "5": # やなちゃん専用挨拶
print("○やなちゃんだ!!(*'∀'人)")
toot_now = ":@" + account['acct'] + ":" + "やなちゃん!!!!!!" + "\n" + '(*>_<*)ノいってらいってらーーーー!!!!'
else:
toot_now = ":@" + account['acct'] + ":" + account['display_name'] + "\n" + 'いってらーーーー!!'
g_vis = "public"
bot.rets(5, toot_now, g_vis)
elif re.compile("ただいま|ただいマストドン|(おうち|家).*([着つ]いた|帰った|帰ってきた)").search(content):
print("○hitしました♪")
print("○優しく迎えます(*'∀'人)")
if account['acct'] == "5": # やなちゃん専用挨拶
print("○やなちゃんだ!!(*'∀'人)")
toot_now = ":@" + account['acct'] + ":" + "やなちゃん!!!!!!" + "\n" + '٩(๑❛ᴗ❛๑)۶おかえりおかえりーー!!'
else:
toot_now = ":@" + account['acct'] + ":" + account[
'display_name'] + "\n" + '( 〃 ❛ᴗ❛ 〃 )おかえりおかえりーー!!'
g_vis = "public"
bot.rets(5, toot_now, g_vis)
else:
try:
f = codecs.open('at_time\\' + account["acct"] + '.txt', 'r', 'UTF-8')
nstr = f.read()
f.close
print(nstr)
tstr = re.sub("\....Z", "", nstr)
last_time = datetime.strptime(tstr, '%Y-%m-%dT%H:%M:%S')
nstr = status['created_at']
tstr = re.sub("\....Z", "", nstr)
now_time = datetime.strptime(tstr, '%Y-%m-%dT%H:%M:%S')
delta = now_time - last_time
print(delta)
if delta.total_seconds() >= 604800:
if account['acct'] == "5": # やなちゃん専用挨拶
print("○やなちゃんだ!!(*'∀'人)")
toot_now = ":@" + account['acct'] + ":" + "やなちゃん!!!!!!" + "\n" + "(*'∀'人)おひさひさーーーー♪"
else:
toot_now = " :@" + account['acct'] + ":\n" + account[
'acct'] + "\n" + "(*'∀'人)おひさひさーーーー♪"
g_vis = "public"
bot.rets(5, toot_now, g_vis)
elif delta.total_seconds() >= 10800:
if now_time.hour in range(3, 9):
to_r = bot.rand_w('time\\kon.txt')
elif now_time.hour in range(9, 19):
to_r = bot.rand_w('time\\kob.txt')
else:
to_r = bot.rand_w('time\\oha.txt')
if account['acct'] == "5": # やなちゃん専用挨拶
print("○やなちゃんだ!!(*'∀'人)")
toot_now = ":@" + account['acct'] + ":" + "やなちゃん!!!!!!" + "\n" + to_r
else:
print("○あいさつします(*'∀'人)")
if account['display_name'] == "":
toot_now = ":@" + account['acct'] + ":" + account['acct'] + "\n" + to_r
else:
toot_now = ":@" + account['acct'] + ":" + account['display_name'] + "\n" + to_r
g_vis = "public"
bot.rets(5, toot_now, g_vis)
except:
print("○初あいさつします(*'∀'人)")
if account['statuses_count'] <= 2:
if account['display_name'] == "":
toot_now = " :@" + account['acct'] + ": @" + account['acct'] + "\n" + account[
'acct'] + "\n" + 'ようこそようこそーーーー♪'
else:
toot_now = " :@" + account['acct'] + ": @" + account['acct'] + "\n" + account[
'display_name'] + "\n" + 'ようこそようこそーーーー♪'
else:
if account['display_name'] == "":
toot_now = " :@" + account['acct'] + ": @" + account['acct'] + "\n" + 'いらっしゃーーーーい♪'
else:
toot_now = " :@" + account['acct'] + ": @" + account['acct'] + "\n" + 'いらっしゃーーーーい♪'
g_vis = "public"
bot.rets(5, toot_now, g_vis)
else:
print("○反応がない人なので挨拶しません(*'∀'人)")
def res06(status):
account = status["account"]
content = Re1.text(status["content"])
if account["acct"] != "JC":
if re.compile("(.+)とマストドン(どちら|どっち)が大[切事]か[分わ]かってない").search(content):
print("○hitしました♪")
sekuhara = bot.block01(status)
if len(content) > 60:
toot_now = "٩(๑`^´๑)۶長い!!!!!!"
g_vis = "public"
bot.rets(5, toot_now, g_vis)
else:
if not sekuhara:
print("○だったら")
toot_now = ":@" + account["acct"] + ":" + (
re.sub('<span(.+)span>|<p>|とマストドン(.*)', "", str(content))) + "しながらマストドンして❤"
g_vis = "public"
bot.rets(5, toot_now, g_vis)
else:
toot_now = "そんなセクハラ分かりません\n(* ,,Ծ‸Ծ,, )プー"
g_vis = "public"
bot.rets(5, toot_now, g_vis)
def fav01(status):
account = status["account"]
if re.compile("ももな|:@JC:").search(status['content']):
bot.n_sta = status
bot.thank(account, 8)
v = threading.Timer(5, bot.fav_now)
v.start()
def check01(status):
account = status["account"]
created_at = status['created_at']
non_bmp_map = dict.fromkeys(range(0x10000, sys.maxunicode + 1), 0xfffd)
f = codecs.open('acct\\' + account["acct"] + '.txt', 'w', 'UTF-8') # 書き込みモードで開く
f.write(str(status["account"]).translate(non_bmp_map)) # アカウント情報の更新
f.close() # ファイルを閉じる
path = 'thank\\' + account["acct"] + '.txt'
if os.path.exists(path):
f = open(path, 'r')
x = f.read()
print("現在の評価値:" + str(x))
f.close()
else:
f = open(path, 'w')
f.write("0")
f.close() # ファイルを閉じる
def check02(status):
account = status["account"]
created_at = status['created_at']
f = codecs.open('at_time\\' + account["acct"] + '.txt', 'w', 'UTF-8') # 書き込みモードで開く
f.write(str(status["created_at"])) # \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z
f.close() # ファイルを閉じる
def thank(account, point):
path = 'thank\\' + account["acct"] + '.txt'
if os.path.exists(path):
f = open(path, 'r')
x = f.read()
y = int(x)
y += point
f.close()
f = open(path, 'w')
f.write(str(y))
f.close()
print("現在の評価値:" + str(y))
else:
f = open(path, 'w')
f.write(str(point))
f.close() # ファイルを閉じる
print("現在の評価値:" + str(0))
def fav_now(): # ニコります
fav = bot.n_sta["id"]
mastodon.status_favourite(fav)
print("◇Fav")
def rand_w(txt_deta):
f = codecs.open(txt_deta, 'r', 'utf-8')
l = []
for x in f:
l.append(x.rstrip("\r\n").replace('\\n', '\n'))
f.close()
m = len(l)
s = random.randint(1, m)
return l[s - 1]
def t_local():
try:
listener = res_toot()
mastodon.local_stream(listener)
except:
print("例外情報\n" + traceback.format_exc())
with open('except.log', 'a') as f:
jst_now = datetime.now(timezone('Asia/Tokyo'))
f.write("【" + str(jst_now) + "】")
traceback.print_exc(file=f)
sleep(180)
bot.t_local()
pass
def t_user():
try:
listener = men_toot()
mastodon.user_stream(listener)
except:
print("例外情報\n" + traceback.format_exc())
with open('except.log', 'a') as f:
jst_now = datetime.now(timezone('Asia/Tokyo'))
f.write("【" + str(jst_now) + "】")
traceback.print_exc(file=f)
sleep(180)
bot.t_user()
pass
class game():
def fav(id):
mastodon.status_favourite(id)
def rensou(status):
"""
toot = bot.toot
toot("٩(๑❛ᴗ❛๑)۶今から連想ゲームを始めます!!", "")
"""
pass
def poem(status):
account = status["account"]
content = Re1.text(status["content"])
if account["acct"] == "twotwo":
if re.compile("トゥトゥトゥトゥートゥ[::]").search(content):
poes = re.search("(トゥトゥトゥ)(トゥートゥ)[::]<br />(.*)", str(content))
Poe = poes.group(3)
if len(content) > 60:
toot_now = "٩(๑`^´๑)۶トゥトゥ!!!!!!"
g_vis = "public"
bot.rets(5, toot_now, g_vis)
else:
Poe = re.sub("<br />", "\\n", Poe)
f = codecs.open('game\\poem_word.txt', 'a', 'UTF-8')
f.write(str(Poe) + " &,@" + account["acct"] + "\r\n")
f.close()
v = threading.Timer(5, game.fav, [status["id"]])
v.start()
elif re.compile("トゥトゥトゥトゥートゥトゥ!").search(content):
f = codecs.open('game\\poem_word.txt', 'r', 'utf-8')
word1 = []
for x in f:
word1.append(x.rstrip("\r\n").replace('\\n', '\n'))
f.close()
m = len(word1)
word2 = []
for x in range(5):
s = random.randint(0, m - 1)
word2.append((word1[s]).split(' &,@'))
poe0 = word2[0]
poe1 = word2[1]
poe2 = word2[2]
poe3 = word2[3]
poe4 = word2[4]
toot_now = poe0[0] + "\n" + poe1[0] + "\n" + poe2[0] + "\n" + poe3[
0] + "\n" + poe4[0] + "\n(by:@" + poe0[1] + ":-:@" + poe1[1] + ":-:@" + poe2[
1] + ":-:@" + poe3[1] + ":-:@" + poe4[1] + ":)\n#ぽえむげーむ"
g_vis = "public"
spo = ":@" + account["acct"] + ":トゥートゥー♪♪"
bot.rets(6, toot_now, g_vis, None, spo)
else:
if re.compile("(ぽえむ|ポエム)(ゲーム|げーむ)[::]").search(content):
poes = re.search("(ぽえむ|ポエム)(ゲーム|げーむ)[::]<br />(.*)", str(content))
Poe = poes.group(3)
Poe = unesc(Poe)
sekuhara = bot.block01(status)
if sekuhara:
toot_now = "٩(๑`^´๑)۶えっちなのはよくない!!!!"
g_vis = "public"
bot.rets(5, toot_now, g_vis)
if len(content) > 60:
toot_now = "٩(๑`^´๑)۶長い!!!!!!"
g_vis = "public"
bot.rets(5, toot_now, g_vis)
else:
Poe = re.sub("<br />", "\\\\n", Poe)
f = codecs.open('game\\poem_word.txt', 'a', 'UTF-8')
f.write(str(Poe) + " &,@" + account["acct"] + "\r\n")
f.close()
v = threading.Timer(5, game.fav, [status["id"]])
v.start()
elif re.compile("ももな.*(ぽえむ|ポエム)(ゲーム|げーむ).*(ひとつ|おねがい|お願い|1つ|一つ)").search(content):
if account["acct"] != "JC":
f = codecs.open('game\\poem_word.txt', 'r', 'utf-8')
word1 = []
for x in f:
word1.append(x.rstrip("\r\n").replace('\\n', '\n'))
f.close()
m = len(word1)
word2 = []
for x in range(5):
s = random.randint(0, m - 1)
word2.append((word1[s]).split(' &,@'))
poe0 = word2[0]
poe1 = word2[1]
poe2 = word2[2]
poe3 = word2[3]
poe4 = word2[4]
toot_now = poe0[0] + "\n" + poe1[0] + "\n" + poe2[0] + "\n" + poe3[
0] + "\n" + poe4[0] + "\n(by:@" + poe0[1] + ":-:@" + poe1[1] + ":-:@" + poe2[
1] + ":-:@" + poe3[1] + ":-:@" + poe4[1] + ":)\n#ぽえむげーむ"
g_vis = "public"
spo = ":@" + account["acct"] + ":にぽえむ♪♪"
bot.rets(6, toot_now, g_vis, None, spo)
def senryu(status):
account = status["account"]
content = Re1.text(status["content"])
if account["acct"] == "twotwo":
if re.compile("トゥートゥートゥートゥ[::]<br />(.+)<br />(.+)<br />(.+)").search(content):
poes = re.search("(トゥートゥー)(トhuゥートゥ)[::]<br />(.+)<br />(.+)<br />(.+)", str(content))
sen1 = poes.group(3)
sen2 = poes.group(4)
sen3 = poes.group(5)
if len(sen1) > 6 or len(sen2) > 8 or len(sen3) > 6:
pass
else:
f = codecs.open('game\\senryu_word.txt', 'a', 'UTF-8')
f.write(unesc(sen1) + ">>>" + unesc(sen2) + ">>>" + unesc(sen3) + ">>>" + account["acct"] + "\r\n")
f.close()
v = threading.Timer(5, game.fav, [status["id"]])
v.start()
elif re.compile("トゥトゥトゥ-トゥートゥ!").search(content):
f = codecs.open('game\\senryu_word.txt', 'r', 'utf-8')
word1 = []
for x in f:
word1.append(x.rstrip("\r\n").replace('\\n', '\n'))
f.close()
m = len(word1)
word2 = []
for x in range(4):
s = random.randint(0, m - 1)
word2.append((word1[s]).split('>>>'))
h0 = word2[0]
h1 = word2[1]
h2 = word2[2]
h3 = word2[3]
toot_now = h0[0] + "\n" + h1[1] + "\n" + h2[2] + "\n(作者::@" + h3[3] + ":)\n:@" + account[
"acct"] + ":トゥートゥトゥトゥートゥ❤\n#川柳げーむ"
g_vis = "public"
bot.rets(6, toot_now, g_vis)
else:
if re.compile("(せんりゅう|川柳)(ゲーム|げーむ)[::]<br />(.+)<br />(.+)<br />(.+)").search(content):
poes = re.search("(せんりゅう|川柳)(ゲーム|げーむ)[::]<br />(.+)<br />(.+)<br />(.+)", str(content))
sen1 = poes.group(3)
sen2 = poes.group(4)
sen3 = poes.group(5)
sekuhara = bot.block01(status)
if sekuhara:
toot_now = "٩(๑`^´๑)۶えっちなのはよくない!!!!"
g_vis = "public"
bot.rets(5, toot_now, g_vis)
if len(sen1) > 6 or len(sen2) > 8 or len(sen3) > 6:
pass
else:
f = codecs.open('game\\senryu_word.txt', 'a', 'UTF-8')
f.write(str(sen1) + ">>>" + str(sen2) + ">>>" + str(sen3) + ">>>" + account["acct"] + "\r\n")
f.close()
v = threading.Timer(5, game.fav, [status["id"]])
v.start()
elif re.compile("ももな.*(せんりゅう|川柳)(ゲーム|げーむ).*(一句|ひとつ|おねがい|お願い|一つ|1つ)").search(content):
if account["acct"] != "JC":
f = codecs.open('game\\senryu_word.txt', 'r', 'utf-8')
word1 = []
for x in f:
word1.append(x.rstrip("\r\n").replace('\\n', '\n'))
f.close()
m = len(word1)
word2 = []
for x in range(4):
s = random.randint(0, m - 1)
word2.append((word1[s]).split('>>>'))
h0 = word2[0]
h1 = word2[1]
h2 = word2[2]
h3 = word2[3]
toot_now = h0[0] + "\n" + h1[1] + "\n" + h2[2] + "\n(作者::@" + h3[3] + ":)\n:@" + account[
"acct"] + ":からのリクエストでした❤\n#川柳げーむ"
g_vis = "public"
bot.rets(6, toot_now, g_vis)
pass
def dice(inp):
l = []
n = []
m = []
x = 0
try:
inp = re.sub("<", "<", str(inp))
inp = re.sub(">", ">", str(inp))
com = re.search("(\d+)[dD](\d+)([:<>]*)(\d*)([\+\-\*/\d]*)(.*)", str(inp))
print(str(com.group()))
for v in range(1, 7):
m.append(com.group(v))
print(m)
if int(m[1]) == 0:
result = "面が0の数字は振れないよ……"
elif int(m[0]) >= 51:
result = "回数が長すぎるとめんどくさいから振らないよ……?"
elif int(m[0]) == 0:
result = "えっ……回数0? じゃあ振らなーーーーい!"
else:
print("○サイコロ振ります(*'∀'人)")
for var in range(0, int(m[0])):
num = random.randint(1, int(m[1]))
num = str(num)
print(num)
if m[4] == True:
ad = m[4]
else:
ad = ""
try:
if ad == "":
dd = 0
else:
dd = int(ad)
if m[5] == "":
fd = "[" + m[3] + m[4] + "]→"
else:
fd = "[" + m[5] + "(" + m[3] + m[4] + ")]→"
sd = ad + fd
if str(m[2]) == ">":
if int(num) >= int(m[3]) + dd:
result = "コロコロ……" + num + sd + "成功だよ!!"
else:
result = "コロコロ……" + num + sd + "失敗だよ……"
else:
if int(num) + dd <= int(m[3]) + dd:
result = "コロコロ……" + num + sd + "成功だよ!!"
else:
result = "コロコロ……" + num + sd + "失敗だよ……"
except:
result = "コロコロ……" + num
l.append(result)
n.append(int(num))
x += int(num)
if ad != "":
x += int(ad)
if int(m[0]) != 1:
result = str(n) + str(ad) + " = " + str(x)
l.append(result)
print(l)
result = '\n'.join(l)
if len(result) > 400:
result = "文字数制限に引っ掛かっちゃった……"
except:
result = "えっ?"
return result
class Emo():
def emo01(time=10800): # 定期的に評価を下げまーーす♪(無慈悲)
while 1:
sleep(time)
data_dir_path = u"./thank/"
file_list = os.listdir(r'./thank/')
for file_name in file_list:
root, ext = os.path.splitext(file_name)
if ext == u'.txt':
abs_name = data_dir_path + '/' + file_name
f = open(abs_name, 'r')
x = f.read()
y = int(x)
y += -1
f.close()
f = open(abs_name, 'w')
f.write(str(y))
f.close()
def emo02(point):
sleep(time)
data_dir_path = u"./thank/"
file_list = os.listdir(r'./thank/')
for file_name in file_list:
root, ext = os.path.splitext(file_name)
if ext == u'.txt':
abs_name = data_dir_path + '/' + file_name
f = open(abs_name, 'r')
x = f.read()
y = int(x)
y += point
f.close()
f = open(abs_name, 'w')
f.write(str(y))
f.close()
pass
def emo03(user, point):
sleep(time)
data_dir_path = u"./thank/"
file_list = os.listdir(r'./thank/')
abs_name = data_dir_path + '/' + user + '.txt'
f = open(abs_name, 'r')
x = f.read()
y = int(x)
y += point
f.close()
f = open(abs_name, 'w')
f.write(str(y))
f.close()
pass
fff = threading.Thread(Emo.emo01, [10800])
fff.start()