Skip to content

Commit

Permalink
update to new deltabot-cli API
Browse files Browse the repository at this point in the history
  • Loading branch information
adbenitez committed Jan 30, 2024
1 parent 57625e6 commit 24c6f92
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
version = "0.2.0"
version = "0.3.0"
name = "webxdcbot"
description = "Example Delta Chat bot + webxdc app"
readme = "README.md"
Expand All @@ -18,7 +18,7 @@ classifiers = [
"Programming Language :: Python"
]
dependencies = [
"deltabot-cli>=1.0.0",
"deltabot-cli>=2.0.0,<3.0",
"fortune-python",
]

Expand Down
23 changes: 9 additions & 14 deletions webxdcbot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"""Minimal bot + webxdc example."""

import json
import logging
from pathlib import Path

from deltabot_cli import BotCli, ChatType, EventType, events
Expand All @@ -14,32 +13,28 @@


@cli.on(events.RawEvent)
def on_event(event):
def on_event(bot, accid, event):
"""process webxdc status updates"""
if event.kind == EventType.WEBXDC_STATUS_UPDATE:
logging.info(event)
rpc = event.rpc
accid = event.accid
bot.logger.info(event)
msgid = event.msg_id
serial = event.status_update_serial - 1
update = json.loads(rpc.get_webxdc_status_updates(accid, msgid, serial))[0]
update = json.loads(bot.rpc.get_webxdc_status_updates(accid, msgid, serial))[0]
resp = get_response(update["payload"])
if resp:
rpc.send_webxdc_status_update(
bot.rpc.send_webxdc_status_update(
accid, msgid, json.dumps(resp), resp.get("info", "")
)


@cli.on(events.NewMessage)
def send_app(event):
@cli.on(events.NewMessage(is_info=False))
def send_app(bot, accid, event):
"""send the webxdc app on every 1:1 (private) message"""
rpc = event.rpc
accid = event.accid
chatid = event.msg.chat_id
if rpc.get_basic_chat_info(accid, chatid).chat_type != ChatType.SINGLE:
if bot.rpc.get_basic_chat_info(accid, chatid).chat_type != ChatType.SINGLE:
return
logging.info(f"new 1:1 message: {event.msg.text!r}")
rpc.send_msg(accid, chatid, {"file": XDC_PATH})
bot.logger.info(f"new 1:1 message: {event.msg.text!r}")
bot.rpc.send_msg(accid, chatid, {"file": XDC_PATH})


def main():
Expand Down

0 comments on commit 24c6f92

Please sign in to comment.