forked from Yinzo/SmartQQBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMsg.py
More file actions
64 lines (48 loc) · 1.96 KB
/
Msg.py
File metadata and controls
64 lines (48 loc) · 1.96 KB
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
55
56
57
58
59
60
61
62
63
64
# -*- coding: utf-8 -*-
# Code by Yinzo: https://github.com/Yinzo
# Origin repository: https://github.com/Yinzo/SmartQQBot
class Msg:
def __init__(self, json_input):
self.poll_type = json_input['poll_type']
self.from_uin = json_input['value']['from_uin']
self.msg_id = json_input['value']['msg_id']
self.msg_type = json_input['value']['msg_type']
self.to_uin = json_input['value']['to_uin']
class MsgWithContent(Msg):
def __init__(self, json_input):
Msg.__init__(self, json_input)
self.raw_content = json_input['value']['content']
self.content = MsgWithContent.combine_msg(self.raw_content)
for i in json_input['value']['content']:
if isinstance(i, list) and i[0] == "font":
self.font = i[1]
self.time = json_input['value']['time']
@staticmethod
def combine_msg(content):
msgtxt = ""
for part in content:
if type(part) == type(u'\u0000'):
msgtxt += part
elif len(part) > 1:
# 如果是图片
if str(part[0]) == "offpic":
msgtxt += "[图片]"
elif str(part[0]) == "cface":
msgtxt += "[表情]"
return msgtxt
# 临时会话消息
class SessMsg(MsgWithContent):
def __init__(self, json_input):
MsgWithContent.__init__(self, json_input)
self.service_type = json_input['value']['service_type']
self.id = json_input['value']['id']
self.ruin = json_input['value']['ruin']
self.flags = json_input['value']['flags']
class PmMsg(MsgWithContent):
def __init__(self, json_input):
MsgWithContent.__init__(self, json_input)
class GroupMsg(MsgWithContent):
def __init__(self, json_input):
MsgWithContent.__init__(self, json_input)
self.group_code = json_input['value']['group_code']
self.send_uin = json_input['value']['send_uin']