-
Notifications
You must be signed in to change notification settings - Fork 34
/
inputModel.py
112 lines (78 loc) · 1.8 KB
/
inputModel.py
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
"""
Represents user input type
https://core.telegram.org/bots/api#available-types
"""
import json
class inputModel(object):
"""
Initialiaze with direct user input without modification.
"""
def __init__(self, input):
self.input = input
"""
Return update's unique identifier
@return integer
"""
def getUpdateID(self):
return self.input['update_id']
"""
Return unique message identifier
@return integer
"""
def getMessageID(self):
return self.input['message'].get('message_id')
"""
Return date the message was sent in Unix time
@return integer
"""
def getDate(self):
return self.input['message'].get('date')
"""
Return UTF-8 text string if it is a text message
@return string | None
"""
def getText(self):
text = self.input['message'].get('text')
if text:
text = text.encode('utf-8','strict') # fix for every type of character input
return text
"""
Return unique identifier for corressponding user or bot
@return integer
"""
def getFromID(self):
return self.input['message'].get('from')['id']
"""
Return first name of corressponding user or bot
@return string
"""
def getFromName(self):
return self.input['message'].get('from')['first_name']
"""
Return conversation ID for private or group chat
@return integer
"""
def getChatID(self):
return self.input['message'].get('chat')['id']
"""
Return location type if entered
@return Location | None
"""
def getLocation(self):
return self.input['message'].get('location')
"""
Return latitude
@return float | None
"""
def getLat(self):
if self.getLocation():
return self.getLocation().get('latitude')
return None
"""
Return longitude
@return float | None
"""
def getLng(self):
if self.getLocation():
return self.getLocation().get('longitude')
return None