mirror of
https://github.com/chatmail/core.git
synced 2026-04-06 15:42:10 +03:00
add a test echo_and_quit examples
This commit is contained in:
@@ -1,37 +1,57 @@
|
||||
|
||||
# instantiate and configure deltachat account
|
||||
# content of echo_and_quit.py
|
||||
|
||||
import sys
|
||||
import optparse
|
||||
import deltachat
|
||||
ac = deltachat.Account("/tmp/db")
|
||||
|
||||
# to see low-level events in the console uncomment the following line
|
||||
# ac.add_account_plugin(deltachat.eventlogger.FFIEventLogger(ac, ""))
|
||||
|
||||
if not ac.is_configured():
|
||||
ac.set_config("addr", "tmpy.94mtm@testrun.org")
|
||||
ac.set_config("mail_pw", "5CbD6VnjD/li")
|
||||
ac.set_config("mvbox_watch", "0")
|
||||
ac.set_config("sentbox_watch", "0")
|
||||
|
||||
class MyPlugin:
|
||||
class SimpleEchoPlugin:
|
||||
@deltachat.hookspec.account_hookimpl
|
||||
def process_incoming_message(self, message):
|
||||
print("process_incoming message", message)
|
||||
if message.text.strip() == "/quit":
|
||||
print("shutting down")
|
||||
ac.shutdown()
|
||||
message.account.shutdown()
|
||||
else:
|
||||
ch = ac.create_chat_by_contact(message.get_sender_contact())
|
||||
ch.send_text("echoing {}".format(message.text))
|
||||
ch = message.account.create_chat_by_contact(message.get_sender_contact())
|
||||
ch.send_text("echoing from {}:\n{}".format(message.get_sender_contact().addr, message.text))
|
||||
|
||||
@deltachat.hookspec.account_hookimpl
|
||||
def process_message_delivered(self, message):
|
||||
print("process_message_delivered", message)
|
||||
|
||||
ac.add_account_plugin(MyPlugin())
|
||||
|
||||
# start IO threads and perform configuration
|
||||
ac.start()
|
||||
def main(argv):
|
||||
p = optparse.OptionParser("simple-echo")
|
||||
p.add_option("-l", action="store_true", help="show low-level events")
|
||||
p.add_option("--db", type="str", help="database file")
|
||||
p.add_option("--email", type="str", help="email address")
|
||||
p.add_option("--password", type="str", help="password")
|
||||
|
||||
print("waiting for /quit or other message on {}".format(ac.get_config("addr")))
|
||||
opts, posargs = p.parse_args(argv)
|
||||
|
||||
ac.wait_shutdown()
|
||||
assert opts.db, "you must specify --db"
|
||||
ac = deltachat.Account(opts.db)
|
||||
|
||||
if opts.l:
|
||||
ac.add_account_plugin(deltachat.eventlogger.FFIEventLogger(ac, "echo"))
|
||||
|
||||
if not ac.is_configured():
|
||||
assert opts.email and opts.password, "you must specify --email and --password"
|
||||
ac.set_config("addr", opts.email)
|
||||
ac.set_config("mail_pw", opts.password)
|
||||
ac.set_config("mvbox_watch", "0")
|
||||
ac.set_config("sentbox_watch", "0")
|
||||
|
||||
ac.add_account_plugin(SimpleEchoPlugin())
|
||||
|
||||
# start IO threads and perform configure if neccessary
|
||||
ac.start(callback_thread=True)
|
||||
|
||||
print("waiting for /quit or message to echo on: {}".format(ac.get_config("addr")))
|
||||
|
||||
ac.wait_shutdown()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv)
|
||||
|
||||
Reference in New Issue
Block a user