aboutsummaryrefslogtreecommitdiff
path: root/ingrex
diff options
context:
space:
mode:
Diffstat (limited to 'ingrex')
-rwxr-xr-xingrex/praser.py62
1 files changed, 51 insertions, 11 deletions
diff --git a/ingrex/praser.py b/ingrex/praser.py
index a05ec1e..1d2c03d 100755
--- a/ingrex/praser.py
+++ b/ingrex/praser.py
@@ -1,26 +1,66 @@
1"Ingrex praser deal with message"
2from datetime import datetime, timedelta 1from datetime import datetime, timedelta
3import platform 2import re
4import os 3import os
5import time 4import time
6 5
7osname = platform.system()
8if osname == "Linux":
9 os.environ['TZ'] = 'Asia/Shanghai'
10 time.tzset()
11
12 6
13class Message(object): 7class Message(object):
14 "Message object"
15 def __init__(self, raw_msg): 8 def __init__(self, raw_msg):
9 os.environ['TZ'] = 'Asia/Shanghai'
10 time.tzset()
11
12 seconds, millis = divmod(raw_msg[1], 1000)
13 timestamp = datetime.fromtimestamp(seconds) + timedelta(milliseconds=millis)
14 self.time = timestamp.strftime('%Y/%m/%d %H:%M:%S:%f')[:-3]
15
16 self.raw = raw_msg 16 self.raw = raw_msg
17 self.guid = raw_msg[0] 17 self.guid = raw_msg[0]
18 self.timestamp = raw_msg[1] 18 self.timestamp = raw_msg[1]
19 seconds, millis = divmod(raw_msg[1], 1000)
20 time = datetime.fromtimestamp(seconds) + timedelta(milliseconds=millis)
21 self.time = time.strftime('%Y/%m/%d %H:%M:%S:%f')[:-3]
22 self.text = raw_msg[2]['plext']['text'] 19 self.text = raw_msg[2]['plext']['text']
23 self.ptype = raw_msg[2]['plext']['plextType'] 20 self.ptype = raw_msg[2]['plext']['plextType']
24 self.team = raw_msg[2]['plext']['team'] 21 self.team = raw_msg[2]['plext']['team']
25 self.type = raw_msg[2]['plext']['markup'][1][1]['plain'] 22 self.type = raw_msg[2]['plext']['markup'][1][1]['plain']
26 23
24 self.msg = ''
25 self.markup = raw_msg[2]['plext']['markup']
26
27 for mark in self.markup:
28 if mark[0] == 'SECURE':
29 self.msg += mark[1]['plain']
30 elif mark[0] == 'SENDER':
31 player = mark[1]['plain']
32 team = mark[1]['team']
33
34 pattern = re.compile(':')
35 match = pattern.search(player)
36 if match:
37 if team == 'RESISTANCE':
38 player = player[:match.span()[0]] + ' 🐳' + player[match.span()[0]:]
39 elif team == 'ENLIGHTENED':
40 player = player[:match.span()[0]] + ' 🐸' + player[match.span()[0]:]
41 self.msg += player
42
43 elif mark[0] == 'PLAYER' or mark[0] == 'AT_PLAYER':
44 player = mark[1]['plain']
45 team = mark[1]['team']
46
47 self.msg += player
48 if team == 'RESISTANCE':
49 self.msg += ' 🐳'
50 elif team == 'ENLIGHTENED':
51 self.msg += ' 🐸'
52
53 elif mark[0] == 'TEXT':
54 self.msg += mark[1]['plain']
55
56 pattern = re.compile('\[secure\]')
57 match = pattern.search(self.msg)
58 if match:
59 if self.msg.find(':') != -1:
60 self.msg = self.msg[:9] + '@' + self.msg[9:]
61 else:
62 self.msg = self.msg[:10] + '@' + self.msg[10:]
63 else:
64 self.msg = '@' + self.msg
65
66 self.msg = self.time + self.msg
Powered by cgit v1.2.3 (git 2.41.0)