-
Notifications
You must be signed in to change notification settings - Fork 30
/
helloworld.py
2204 lines (2177 loc) · 107 KB
/
helloworld.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
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 -*-
'''
Free to use, all credits belong to me, Zero Cool.
Do not sell or rent it!
© 2018 Hello World
'''
from important import *
# Setup Argparse
parser = argparse.ArgumentParser(description='Selfbot Hello World')
parser.add_argument('-t', '--token', type=str, metavar='', required=False, help='Token | Example : Exxxx')
parser.add_argument('-e', '--email', type=str, default='', metavar='', required=False, help='Email Address | Example : [email protected]')
parser.add_argument('-p', '--passwd', type=str, default='', metavar='', required=False, help='Password | Example : xxxx')
parser.add_argument('-a', '--apptype', type=str, default='', metavar='', required=False, choices=list(ApplicationType._NAMES_TO_VALUES), help='Application Type | Example : CHROMEOS')
parser.add_argument('-s', '--systemname', type=str, default='', metavar='', required=False, help='System Name | Example : Chrome_OS')
parser.add_argument('-c', '--channelid', type=str, default='', metavar='', required=False, help='Channel ID | Example : 1341209950')
parser.add_argument('-T', '--traceback', type=str2bool, nargs='?', default=False, metavar='', required=False, const=True, choices=[True, False], help='Using Traceback | Use : True/False')
parser.add_argument('-S', '--showqr', type=str2bool, nargs='?', default=False, metavar='', required=False, const=True, choices=[True, False], help='Show QR | Use : True/False')
args = parser.parse_args()
# Login Client
listAppType = ['DESKTOPWIN', 'DESKTOPMAC', 'IOSIPAD', 'CHROMEOS']
try:
print ('##----- LOGIN CLIENT -----##')
line = None
if args.apptype:
tokenPath = Path('authToken.txt')
if tokenPath.exists():
tokenFile = tokenPath.open('r')
else:
tokenFile = tokenPath.open('w+')
savedAuthToken = tokenFile.read().strip()
authToken = savedAuthToken if savedAuthToken and not args.token else args.token
idOrToken = authToken if authToken else args.email
try:
line = LINE(idOrToken, args.passwd, appType=args.apptype, systemName=args.systemname, channelId=args.channelid, showQr=args.showqr)
tokenFile.close()
tokenFile = tokenPath.open('w+')
tokenFile.write(line.authToken)
tokenFile.close()
except TalkException as talk_error:
if args.traceback: traceback.print_tb(talk_error.__traceback__)
sys.exit('++ Error : %s' % talk_error.reason.replace('_', ' '))
except Exception as error:
if args.traceback: traceback.print_tb(error.__traceback__)
sys.exit('++ Error : %s' % str(error))
else:
for appType in listAppType:
tokenPath = Path('authToken.txt')
if tokenPath.exists():
tokenFile = tokenPath.open('r')
else:
tokenFile = tokenPath.open('w+')
savedAuthToken = tokenFile.read().strip()
authToken = savedAuthToken if savedAuthToken and not args.token else args.token
idOrToken = authToken if authToken else args.email
try:
line = LINE(idOrToken, args.passwd, appType=appType, systemName=args.systemname, channelId=args.channelid, showQr=args.showqr)
tokenFile.close()
tokenFile = tokenPath.open('w+')
tokenFile.write(line.authToken)
tokenFile.close()
break
except TalkException as talk_error:
print ('++ Error : %s' % talk_error.reason.replace('_', ' '))
if args.traceback: traceback.print_tb(talk_error.__traceback__)
if talk_error.code == 1:
continue
sys.exit(1)
except Exception as error:
print ('++ Error : %s' % str(error))
if args.traceback: traceback.print_tb(error.__traceback__)
sys.exit(1)
except Exception as error:
print ('++ Error : %s' % str(error))
if args.traceback: traceback.print_tb(error.__traceback__)
sys.exit(1)
if line:
print ('++ Auth Token : %s' % line.authToken)
print ('++ Timeline Token : %s' % line.tl.channelAccessToken)
print ('##----- LOGIN CLIENT (Success) -----##')
else:
sys.exit('##----- LOGIN CLIENT (Failed) -----##')
myMid = line.profile.mid
programStart = time.time()
oepoll = OEPoll(line)
tmp_text = []
lurking = {}
settings = livejson.File('setting.json', True, False, 4)
bool_dict = {
True: ['Yes', 'Active', 'Success', 'Open', 'On'],
False: ['No', 'Not Active', 'Failed', 'Close', 'Off']
}
# Backup profile
profile = line.getContact(myMid)
settings['myProfile']['displayName'] = profile.displayName
settings['myProfile']['statusMessage'] = profile.statusMessage
settings['myProfile']['pictureStatus'] = profile.pictureStatus
coverId = line.profileDetail['result']['objectId']
settings['myProfile']['coverId'] = coverId
# Check Json Data
if not settings:
print ('##----- LOAD DEFAULT JSON -----##')
try:
default_settings = line.server.getJson('https://17hosting.id/default.json')
settings.update(default_settings)
print ('##----- LOAD DEFAULT JSON (Success) -----##')
except Exception:
print ('##----- LOAD DEFAULT JSON (Failed) -----##')
def restartProgram():
print ('##----- PROGRAM RESTARTED -----##')
python = sys.executable
os.execl(python, python, *sys.argv)
def logError(error, write=True):
errid = str(random.randint(100, 999))
filee = open('tmp/errors/%s.txt'%errid, 'w') if write else None
if args.traceback: traceback.print_tb(error.__traceback__)
if write:
traceback.print_tb(error.__traceback__, file=filee)
filee.close()
with open('errorLog.txt', 'a') as e:
e.write('\n%s : %s'%(errid, str(error)))
print ('++ Error : {error}'.format(error=error))
def command(text):
pesan = text.lower()
if settings['setKey']['status']:
if pesan.startswith(settings['setKey']['key']):
cmd = pesan.replace(settings['setKey']['key'],'')
else:
cmd = 'Undefined command'
else:
cmd = text.lower()
return cmd
def genImageB64(path):
with open(path, 'rb') as img_file:
encode_str = img_file.read()
b64img = base64.b64encode(encode_str)
return b64img.decode('utf-8')
def genUrlB64(url):
return base64.b64encode(url.encode('utf-8')).decode('utf-8')
def removeCmd(text, key=''):
if key == '':
setKey = '' if not settings['setKey']['status'] else settings['setKey']['key']
else:
setKey = key
text_ = text[len(setKey):]
sep = text_.split(' ')
return text_[len(sep[0] + ' '):]
def multiCommand(cmd, list_cmd=[]):
if True in [cmd.startswith(c) for c in list_cmd]:
return True
else:
return False
def replaceAll(text, dic):
try:
rep_this = dic.items()
except:
rep_this = dic.iteritems()
for i, j in rep_this:
text = text.replace(i, j)
return text
def help():
key = '' if not settings['setKey']['status'] else settings['setKey']['key']
with open('help.txt', 'r') as f:
text = f.read()
helpMsg = text.format(key=key.title())
return helpMsg
def parsingRes(res):
result = ''
textt = res.split('\n')
for text in textt:
if True not in [text.startswith(s) for s in ['╭', '├', '│', '╰']]:
result += '\n│ ' + text
else:
if text == textt[0]:
result += text
else:
result += '\n' + text
return result
def mentionMembers(to, mids=[]):
if myMid in mids: mids.remove(myMid)
parsed_len = len(mids)//20+1
result = '╭───「 Mention Members 」\n'
mention = '@zeroxyuuki\n'
no = 0
for point in range(parsed_len):
mentionees = []
for mid in mids[point*20:(point+1)*20]:
no += 1
result += '│ %i. %s' % (no, mention)
slen = len(result) - 12
elen = len(result) + 3
mentionees.append({'S': str(slen), 'E': str(elen - 4), 'M': mid})
if mid == mids[-1]:
result += '╰───「 Hello World 」\n'
if result:
if result.endswith('\n'): result = result[:-1]
line.sendMessage(to, result, {'MENTION': json.dumps({'MENTIONEES': mentionees})}, 0)
result = ''
def cloneProfile(mid):
contact = line.getContact(mid)
profile = line.getProfile()
profile.displayName, profile.statusMessage = contact.displayName, contact.statusMessage
line.updateProfile(profile)
if contact.pictureStatus:
pict = line.downloadFileURL('http://dl.profile.line-cdn.net/' + contact.pictureStatus)
line.updateProfilePicture(pict)
coverId = line.getProfileDetail(mid)['result']['objectId']
line.updateProfileCoverById(coverId)
def backupProfile():
profile = line.getContact(myMid)
settings['myProfile']['displayName'] = profile.displayName
settings['myProfile']['pictureStatus'] = profile.pictureStatus
settings['myProfile']['statusMessage'] = profile.statusMessage
coverId = line.getProfileDetail()['result']['objectId']
settings['myProfile']['coverId'] = str(coverId)
def restoreProfile():
profile = line.getProfile()
profile.displayName = settings['myProfile']['displayName']
profile.statusMessage = settings['myProfile']['statusMessage']
line.updateProfile(profile)
if settings['myProfile']['pictureStatus']:
pict = line.downloadFileURL('http://dl.profile.line-cdn.net/' + settings['myProfile']['pictureStatus'])
line.updateProfilePicture(pict)
coverId = settings['myProfile']['coverId']
line.updateProfileCoverById(coverId)
def executeCmd(msg, text, txt, cmd, msg_id, receiver, sender, to, setKey):
if cmd == 'logoutbot':
line.sendMessage(to, 'Bot will logged out')
sys.exit('##----- PROGRAM STOPPED -----##')
elif cmd == 'logoutdevicee':
line.logout()
sys.exit('##----- CLIENT LOGOUT -----##')
elif cmd == 'restart':
line.sendMessage(to, 'Bot will restarting, please wait until the bot can operate ♪')
settings['restartPoint'] = to
restartProgram()
elif cmd == 'help':
line.sendReplyMessage(msg_id, to, help())
elif cmd == 'speed':
start = time.time()
line.sendMessage(to, 'Checking speed')
elapse = time.time() - start
line.sendMessage(to, 'Speed sending message took %s seconds' % str(elapse))
elif cmd == 'me':
line.sendContact(to, myMid)
elif cmd == 'runtime':
runtime = time.time() - programStart
line.sendMessage(to, 'Bot already running on ' + format_timespan(runtime))
elif cmd == 'author':
line.sendMessage(to, 'Author is linepy')
elif cmd == 'about':
res = '╭───「 About 」'
res += '\n├ Type : Selfbot Hello World'
res += '\n├ Version : 3.0.8'
res += '\n├ Library : linepy (Python)'
res += '\n├ Creator : Zero Cool'
res += '\n╰───「 Hello World 」'
line.sendMessage(to, res)
elif cmd == 'status':
res = '╭───「 Status 」'
res += '\n├ Auto Add : ' + bool_dict[settings['autoAdd']['status']][1]
res += '\n├ Auto Join : ' + bool_dict[settings['autoJoin']['status']][1]
res += '\n├ Auto Respond : ' + bool_dict[settings['autoRespond']['status']][1]
res += '\n├ Auto Respond Mention : ' + bool_dict[settings['autoRespondMention']['status']][1]
res += '\n├ Auto Read : ' + bool_dict[settings['autoRead']][1]
res += '\n├ Setting Key : ' + bool_dict[settings['setKey']['status']][1]
res += '\n├ Mimic : ' + bool_dict[settings['mimic']['status']][1]
res += '\n├ Greetings Join : ' + bool_dict[settings['greet']['join']['status']][1]
res += '\n├ Greetings Leave : ' + bool_dict[settings['greet']['leave']['status']][1]
res += '\n├ Check Contact : ' + bool_dict[settings['checkContact']][1]
res += '\n├ Check Post : ' + bool_dict[settings['checkPost']][1]
res += '\n├ Check Sticker : ' + bool_dict[settings['checkSticker']][1]
res += '\n╰───「 Hello World 」'
line.sendMessage(to, parsingRes(res))
elif cmd == 'abort':
aborted = False
if to in settings['changeGroupPicture']:
settings['changeGroupPicture'].remove(to)
line.sendMessage(to, 'Change group picture aborted')
aborted = True
if settings['changePictureProfile']:
settings['changePictureProfile'] = False
line.sendMessage(to, 'Change picture profile aborted')
aborted = True
if settings['changeCoverProfile']:
settings['changeCoverProfile'] = False
line.sendMessage(to, 'Change cover profile aborted')
aborted = True
if not aborted:
line.sendMessage(to, 'Failed abort, nothing to abort')
elif cmd.startswith('error'):
textt = removeCmd(text, setKey)
texttl = textt.lower()
cond = textt.split(' ')
res = '╭───「 Error 」'
res += '\n├ Usage : '
res += '\n│ • {key}Error'
res += '\n│ • {key}Error Logs'
res += '\n│ • {key}Error Reset'
res += '\n│ • {key}Error Detail <errid>'
res += '\n╰───「 Hello World 」'
if cmd == 'error':
line.sendMessage(to, parsingRes(res).format_map(SafeDict(key=setKey.title())))
elif cond[0].lower() == 'logs':
try:
filee = open('errorLog.txt', 'r')
except FileNotFoundError:
return line.sendMessage(to, 'Failed display error logs, error logs file not found')
errors = [err.strip() for err in filee.readlines()]
filee.close()
if not errors: return line.sendMessage(to, 'Failed display error logs, empty error logs')
res = '╭───「 Error Logs 」'
res += '\n├ List :'
parsed_len = len(errors)//200+1
no = 0
for point in range(parsed_len):
for error in errors[point*200:(point+1)*200]:
if not error: continue
no += 1
res += '\n│ %i. %s' % (no, error)
if error == errors[-1]:
res += '\n╰───「 Hello World 」'
if res:
if res.startswith('\n'): res = res[1:]
line.sendMessage(to, res)
res = ''
elif cond[0].lower() == 'reset':
filee = open('errorLog.txt', 'w')
filee.write('')
filee.close()
shutil.rmtree('tmp/errors/', ignore_errors=True)
os.system('mkdir tmp/errors')
line.sendMessage(to, 'Success reset error logs')
elif cond[0].lower() == 'detail':
if len(cond) < 2:
return line.sendMessage(to, parsingRes(res).format_map(SafeDict(key=setKey.title())))
errid = cond[1]
if os.path.exists('tmp/errors/%s.txt' % errid):
with open('tmp/errors/%s.txt' % errid, 'r') as f:
line.sendMessage(to, f.read())
else:
return line.sendMessage(to, 'Failed display details error, errorid not valid')
else:
line.sendMessage(to, parsingRes(res).format_map(SafeDict(key=setKey.title())))
elif txt.startswith('setkey'):
textt = removeCmd(text, setKey)
texttl = textt.lower()
res = '╭───「 Setting Key 」'
res += '\n├ Status : ' + bool_dict[settings['setKey']['status']][1]
res += '\n├ Key : ' + settings['setKey']['key'].title()
res += '\n├ Usage : '
res += '\n│ • Setkey'
res += '\n│ • Setkey <on/off>'
res += '\n│ • Setkey <key>'
res += '\n╰───「 Hello World 」'
if txt == 'setkey':
line.sendMessage(to, parsingRes(res))
elif texttl == 'on':
if settings['setKey']['status']:
line.sendMessage(to, 'Failed activate setkey, setkey already active')
else:
settings['setKey']['status'] = True
line.sendMessage(to, 'Success activated setkey')
elif texttl == 'off':
if not settings['setKey']['status']:
line.sendMessage(to, 'Failed deactivate setkey, setkey already deactive')
else:
settings['setKey']['status'] = False
line.sendMessage(to, 'Success deactivated setkey')
else:
settings['setKey']['key'] = texttl
line.sendMessage(to, 'Success change set key to (%s)' % textt)
elif cmd.startswith('autoadd'):
textt = removeCmd(text, setKey)
texttl = textt.lower()
cond = textt.split(' ')
res = '╭───「 Auto Add 」'
res += '\n├ Status : ' + bool_dict[settings['autoAdd']['status']][1]
res += '\n├ Reply : ' + bool_dict[settings['autoAdd']['reply']][0]
res += '\n├ Reply Message : ' + settings['autoAdd']['message']
res += '\n├ Usage : '
res += '\n│ • {key}AutoAdd'
res += '\n│ • {key}AutoAdd <on/off>'
res += '\n│ • {key}AutoAdd Reply <on/off>'
res += '\n│ • {key}AutoAdd <message>'
res += '\n╰───「 Hello World 」'
if cmd == 'autoadd':
line.sendMessage(to, parsingRes(res).format_map(SafeDict(key=setKey.title())))
elif texttl == 'on':
if settings['autoAdd']['status']:
line.sendMessage(to, 'Autoadd already active')
else:
settings['autoAdd']['status'] = True
line.sendMessage(to, 'Success activated autoadd')
elif texttl == 'off':
if not settings['autoAdd']['status']:
line.sendMessage(to, 'Autoadd already deactive')
else:
settings['autoAdd']['status'] = False
line.sendMessage(to, 'Success deactivated autoadd')
elif cond[0].lower() == 'reply':
if len(cond) < 2:
return line.sendMessage(to, parsingRes(res).format_map(SafeDict(key=setKey.title())))
if cond[1].lower() == 'on':
if settings['autoAdd']['reply']:
line.sendMessage(to, 'Reply message autoadd already active')
else:
settings['autoAdd']['reply'] = True
line.sendMessage(to, 'Success activate reply message autoadd')
elif cond[1].lower() == 'off':
if not settings['autoAdd']['reply']:
line.sendMessage(to, 'Reply message autoadd already deactive')
else:
settings['autoAdd']['reply'] = False
line.sendMessage(to, 'Success deactivate reply message autoadd')
else:
line.sendMessage(to, parsingRes(res).format_map(SafeDict(key=setKey.title())))
else:
settings['autoAdd']['message'] = textt
line.sendMessage(to, 'Success change autoadd message to `%s`' % textt)
elif cmd.startswith('autojoin'):
textt = removeCmd(text, setKey)
texttl = textt.lower()
cond = textt.split(' ')
res = '╭───「 Auto Join 」'
res += '\n├ Status : ' + bool_dict[settings['autoJoin']['status']][1]
res += '\n├ Reply : ' + bool_dict[settings['autoJoin']['reply']][0]
res += '\n├ Reply Message : ' + settings['autoJoin']['message']
res += '\n├ Usage : '
res += '\n│ • {key}AutoJoin'
res += '\n│ • {key}AutoJoin <on/off>'
res += '\n│ • {key}AutoJoin Ticket <on/off>'
res += '\n│ • {key}AutoJoin Reply <on/off>'
res += '\n│ • {key}AutoJoin <message>'
res += '\n╰───「 Hello World 」'
if cmd == 'autojoin':
line.sendMessage(to, parsingRes(res).format_map(SafeDict(key=setKey.title())))
elif texttl == 'on':
if settings['autoJoin']['status']:
line.sendMessage(to, 'Autojoin already active')
else:
settings['autoJoin']['status'] = True
line.sendMessage(to, 'Success activated autojoin')
elif texttl == 'off':
if not settings['autoJoin']['status']:
line.sendMessage(to, 'Autojoin already deactive')
else:
settings['autoJoin']['status'] = False
line.sendMessage(to, 'Success deactivated autojoin')
elif cond[0].lower() == 'reply':
if len(cond) < 2:
return line.sendMessage(to, parsingRes(res).format_map(SafeDict(key=setKey.title())))
if cond[1].lower() == 'on':
if settings['autoJoin']['reply']:
line.sendMessage(to, 'Reply message autojoin already active')
else:
settings['autoJoin']['reply'] = True
line.sendMessage(to, 'Success activate reply message autojoin')
elif cond[1].lower() == 'off':
if not settings['autoJoin']['reply']:
line.sendMessage(to, 'Reply message autojoin already deactive')
else:
settings['autoJoin']['reply'] = False
line.sendMessage(to, 'Success deactivate reply message autojoin')
else:
line.sendMessage(to, parsingRes(res).format_map(SafeDict(key=setKey.title())))
elif cond[0].lower() == 'ticket':
if len(cond) < 2:
return line.sendMessage(to, parsingRes(res).format_map(SafeDict(key=setKey.title())))
if cond[1].lower() == 'on':
if settings['autoJoin']['ticket']:
line.sendMessage(to, 'Autojoin ticket already active')
else:
settings['autoJoin']['ticket'] = True
line.sendMessage(to, 'Success activate autojoin ticket')
elif cond[1].lower() == 'off':
if not settings['autoJoin']['ticket']:
line.sendMessage(to, 'Autojoin ticket already deactive')
else:
settings['autoJoin']['ticket'] = False
line.sendMessage(to, 'Success deactivate autojoin ticket')
else:
line.sendMessage(to, parsingRes(res).format_map(SafeDict(key=setKey.title())))
else:
settings['autoJoin']['message'] = textt
line.sendMessage(to, 'Success change autojoin message to `%s`' % textt)
elif cmd.startswith('autorespondmention'):
textt = removeCmd(text, setKey)
texttl = textt.lower()
res = '╭───「 Auto Respond 」'
res += '\n├ Status : ' + bool_dict[settings['autoRespondMention']['status']][1]
res += '\n├ Reply Message : ' + settings['autoRespondMention']['message']
res += '\n├ Usage : '
res += '\n│ • {key}AutoRespondMention'
res += '\n│ • {key}AutoRespondMention <on/off>'
res += '\n│ • {key}AutoRespondMention <message>'
res += '\n╰───「 Hello World 」'
if cmd == 'autorespondmention':
line.sendMessage(to, parsingRes(res).format_map(SafeDict(key=setKey.title())))
elif texttl == 'on':
if settings['autoRespondMention']['status']:
line.sendMessage(to, 'Autorespondmention already active')
else:
settings['autoRespondMention']['status'] = True
line.sendMessage(to, 'Success activated autorespondmention')
elif texttl == 'off':
if not settings['autoRespondMention']['status']:
line.sendMessage(to, 'Autorespondmention already deactive')
else:
settings['autoRespondMention']['status'] = False
line.sendMessage(to, 'Success deactivated autorespondmention')
else:
settings['autoRespondMention']['message'] = textt
line.sendMessage(to, 'Success change autorespondmention message to `%s`' % textt)
elif cmd.startswith('autorespond'):
textt = removeCmd(text, setKey)
texttl = textt.lower()
res = '╭───「 Auto Respond 」'
res += '\n├ Status : ' + bool_dict[settings['autoRespond']['status']][1]
res += '\n├ Reply Message : ' + settings['autoRespond']['message']
res += '\n├ Usage : '
res += '\n│ • {key}AutoRespond'
res += '\n│ • {key}AutoRespond <on/off>'
res += '\n│ • {key}AutoRespond <message>'
res += '\n╰───「 Hello World 」'
if cmd == 'autorespond':
line.sendMessage(to, parsingRes(res).format_map(SafeDict(key=setKey.title())))
elif texttl == 'on':
if settings['autoRespond']['status']:
line.sendMessage(to, 'Autorespond already active')
else:
settings['autoRespond']['status'] = True
line.sendMessage(to, 'Success activated autorespond')
elif texttl == 'off':
if not settings['autoRespond']['status']:
line.sendMessage(to, 'Autorespond already deactive')
else:
settings['autoRespond']['status'] = False
line.sendMessage(to, 'Success deactivated autorespond')
else:
settings['autoRespond']['message'] = textt
line.sendMessage(to, 'Success change autorespond message to `%s`' % textt)
elif cmd.startswith('autoread '):
textt = removeCmd(text, setKey)
texttl = textt.lower()
if texttl == 'on':
if settings['autoRead']:
line.sendMessage(to, 'Autoread already active')
else:
settings['autoRead'] = True
line.sendMessage(to, 'Success activated autoread')
elif texttl == 'off':
if not settings['autoRead']:
line.sendMessage(to, 'Autoread already deactive')
else:
settings['autoRead'] = False
line.sendMessage(to, 'Success deactivated autoread')
elif cmd.startswith('checkcontact '):
textt = removeCmd(text, setKey)
texttl = textt.lower()
if texttl == 'on':
if settings['checkContact']:
line.sendMessage(to, 'Checkcontact already active')
else:
settings['checkContact'] = True
line.sendMessage(to, 'Success activated checkcontact')
elif texttl == 'off':
if not settings['checkContact']:
line.sendMessage(to, 'Checkcontact already deactive')
else:
settings['checkContact'] = False
line.sendMessage(to, 'Success deactivated checkcontact')
elif cmd.startswith('checkpost '):
textt = removeCmd(text, setKey)
texttl = textt.lower()
if texttl == 'on':
if settings['checkPost']:
line.sendMessage(to, 'Checkpost already active')
else:
settings['checkPost'] = True
line.sendMessage(to, 'Success activated checkpost')
elif texttl == 'off':
if not settings['checkPost']:
line.sendMessage(to, 'Checkpost already deactive')
else:
settings['checkPost'] = False
line.sendMessage(to, 'Success deactivated checkpost')
elif cmd.startswith('checksticker '):
textt = removeCmd(text, setKey)
texttl = textt.lower()
if texttl == 'on':
if settings['checkSticker']:
line.sendMessage(to, 'Checksticker already active')
else:
settings['checkSticker'] = True
line.sendMessage(to, 'Success activated checksticker')
elif texttl == 'off':
if not settings['checkSticker']:
line.sendMessage(to, 'Checksticker already deactive')
else:
settings['checkSticker'] = False
line.sendMessage(to, 'Success deactivated checksticker')
elif cmd.startswith('myprofile'):
textt = removeCmd(text, setKey)
texttl = textt.lower()
profile = line.getProfile()
res = '╭───「 My Profile 」'
res += '\n├ MID : ' + profile.mid
res += '\n├ Display Name : ' + str(profile.displayName)
res += '\n├ Status Message : ' + str(profile.statusMessage)
res += '\n├ Usage : '
res += '\n│ • {key}MyProfile'
res += '\n│ • {key}MyProfile MID'
res += '\n│ • {key}MyProfile Name'
res += '\n│ • {key}MyProfile Bio'
res += '\n│ • {key}MyProfile Pict'
res += '\n│ • {key}MyProfile Cover'
res += '\n│ • {key}MyProfile Change Name <name>'
res += '\n│ • {key}MyProfile Change Bio <bio>'
res += '\n│ • {key}MyProfile Change Pict'
res += '\n│ • {key}MyProfile Change Cover'
res += '\n╰───「 Hello World 」'
if cmd == 'myprofile':
if profile.pictureStatus:
line.sendImageWithURL(to, 'http://dl.profile.line-cdn.net/' + profile.pictureStatus)
cover = line.getProfileCoverURL(profile.mid)
line.sendImageWithURL(to, str(cover))
line.sendMessage(to, parsingRes(res).format_map(SafeDict(key=setKey.title())))
elif texttl == 'mid':
line.sendMessage(to, '「 MID 」\n' + str(profile.mid))
elif texttl == 'name':
line.sendMessage(to, '「 Display Name 」\n' + str(profile.displayName))
elif texttl == 'bio':
line.sendMessage(to, '「 Status Message 」\n' + str(profile.statusMessage))
elif texttl == 'pict':
if profile.pictureStatus:
path = 'http://dl.profile.line-cdn.net/' + profile.pictureStatus
line.sendImageWithURL(to, path)
line.sendMessage(to, '「 Picture Status 」\n' + path)
else:
line.sendMessage(to, 'Failed display picture status, user doesn\'t have a picture status')
elif texttl == 'cover':
cover = line.getProfileCoverURL(profile.mid)
line.sendImageWithURL(to, str(cover))
line.sendMessage(to, '「 Cover Picture 」\n' + str(cover))
elif texttl.startswith('change '):
texts = textt[7:]
textsl = texts.lower()
if textsl.startswith('name '):
name = texts[5:]
if len(name) <= 20:
profile.displayName = name
line.updateProfile(profile)
line.sendMessage(to, 'Success change display name, changed to `%s`' % name)
else:
line.sendMessage(to, 'Failed change display name, the length of the name cannot be more than 20')
elif textsl.startswith('bio '):
bio = texts[4:]
if len(bio) <= 500:
profile.statusMessage = bio
line.updateProfile(profile)
line.sendMessage(to, 'Success change status message, changed to `%s`' % bio)
else:
line.sendMessage(to, 'Failed change status message, the length of the bio cannot be more than 500')
elif textsl == 'pict':
settings['changePictureProfile'] = True
line.sendMessage(to, 'Please send the image to set in picture profile, type `{key}Abort` if want cancel it.\nFYI: Downloading images will fail if too long upload the image'.format(key=setKey.title()))
elif textsl == 'cover':
settings['changeCoverProfile'] = True
line.sendMessage(to, 'Please send the image to set in cover profile, type `{key}Abort` if want cancel it.\nFYI: Downloading images will fail if too long upload the image'.format(key=setKey.title()))
else:
line.sendMessage(to, parsingRes(res).format_map(SafeDict(key=setKey.title())))
else:
line.sendMessage(to, parsingRes(res).format_map(SafeDict(key=setKey.title())))
elif cmd.startswith('profile'):
textt = removeCmd(text, setKey)
texttl = textt.lower()
profile = line.getContact(to) if msg.toType == 0 else None
res = '╭───「 My Profile 」'
if profile:
res += '\n├ MID : ' + profile.mid
res += '\n├ Display Name : ' + str(profile.displayName)
if profile.displayNameOverridden: res += '\n├ Display Name Overridden : ' + str(profile.displayNameOverridden)
res += '\n├ Status Message : ' + str(profile.statusMessage)
res += '\n├ Usage : '
res += '\n│ • {key}Profile'
res += '\n│ • {key}Profile Mid'
res += '\n│ • {key}Profile Name'
res += '\n│ • {key}Profile Bio'
res += '\n│ • {key}Profile Pict'
res += '\n│ • {key}Profile Cover'
res += '\n│ • {key}Profile Steal Profile <mention>'
res += '\n│ • {key}Profile Steal Mid <mention>'
res += '\n│ • {key}Profile Steal Name <mention>'
res += '\n│ • {key}Profile Steal Bio <mention>'
res += '\n│ • {key}Profile Steal Pict <mention>'
res += '\n│ • {key}Profile Steal Cover <mention>'
res += '\n╰───「 Hello World 」'
if cmd == 'profile':
if profile:
if profile.pictureStatus:
line.sendImageWithURL(to, 'http://dl.profile.line-cdn.net/' + profile.pictureStatus)
cover = line.getProfileCoverURL(profile.mid)
line.sendImageWithURL(to, str(cover))
line.sendMessage(to, parsingRes(res).format_map(SafeDict(key=setKey.title())))
elif texttl == 'mid':
if msg.toType != 0: return line.sendMessage(to, 'Failed display mid user, use this command only in personal chat')
line.sendMessage(to, '「 MID 」\n' + str(profile.mid))
elif texttl == 'name':
if msg.toType != 0: return line.sendMessage(to, 'Failed display mid user, use this command only in personal chat')
line.sendMessage(to, '「 Display Name 」\n' + str(profile.displayName))
elif texttl == 'bio':
if msg.toType != 0: return line.sendMessage(to, 'Failed display mid user, use this command only in personal chat')
line.sendMessage(to, '「 Status Message 」\n' + str(profile.statusMessage))
elif texttl == 'pict':
if msg.toType != 0: return line.sendMessage(to, 'Failed display mid user, use this command only in personal chat')
if profile.pictureStatus:
path = 'http://dl.profile.line-cdn.net/' + profile.pictureStatus
line.sendImageWithURL(to, path)
line.sendMessage(to, '「 Picture Status 」\n' + path)
else:
line.sendMessage(to, 'Failed display picture status, user doesn\'t have a picture status')
elif texttl == 'cover':
if msg.toType != 0: return line.sendMessage(to, 'Failed display mid user, use this command only in personal chat')
cover = line.getProfileCoverURL(profile.mid)
line.sendImageWithURL(to, str(cover))
line.sendMessage(to, '「 Cover Picture 」\n' + str(cover))
elif texttl.startswith('steal '):
texts = textt[6:]
textsl = texts.lower()
if textsl.startswith('profile '):
if 'MENTION' in msg.contentMetadata.keys():
mentions = ast.literal_eval(msg.contentMetadata['MENTION'])
for mention in mentions['MENTIONEES']:
profile = line.getContact(mention['M'])
if profile.pictureStatus:
line.sendImageWithURL(to, 'http://dl.profile.line-cdn.net/' + profile.pictureStatus)
cover = line.getProfileCoverURL(profile.mid)
line.sendImageWithURL(to, str(cover))
res = '╭───「 Profile 」'
res += '\n├ MID : ' + profile.mid
res += '\n├ Display Name : ' + str(profile.displayName)
if profile.displayNameOverridden: res += '\n├ Display Name Overridden : ' + str(profile.displayNameOverridden)
res += '\n├ Status Message : ' + str(profile.statusMessage)
res += '\n╰───「 Hello World 」'
line.sendMessage(to, parsingRes(res))
else:
line.sendMessage(to, 'Failed steal profile, no one user mentioned')
elif textsl.startswith('mid '):
res = '╭───「 MID 」'
no = 0
if 'MENTION' in msg.contentMetadata.keys():
mentions = ast.literal_eval(msg.contentMetadata['MENTION'])
if len(mentions['MENTIONEES']) == 1:
mid = mentions['MENTIONEES'][0]['M']
return line.sendMessage(to, '「 MID 」\n' + mid)
for mention in mentions['MENTIONEES']:
mid = mention['M']
no += 1
res += '\n│ %i. %s' % (no, mid)
res += '\n╰───「 Hello World 」'
line.sendMessage(to, parsingRes(res))
else:
line.sendMessage(to, 'Failed steal mid, no one user mentioned')
elif textsl.startswith('name '):
res = '╭───「 Display Name 」'
no = 0
if 'MENTION' in msg.contentMetadata.keys():
mentions = ast.literal_eval(msg.contentMetadata['MENTION'])
if len(mentions['MENTIONEES']) == 1:
profile = line.getContact(mentions['MENTIONEES'][0]['M'])
return line.sendMessage(to, '「 Display Name 」\n' + str(profile.displayName))
for mention in mentions['MENTIONEES']:
mid = mention['M']
profile = line.getContact(mid)
no += 1
res += '\n│ %i. %s' % (no, profile.displayName)
res += '\n╰───「 Hello World 」'
line.sendMessage(to, parsingRes(res))
else:
line.sendMessage(to, 'Failed steal display name, no one user mentioned')
elif textsl.startswith('bio '):
res = '╭───「 Status Message 」'
no = 0
if 'MENTION' in msg.contentMetadata.keys():
mentions = ast.literal_eval(msg.contentMetadata['MENTION'])
if len(mentions['MENTIONEES']) == 1:
profile = line.getContact(mentions['MENTIONEES'][0]['M'])
return line.sendMessage(to, '「 Status Message 」\n' + str(profile.statusMessage))
for mention in mentions['MENTIONEES']:
mid = mention['M']
profile = line.getContact(mid)
no += 1
res += '\n│ %i. %s' % (no, profile.statusMessage)
res += '\n╰───「 Hello World 」'
line.sendMessage(to, parsingRes(res))
else:
line.sendMessage(to, 'Failed steal status message, no one user mentioned')
elif textsl.startswith('pict '):
res = '╭───「 Picture Status 」'
no = 0
if 'MENTION' in msg.contentMetadata.keys():
mentions = ast.literal_eval(msg.contentMetadata['MENTION'])
if len(mentions['MENTIONEES']) == 1:
profile = line.getContact(mentions['MENTIONEES'][0]['M'])
if profile.pictureStatus:
path = 'http://dl.profile.line-cdn.net/' + profile.pictureStatus
line.sendImageWithURL(to, path)
return line.sendMessage(to, '「 Picture Status 」\n' + path)
else:
return line.sendMessage(to, 'Failed steal picture status, user `%s` doesn\'t have a picture status' % profile.displayName)
for mention in mentions['MENTIONEES']:
mid = mention['M']
profile = line.getContact(mid)
no += 1
if profile.pictureStatus:
path = 'http://dl.profile.line-cdn.net/' + profile.pictureStatus
line.sendImageWithURL(to, path)
res += '\n│ %i. %s' % (no, path)
else:
res += '\n│ %i. Not Found' % no
res += '\n╰───「 Hello World 」'
line.sendMessage(to, parsingRes(res))
else:
line.sendMessage(to, 'Failed steal picture status, no one user mentioned')
elif textsl.startswith('cover '):
res = '╭───「 Cover Picture 」'
no = 0
if 'MENTION' in msg.contentMetadata.keys():
mentions = ast.literal_eval(msg.contentMetadata['MENTION'])
if len(mentions['MENTIONEES']) == 1:
mid = mentions['MENTIONEES'][0]['M']
cover = line.getProfileCoverURL(mid)
line.sendImageWithURL(to, str(cover))
line.sendMessage(to, '「 Cover Picture 」\n' + str(cover))
for mention in mentions['MENTIONEES']:
mid = mention['M']
no += 1
cover = line.getProfileCoverURL(mid)
line.sendImageWithURL(to, str(cover))
res += '\n│ %i. %s' % (no, cover)
res += '\n╰───「 Hello World 」'
line.sendMessage(to, parsingRes(res))
else:
line.sendMessage(to, 'Failed steal cover picture, no one user mentioned')
else:
line.sendMessage(to, parsingRes(res).format_map(SafeDict(key=setKey.title())))
else:
line.sendMessage(to, parsingRes(res).format_map(SafeDict(key=setKey.title())))
elif cmd.startswith('mimic'):
textt = removeCmd(text, setKey)
texttl = textt.lower()
targets = ''
if settings['mimic']['target']:
no = 0
for target, status in settings['mimic']['target'].items():
no += 1
try:
name = line.getContact(target).displayName
except TalkException:
name = 'Unknown'
targets += '\n│ %i. %s//%s' % (no, name, bool_dict[status][1])
else:
targets += '\n│ Nothing'
res = '╭───「 Mimic 」'
res += '\n├ Status : ' + bool_dict[settings['mimic']['status']][1]
res += '\n├ List :'
res += targets
res += '\n├ Usage : '
res += '\n│ • {key}Mimic'
res += '\n│ • {key}Mimic <on/off>'
res += '\n│ • {key}Mimic Reset'
res += '\n│ • {key}Mimic Add <mention>'
res += '\n│ • {key}Mimic Del <mention>'
res += '\n╰───「 Hello World 」'
if cmd == 'mimic':
line.sendMessage(to, parsingRes(res).format_map(SafeDict(key=setKey.title())))
elif texttl == 'on':
if settings['mimic']['status']:
line.sendMessage(to, 'Mimic already active')
else:
settings['mimic']['status'] = True
line.sendMessage(to, 'Success activated mimic')
elif texttl == 'off':
if not settings['mimic']['status']:
line.sendMessage(to, 'Mimic already deactive')
else:
settings['mimic']['status'] = False
line.sendMessage(to, 'Success deactivated mimic')
elif texttl == 'reset':
settings['mimic']['target'] = {}
line.sendMessage(to, 'Success reset mimic list')
elif texttl.startswith('add '):
res = '╭───「 Mimic 」'
res += '\n├ Status : Add Target'
res += '\n├ Added :'
no = 0
if 'MENTION' in msg.contentMetadata.keys():
mentions = ast.literal_eval(msg.contentMetadata['MENTION'])
for mention in mentions['MENTIONEES']:
mid = mention['M']
settings['mimic']['target'][mid] = True
no += 1
try:
name = line.getContact(mid).displayName
except TalkException:
name = 'Unknown'
res += '\n│ %i. %s' % (no, name)
if no == 0: res += '\n│ Nothing'
res += '\n╰───「 Hello World 」'
line.sendMessage(to, res)
else:
line.sendMessage(to, 'Failed add mimic target, no one user mentioned')
elif texttl.startswith('del '):
res = '╭───「 Mimic 」'
res += '\n├ Status : Del Target'
res += '\n├ Deleted :'
no = 0
if 'MENTION' in msg.contentMetadata.keys():
mentions = ast.literal_eval(msg.contentMetadata['MENTION'])
for mention in mentions['MENTIONEES']:
mid = mention['M']
if mid in settings['mimic']['target']:
settings['mimic']['target'][mid] = False
no += 1
try:
name = line.getContact(mid).displayName
except TalkException:
name = 'Unknown'
res += '\n│ %i. %s' % (no, name)
if no == 0: res += '\n│ Nothing'
res += '\n╰───「 Hello World 」'
line.sendMessage(to, res)
else:
line.sendMessage(to, 'Failed del mimic target, no one user mentioned')
else:
line.sendMessage(to, parsingRes(res).format_map(SafeDict(key=setKey.title())))
elif cmd.startswith('broadcast'):
textt = removeCmd(text, setKey)
texttl = textt.lower()
cond = textt.split(' ')
res = '╭───「 Broadcast 」'
res += '\n├ Broadcast Type : '
res += '\n│ 1 : Friends'
res += '\n│ 2 : Groups'
res += '\n│ 0 : All'
res += '\n├ Usage : '
res += '\n│ • {key}Broadcast'
res += '\n│ • {key}Broadcast <type> <message>'
res += '\n╰───「 Hello World 」'
if cmd == 'broadcast':
line.sendMessage(to, parsingRes(res).format(key=setKey.title()))
elif cond[0] == '1':
if len(cond) < 2:
return line.sendMessage(to, 'Failed broadcast, no message detected')
res = '「 Broadcast 」\n'
res += textt[2:]
res += '\n\n「 Hello World 」'
targets = line.getAllContactIds()
for target in targets:
try:
line.sendMessage(target, res)
except TalkException:
targets.remove(target)
continue
time.sleep(0.8)
line.sendMessage(to, 'Success broadcast to all friends, sent to %i friends' % len(targets))
elif cond[0] == '2':
if len(cond) < 2:
return line.sendMessage(to, 'Failed broadcast, no message detected')
res = '「 Broadcast 」\n'
res += textt[2:]
res += '\n\n「 Hello World 」'
targets = line.getGroupIdsJoined()
for target in targets:
try:
line.sendMessage(target, res)