mirror of
https://github.com/chatmail/core.git
synced 2026-04-05 23:22:11 +03:00
refine example doc and address https://github.com/deltachat/deltachat-core-rust/pull/1307#pullrequestreview-380876587
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
|
||||
# content of echo_and_quit.py
|
||||
|
||||
import deltachat
|
||||
from deltachat import account_hookimpl, run_cmdline
|
||||
|
||||
|
||||
class EchoPlugin:
|
||||
@deltachat.hookspec.account_hookimpl
|
||||
@account_hookimpl
|
||||
def process_incoming_message(self, message):
|
||||
print("process_incoming message", message)
|
||||
if message.text.strip() == "/quit":
|
||||
@@ -17,13 +17,13 @@ class EchoPlugin:
|
||||
text = message.text
|
||||
message.chat.send_text("echoing from {}:\n{}".format(addr, text))
|
||||
|
||||
@deltachat.hookspec.account_hookimpl
|
||||
@account_hookimpl
|
||||
def process_message_delivered(self, message):
|
||||
print("process_message_delivered", message)
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
deltachat.run_cmdline(argv=argv, account_plugins=[EchoPlugin()])
|
||||
run_cmdline(argv=argv, account_plugins=[EchoPlugin()])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -1,34 +1,39 @@
|
||||
|
||||
# content of group_tracking.py
|
||||
|
||||
import deltachat
|
||||
from deltachat import account_hookimpl, run_cmdline
|
||||
|
||||
|
||||
class GroupTrackingPlugin:
|
||||
@deltachat.hookspec.account_hookimpl
|
||||
@account_hookimpl
|
||||
def process_incoming_message(self, message):
|
||||
print("*** process_incoming_message addr={} msg={!r}".format(
|
||||
message.get_sender_contact().addr, message.text))
|
||||
for member in message.chat.get_contacts():
|
||||
print("chat member: {}".format(member.addr))
|
||||
print("process_incoming message", message)
|
||||
if message.text.strip() == "/quit":
|
||||
message.account.shutdown()
|
||||
else:
|
||||
# unconditionally accept the chat
|
||||
message.accept_sender_contact()
|
||||
addr = message.get_sender_contact().addr
|
||||
text = message.text
|
||||
message.chat.send_text("echoing from {}:\n{}".format(addr, text))
|
||||
|
||||
@deltachat.hookspec.account_hookimpl
|
||||
@account_hookimpl
|
||||
def configure_completed(self, success):
|
||||
print("*** configure_completed:", success)
|
||||
|
||||
@deltachat.hookspec.account_hookimpl
|
||||
@account_hookimpl
|
||||
def member_added(self, chat, contact):
|
||||
print("*** member_added", contact.addr, "from", chat)
|
||||
for member in chat.get_contacts():
|
||||
print("chat member: {}".format(member.addr))
|
||||
|
||||
@deltachat.hookspec.account_hookimpl
|
||||
@account_hookimpl
|
||||
def member_removed(self, chat, contact):
|
||||
print("*** member_removed", contact.addr, "from", chat)
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
deltachat.run_cmdline(argv=argv, account_plugins=[GroupTrackingPlugin()])
|
||||
run_cmdline(argv=argv, account_plugins=[GroupTrackingPlugin()])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -57,6 +57,9 @@ def test_group_tracking_plugin(acfactory, lp):
|
||||
contact3 = ac1.create_contact(ac2.get_config("addr"))
|
||||
ch.add_contact(contact3)
|
||||
|
||||
reply = ac1._evtracker.wait_next_incoming_message()
|
||||
assert "hello" in reply.text
|
||||
|
||||
lp.sec("now looking at what the bot received")
|
||||
botproc.fnmatch_lines("""
|
||||
*member_added {}*
|
||||
|
||||
Reference in New Issue
Block a user