forked from Amanbhandula/SmokeDetector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chatexchange_extension.py
31 lines (22 loc) · 936 Bytes
/
chatexchange_extension.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
# coding=utf-8
from chatexchange import client, events, rooms
import sys
from datetime import datetime
from helpers import log
class Room(rooms.Room):
def watch_socket(self, event_callback):
self._client.last_activity = datetime.utcnow()
def on_activity(activity):
self._client.last_activity = datetime.utcnow()
for event in self._events_from_activity(activity, self.id):
if isinstance(event, events.MessageEdited):
del event.message.content_source
event_callback(event, self._client)
return self._client._br.watch_room_socket(self.id, on_activity)
class Client(client.Client):
def __init__(self, host):
super().__init__(host)
self.last_activity = None
def get_room(self, room_id, **attrs_to_set):
return self._get_and_set_deduplicated(
Room, room_id, self._rooms, attrs_to_set)