aboutsummaryrefslogtreecommitdiff
blob: 97057dda57449276ec1ee10f04661580f87c8d51 (plain) (blame)
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
65
66
from datetime import datetime, timedelta
import re
import os
import time


class Message(object):
    def __init__(self, raw_msg):
        os.environ['TZ'] = 'Asia/Shanghai'
        time.tzset()

        seconds, millis = divmod(raw_msg[1], 1000)
        timestamp = datetime.fromtimestamp(seconds) + timedelta(milliseconds=millis)
        self.time = timestamp.strftime('%Y/%m/%d %H:%M:%S:%f')[:-3]

        self.raw = raw_msg
        self.guid = raw_msg[0]
        self.timestamp = raw_msg[1]
        self.text = raw_msg[2]['plext']['text']
        self.ptype = raw_msg[2]['plext']['plextType']
        self.team = raw_msg[2]['plext']['team']
        self.type = raw_msg[2]['plext']['markup'][1][1]['plain']

        self.msg = ''
        self.markup = raw_msg[2]['plext']['markup']

        for mark in self.markup:
            if mark[0] == 'SECURE':
                self.msg += mark[1]['plain']
            elif mark[0] == 'SENDER':
                player = mark[1]['plain']
                team = mark[1]['team']

                pattern = re.compile(':')
                match = pattern.search(player)
                if match:
                    if team == 'RESISTANCE':
                        player = player[:match.span()[0]] + ' 🐳' + player[match.span()[0]:]
                    elif team == 'ENLIGHTENED':
                        player = player[:match.span()[0]] + ' 🐸' + player[match.span()[0]:]
                self.msg += player

            elif mark[0] == 'PLAYER' or mark[0] == 'AT_PLAYER':
                player = mark[1]['plain']
                team = mark[1]['team']

                self.msg += player
                if team == 'RESISTANCE':
                    self.msg += ' 🐳'
                elif team == 'ENLIGHTENED':
                    self.msg += ' 🐸'

            elif mark[0] == 'TEXT':
                self.msg += mark[1]['plain']

        pattern = re.compile('\[secure\]')
        match = pattern.search(self.msg)
        if match:
            if self.msg.find(':') != -1:
                self.msg = self.msg[:9] + '@' + self.msg[9:]
            else:
                self.msg = self.msg[:10] + '@' + self.msg[10:]
        else:
            self.msg = '@' + self.msg

        self.msg = self.time + ' ' + self.msg
Powered by cgit v1.2.3 (git 2.41.0)