forked from grapeot/WechatForwardBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHistoryRecorder.py
More file actions
25 lines (23 loc) · 858 Bytes
/
Copy pathHistoryRecorder.py
File metadata and controls
25 lines (23 loc) · 858 Bytes
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
from time import time
from pymongo import MongoClient
from ProcessInterface import ProcessInterface
from utilities import *
from itchat.content import *
class HistoryRecorder(ProcessInterface):
def __init__(self):
self.client = MongoClient()
self.coll = self.client[dbName][collName]
logging.info('HistoryRecorder connected to MongoDB.')
# Record an itchat message to mongodb
# Currently only support text messages in group chats
def process(self, msg, type):
if type != TEXT:
return
r = {
'content': msg['Content'],
'from': msg['ActualNickName'],
'fromId': msg['ToUserName'],
'to': msg['User']['NickName'] if 'User' in msg and 'UserName' in msg['User'] else 'N/A',
'timestamp': time()
}
self.coll.insert(r)