-
Notifications
You must be signed in to change notification settings - Fork 0
/
message.py
45 lines (39 loc) · 1.28 KB
/
message.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
import datetime
from user import User
class BotMessage(object):
def __init__(self, botmessage, config):
self.config = config
self.message = botmessage # entire message
self.messagetext = botmessage.get('text', '') # text portion of message
self.messageid = botmessage.get('message_id', '') # message id
self.user = User(botmessage['from'], config) # details about user who sent message
#
# return the first element of the message which is designated as the command
# string
#
@property
def command(self):
return self.messagetext.split()[0]
#
# return subcommand if present else None. the first word after a command is
# the subcommand
#
@property
def subcommand(self):
return self.messagetext.split()[1] if self.messagetext.split() > 2 else \
None
#
# return message string after the command string. this comprises the
# subcommands and args to the command
#
@property
def args(self):
return self.messagetext.split()[1:] if len(self.messagetext.split()) > 1 \
else ""
#
# return date when the message was sent by the user
#
@property
def date(self):
return datetime.datetime.fromtimestamp(self.message['date']). \
strftime('%Y-%m-%d %H:%M:%S')