Skip to content

Commit

Permalink
part of #183: add GETCHANNELMESSAGES
Browse files Browse the repository at this point in the history
  • Loading branch information
abma committed Oct 3, 2017
1 parent e7fd902 commit 9aa7f9f
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions protocol/Protocol.py
Expand Up @@ -8,6 +8,7 @@
import Battle
import importlib
import logging
import datetime

from Crypto.Hash import MD5
import base64
Expand Down Expand Up @@ -81,6 +82,7 @@
'SAYPRIVATEEX',
'SETCHANNELKEY',
'UNMUTE',
'GETCHANNELMESSAGES',
########
# ignore
'IGNORE',
Expand Down Expand Up @@ -2077,6 +2079,28 @@ def in_CHANNELTOPIC(self, client, chan, topic):
if channel.isOp(client):
channel.setTopic(client, topic)

def in_GETCHANNELMESSAGES(self, client, chan, timestr):
'''
Get historical messages from the chan since the specified time
@required.str chan: The target channel
@required.str time: messages to get since this unix timestamp
'''
if not chan in self._root.channels:
return

channel = self._root.channels[chan]
if not client.session_id in channel.users:
self.out_FAILED(client, "GETCHANNELMESSAGES", "Can't get channel messages when not joined", True)
return
try:
timestamp = datetime.datetime.fromtimestamp(int(timestr))
except ValueError:
self.out_FAILED(client, "GETCHANNELMESSAGES", "Invalid timestamp", True)
return
msgs = self.userdb.get_channel_messages(client.db_id, channel.id, timestamp)
for msg in msgs:
client.Send("SAID " + self._dictToTags( { "chanName": chan, "time": str(time.mktime(msg[0].timetuple())), "userName": msg[1], "msg": msg[2]} ))

def in_FORCELEAVECHANNEL(self, client, chan, username, reason=''):
'''
Kick target user from target channel.
Expand Down

0 comments on commit 9aa7f9f

Please sign in to comment.