forked from Nadyatjia/BotLinePython3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoco4bot.py
More file actions
1352 lines (1347 loc) · 67.5 KB
/
coco4bot.py
File metadata and controls
1352 lines (1347 loc) · 67.5 KB
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
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
from linepy import *
from datetime import datetime
from time import sleep
from bs4 import BeautifulSoup
from humanfriendly import format_timespan, format_size, format_number, format_length
import time, random, sys, json, codecs, threading, glob, re, string, os, requests, subprocess, six, ast, pytz, urllib, urllib.parse
from gtts import gTTS
from googletrans import Translator
#==============================================================================#
botStart = time.time()
cl = LINE()
cl.log("Auth Token : " + str(cl.authToken))
channelToken = cl.getChannelResult()
cl.log("Channel Token : " + str(channelToken))
ghost = LINE()
ghost.log("Auth Token : " + str(cl.authToken))
channelToken = cl.getChannelResult()
ghost.log("Channel Token : " + str(channelToken))
kicker01 = LINE()
kicker01.log("Auth Token : " + str(cl.authToken))
channelToken = cl.getChannelResult()
kicker01.log("Channel Token : " + str(channelToken))
kicker02 = LINE()
kicker02.log("Auth Token : " + str(cl.authToken))
channelToken = cl.getChannelResult()
kicker02.log("Channel Token : " + str(channelToken))
oepoll = OEPoll(cl)
readOpen = codecs.open("read.json","r","utf-8")
settingsOpen = codecs.open("temp.json","r","utf-8")
read = json.load(readOpen)
settings = json.load(settingsOpen)
myProfile = {
"displayName": "",
"statusMessage": "",
"pictureStatus": ""
}
clProfile = cl.getProfile()
clMID = cl.profile.mid
ghostMID = ghost.profile.mid
kicker01MID = kicker01.profile.mid
kicker02MID = kicker02.profile.mid
myProfile["displayName"] = clProfile.displayName
myProfile["statusMessage"] = clProfile.statusMessage
myProfile["pictureStatus"] = clProfile.pictureStatus
KAC = [kicker01,kicker02]
admin = ['u28d781fa3ba9783fd5144390352b0c24',clMID,kicker01MID,kicker02MID,ghostMID]
wait2 = {
'readPoint':{},
'readMember':{},
'setTime':{},
'ROM':{}
}
setTime = {}
setTime = wait2['setTime']
msg_dict = {}
bl = [""]
def cTime_to_datetime(unixtime):
return datetime.datetime.fromtimestamp(int(str(unixtime)[:len(str(unixtime))-3]))
def restartBot():
print ("[ 訊息 ] 機器重啟")
backupData()
python = sys.executable
os.execl(python, python, *sys.argv)
def backupData():
try:
backup = settings
f = codecs.open('temp.json','w','utf-8')
json.dump(backup, f, sort_keys=True, indent=4, ensure_ascii=False)
backup = read
f = codecs.open('read.json','w','utf-8')
json.dump(backup, f, sort_keys=True, indent=4, ensure_ascii=False)
return True
except Exception as error:
logError(error)
return False
def restart_program():
python = sys.executable
os.execl(python, python, * sys.argv)
def logError(text):
cl.log("[ 錯誤 ] " + str(text))
time_ = datetime.now()
with open("errorLog.txt","a") as error:
error.write("\n[%s] %s" % (str(time), text))
def sendMessageWithMention(to, mid):
try:
aa = '{"S":"0","E":"3","M":'+json.dumps(mid)+'}'
text_ = '@x '
cl.sendMessage(to, text_, contentMetadata={'MENTION':'{"MENTIONEES":['+aa+']}'}, contentType=0)
except Exception as error:
logError(error)
def helpmessage():
helpMessage = """
╔═══════════
♥ ✿ CoCo指令表 ✿ ♥
棉花糖の特製機
════✪〘 查看指令表 〙✪════
↪ 「Help」查看全部指令
↪ 「HelpTag」查看標註指令
↪ 「HelpKick」查看踢人指令
↪ 「HelpBot」查看機器指令
════✪〘 狀態 〙✪═══════
↪ 「Rebot」重新啟動機器
↪ 「Runtime」查看機器運行時間
↪ 「Speed」查看機器速度
↪ 「Set」查看設定
↪ 「About」查看自己的狀態
↪ 「Look Protect」查看這個群組的保護狀態
════✪〘 設定 〙✪═══════
↪ 「Add On/Off」自動加入好友 打開/關閉
↪ 「Join On/Off」自動進入群組 打開/關閉
↪ 「Leave On/Off」自動離開副本 打開/關閉
↪ 「Read On/Off」自動已讀 打開/關閉
↪ 「Tag On/Off」標註提醒 打開/關閉
↪ 「Qr On/Off」網址保護 打開/關閉
↪ 「Inviteprotect On/Off」邀請保護 打開/關閉
↪ 「Protect On/Off」群組保護 打開/關閉
↪ 「Allprotect On/Off」全部保護 打開/關閉
↪ 「Contact On/Off」好友資料詳細訊息 打開/關閉
↪ 「Reread On/Off」查看收回 打開/關閉
↪ 「Inviteprotect List」查看邀請保護中的群組
↪ 「Qr List」查看網址保護中的群組
↪ 「Protect List」查看踢人保護中的群組
════✪〘 自己 〙✪═══════
↪ 「Me」丟出自己好友資料
↪ 「Mid」查看自己系統識別碼
↪ 「Contact @」標註查看好友資料
↪ 「Mid @」標註查看系統識別碼
════✪〘 群組 〙✪═══════
↪ 「Gurl」丟出群組網址
↪ 「O/Curl」打開/關閉群組網址
↪ 「Ginfo」查看群組狀態
↪ 「Ri @」標註來回機票
↪ 「Tk @」標注踢出成員
↪ 「Nk Name」使用名子踢出成員
↪ 「Uk mid」使用系統識別碼踢出成員
↪ 「Cancel」取消所有成員邀請
↪ 「Gcancel」取消所有群組邀請
↪ 「Gn Name」更改群組名稱
↪ 「Gc @」標註查看個人資料
↪ 「Inv mid」使用系統識別碼邀請進入群組
↪ 「Ban @」標註加入黑單
↪ 「Unban @」標註解除黑單
↪ 「Clear Ban」清空黑單
↪ 「Kill Ban」剔除黑單
↪ 「Nkk Name」使用名子踢出成員
↪ 「Tkk @」標注踢出成員
════✪〘 特別 〙✪═══════
↪ 「Tagall」標註群組所有成員
↪ 「S N/F/R」已讀點 開啟/關閉/重設
↪ 「R」查看已讀
↪ 「F/Gbc」好友/群組廣播
↪「/invitemeto:」使用群組識別碼邀請至群組
↪ 「Time」查看現在的時間
╚═〘 Credits By: ©CoCo™ 〙
"""
return helpMessage
def helpmessagetag():
helpMessageTag ="""
╔══[ 標注指令 ]════════
↪ 「Ri @」標註來回機票
↪ 「Tk @」標注踢出成員
↪ 「Vk @」標註踢出並清除訊息
↪ 「Gc @」標註查看個人資料
↪ 「Mid @」標註查看系統識別碼
↪ 「Name @」標註查看名稱
↪ 「Bio @」標註查看狀態消息
↪ 「Picture @」標註查看頭貼
↪ 「VideoProfile @」標註查看動態頭貼
↪ 「Cover @」標注查看封面
↪ 「Copy @」標註複製配置文件
↪ 「Ban @」標註加入黑單
↪ 「Unban @」標註解除黑單
↪ 「Tkk @」標注踢出成員
╚═〘 Credits By: ©CoCo™ 〙
"""
return helpMessageTag
def helpmessagekick():
helpMessageKick ="""
╔══[ 踢人指令 ]════════
↪ 「Ri @」標註來回機票
↪ 「Tk @」標注踢出成員
↪ 「Nk Name」使用名子踢出成員
↪ 「Uk mid」使用系統識別碼踢出成員
↪ 「Kill ban」踢出黑單成員
↪ 「Nkk Name」使用名子踢出成員
↪ 「Tkk @」標注踢出成員
╚═〘 Credits By: ©CoCo™ 〙
"""
return helpMessageKick
def helpmessagebot():
helpMessageBot ="""
╔══〘 設定 〙✪═══════
↪ 「Add On/Off」自動加入好友 打開/關閉
↪ 「Join On/Off」自動進入群組 打開/關閉
↪ 「Leave On/Off」自動離開副本 打開/關閉
↪ 「Read On/Off」自動已讀 打開/關閉
↪ 「Tag On/Off」標註提醒 打開/關閉
↪ 「Qr On/Off」網址保護 打開/關閉
↪ 「Inviteprotect On/Off」邀請保護 打開/關閉
↪ 「Protect On/Off」群組保護 打開/關閉
↪ 「Allprotect On」全部保護 打開
↪ 「Contact On/Off」好友資料詳細訊息 打開/關閉
↪ 「Reread On/Off」查看收回 打開/關閉
"""
return helpMessageBot
def lineBot(op):
try:
if op.type == 0:
return
if op.type == 5:
contact = cl.getContact(param2)
print ("[ 5 ] 通知添加好友 名字: " + contact.displayName)
if settings["autoAdd"] == True:
cl.sendMessage(op.param1, "你好 {} 謝謝你加本機為好友 :D\n 本機為CoCo製作\n line.me/ti/p/1MRX_Gjbmv".format(str(cl.getContact(op.param1).displayName)))
kicker01.sendMessage(op.param1, "你好 {} 謝謝你加本機為好友 :D\n 本機為CoCo製作\n line.me/ti/p/1MRX_Gjbmv".format(str(cl.getContact(op.param1).displayName)))
kicker02.sendMessage(op.param1, "你好 {} 謝謝你加本機為好友 :D\n 本機為CoCo製作\n line.me/ti/p/1MRX_Gjbmv".format(str(cl.getContact(op.param1).displayName)))
if op.type == 11:
group = cl.getGroup(op.param1)
contact = cl.getContact(op.param2)
print ("[11]有人打開群組網址 群組名稱: " + str(group.name) + "\n" + op.param1 + "\n名字: " + contact.displayName)
if op.param1 in settings["qrprotect"]:
if op.param2 in admin:
pass
else:
gs = cl.getGroup(op.param1)
invsend = 0
Ti = cl.reissueGroupTicket(op.param1)
ghost.acceptGroupInvitationByTicket(op.param1,Ti)
time.sleep(0.2)
ghost.kickoutFromGroup(op.param1,[op.param2])
time.sleep(0.2)
gs.preventJoinByTicket = True
ghost.leaveRoom(op.param1)
cl.updateGroup(gs)
if op.type == 13:
contact1 = cl.getContact(op.param2)
contact2 = cl.getContact(op.param3)
group = cl.getGroup(op.param1)
print ("[ 13 ] 通知邀請群組: " + str(group.name) + "\n邀請者: " + contact1.displayName + "\n被邀請者" + contact2.displayName)
if op.param1 in settings["inviteprotect"]:
if op.param2 in admin:
pass
else:
cl.cancelGroupInvitation(op.param3)
if clMID in op.param3:
if settings["autoJoin"] == True:
if op.param2 in admin:
print ("進入群組: " + str(group.name))
cl.acceptGroupInvitation(op.param1)
if settings["kickerjoin"] == True:
G = cl.getGroup(op.param1)
G.preventedJoinByTicket = False
cl.updateGroup(G)
invsend = 0
Ti = cl.reissueGroupTicket(op.param1)
kicker01.acceptGroupInvitationByTicket(op.param1, Ti)
kicker02.acceptGroupInvitationByTicket(op.param1, Ti)
G.preventedJoinByTicket = True
cl.updateGroup(G)
if op.type == 19:
contact1 = cl.getContact(op.param2)
group = cl.getGroup(op.param1)
contact2 = cl.getContact(op.param3)
print ("[19]有人把人踢出群組 群組名稱: " + str(group.name) + "\n" + op.param1 +"\n踢人者: " + contact1.displayName + "\nMid: " + contact1.mid + "\n被踢者" + contact2.displayName + "\nMid:" + contact2.mid )
if op.param1 in settings["protect"]:
if op.param2 in admin:
pass
else:
cl.kickoutFromGroup(op.param1,[op.param2])
settings["blacklist"][op.param2] = True
else:
pass
if clMID in op.param3:
if op.param2 in admin:
pass
else:
try:
print ("[19]有人踢機器 群組名稱: " + str(group.name) +"\n踢人者: " + contact.displayName + "\nMid: " + contact.mid + "\n\n")
kicker01.kickoutFromGroup(op.param1,[op.param2])
except:
try:
random.choice(KAC).kickoutFromGroup(op.param1,[op.param2])
except:
print ("機器踢人規制或是不在群組、\n["+op.param1+"]\nの\n["+op.param2+"]\n我踢不了他。\n把他加進黑名單。")
if op.param2 in settings["blacklist"]:
pass
else:
settings["blacklist"][op.param2] = True
G = kicker01.getGroup(op.param1)
G.preventedJoinByTicket = False
kicker01.updateGroup(G)
invsend = 0
Ti = kicker01.reissueGroupTicket(op.param1)
cl.acceptGroupInvitationByTicket(op.param1, Ti)
kicker01.acceptGroupInvitationByTicket(op.param1, Ti)
kicker02.acceptGroupInvitationByTicket(op.param1, Ti)
G.preventedJoinByTicket = True
cl.updateGroup(G)
if kicker01MID in op.param3:
if op.param2 in admin:
pass
else:
try:
print ("[19]有人踢機器 群組名稱: " + str(group.name) +"\n踢人者: " + contact.displayName + "\nMid: " + contact.mid + "\n\n")
kicker02.kickoutFromGroup(op.param1,[op.param2])
except:
try:
random.choice(KAC).kickoutFromGroup(op.param1,[op.param2])
except:
print ("機器踢人規制或是不在群組、\n["+op.param1+"]\nの\n["+op.param2+"]\n我踢不了他。\n把他加進黑名單。")
if op.param2 in settings["blacklist"]:
pass
else:
settings["blacklist"][op.param2] = True
G = kicker02.getGroup(op.param1)
G.preventedJoinByTicket = False
kicker02.updateGroup(G)
invsend = 0
Ti = kicker02.reissueGroupTicket(op.param1)
cl.acceptGroupInvitationByTicket(op.param1, Ti)
kicker01.acceptGroupInvitationByTicket(op.param1, Ti)
kicker02.acceptGroupInvitationByTicket(op.param1, Ti)
G.preventedJoinByTicket = True
cl.updateGroup(G)
if kicker02MID in op.param3:
if op.param2 in admin:
pass
else:
try:
print ("[19]有人踢機器 群組名稱: " + str(group.name) +"\n踢人者: " + contact.displayName + "\nMid: " + contact.mid + "\n\n")
cl.kickoutFromGroup(op.param1,[op.param2])
except:
try:
random.choice(KAC).kickoutFromGroup(op.param1,[op.param2])
except:
print ("機器踢人規制或是不在群組、\n["+op.param1+"]\nの\n["+op.param2+"]\n我踢不了他。\n把他加進黑名單。")
if op.param2 in settings["blacklist"]:
pass
else:
settings["blacklist"][op.param2] = True
G = cl.getGroup(op.param1)
G.preventedJoinByTicket = False
cl.updateGroup(G)
invsend = 0
Ti = cl.reissueGroupTicket(op.param1)
cl.acceptGroupInvitationByTicket(op.param1, Ti)
kicker01.acceptGroupInvitationByTicket(op.param1, Ti)
kicker02.acceptGroupInvitationByTicket(op.param1, Ti)
G.preventedJoinByTicket = True
cl.updateGroup(G)
if op.type == 24:
if settings["autoLeave"] == True:
cl.leaveRoom(op.param1)
kicker01.leaveRoom(op.param1)
kicker02.leaveRoom(op.param1)
if op.type == 26 or op.type == 25:
msg = op.message
text = msg.text
msg_id = msg.id
receiver = msg.to
sender = msg._from
if msg.toType == 0:
if sender != cl.profile.mid:
to = sender
else:
to = receiver
else:
to = receiver
if msg.contentType == 13:
if settings["contact"] == True:
msg.contentType = 0
if 'displayName' in msg.contentMetadata:
contact = cl.getContact(msg.contentMetadata["mid"])
try:
cu = cl.getProfileCoverURL(msg.contentMetadata["mid"])
except:
cu = ""
cl.sendMessage(msg.to,"[顯示名稱]:\n" + msg.contentMetadata["顯示名稱"] + "\n[mid]:\n" + msg.contentMetadata["mid"] + "\n[狀態消息]:\n" + contact.statusMessage + "\n[圖片網址]:\nhttp://dl.profile.line-cdn.net/" + contact.pictureStatus + "\n[封面網址]:\n" + str(cu))
else:
contact = cl.getContact(msg.contentMetadata["mid"])
try:
cu = cl.getProfileCoverURL(msg.contentMetadata["mid"])
except:
cu = ""
cl.sendMessage(msg.to,"[顯示名稱]:\n" + contact.displayName + "\n[mid]:\n" + msg.contentMetadata["mid"] + "\n[狀態消息]:\n" + contact.statusMessage + "\n[圖片網址]:\nhttp://dl.profile.line-cdn.net/" + contact.pictureStatus + "\n[封面網址]:\n" + str(cu))
elif msg.contentType == 16:
if settings["timeline"] == True:
msg.contentType = 0
msg.text = "文章網址\n" + msg.contentMetadata["postEndUrl"]
cl.sendMessage(msg.to,msg.text)
if msg.contentType == 0:
if text is None:
return
if sender in admin:
if text.lower() == 'help':
helpMessage = helpmessage()
cl.sendMessage(to, str(helpMessage))
cl.sendContact(to, "u28d781fa3ba9783fd5144390352b0c24")
elif text.lower() == 'helptag':
helpMessageTag = helpmessagetag()
cl.sendMessage(to, str(helpMessageTag))
elif text.lower() == 'helpkick':
helpMessageKick = helpmessagekick()
cl.sendMessage(to, str(helpMessageKick))
elif text.lower() == 'helpbot':
helpMessageBot = helpMessageBot()
cl.sendMessage(to, str(helpMessageBot))
elif "Fbc:" in msg.text:
bctxt = text.replace("Fbc:","")
t = cl.getAllContactIds()
for manusia in t:
cl.sendMessage(manusia,(bctxt))
elif "Gbc:" in msg.text:
bctxt = text.replace("Gbc:","")
n = cl.getGroupIdsJoined()
for manusia in n:
cl.sendMessage(manusia,(bctxt))
elif 'alljoin' in text.lower():
if msg.toType == 2:
G = cl.getGroup(to)
if G.preventedJoinByTicket == False:
cl.updateGroup(G)
invsend = 0
Ti = cl.reissueGroupTicket(to)
kicker01.acceptGroupInvitationByTicket(to, Ti)
kicker02.acceptGroupInvitationByTicket(to, Ti)
G.preventedJoinByTicket = True
cl.updateGroup(G)
else:
G.preventedJoinByTicket = False
cl.updateGroup(G)
invsend = 0
Ti = cl.reissueGroupTicket(to)
kicker01.acceptGroupInvitationByTicket(to, Ti)
kicker02.acceptGroupInvitationByTicket(to, Ti)
G.preventedJoinByTicket = True
cl.updateGroup(G)
elif text.lower() == 'bot bye':
if msg.toType == 2:
ginfo = cl.getGroup(to)
try:
kicker01.leaveGroup(to)
kicker02.leaveGroup(to)
except:
pass
elif text.lower() == 'test':
time0 = timeit.timeit('"-".join(str(n) for n in range(100))', number=5000)
str1 = str(time0)
start = time.time()
cl.sendMessage(to,'處理速度\n' + str1 + '秒')
elapsed_time = time.time() - start
cl.sendMessage(to,'指令反應\n' + format(str(elapsed_time)) + '秒')
kicker01.sendMessage(to, 'ok')
kicker02.sendMessage(to, 'ok')
elif text.lower() == 'gj':
if msg.toType == 2:
G = cl.getGroup(msg.to)
G.preventedJoinByTicket = False
cl.updateGroup(G)
invsend = 0
Ti = cl.reissueGroupTicket(msg.to)
ghost.acceptGroupInvitationByTicket(msg.to,Ti)
G.preventedJoinByTicket = True
cl.updateGroup(G)
elif text.lower() == 'gbye':
if msg.toType == 2:
ginfo = cl.getGroup(to)
try:
ghost.leaveGroup(to)
except:
pass
elif "Ri " in msg.text:
Ri0 = text.replace("Ri ","")
Ri1 = Ri0.rstrip()
Ri2 = Ri1.replace("@","")
Ri3 = Ri2.rstrip()
_name = Ri3
gs = cl.getGroup(msg.to)
targets = []
for s in gs.members:
if _name in s.displayName:
targets.append(s.mid)
if targets == []:
pass
else:
for target in targets:
if target in admin:
pass
else:
try:
cl.kickoutFromGroup(to,[target])
cl.findAndAddContactsByMid(target)
cl.inviteIntoGroup(to,[target])
except:
pass
elif "Uk " in msg.text:
midd = text.replace("Uk ","")
cl.kickoutFromGroup(to,[midd])
elif "Tk " in msg.text:
key = eval(msg.contentMetadata["MENTION"])
key["MENTIONEES"][0]["M"]
targets = []
for x in key["MENTIONEES"]:
targets.append(x["M"])
for target in targets:
if target in admin:
pass
else:
try:
cl.kickoutFromGroup(to,[target])
time.sleep(0.1)
except:
pass
elif "Tkk " in msg.text:
key = eval(msg.contentMetadata["MENTION"])
key["MENTIONEES"][0]["M"]
targets = []
for x in key["MENTIONEES"]:
targets.append(x["M"])
for target in targets:
if target in admin:
pass
else:
try:
klist = [kicker01,kicker02]
kickers = random.choice(klist)
kickers.kickoutFromGroup(to,[target])
time.sleep(0.1)
except:
pass
elif "Nk " in msg.text:
_name = text.replace("Nk ","")
gs = cl.getGroup(to)
targets = []
for g in gs.members:
if _name in g.displayName:
targets.append(g.mid)
if targets == []:
pass
else:
for target in targets:
if target in admin:
pass
else:
try:
cl.kickoutFromGroup(to,[target])
time.sleep(0.1)
except:
pass
elif "Nkk " in msg.text:
_name = text.replace("Nkk ","")
gs = cl.getGroup(to)
targets = []
for g in gs.members:
if _name in g.displayName:
targets.append(g.mid)
if targets == []:
pass
else:
for target in targets:
if target in admin:
pass
else:
try:
klist = [kicker01,kicker02]
kickers = random.choice(klist)
kickers.kickoutFromGroup(to,[target])
time.sleep(0.1)
except:
pass
elif "Ulti " in msg.text:
key = eval(msg.contentMetadata["MENTION"])
key["MENTIONEES"][0]["M"]
gs = cl.getGroup(msg.to)
gs.preventJoinByTicket = False
cl.updateGroup(gs)
invsend = 0
Ti = cl.reissueGroupTicket(msg.to)
klist = [ghost]
kickers = random.choice(klist)
ghost.acceptGroupInvitationByTicket(to, Ti)
time.sleep(0.2)
targets = []
for x in key["MENTIONEES"]:
targets.append(x["M"])
else:
for target in targets:
try:
kickers.kickoutFromGroup(msg.to,[target])
ghost.leaveGroup(msg.to)
gs.preventJoinByTicket = True
cl.updateGroup(gs)
except:
pass
elif "NT " in msg.text:
_name = text.replace("NT ","")
gs = cl.getGroup(to)
targets = []
net_ = ""
for g in gs.members:
if _name in g.displayName:
targets.append(g.mid)
if targets == []:
cl.sendMessage(to, "這個群組沒有這個人")
else:
for target in targets:
try:
sendMessageWithMention(to,target)
except:
pass
elif text.lower() == 'zt':
gs = cl.getGroup(to)
targets = []
for g in gs.members:
if g.displayName in "":
targets.append(g.mid)
if targets == []:
cl.sendMessage(to, "這個群組沒有名字0字的人")
else:
mc = ""
for target in targets:
mc += sendMessageWithMention(to,target) + "\n"
cl.sendMessage(to, mc)
elif "Mc " in msg.text:
mmid = msg.text.replace("Mc ","")
cl.sendContact(to, mmid)
elif "Sc " in msg.text:
ggid = msg.text.replace("Sc ","")
group = cl.getGroup(ggid)
try:
gCreator = group.creator.displayName
except:
gCreator = "未找到"
if group.invitee is None:
gPending = "0"
else:
gPending = str(len(group.invitee))
if group.preventedJoinByTicket == True:
gQr = "關閉"
gTicket = "沒有"
else:
gQr = "開啟"
gTicket = "https://cl.me/R/ti/g/{}".format(str(cl.reissueGroupTicket(group.id)))
path = "http://dl.profile.line-cdn.net/" + group.pictureStatus
ret_ = "╔══[ 群組資料 ]"
ret_ += "\n╠ 顯示名稱 : {}".format(str(group.name))
ret_ += "\n╠ 群組ID : {}".format(group.id)
ret_ += "\n╠ 群組作者 : {}".format(str(gCreator))
ret_ += "\n╠ 成員數量 : {}".format(str(len(group.members)))
ret_ += "\n╠ 邀請數量 : {}".format(gPending)
ret_ += "\n╠ 群組網址 : {}".format(gQr)
ret_ += "\n╠ 群組網址 : {}".format(gTicket)
ret_ += "\n╚══[ 完 ]"
cl.sendMessage(to, str(ret_))
cl.sendImageWithURL(to, path)
elif msg.text in ["c","C","cancel","Cancel"]:
if msg.toType == 2:
X = cl.getGroup(msg.to)
if X.invitee is not None:
gInviMids = (contact.mid for contact in X.invitee)
ginfo = cl.getGroup(msg.to)
sinvitee = str(len(ginfo.invitee))
start = time.time()
for cancelmod in gInviMids:
cl.cancelGroupInvitation(msg.to, [cancelmod])
elapsed_time = time.time() - start
cl.sendMessage(to, "已取消完成\n取消時間: %s秒" % (elapsed_time))
cl.sendMessage(to, "取消人數:" + sinvitee)
else:
cl.sendMessage(to, "沒有任何人在邀請中!!")
elif text.lower() == 'gcancel':
gid = cl.getGroupIdsInvited()
start = time.time()
for i in gid:
cl.rejectGroupInvitation(i)
elapsed_time = time.time() - start
cl.sendMessage(to, "全部群組邀請已取消")
cl.sendMessage(to, "取消時間: %s秒" % (elapsed_time))
elif "Gn " in msg.text:
if msg.toType == 2:
X = cl.getGroup(msg.to)
X.name = msg.text.replace("Gn ","")
cl.updateGroup(X)
else:
cl.sendMessage(msg.to,"無法使用在群組外")
elif "Gc" in msg.text:
if msg.toType == 2:
key = eval(msg.contentMetadata["MENTION"])
u = key["MENTIONEES"][0]["M"]
contact = cl.getContact(u)
cu = cl.getProfileCoverURL(mid=u)
try:
cl.sendMessage(msg.to,"名字:\n" + contact.displayName + "\n\n系統識別碼:\n" + contact.mid + "\n\n個性簽名:\n" + contact.statusMessage + "\n\n頭貼網址 :\nhttp://dl.profile.line-cdn.net/" + contact.pictureStatus + "\n\n封面網址 :\n" + str(cu))
except:
cl.sendMessage(msg.to,"名字:\n" + contact.displayName + "\n\n系統識別碼:\n" + contact.mid + "\n\n個性簽名:\n" + contact.statusMessage + "\n\n封面網址:\n" + str(cu))
elif "Inv " in msg.text:
midd = msg.text.replace("Inv ","")
cl.findAndAddContactsByMid(midd)
cl.inviteIntoGroup(msg.to,[midd])
elif "Ban" in msg.text:
if msg.toType == 2:
print ("[Ban] 成功")
key = eval(msg.contentMetadata["MENTION"])
key["MENTIONEES"][0]["M"]
targets = []
for x in key["MENTIONEES"]:
targets.append(x["M"])
if targets == []:
pass
else:
for target in targets:
try:
settings["blacklist"][target] = True
cl.sendMessage(to, "已加入黑名單")
except:
pass
elif "Unban" in msg.text:
if msg.toType == 2:
print ("[UnBan] 成功")
key = eval(msg.contentMetadata["MENTION"])
key["MENTIONEES"][0]["M"]
targets = []
for x in key["MENTIONEES"]:
targets.append(x["M"])
if targets == []:
pass
else:
for target in targets:
try:
del settings["blacklist"][target]
cl.sendMessage(to, "已解除黑名單")
except:
pass
elif text.lower() == 'clear ban':
for mi_d in settings["blacklist"]:
settings["blacklist"] = {}
cl.sendMessage(to, "已清空黑名單")
elif text.lower() == 'banlist':
if settings["blacklist"] == {}:
cl.sendMessage(to, "沒有黑名單")
else:
cl.sendMessage(to, "以下是黑名單")
mc = ""
for mi_d in settings["blacklist"]:
mc += "->" + cl.getContact(mi_d).displayName + "\n"
cl.sendMessage(to, mc)
elif text.lower() == 'banmid':
if settings["blacklist"] == {}:
cl.sendMessage(to, "沒有黑名單")
else:
cl.sendMessage(to, "以下是黑名單")
mc = ""
for mi_d in settings["blacklist"]:
mc += "->" + cl.getContact(mi_d).mid + "\n"
cl.sendMessage(to, mc)
elif text.lower() == 'kill ban':
if msg.toType == 2:
group = cl.getGroup(to)
gMembMids = [contact.mid for contact in group.members]
matched_list = []
for tag in settings["blacklist"]:
matched_list+=filter(lambda str: str == tag, gMembMids)
if matched_list == []:
print ("1")
cl.sendMessage(to, "沒有黑名單")
return
klist = [kicker01,kicker02]
kickers = random.choice(klist)
for jj in matched_list:
kickers.kickoutFromGroup(to, [jj])
cl.sendMessage(to, "黑名單以踢除")
elif "/invitemeto:" in msg.text:
gid = msg.text.replace("/invitemeto:","")
if gid == "":
cl.sendMessage(to,"請輸入群組ID")
else:
try:
cl.findAndAddContactsByMid(msg.from_)
cl.inviteIntoGroup(gid,[msg.from_])
except:
cl.sendMessage(to,"我不在那個群組裡")
elif msg.text in ["SR","Setread"]:
cl.sendMessage(msg.to, "設置已讀點")
try:
del wait2['readPoint'][msg.to]
del wait2['readMember'][msg.to]
except:
pass
now2 = datetime.now()
wait2['readPoint'][msg.to] = msg.id
wait2['readMember'][msg.to] = ""
wait2['setTime'][msg.to] = datetime.strftime(now2,"%H:%M")
wait2['ROM'][msg.to] = {}
print ("設置已讀點")
elif msg.text in ["LR","Lookread"]:
if msg.to in wait2['readPoint']:
print ("查詢已讀")
if wait2["ROM"][msg.to].items() == []:
chiya = ""
else:
chiya = ""
for rom in wait2["ROM"][msg.to].items():
chiya += rom[1] + "\n"
cl.sendMessage(msg.to, "||已讀順序||%s\n\n||已讀的人||\n\n%s\n[%s]" % (wait2['readMember'][msg.to],chiya,setTime[msg.to]))
else:
cl.sendMessage(msg.to, "請輸入SR設置已讀點")
elif text.lower() == 'readset':
try:
del cctv['point'][msg.to]
del cctv['sidermem'][msg.to]
del cctv['cyduk'][msg.to]
except:
pass
cctv['point'][msg.to] = msg.id
cctv['sidermem'][msg.to] = ""
cctv['cyduk'][msg.to]=True
elif text.lower() == 'offread':
if msg.to in cctv['point']:
cctv['cyduk'][msg.to]=False
cl.sendMessage(to, cctv['sidermem'][msg.to])
else:
cl.sendMessage(to, "readset")
elif msg.text in ["Friendlist"]:
anl = cl.getAllContactIds()
ap = ""
for q in anl:
ap += "• "+cl.getContact(q).displayName + "\n"
cl.sendMessage(msg.to,"「 朋友列表 」\n"+ap+"人數 : "+str(len(anl)))
elif text.lower() == 'speed' or text.lower() == 'sp':
time0 = timeit.timeit('"-".join(str(n) for n in range(100))', number=10000)
str1 = str(time0)
start = time.time()
cl.sendMessage(to,'處理速度\n' + str1 + '秒')
elapsed_time = time.time() - start
cl.sendMessage(to,'指令反應\n' + format(str(elapsed_time)) + '秒')
elif text.lower() == 'rebot':
cl.sendMessage(to, "重新啟動")
restartBot()
elif text.lower() == 'runtime':
timeNow = time.time()
runtime = timeNow - botStart
runtime = format_timespan(runtime)
cl.sendMessage(to, "機器運行時間 {}".format(str(runtime)))
elif text.lower() == 'about':
try:
arr = []
owner = "u28d781fa3ba9783fd5144390352b0c24"
creator = cl.getContact(owner)
contact = cl.getContact(clMID)
grouplist = cl.getGroupIdsJoined()
contactlist = cl.getAllContactIds()
blockedlist = cl.getBlockedContactIds()
ret_ = "╔══[ 關於自己 ]"
ret_ += "\n╠ 名稱 : {}".format(contact.displayName)
ret_ += "\n╠ 群組 : {}".format(str(len(grouplist)))
ret_ += "\n╠ 好友 : {}".format(str(len(contactlist)))
ret_ += "\n╠ 黑單 : {}".format(str(len(blockedlist)))
ret_ += "\n╠══[ 關於機器 ]"
ret_ += "\n╠ 版本 : 棉花糖特製機v1.0"
ret_ += "\n╠ 作者 : {}".format(creator.displayName)
ret_ += "\n╚══[ 未經許可禁止重製 ]"
cl.sendMessage(to, str(ret_))
except Exception as e:
cl.sendMessage(msg.to, str(e))
elif text.lower() == 'set':
try:
ret_ = "╔══[ 設定 ]"
if settings["autoAdd"] == True: ret_ += "\n╠ 自動加入好友 ✅"
else: ret_ += "\n╠ 自動加入好友 ❌"
if settings["autoJoin"] == True: ret_ += "\n╠ 自動加入群組 ✅"
else: ret_ += "\n╠ 自動加入群組 ❌"
if settings["autoLeave"] == True: ret_ += "\n╠ 自動離開副本 ✅"
else: ret_ += "\n╠ 自動離開副本 ❌"
if settings["autoRead"] == True: ret_ += "\n╠ 自動已讀 ✅"
else: ret_ += "\n╠ 自動已讀 ❌"
if settings["inviteprotect"] == True: ret_ += "\n╠ 群組邀請保護 ✅"
else: ret_ += "\n╠ 群組邀請保護 ❌"
if settings["qrprotect"] == True: ret_ += "\n╠ 群組網址保護 ✅"
else: ret_ += "\n╠ 群組網址保護 ❌"
if settings["protect"] == True: ret_ += "\n╠ 群組保護 ✅"
else: ret_ += "\n╠ 群組保護 ❌"
if settings["detectMention"] == True: ret_ += "\n╠ 標注提醒 ✅"
else: ret_ += "\n╠ 標注提醒 ❌"
if settings["contact"] == True: ret_ += "\n╠ 詳細資料 ✅"
else: ret_ += "\n╠ 詳細資料 ❌"
if settings["reread"] == True: ret_ += "\n╠ 查詢收回開啟 ✅"
else: ret_ += "\n╠ 查詢收回關閉 ❌"
ret_ += "\n╚══[ 設定 ]"
cl.sendMessage(to, str(ret_))
except Exception as e:
cl.sendMessage(msg.to, str(e))
elif text.lower() == 'add on':
settings["autoAdd"] = True
cl.sendMessage(to, "自動加入好友已開啟")
elif text.lower() == 'add off':
settings["autoAdd"] = False
cl.sendMessage(to, "自動加入好友已關閉")
elif text.lower() == 'join on':
settings["autoJoin"] = True
cl.sendMessage(to, "自動加入群組已開啟")
elif text.lower() == 'join off':
settings["autoJoin"] = False
cl.sendMessage(to, "自動加入群組已關閉")
elif text.lower() == 'leave on':
settings["autoLeave"] = True
cl.sendMessage(to, "自動離開副本已開啟")
elif text.lower() == 'leave off':
settings["autoLeave"] = False
cl.sendMessage(to, "自動離開副本已關閉")
elif text.lower() == 'read on':
settings["autoRead"] = True
cl.sendMessage(to, "自動已讀已開啟")
elif text.lower() == 'read off':
settings["autoRead"] = False
cl.sendMessage(to, "自動已讀已關閉")
elif text.lower() == 'tag on':
settings["detectMention"] = True
cl.sendMessage(to, "標註提醒已開啟")
elif text.lower() == 'tag off':
settings["detectMention"] = False
cl.sendMessage(to, "標註提醒已關閉")
elif text.lower() == 'clonecontact':
settings["copy"] = True
cl.sendMessage(to, "請丟出好友資料以便複製")
elif text.lower() == 'contact on':
settings["contact"] = True
cl.sendMessage(to, "查看好友資料詳情開啟")
elif text.lower() == 'contact off':
settings["contact"] = False
cl.sendMessage(to, "查看好友資料詳情關閉")
elif text.lower() == 'inviteprotect on':
gid = cl.getGroup(to)
settings["inviteprotect"][gid.id] = True
cl.sendMessage(to, "群組邀請保護已開啟")
elif text.lower() == 'inviteprotect off':
del settings["inviteprotect"][gid.id]
cl.sendMessage(to, "群組邀請保護已關閉")
elif text.lower() == 'inviteprotect list':
if settings["inviteprotect"] == {}:
cl.sendMessage(to, "沒有網址保護中的群組")
else:
cl.sendMessage(to, "以下是網址保護中的群組")
mc = ""
for gi_d in settings["inviteprotect"]:
mc += "->" + cl.getGroup(gi_d).name + "\n"
cl.sendMessage(to, mc)
elif text.lower() == 'qr on':
gid = cl.getGroup(to)
settings["qrprotect"][gid.id] = True
cl.sendMessage(to, "群組網址保護已開啟")
elif text.lower() == 'qr off':
del settings["qrprotect"][gid.id]
cl.sendMessage(to, "群組網址保護已關閉")
elif text.lower() == 'qr list':
if settings["qrprotect"] == {}:
cl.sendMessage(to, "沒有網址保護中的群組")
else:
cl.sendMessage(to, "以下是網址保護中的群組")
mc = ""
for gi_d in settings["qrprotect"]:
mc += "->" + cl.getGroup(gi_d).name + "\n"
cl.sendMessage(to, mc)
elif text.lower() == 'allprotect on':
gid = cl.getGroup(to)
settings["qrprotect"][gid.id] = True
settings["protect"][gid.id] = True
settings["inviteprotect"][gid.id] = True
cl.sendMessage(to, "這群已經開啟全部保護")
elif text.lower() == 'allprotect off':
gid = cl.getGroup(to)
del settings["qrprotect"][gid.id]
del settings["qrprotect"][gid.id]
del settings["inviteprotect"][gid.id]
cl.sendMessage(to, "這群已經關閉全部保護")
elif text.lower() == 'protect on':
gid = cl.getGroup(to)
settings["protect"][gid.id] = True
cl.sendMessage(to, "群組保護已開啟")
elif text.lower() == 'protect off':
gid = cl.getGroup(to)
del settings["protect"][gid.id]
cl.sendMessage(to, "群組保護已關閉")
elif text.lower() == 'protectlist':
if settings["protect"] == {}:
cl.sendMessage(to, "沒有保護中的群組")
else:
cl.sendMessage(to, "以下是保護中的群組")
mc = ""
for gi_d in settings["protect"]:
mc += "->" + cl.getGroup(gi_d).name + "\n"
cl.sendMessage(to, mc)
elif text.lower() == 'look protect':
ret_ = "╔══[ 保護狀態 ]"
gid = cl.getGroup(to)