-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
702 lines (646 loc) · 31.4 KB
/
app.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
from flask import Flask, request, abort
from linebot import (
LineBotApi, WebhookHandler
)
from linebot.exceptions import (
InvalidSignatureError
)
from linebot.models import *
import requests, json
import errno
import os
import sys, random, datetime, time, re
import tempfile
import urllib
import cmds
import cinemaxxi
import yify_torrent
import imdbthing
import acc
import sesuatu
import imp
import schedule
import notif
import quiz
from acc import (namaBot, google_key, line_bot_api, handler, db, owner)
from sesuatu import (mau_nonton, pengaturan, panggil)
from bs4 import BeautifulSoup
from linebot.exceptions import LineBotApiError
from linebot.models import (
MessageEvent, TextMessage, TextSendMessage,
SourceUser, SourceGroup, SourceRoom,
TemplateSendMessage, ConfirmTemplate, MessageAction,
ButtonsTemplate, ImageCarouselTemplate, ImageCarouselColumn, URIAction,
PostbackAction, DatetimePickerAction,
CarouselTemplate, CarouselColumn, PostbackEvent,
StickerMessage, StickerSendMessage, LocationMessage, LocationSendMessage,
ImageMessage, VideoMessage, AudioMessage, FileMessage,
UnfollowEvent, FollowEvent, JoinEvent, LeaveEvent, BeaconEvent,
FlexSendMessage, BubbleContainer, CarouselContainer, ImageComponent, BoxComponent,
TextComponent, SpacerComponent, IconComponent, ButtonComponent,
SeparatorComponent, Error, ErrorDetail
)
app = Flask(__name__)
sleep = False
#===========[ NOTE SAVER ]=======================
notes = {}
perintah = {}
# Post Request
@app.route("/callback", methods=['POST'])
def callback():
signature = request.headers['X-Line-Signature']
body = request.get_data(as_text=True)
app.logger.info("Request body: " + body)
try:
handler.handle(body, signature)
except InvalidSignatureError:
abort(400)
return 'OK'
@handler.add(JoinEvent)
def handle_join(event):
line_bot_api.reply_message(event.reply_token, [
TextSendMessage(
text="Terima Kasih telah memasukkan "+namaBot.capitalize()+" dalam chat ini ;D\nJika kalian membutuhkan bantuanku, panggil saja :)"
),
TextSendMessage(
text='Agar dapat menggunakan fitur-fitur yang ada, harus add '+namaBot.capitalize()+' sebagai teman dulu yak ;D',
quick_reply=QuickReply(
items=[
QuickReplyButton(
action=MessageAction(
label=namaBot.capitalize(),
text=namaBot.capitalize()
)
)
]
)
)
]
)
if isinstance(event.source, SourceGroup):
ruang = event.source.sender_id
elif isinstance(event.source, SourceRoom):
ruang = event.source.room_id
db.child(event.source.type).child(ruang).set(time.time())
try:
jumlah = db.child(event.source.type).get().val()["total"]
db.child(event.source.type).child("total").update(jumlah+1)
except:
db.child(event.source.type).child("total").set(1)
@handler.add(LeaveEvent)
def handle_leave(event):
if isinstance(event.source, SourceGroup):
ruang = event.source.sender_id
elif isinstance(event.source, SourceRoom):
ruang = event.source.room_id
db.child(event.source.type).child(ruang).remove()
try:
jumlah = db.child(event.source.type).get().val()["total"]
db.child(event.source.type).child("total").update(jumlah-1)
except:
db.child(event.source.type).child("total").set(0)
@handler.add(FollowEvent)
def handle_follow(event):
line_bot_api.reply_message(event.reply_token,
[
TextSendMessage(
text='Terima kasih telah menambahkan '+namaBot+' sebagai teman ;D\n'+namaBot+' akan membantu kamu ketika kamu ingin bermain, cek film bioskop, download film, dan download youtube ;)\nKak '+line_bot_api.get_profile(event.source.user_id).display_name+' bisa mematikan notifikasi jika '+namaBot+' mengganggu :('
),
TextSendMessage(
text='Panggil saja namaku jika kamu ingin ditemani ;D',
quick_reply=QuickReply(
items=[
QuickReplyButton(
action=MessageAction(
label='Panggil',
text=namaBot.capitalize()
)
)
]
)
)
]
)
data = {'nama':line_bot_api.get_profile(event.source.user_id).display_name,
'foto':line_bot_api.get_profile(event.source.user_id).picture_url,
'status':line_bot_api.get_profile(event.source.user_id).status_message,
'waktu_add':time.time()}
db.child("pengguna").child(event.source.user_id).set(data)
try:
jumlah = db.child("pengguna").get().val()["total"]
db.child("pengguna").child("total").update(jumlah+1)
except:
db.child("pengguna").child("total").set(1)
@handler.add(PostbackEvent)
def handle_postback(event):
cmds.handle_postback(event)
yify_torrent.handle_postback(event)
cinemaxxi.handle_postback(event)
notif.handle_postback(event)
quiz.handle_postback(event)
imdbthing.handle_postback(event)
sender = event.source.user_id
if isinstance(event.source, SourceGroup):
kirim = gid
elif isinstance(event.source, SourceRoom):
kirim = event.source.room_id
else:
kirim = sender
try:
if event.postback.data[0] == '/':
data = event.postback.data[1:].split(" ",1)
if len(data) > 1:
cmd, args = data[0].lower(), data[1]
else:
cmd, args = data[0].lower(), ""
if cmd == "pengaturan":
line_bot_api.reply_message(event.reply_token, pengaturan(sender))
elif cmd == "lokasi":
line_bot_api.reply_message(event.reply_token,
TextSendMessage(
text='Share lokasi dulu kak '+panggil(sender)+' ;)',
quick_reply=QuickReply(
items=[
QuickReplyButton(
action=LocationAction(
label='Share lokasi'
)
)
]
)
)
)
perintah.update({sender:['lokasi',time.time()]})
elif cmd == "nick":
if args == sender:
gunakan = args
else:
gunakan = sender
line_bot_api.reply_message(event.reply_token, TextSendMessage(text="Kak "+panggil(gunakan)+" mau dipanggil apa?"))
perintah.update({sender:['panggilan', time.time()]})
elif cmd == "tanggal_lahir":
if args == sender:
gunakan = args
else:
gunakan = sender
db.child("pengguna").child(gunakan).child("tambahan").child("tanggal_lahir").set(event.postback.params['date'])
sekarang = datetime.datetime.utcfromtimestamp(time.time())
tanggal = int(sekarang.strftime('%d'))
bulan = int(sekarang.strftime('%m'))
tahun = int(sekarang.strftime('%Y'))
utahun, ubulan, utanggal = event.postback.params['date'].split('-')
umur = tahun - int(utahun)
if tanggal < int(utanggal):
if bulan < int(ubulan):
umur = umur - 1
line_bot_api.reply_message(event.reply_token, TextSendMessage(text="Kak "+panggil(gunakan)+" sekarang berumur "+str(umur)+" tahun ;D"))
except Exception as e:
try:
et, ev, tb = sys.exc_info()
lineno = tb.tb_lineno
fn = tb.tb_frame.f_code.co_filename
if sender != owner:
line_bot_api.reply_message(event.reply_token, [
TextSendMessage(text='Oopps.. '+namaBot.capitalize()+' ada kesalahan kak :('),
TextSendMessage(text='Tapi tenang kak, laporan kesalahan ini terkirim ke owner untuk diperbaiki ;D')
]
)
line_bot_api.push_message(owner, TextSendMessage(text="[Expectation Failed] %s Line %i - %s"% (fn, lineno, str(e))))
except:
line_bot_api.push_message(owner, TextSendMessage(text="Undescribeable error detected!!"))
@handler.add(MessageEvent, message=LocationMessage)
def handle_location_message(event):
cinemaxxi.handle_location_message(event)
if event.source.user_id in perintah:
komando, waktu = perintah[event.source.user_id]
if komando == "lokasi":
line_bot_api.reply_message(event.reply_token, TextSendMessage(text='Kak '+panggil(event.source.user_id)+' sekarang berada di '+event.message.address+' ;)'))
data = {'nama_lokasi':event.message.address,
'latitude':event.message.latitude,
'longitude':event.message.longitude}
db.child("pengguna").child(event.source.user_id).child("tambahan").child("lokasi").set(data)
del perintah[event.source.user_id]
@handler.add(MessageEvent, message=TextMessage)
def handle_message(event):
sender = event.source.user_id
text = event.message.text
try:
startTime = time.time()
cmds.handle_message(event)
cinemaxxi.handle_message(event)
yify_torrent.handle_message(event)
quiz.handle_message(event)
notif.handle_message(event)
imdbthing.handle_message(event)
gid = event.source.sender_id #get group_id
profil = line_bot_api.get_profile(sender)
try:
nama = panggil(sender) #Ini buat nama
except:
data = {'nama':line_bot_api.get_profile(event.source.user_id).display_name,
'foto':line_bot_api.get_profile(event.source.user_id).picture_url,
'status':line_bot_api.get_profile(event.source.user_id).status_message,
'waktu_add':time.time()}
db.child("pengguna").child(event.source.user_id).set(data)
gambar = profil.picture_url #Ini profile picture
status = profil.status_message #Ini status di line
def stimey(total_seconds):
try:
MINUTE = 60
HOUR = MINUTE * 60
DAY = HOUR * 24
days = int( total_seconds / DAY )
hours = int( ( total_seconds % DAY ) / HOUR )
minutes = int( ( total_seconds % HOUR ) / MINUTE )
seconds = int( total_seconds % MINUTE )
string = list()
if days > 0:
string.append(str(days) + " hari")
if hours > 0:
string.append(str(hours) + " jam")
if minutes > 0:
string.append(str(minutes) + " menit")
if seconds > 0:
string.append(str(seconds) + " detik")
else:
if len(string) == 0:string.append("0 detik")
if len(string) > 1:
return ", ".join(string[:-1])+", dan "+string[-1]
else:
return ", ".join(string)
except Exception as e:
try:
et, ev, tb = sys.exc_info()
lineno = tb.tb_lineno
fn = tb.tb_frame.f_code.co_filename
if sender != owner:
line_bot_api.reply_message(event.reply_token, [TextSendMessage(text='Oopps.. '+namaBot.capitalize()+' ada kesalahan kak :('),TextSendMessage(text='Tapi tenang kak, laporan kesalahan ini terkirim ke owner untuk diperbaiki ;D')])
line_bot_api.push_message(owner, TextSendMessage(text="[Expectation Failed] %s Line %i - %s"% (fn, lineno, str(e))))
except:
line_bot_api.push_message(owner, TextSendMessage(text="Undescribeable error detected!!"))
if isinstance(event.source, SourceGroup):
kirim = gid
elif isinstance(event.source, SourceRoom):
kirim = event.source.room_id
else:
kirim = sender
def balas(args):
line_bot_api.reply_message(event.reply_token, TextSendMessage(text=args))
def message(args):
line_bot_api.push_message(kirim, TextSendMessage(text=args))
def img(args):
line_bot_api.push_message(kirim, ImageSendMessage(
original_content_url=args,
preview_image_url=args))
if sender in perintah:
komando, waktu = perintah[sender]
if komando == "panggilan":
if text == "Ubah nama panggilan":return
db.child("pengguna").child(sender).child("tambahan").child("panggilan").set(text)
line_bot_api.reply_message(event.reply_token, TextSendMessage(text="Mulai sekarang kakak akan kupanggil "+text+" ;D"))
del perintah[sender]
if text.lower() == namaBot:
pesan = FlexSendMessage(
alt_text="Menu",
contents=CarouselContainer(
contents=[
BubbleContainer(
styles=BubbleStyle(
header=BlockStyle(
background_color='#223e7c'
)
),
header=BoxComponent(
layout='vertical',
contents=[
TextComponent(
text='MENU',
align='center',
color='#ffffff'
)
]
),
body=BoxComponent(
layout='vertical',
spacing='md',
contents=[
BoxComponent(
layout='horizontal',
spacing='sm',
contents=[
BoxComponent(
layout='vertical',
spacing='sm',
contents=[
ImageComponent(
url='https://i.postimg.cc/k4ybdVvm/movie-icon-11.png',
align='center',
action=MessageAction(
label='Film',
text='Nonton film kuy'
)
),
TextComponent(
text='Film',
size='xs',
align='center'
)
]
),
BoxComponent(
layout='vertical',
spacing='sm',
contents=[
ImageComponent(
url='https://goo.gl/Rtqc1r',
align='center',
action=MessageAction(
label='Drama',
text='Mau nonton drama nih'
)
),
TextComponent(
text='Drama',
size='xs',
align='center'
)
]
),
BoxComponent(
layout='vertical',
spacing='sm',
contents=[
ImageComponent(
url='https://goo.gl/S9GjL7',
align='center',
action=MessageAction(
label='YouTube',
text='Mau nonton YouTube'
)
),
TextComponent(
text='YouTube',
size='xs',
align='center'
)
]
)
]
),
BoxComponent(
layout='horizontal',
spacing='sm',
contents=[
BoxComponent(
layout='vertical',
spacing='sm',
contents=[
ImageComponent(
url='https://i.postimg.cc/DzD04rPf/70.png',
align='center',
action=PostbackAction(
label='Main',
text='Main kuy',
data='/main'
)
),
TextComponent(
text='Permainan',
size='xs',
align='center'
)
]
),
BoxComponent(
layout='vertical',
spacing='sm',
contents=[
ImageComponent(
url='https://i.postimg.cc/q75v5Q3X/69.png',
align='center',
action=PostbackAction(
label='Pengingat',
text='Atur pengingat',
data='/pengingat'
)
),
TextComponent(
text='Pengingat',
wrap=True,
size='xs',
align='center'
)
]
),
BoxComponent(
layout='vertical',
spacing='sm',
contents=[
ImageComponent(
url='https://i.postimg.cc/YqqXtBh6/settings-3-icon.png',
align='center',
action=PostbackAction(
label='Pengaturan',
text='Pengaturan',
data='/pengaturan'
)
),
TextComponent(
text='Pengaturan',
size='xs',
align='center',
wrap=True
)
]
)
]
)
]
),
footer=BoxComponent(
layout='baseline',
contents=[
TextComponent(
text='© YRP',
size='xxs',
align='start'
),
TextComponent(
text=namaBot.capitalize()+' '+os.environ.get('HEROKU_RELEASE_VERSION'),
size='xxs',
align='end'
)
]
)
)
]
)
)
line_bot_api.reply_message(event.reply_token, [TextComponent(text="Kamu ingin apa hari ini?"), pesan])
elif text == "Nonton film kuy":
balas("Ini aku punya beberapa fungsi kalau kak "+nama+" mau nonton film ;)")
line_bot_api.push_message(kirim, mau_nonton())
elif namaBot in text.lower() and not text.lower() == namaBot and not sender in cmds.perintah:
if "apa" in text.lower():
if text.lower()[len(text)-1] == "?":
balas(random.choice(["Ya","Tidak","Terkadang","Mungkin","Coba tanya lagi","Entah","Hmm..."]))
else:
balas("Situ bertanya?")
#=====[ LEAVE GROUP OR ROOM ]==========
elif 'get out' == text.lower() or 'bye' == text.lower():
if sender != owner:
balas("STFU!")
return
if isinstance(event.source, SourceGroup):
line_bot_api.reply_message(
event.reply_token, TextSendMessage(text='Good Bye Cruel World'))
line_bot_api.leave_group(event.source.group_id)
elif isinstance(event.source, SourceRoom):
line_bot_api.reply_message(
event.reply_token, TextSendMessage(text='Good Bye Cruel World'))
line_bot_api.leave_room(event.source.room_id)
else:
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text="No!"))
################################################
elif text.lower() == "who am i?":
#message("You're "+nama)
line_bot_api.reply_message(event.reply_token, TextSendMessage(text="You're "+nama))
line_bot_api.push_message(kirim, ImageSendMessage(
original_content_url=gambar,
preview_image_url=gambar
))
elif text[0] == "=":
data = text[1:].split(" ",1)
if len(data) > 1:
cmd, args = data[0].lower(), data[1]
else:
cmd, args = data[0].lower(), ""
if cmd == "e":
if sender != owner:
message('STFU!')
return
try:
ret = eval(args)
if ret == None:
message("Done.")
return
message(str(ret))
except Exception as e:
try:
et, ev, tb = sys.exc_info()
lineno = tb.tb_lineno
fn = tb.tb_frame.f_code.co_filename
message("[Expectation Failed] %s Line %i - %s"% (fn, lineno, str(e)))
except:
message("Undescribeable error detected!!")
#=====[ FLEX MESSAGE ]==========
elif text == 'flex':
bubble = BubbleContainer(
direction='ltr',
hero=ImageComponent(
url='https://i.pinimg.com/originals/0b/45/54/0b45541af3e8d77e23498c1bc8d552f6.jpg',
size='full',
aspect_ratio='20:13',
aspect_mode='cover',
action=URIAction(uri='http://line.me/ti/p/~freedom_for_all', label='label')
),
body=BoxComponent(
layout='vertical',
contents=[
# title
TextComponent(text='Noir', weight='bold', size='xl'),
# review
BoxComponent(
layout='baseline',
margin='md',
contents=[
IconComponent(size='sm', url='https://example.com/gold_star.png'),
IconComponent(size='sm', url='https://example.com/grey_star.png'),
IconComponent(size='sm', url='https://example.com/gold_star.png'),
IconComponent(size='sm', url='https://example.com/gold_star.png'),
IconComponent(size='sm', url='https://example.com/grey_star.png'),
TextComponent(text='4.0', size='sm', color='#999999', margin='md',
flex=0)
]
),
# info
BoxComponent(
layout='vertical',
margin='lg',
spacing='sm',
contents=[
BoxComponent(
layout='baseline',
spacing='sm',
contents=[
TextComponent(
text='Place',
color='#aaaaaa',
size='sm',
flex=1
),
TextComponent(
text='Ujung Pandang, Indonesia',
wrap=True,
color='#666666',
size='sm',
flex=5
)
],
),
BoxComponent(
layout='baseline',
spacing='sm',
contents=[
TextComponent(
text='Time',
color='#aaaaaa',
size='sm',
flex=1
),
TextComponent(
text="10:00 - 23:00",
wrap=True,
color='#666666',
size='sm',
flex=5,
),
],
),
],
)
],
),
footer=BoxComponent(
layout='vertical',
spacing='sm',
contents=[
# separator
SeparatorComponent(),
# websiteAction
ButtonComponent(
style='link',
height='sm',
action=URIAction(label='Noir', uri="https://line.me/ti/p/~freedom_for_all")
)
]
),
)
message = FlexSendMessage(alt_text="Hi there!", contents=bubble)
line_bot_api.reply_message(
event.reply_token,
message
)
#=======================================================================================================================
############ ERROR HANDLING ############
except LineBotApiError as e:
print(e.status_code)
print(e.error.message)
print(e.error.details)
import os
if __name__ == "__main__":
sesuatu.reminder()
port = int(os.environ.get('PORT', 5000))
app.run(host='0.0.0.0', port=port)