-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEchoBot.py
54 lines (43 loc) · 1.7 KB
/
EchoBot.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
from fbchat import Client
import ReadMsg
import FbChat
from fbchat import log
from threading import Thread
class EchoBot(Client):
EMAIL_BOT = "[email protected]"
PASS_BOT = "94122015402"
readMsg = None
fbChat = None
auxCode = 0
auxAuthor = None
lsReadMsg = {}
def __init__(self, email, password):
super(EchoBot, self).__init__(email, password)
self.fbChat = FbChat.FbChat(email, password)
def onMessage(self, author_id, message_object, thread_id, thread_type, **kwargs):
self.markAsDelivered(author_id, thread_id)
self.markAsRead(author_id)
# imprimir el log para ver lo que esta pasando.
log.info("{} from {} in {}".format(message_object, thread_id, thread_type.name))
# if self.auxCode != 0:
# self.fbChat.setIdChat(self.auxAuthor)
# self.readMsg.decifrarComando(self.auxCode, self.auxCode)
if author_id != self.uid:
self.setReadMsgByAuthorId(author_id)
self.fbChat.setIdChat(author_id)
subproceso = Thread(target=self.subproceso, args=(message_object.text,))
subproceso.start()
# self.auxCode = self.readMsg.decifrarComando()
# if self.auxCode != 0:
# self.auxAuthor = author_id
def subproceso(self, msg):
self.readMsg.decifrarComando(msg)
def setReadMsgByAuthorId(self, author_id):
obj = self.lsReadMsg.get(author_id, 0)
if obj == 0:
self.readMsg = ReadMsg.ReadMsg(self.fbChat, author_id)
self.lsReadMsg.update({author_id: self.readMsg})
else:
self.readMsg = obj
client = EchoBot(EchoBot.EMAIL_BOT, EchoBot.PASS_BOT)
client.listen()