Completed
Pull Request — develop (#255)
by
unknown
26s
created

TextMessage.__str__()   A

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 2
ccs 2
cts 2
cp 1
c 0
b 0
f 0
rs 10
cc 1
crap 1
1
# -*- coding: utf-8 -*-
2
3 15
import six
4 15
from werobot.messages.entries import StringEntry, IntEntry, FloatEntry
5
from werobot.messages.base import WeRoBotMetaClass
6 15
7
8
class MessageMetaClass(WeRoBotMetaClass):
9 15
    pass
10 15
11 15
12
@six.add_metaclass(MessageMetaClass)
13 15
class WeChatMessage(object):
14 15
    message_id = IntEntry('MsgId', 0)
15 15
    target = StringEntry('ToUserName')
16 15
    source = StringEntry('FromUserName')
17 15
    time = IntEntry('CreateTime', 0)
18
19 15
    def __init__(self, message):
20 15
        self.__dict__.update(message)
21
22
23 15
class TextMessage(WeChatMessage):
24 15
    __type__ = 'text'
25 15
    content = StringEntry('Content')
26 15
27 15
    def __str__(self):
28 15
        return self.content
29
30 15
31 15
class ImageMessage(WeChatMessage):
32
    __type__ = 'image'
33
    img = StringEntry('PicUrl')
34 15
35 15
36 15
class LocationMessage(WeChatMessage):
37
    __type__ = 'location'
38
    location_x = FloatEntry('Location_X')
39 15
    location_y = FloatEntry('Location_Y')
40 15
    label = StringEntry('Label')
41 15
    scale = IntEntry('Scale')
42
43
    @property
44 15
    def location(self):
45 15
        return self.location_x, self.location_y
46 15
47 15
48 15
class LinkMessage(WeChatMessage):
49 15
    __type__ = 'link'
50
    title = StringEntry('Title')
51 15
    description = StringEntry('Description')
52
    url = StringEntry('Url')
53 15
54
55
class VoiceMessage(WeChatMessage):
56 15
    __type__ = 'voice'
57 15
    media_id = StringEntry('MediaId')
58 15
    format = StringEntry('Format')
59 15
    recognition = StringEntry('Recognition')
60 15
61
62
class VideoMessage(WeChatMessage):
63 15
    __type__ = ['video', 'shortvideo']
64 15
    media_id = StringEntry('MediaId')
65 15
    thumb_media_id = StringEntry('ThumbMediaId')
66 15
67 15
68
class UnknownMessage(WeChatMessage):
69
    __type__ = 'unknown'
70