-
Notifications
You must be signed in to change notification settings - Fork 2
/
start.py
42 lines (33 loc) · 1.44 KB
/
start.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
# -*- coding: utf-8 -*-
import fbchat
from fbchat.models import *
from options import *
from utils import *
class Client(fbchat.Client):
def onMessage(self, message_object, author_id, thread_id, thread_type, **kwargs):
if self.uid == author_id:
return
if thread_type != ThreadType.GROUP:
return
if not ALL_GROUPS and thread_id not in GROUP_IDS:
return
if not EXACT and MENTION not in message_object.text:
return
if EXACT and message_object.text != MENTION:
return
group = self.fetchGroupInfo(thread_id)[thread_id]
mentions = [Mention(uid, 0, len(MENTION)) for uid in group.participants]
self.send(Message(text=MENTION, mentions=mentions), thread_id=thread_id, thread_type=thread_type)
@d_if(AUTO_ACCEPT)
def onInbox(self, **kwargs):
self.accept_pending()
def accept_pending(self):
thread_ids = []
thread_ids += [thread.uid for thread in self.fetchThreadList(thread_location=ThreadLocation.PENDING, limit=20)
if thread.type == ThreadType.GROUP]
thread_ids += [thread.uid for thread in self.fetchThreadList(thread_location=ThreadLocation.OTHER, limit=20)
if thread.type == ThreadType.GROUP]
self.moveThreads(ThreadLocation.INBOX, thread_ids)
if __name__ == "__main__":
client = Client(FB_EMAIL, FB_PASSWORD, session_cookies=FB_SESSION)
client.listen()