refine member/add remove further, and introduce ac_outgoing_message

This commit is contained in:
holger krekel
2020-04-19 12:31:15 +02:00
parent a1c82eaea6
commit 02cda1e611
6 changed files with 51 additions and 23 deletions

View File

@@ -30,7 +30,7 @@ class Chat(object):
return not (self == other)
def __repr__(self):
return "<Chat id={} name={} dc_context={}>".format(self.id, self.get_name(), self._dc_context)
return "<Chat id={} name={}>".format(self.id, self.get_name())
@property
def _dc_chat(self):

View File

@@ -48,6 +48,10 @@ class PerAccount:
def ac_incoming_message(self, message):
""" Called on any incoming message (to deaddrop or chat). """
@account_hookspec
def ac_outgoing_message(self, message):
""" Called on each outgoing message (both system and "normal")."""
@account_hookspec
def ac_message_delivered(self, message):
""" Called when an outgoing message has been delivered to SMTP. """
@@ -57,12 +61,12 @@ class PerAccount:
""" Chat was created or modified regarding membership, avatar, title. """
@account_hookspec
def ac_member_added(self, chat, contact, sender):
def ac_member_added(self, chat, contact, message):
""" Called for each contact added to an accepted chat. """
@account_hookspec
def ac_member_removed(self, chat, contact, sender):
""" Called for each contact removed from a chat. """
def ac_member_removed(self, chat, contact, message):
""" Called for each contact removed from a chat. """
class Global:

View File

@@ -28,7 +28,9 @@ class Message(object):
return self.account == other.account and self.id == other.id
def __repr__(self):
return "<Message id={} dc_context={}>".format(self.id, self._dc_context)
c = self.get_sender_contact()
return "<Message id={} sender={}/{} outgoing={} chat={}/{}>".format(
self.id, c.id, c.addr, self.is_outgoing(), self.chat.id, self.chat.get_name())
@classmethod
def from_db(cls, account, id):
@@ -322,14 +324,17 @@ def get_viewtype_code_from_name(view_type_name):
"available {!r}".format(view_type_name, list(_view_type_mapping.values())))
#
# some helper code for turning system messages into hook events
#
def map_system_message(msg):
if msg.is_system_message():
res = parse_system_add_remove(msg.text)
if res:
contact = msg.account.get_contact_by_addr(res[1])
if contact:
d = dict(chat=msg.chat, contact=contact, sender=msg.get_sender_contact())
d = dict(chat=msg.chat, contact=contact, message=msg)
return "ac_member_" + res[0], d

View File

@@ -347,15 +347,21 @@ class BotProcess:
patterns = [x.strip() for x in Source(pattern_lines.rstrip()).lines if x.strip()]
for next_pattern in patterns:
print("+++FNMATCH:", next_pattern)
ignored = []
while 1:
line = self.stdout_queue.get(timeout=15)
if line is None:
if ignored:
print("BOT stdout terminated after these lines")
for line in ignored:
print(line)
raise IOError("BOT stdout-thread terminated")
if fnmatch.fnmatch(line, next_pattern):
print("+++MATCHED:", line)
break
else:
print("+++IGN:", line)
ignored.append(line)
@pytest.fixture