作者 陈俊学

2.3.2

重构异步消息处理类

新增"戳你一下"
新增"打招呼消息"
@@ -4,5 +4,5 @@ SERVER: @@ -4,5 +4,5 @@ SERVER:
4 reconnect_interval: 3 4 reconnect_interval: 3
5 5
6 VERSION: 6 VERSION:
7 - code: 121  
8 - name: 2.3.1  
  7 + code: 122
  8 + name: 2.3.2
@@ -181,7 +181,7 @@ class CallBack(): @@ -181,7 +181,7 @@ class CallBack():
181 else: 181 else:
182 if thread_type == ThreadType.GROUP: 182 if thread_type == ThreadType.GROUP:
183 body['roomSender'] = author_id 183 body['roomSender'] = author_id
184 - 184 + print(message_object)
185 if message_object.text: 185 if message_object.text:
186 body['content'] = message_object.text 186 body['content'] = message_object.text
187 self._notify_(type_="textMsg", client=client, body=body) 187 self._notify_(type_="textMsg", client=client, body=body)
@@ -225,6 +225,7 @@ class CallBack(): @@ -225,6 +225,7 @@ class CallBack():
225 self._notify_(type_="stickerMsg", client=client, body=body) 225 self._notify_(type_="stickerMsg", client=client, body=body)
226 else: 226 else:
227 print(message_object) 227 print(message_object)
  228 + self.onUnknownMesssageType(client=client, msg=msg)
228 229
229 if not self.queue: 230 if not self.queue:
230 client.markAsDelivered(thread_id, message_object.uid) 231 client.markAsDelivered(thread_id, message_object.uid)
@@ -1126,6 +1127,11 @@ class CallBack(): @@ -1126,6 +1127,11 @@ class CallBack():
1126 msg: A full set of the data received 1127 msg: A full set of the data received
1127 """ 1128 """
1128 type_ = msg.get('type') 1129 type_ = msg.get('type')
  1130 + try:
  1131 + lwa_type = msg['attachments'][0]['mercury']['extensible_attachment']['story_attachment']['target'][
  1132 + 'lwa_type']
  1133 + except:
  1134 + lwa_type = None
1129 1135
1130 if type_ == 'jewel_friending_notifs': 1136 if type_ == 'jewel_friending_notifs':
1131 self.onFriendConfirmRequest(client) 1137 self.onFriendConfirmRequest(client)
@@ -1133,6 +1139,8 @@ class CallBack(): @@ -1133,6 +1139,8 @@ class CallBack():
1133 self.onAdminTextMessage(client, msg) 1139 self.onAdminTextMessage(client, msg)
1134 elif type_ == 'live_poke': 1140 elif type_ == 'live_poke':
1135 self.onLivePoke(client, msg) 1141 self.onLivePoke(client, msg)
  1142 + elif lwa_type == 'WAVE':
  1143 + self.onWavePoke(client, msg)
1136 else: 1144 else:
1137 log.debug("message : {}".format(msg)) 1145 log.debug("message : {}".format(msg))
1138 1146
@@ -1186,6 +1194,25 @@ class CallBack(): @@ -1186,6 +1194,25 @@ class CallBack():
1186 } 1194 }
1187 self._notify_(type_="systemMsg", client=client, body=body) 1195 self._notify_(type_="systemMsg", client=client, body=body)
1188 1196
  1197 + def onWavePoke(self, client, msg):
  1198 + messageMetadata = msg['messageMetadata']
  1199 + attachments = msg['attachments'][0]
  1200 + image = attachments['mercury']['extensible_attachment']['story_attachment']['media']['image']
  1201 + description = attachments['mercury']['extensible_attachment']['story_attachment']['description']
  1202 + title_with_entities = attachments['mercury']['extensible_attachment']['story_attachment']['title_with_entities']
  1203 + body = {
  1204 + 'to': client.uid,
  1205 + 'from': messageMetadata['actorFbId'],
  1206 + 'content': title_with_entities['text'],
  1207 + 'image': image,
  1208 + 'description': description['text'],
  1209 + 'wave_time': messageMetadata['timestamp'],
  1210 + 'type': 'wave_poke',
  1211 + 'class': 'LightweightAction',
  1212 + 'msgId': messageMetadata['messageId']
  1213 + }
  1214 + self._notify_(type_="systemMsg", client=client, body=body)
  1215 +
1189 def onWebNotice(self, client, kwargs): 1216 def onWebNotice(self, client, kwargs):
1190 self._notify_(type_="webNotice", client=client, body=kwargs) 1217 self._notify_(type_="webNotice", client=client, body=kwargs)
1191 if kwargs['notif_type'] == 'family_request': 1218 if kwargs['notif_type'] == 'family_request':
@@ -259,4 +259,3 @@ class Executor(): @@ -259,4 +259,3 @@ class Executor():
259 item['type'] = 'unknown' 259 item['type'] = 'unknown'
260 list_msg.append(item) 260 list_msg.append(item)
261 return list_msg 261 return list_msg
262 -  
@@ -25,8 +25,6 @@ import retrying @@ -25,8 +25,6 @@ import retrying
25 from bs4 import BeautifulSoup 25 from bs4 import BeautifulSoup
26 from fbchat import (Client, FBchatException, FBchatUserError, Message, Sticker, 26 from fbchat import (Client, FBchatException, FBchatUserError, Message, Sticker,
27 ThreadType, _exception, _graphql, _util, log) 27 ThreadType, _exception, _graphql, _util, log)
28 -from furl import furl  
29 -  
30 from lib import common, download, google_map, graph 28 from lib import common, download, google_map, graph
31 from lib._mqtt import MqttClient 29 from lib._mqtt import MqttClient
32 from lib.common import College, WorkPlace 30 from lib.common import College, WorkPlace
@@ -2028,7 +2026,7 @@ class FacebookClient(Client): @@ -2028,7 +2026,7 @@ class FacebookClient(Client):
2028 pic_id = li.attrs.get('data-fbid', None) 2026 pic_id = li.attrs.get('data-fbid', None)
2029 url = li.attrs.get('data-starred-src', None) 2027 url = li.attrs.get('data-starred-src', None)
2030 label = li.a.attrs.get('aria-label', None) 2028 label = li.a.attrs.get('aria-label', None)
2031 - set_id = furl(li.a.attrs['href']).args.get('set', None) 2029 + set_id = furl.furl(li.a.attrs['href']).args.get('set', None)
2032 data = { 2030 data = {
2033 'pic_id': pic_id, 2031 'pic_id': pic_id,
2034 'set_id': set_id, 2032 'set_id': set_id,
@@ -2070,7 +2068,7 @@ class FacebookClient(Client): @@ -2070,7 +2068,7 @@ class FacebookClient(Client):
2070 pic_id = li.attrs.get('data-fbid', None) 2068 pic_id = li.attrs.get('data-fbid', None)
2071 url = li.attrs.get('data-starred-src', None) 2069 url = li.attrs.get('data-starred-src', None)
2072 label = li.a.attrs.get('aria-label', None) 2070 label = li.a.attrs.get('aria-label', None)
2073 - set_id = furl(li.a.attrs['href']).args.get('set', None) 2071 + set_id = furl.furl(li.a.attrs['href']).args.get('set', None)
2074 data = { 2072 data = {
2075 'pic_id': pic_id, 2073 'pic_id': pic_id,
2076 'set_id': set_id, 2074 'set_id': set_id,