-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.py
41 lines (31 loc) · 1.09 KB
/
index.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
from utils import get_response
from time import sleep
from whatsapp_wrapper import WhatsappWrapper
print("Starting selenium instance and logging to whatsap00p-web...")
profile_path = "/home/slapbot/.mozilla/firefox/xf0clnwz.whatsapp-user"
ww = WhatsappWrapper(profile_path)
print("Getting all chats...")
chats = ww.get_all_chats()
test_chat = chats[0]
global_cache = {}
print("Ready!")
language = "english"
def loop():
print("Starting to look for new messages...")
messages = test_chat.get_messages()
last_message = messages[-1]
last_message_timestamp = last_message.timestamp.timestamp()
if last_message_timestamp in global_cache:
print("No new message was found.")
return
print("A new message is found.")
global_cache[last_message.timestamp.timestamp()] = 1
resp, language = get_response(last_message.content, language)
if resp is not False:
print("Replying back the response as {}".format(resp))
test_chat.send_message(resp)
print("Message was an incorrect input.")
return language
while True:
language = loop()
sleep(2)