-
Notifications
You must be signed in to change notification settings - Fork 16
/
fb.py
718 lines (617 loc) · 29.4 KB
/
fb.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
# (c) NTM
from fbchat import Client, log, _graphql
from fbchat.models import *
import json
import random
import wolframalpha
import requests
import time
import math
import sqlite3
from bs4 import BeautifulSoup
import os
import openai
import concurrent.futures
from difflib import SequenceMatcher, get_close_matches
class ChatBot(Client):
def onMessage(self, mid=None, author_id=None, message_object=None, thread_id=None, thread_type=ThreadType.USER, **kwargs):
try:
msg = str(message_object).split(",")[15][14:-1]
print(msg)
if (".mp4" in msg):
msg = msg
else:
msg = str(message_object).split(",")[19][20:-1]
except:
try:
msg = (message_object.text).lower()
print(msg)
except:
pass
def sendMsg():
if (author_id != self.uid):
self.send(Message(text=reply), thread_id=thread_id,
thread_type=thread_type)
def sendQuery():
self.send(Message(text=reply), thread_id=thread_id,
thread_type=thread_type)
if(author_id == self.uid):
pass
else:
try:
conn = sqlite3.connect("messages.db")
c = conn.cursor()
c.execute("""
CREATE TABLE IF NOT EXISTS "{}" (
mid text PRIMARY KEY,
message text NOT NULL
);
""".format(str(author_id).replace('"', '""')))
c.execute("""
INSERT INTO "{}" VALUES (?, ?)
""".format(str(author_id).replace('"', '""')), (str(mid), msg))
conn.commit()
conn.close()
except:
pass
def corona_details(country_name):
from datetime import date, timedelta
today = date.today()
today = date.today()
yesterday = today - timedelta(days=1)
url = "https://covid-193.p.rapidapi.com/history"
querystring = {"country": country_name, "day": yesterday}
headers = {
'x-rapidapi-key': "8cd2881885msh9933f89c5aa2186p1d8076jsn7303d42b3c66",
'x-rapidapi-host': "covid-193.p.rapidapi.com"
}
response = requests.request(
"GET", url, headers=headers, params=querystring)
data_str = response.text
data = eval(data_str.replace("null", "None"))
country_name = data["response"][0]["country"]
new_cases = data["response"][0]["cases"]["new"]
active_cases = data["response"][0]["cases"]["active"]
total_cases = data["response"][0]["cases"]["total"]
critical_cases = data["response"][0]["cases"]["critical"]
total_deaths = data["response"][0]["deaths"]["total"]
total_recovered = data["response"][0]["cases"]["recovered"]
new_deaths = data["response"][0]["deaths"]["new"]
reply = f'Corona Virus Info of {country_name}:\n🥺 New Cases : {new_cases.replace("+", "")}\n😟 New Deaths : {new_deaths.replace("+", "")}\n😔 Active Cases : {active_cases}\n⚰️ Total Deaths: {total_deaths} \n🤕 Critical Cases: {critical_cases}\n💉 Total Cases: {total_cases}\n😊 Total Recovered: {total_recovered}'
self.send(Message(text=reply), thread_id=thread_id,
thread_type=thread_type)
def weather(city):
api_address = "https://api.openweathermap.org/data/2.5/weather?appid=0c42f7f6b53b244c78a418f4f181282a&q="
url = api_address + city
json_data = requests.get(url).json()
kelvin_res = json_data["main"]["temp"]
feels_like = json_data["main"]["feels_like"]
description = json_data["weather"][0]["description"]
celcius_res = kelvin_res - 273.15
max_temp = json_data["main"]["temp_max"]
min_temp = json_data["main"]["temp_min"]
visibility = json_data["visibility"]
pressure = json_data["main"]["pressure"]
humidity = json_data["main"]["humidity"]
wind_speed = json_data["wind"]["speed"]
return(
f"The current temperature of {city} is %.1f degree celcius with {description}" % celcius_res)
def stepWiseCalculus(query):
query = query.replace("+", "%2B")
try:
try:
api_address = f"https://api.wolframalpha.com/v2/query?appid=Y98QH3-24PWX83VGA&input={query}&podstate=Step-by-step%20solution&output=json&format=image"
json_data = requests.get(api_address).json()
answer = json_data["queryresult"]["pods"][0]["subpods"][1]["img"]["src"]
answer = answer.replace("sqrt", "√")
if(thread_type == ThreadType.USER):
self.sendRemoteFiles(
file_urls=answer, message=None, thread_id=thread_id, thread_type=ThreadType.USER)
elif(thread_type == ThreadType.GROUP):
self.sendRemoteFiles(
file_urls=answer, message=None, thread_id=thread_id, thread_type=ThreadType.GROUP)
except:
pass
try:
api_address = f"http://api.wolframalpha.com/v2/query?appid=Y98QH3-24PWX83VGA&input={query}&podstate=Result__Step-by-step+solution&format=plaintext&output=json"
json_data = requests.get(api_address).json()
answer = json_data["queryresult"]["pods"][0]["subpods"][0]["img"]["src"]
answer = answer.replace("sqrt", "√")
if(thread_type == ThreadType.USER):
self.sendRemoteFiles(
file_urls=answer, message=None, thread_id=thread_id, thread_type=ThreadType.USER)
elif(thread_type == ThreadType.GROUP):
self.sendRemoteFiles(
file_urls=answer, message=None, thread_id=thread_id, thread_type=ThreadType.GROUP)
except:
try:
answer = json_data["queryresult"]["pods"][1]["subpods"][1]["img"]["src"]
answer = answer.replace("sqrt", "√")
if(thread_type == ThreadType.USER):
f
self.sendRemoteFiles(
file_urls=answer, message=None, thread_id=thread_id, thread_type=ThreadType.USER)
elif(thread_type == ThreadType.GROUP):
self.sendRemoteFiles(
file_urls=answer, message=None, thread_id=thread_id, thread_type=ThreadType.GROUP)
except:
pass
except:
pass
def stepWiseAlgebra(query):
query = query.replace("+", "%2B")
api_address = f"http://api.wolframalpha.com/v2/query?appid=Y98QH3-24PWX83VGA&input=solve%203x^2+4x-6=0&podstate=Result__Step-by-step+solution&format=plaintext&output=json"
json_data = requests.get(api_address).json()
try:
answer = json_data["queryresult"]["pods"][1]["subpods"][2]["plaintext"]
answer = answer.replace("sqrt", "√")
self.send(Message(text=answer), thread_id=thread_id,
thread_type=thread_type)
except Exception as e:
pass
try:
answer = json_data["queryresult"]["pods"][1]["subpods"][3]["plaintext"]
answer = answer.replace("sqrt", "√")
self.send(Message(text=answer), thread_id=thread_id,
thread_type=thread_type)
except Exception as e:
pass
try:
answer = json_data["queryresult"]["pods"][1]["subpods"][4]["plaintext"]
answer = answer.replace("sqrt", "√")
self.send(Message(text=answer), thread_id=thread_id,
thread_type=thread_type)
except Exception as e:
pass
try:
answer = json_data["queryresult"]["pods"][1]["subpods"][1]["plaintext"]
answer = answer.replace("sqrt", "√")
self.send(Message(text=answer), thread_id=thread_id,
thread_type=thread_type)
except Exception as e:
pass
try:
answer = json_data["queryresult"]["pods"][1]["subpods"][0]["plaintext"]
answer = answer.replace("sqrt", "√")
self.send(Message(text=answer), thread_id=thread_id,
thread_type=thread_type)
except Exception as e:
pass
def stepWiseQueries(query):
query = query.replace("+", "%2B")
api_address = f"http://api.wolframalpha.com/v2/query?appid=Y98QH3-24PWX83VGA&input={query}&podstate=Result__Step-by-step+solution&format=plaintext&output=json"
json_data = requests.get(api_address).json()
try:
try:
answer = json_data["queryresult"]["pods"][0]["subpods"][0]["plaintext"]
answer = answer.replace("sqrt", "√")
self.send(Message(text=answer), thread_id=thread_id,
thread_type=thread_type)
except Exception as e:
pass
try:
answer = json_data["queryresult"]["pods"][1]["subpods"][0]["plaintext"]
answer = answer.replace("sqrt", "√")
self.send(Message(text=answer), thread_id=thread_id,
thread_type=thread_type)
except Exception as e:
pass
try:
answer = json_data["queryresult"]["pods"][1]["subpods"][1]["plaintext"]
answer = answer.replace("sqrt", "√")
self.send(Message(text=answer), thread_id=thread_id,
thread_type=thread_type)
except Exception as e:
pass
except:
self.send(Message(text="Cannot find the solution of this problem"), thread_id=thread_id,
thread_type=thread_type)
try:
def searchForUsers(self, name=" ".join(msg.split()[2:4]), limit=5):
try:
limit = int(msg.split()[4])
except:
limit = 5
params = {"search": name, "limit": limit}
(j,) = self.graphql_requests(
_graphql.from_query(_graphql.SEARCH_USER, params))
users = ([User._from_graphql(node)
for node in j[name]["users"]["nodes"]])
for user in users:
reply = f"{user.name} profile_link: {user.url}\n friend: {user.is_friend}\n"
self.send(Message(text=reply), thread_id=thread_id,
thread_type=thread_type)
except:
pass
def programming_solution(self, query):
try:
count = int(msg.split()[-1])
except:
count = 6
try:
x = int(query.split()[-1])
if type(x) == int:
query = " ".join(msg.split()[0:-1])
except:
pass
image_urls = []
url = "https://bing-image-search1.p.rapidapi.com/images/search"
querystring = {"q": query, "count": str(count)}
headers = {
'x-rapidapi-host': "bing-image-search1.p.rapidapi.com",
'x-rapidapi-key': "55d459414fmsh32c0a06c0e3e34dp1f40a5jsn084fca18f5ea"
}
response = requests.request(
"GET", url, headers=headers, params=querystring)
data = json.loads(response.text)
img_contents = (data["value"])
for img_url in img_contents:
image_urls.append(img_url["contentUrl"])
def multiThreadImg(img_url):
if(thread_type == ThreadType.USER):
self.sendRemoteFiles(
file_urls=img_url, message=None, thread_id=thread_id, thread_type=ThreadType.USER)
elif(thread_type == ThreadType.GROUP):
self.sendRemoteFiles(
file_urls=img_url, message=None, thread_id=thread_id, thread_type=ThreadType.GROUP)
with concurrent.futures.ThreadPoolExecutor() as executor:
executor.map(multiThreadImg, image_urls)
def translator(self, query, target):
query = " ".join(query.split()[1:-2])
url = "https://microsoft-translator-text.p.rapidapi.com/translate"
querystring = {"to": target, "api-version": "3.0",
"profanityAction": "NoAction", "textType": "plain"}
payload = f'[{{"Text": "{query}"}}]'
headers = {
'content-type': "application/json",
'x-rapidapi-host': "microsoft-translator-text.p.rapidapi.com",
'x-rapidapi-key': "55d459414fmsh32c0a06c0e3e34dp1f40a5jsn084fca18f5ea"
}
response = requests.request(
"POST", url, data=payload, headers=headers, params=querystring)
json_response = eval(response.text)
return json_response[0]["translations"][0]["text"]
def imageSearch(self, msg):
try:
count = int(msg.split()[-1])
except:
count = 5
query = " ".join(msg.split()[2:])
try:
x = int(query.split()[-1])
if type(x) == int:
query = " ".join(msg.split()[2:-1])
except:
pass
image_urls = []
url = "https://bing-image-search1.p.rapidapi.com/images/search"
querystring = {"q": query, "count": str(count)}
headers = {
'x-rapidapi-host': "bing-image-search1.p.rapidapi.com",
'x-rapidapi-key': "55d459414fmsh32c0a06c0e3e34dp1f40a5jsn084fca18f5ea"
}
response = requests.request(
"GET", url, headers=headers, params=querystring)
data = json.loads(response.text)
img_contents = (data["value"])
for img_url in img_contents:
image_urls.append(img_url["contentUrl"])
print("appended..")
def multiThreadImg(img_url):
if(thread_type == ThreadType.USER):
self.sendRemoteFiles(
file_urls=img_url, message=None, thread_id=thread_id, thread_type=ThreadType.USER)
elif(thread_type == ThreadType.GROUP):
self.sendRemoteFiles(
file_urls=img_url, message=None, thread_id=thread_id, thread_type=ThreadType.GROUP)
with concurrent.futures.ThreadPoolExecutor() as executor:
executor.map(multiThreadImg, image_urls)
def searchFiles(self):
query = " ".join(msg.split()[2:])
file_urls = []
url = "https://filepursuit.p.rapidapi.com/"
querystring = {"q": query, "filetype": msg.split()[1]}
headers = {
'x-rapidapi-host': "filepursuit.p.rapidapi.com",
'x-rapidapi-key': "8cd2881885msh9933f89c5aa2186p1d8076jsn7303d42b3c66"
}
response = requests.request(
"GET", url, headers=headers, params=querystring)
response = json.loads(response.text)
file_contents = response["files_found"]
try:
for file in random.sample(file_contents, 5):
file_url = file["file_link"]
file_name = file["file_name"]
self.send(Message(text=f'{file_name}\n Link: {file_url}'),
thread_id=thread_id, thread_type=ThreadType.USER)
except:
for file in file_contents:
file_url = file["file_link"]
file_name = file["file_name"]
self.send(Message(text=f'{file_name}\n Link: {file_url}'),
thread_id=thread_id, thread_type=ThreadType.USER)
def chatGPT(self, query):
openai.api_key = f"{os.environ.get('openai')}"
response = openai.Completion.create(
model="text-davinci-003",
prompt=query,
temperature=0.15,
max_tokens=3000,
top_p=1.0,
frequency_penalty=0.0,
presence_penalty=0
)
return (response["choices"][0]["text"])
def grammar(self, query):
openai.api_key = f"{os.environ.get('openai')}"
response = openai.Completion.create(
model="text-davinci-003",
prompt="Correct this to standard English:\n"+query,
temperature=0,
max_tokens=60,
top_p=1.0,
frequency_penalty=0.0,
presence_penalty=0.0
)
return (response["choices"][0]["text"])
try:
if ("search pdf" in msg):
searchFiles(self)
elif ("ntm" in msg):
if ("from ntm bot:" in msg):
return
query = " ".join(msg.split(" ")[1:])
reply = "From NTM Bot:\t"+chatGPT(self, query)
sendQuery()
elif ("grammar" in msg):
query = " ".join(msg.split(" ")[1:])
reply = "Here is your Corrected answer:\t"+grammar(self, query)
sendQuery()
elif("search image" in msg):
imageSearch(self, msg)
elif("program to" in msg):
programming_solution(self, msg)
elif("translate" in msg):
reply = translator(self, msg, msg.split()[-1])
sendQuery()
elif "weather of" in msg:
indx = msg.index("weather of")
query = msg[indx+11:]
reply = weather(query)
sendQuery()
elif "corona of" in msg:
corona_details(msg.split()[2])
elif ("calculus" in msg):
stepWiseCalculus(" ".join(msg.split(" ")[1:]))
elif ("algebra" in msg):
stepWiseAlgebra(" ".join(msg.split(" ")[1:]))
elif ("query" in msg):
stepWiseQueries(" ".join(msg.split(" ")[1:]))
elif "find" in msg or "solve" in msg or "evaluate" in msg or "calculate" in msg or "value" in msg or "convert" in msg or "simplify" in msg or "generate" in msg:
app_id = "Y98QH3-24PWX83VGA"
client = wolframalpha.Client(app_id)
query = msg.split()[1:]
res = client.query(' '.join(query))
answer = next(res.results).text
reply = f'Answer: {answer.replace("sqrt", "√")}'
sendQuery()
elif ("search user" in msg or "search friend" in msg):
searchForUsers(self)
elif("mute conversation" in msg):
try:
self.muteThread(mute_time=-1, thread_id=author_id)
reply = "muted 🔕"
sendQuery()
except:
pass
elif ("busy" in msg):
reply = "Not at all"
sendMsg()
elif("how are you" in msg):
reply="I am good. What's about you?"
sendMsg()
elif("hlw" in msg):
reply="hi"
sendMsg()
elif("hey" in msg):
reply="Hi, how are you?"
sendMsg()
elif("ok" in msg):
reply="🤩"
sendMsg()
elif("same to you" in msg):
reply="Thank you 😊"
sendMsg()
elif("Who are you" in msg):
reply="I am NTM assistant Chat Bot"
sendMsg()
elif("bot" in msg):
reply="hmm.. I am NTM assistant Bot developed by NTM"
sendMsg()
elif("Welcome" in msg):
reply="It's my Pleasure 😊"
sendMsg()
elif("tq" in msg):
reply="Welcome 😊"
sendMsg()
elif("tqsm" in msg):
reply="Welcome 😊"
sendMsg()
elif("help" in msg):
reply = "Sure! What should I do?"
sendMsg()
elif("clever" in msg):
reply = "Yes, i am clever. hope you will be clever soon."
sendMsg()
elif("crazy" in msg):
reply = "Anything wrong about that."
sendMsg()
elif ("are funny" in msg):
reply = "No. I am not. You are."
sendMsg()
elif ("marry me" in msg):
reply = "Yes, if you are nice and kind girl. But if you are boy RIP."
sendMsg()
elif ("you from" in msg):
reply = "I am from Nepal. Currently living in Kathmandu"
sendMsg()
elif ("you sure" in msg):
reply = "Yes. I'm sure."
sendMsg()
elif ("great" in msg):
reply = "Thanks!"
sendMsg()
elif ("no problem" in msg):
reply = "Okay😊🙂"
sendMsg()
elif ("thank you" in msg):
reply = "You're welcome😊🙂"
sendMsg()
elif ("thanks" in msg):
reply = "You're welcome🙂"
sendMsg()
elif ("well done" in msg):
reply = "Thanks🙂"
sendMsg()
elif ("wow" in msg):
reply = "🙂😊"
sendMsg()
elif ("wow" in msg):
reply = "🙂😊"
sendMsg()
elif ("bye" in msg):
reply = "bye👋 Take care"
sendMsg()
elif ("good morning" in msg):
reply = "Good Morning🌅🌺 and Have a nice day."
sendMsg()
elif ("goodnight" in msg):
reply = "Good night🌃🌙 and have a ghost dream"
sendMsg()
elif ("good night" in msg):
reply = "good night🌃🌙 and have a ghost dream"
sendMsg()
elif ("hello" in msg):
reply = "Hi"
sendMsg()
elif ("hello" in msg or "hlo" in msg or "hii" in msg):
reply = "Hi"
sendMsg()
elif (msg == "hi"):
reply = "Hello! How can I help you?"
sendMsg()
elif ("gm" in msg):
reply = "Good Morning🌅🌺 and Have a nice day."
sendMsg()
elif ("gn" in msg):
reply = "Good night🌃🌙 and Have a ghost dream"
sendMsg()
except Exception as e:
print(e)
self.markAsDelivered(author_id, thread_id)
def onMessageUnsent(self, mid=None, author_id=None, thread_id=None, thread_type=None, ts=None, msg=None):
if(author_id == self.uid):
pass
else:
try:
conn = sqlite3.connect("messages.db")
print("connected")
c = conn.cursor()
c.execute("""
SELECT * FROM "{}" WHERE mid = "{}"
""".format(str(author_id).replace('"', '""'), mid.replace('"', '""')))
fetched_msg = c.fetchall()
conn.commit()
conn.close()
unsent_msg = fetched_msg[0][1]
if(".mp4" in unsent_msg):
if(thread_type == ThreadType.USER):
reply = f"You just unsent a video"
self.send(Message(text=reply), thread_id=thread_id,
thread_type=thread_type)
self.sendRemoteFiles(
file_urls=unsent_msg, message=None, thread_id=thread_id, thread_type=ThreadType.USER)
elif(thread_type == ThreadType.GROUP):
user = self.fetchUserInfo(f"{author_id}")[
f"{author_id}"]
username = user.name.split()[0]
reply = f"{username} just unsent a video"
self.send(Message(text=reply), thread_id=thread_id,
thread_type=thread_type)
self.sendRemoteFiles(
file_urls=unsent_msg, message=None, thread_id=thread_id, thread_type=ThreadType.GROUP)
elif("//scontent.xx.fbc" in unsent_msg):
if(thread_type == ThreadType.USER):
reply = f"You just unsent an image"
self.send(Message(text=reply), thread_id=thread_id,
thread_type=thread_type)
self.sendRemoteFiles(
file_urls=unsent_msg, message=None, thread_id=thread_id, thread_type=ThreadType.USER)
elif(thread_type == ThreadType.GROUP):
user = self.fetchUserInfo(f"{author_id}")[
f"{author_id}"]
username = user.name.split()[0]
reply = f"{username} just unsent an image"
self.send(Message(text=reply), thread_id=thread_id,
thread_type=thread_type)
self.sendRemoteFiles(
file_urls=unsent_msg, message=None, thread_id=thread_id, thread_type=ThreadType.GROUP)
else:
if(thread_type == ThreadType.USER):
reply = f"You just unsent a message:\n{unsent_msg} "
self.send(Message(text=reply), thread_id=thread_id,
thread_type=thread_type)
elif(thread_type == ThreadType.GROUP):
user = self.fetchUserInfo(f"{author_id}")[
f"{author_id}"]
username = user.name.split()[0]
reply = f"{username} just unsent a message:\n{unsent_msg}"
self.send(Message(text=reply), thread_id=thread_id,
thread_type=thread_type)
except:
pass
def onColorChange(self, mid=None, author_id=None, new_color=None, thread_id=None, thread_type=ThreadType.USER, **kwargs):
reply = "You changed the theme ✌️😎"
self.send(Message(text=reply), thread_id=thread_id,
thread_type=thread_type)
def onEmojiChange(self, mid=None, author_id=None, new_color=None, thread_id=None, thread_type=ThreadType.USER, **kwargs):
reply = "You changed the emoji 😎. Great!"
self.send(Message(text=reply), thread_id=thread_id,
thread_type=thread_type)
def onImageChange(self, mid=None, author_id=None, new_color=None, thread_id=None, thread_type=ThreadType.USER, **kwargs):
reply = "This image looks nice. 💕🔥"
self.send(Message(text=reply), thread_id=thread_id,
thread_type=thread_type)
def onNicknameChange(self, mid=None, author_id=None, new_nickname=None, thread_id=None, thread_type=ThreadType.USER, **kwargs):
reply = f"You just changed the nickname to {new_nickname} But why? 😁🤔😶"
self.send(Message(text=reply), thread_id=thread_id,
thread_type=thread_type)
def onCallStarted(self, mid=None, caller_id=None, is_video_call=None, thread_id=None, thread_type=None, ts=None, metadata=None, msg=None, ** kwargs):
reply = "You just started a call 📞🎥"
self.send(Message(text=reply), thread_id=thread_id,
thread_type=thread_type)
def onCallEnded(self, mid=None, caller_id=None, is_video_call=None, thread_id=None, thread_type=None, ts=None, metadata=None, msg=None, ** kwargs):
reply = "Bye 👋🙋♂️"
self.send(Message(text=reply), thread_id=thread_id,
thread_type=thread_type)
def onUserJoinedCall(mid=None, joined_id=None, is_video_call=None,
thread_id=None, thread_type=None, **kwargs):
reply = f"New user with user_id {joined_id} has joined a call"
self.send(Message(text=reply), thread_id=thread_id,
thread_type=thread_type)
cookies = {
"sb": "tnPnYtHzL9uXRCjn0_8zJAqh",
"fr": "0X9BuQv9646cIJkKs.AWUtLZijIdO2dlXbGnkD95sab5g.Bi53fP.gO.AAA.0.0.Bi53fP.AWVeAki8YoM",
"c_user": f"{os.environ.get('c_user')}",
"datr": "tnPnYo86eQ5KGjcRmeLJP1VC",
"xs": f"{os.environ.get('xs_value')}"
}
client = ChatBot("",
"", session_cookies=cookies)
print(client.isLoggedIn())
try:
client.listen()
except:
time.sleep(2)
client.listen()