Skip to content

Commit

Permalink
upgrade to deltachat2 v0.5.0 and add BotCli.after()
Browse files Browse the repository at this point in the history
  • Loading branch information
adbenitez committed Apr 27, 2024
1 parent 6964aff commit 859c330
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
6 changes: 5 additions & 1 deletion deltabot_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@ def __init__(self, app_name: str, log_level: str = "info") -> None:
self._start_hooks: Set[CliEventHook] = set()
self._bot: Bot

def on(self, event: Union[type, EventFilter]) -> HookDecorator: # noqa
def on(self, event: Union[type, EventFilter]) -> HookDecorator:
"""Register decorated function as listener for the given event."""
return self._hooks.on(event)

def after(self, event: Union[type, EventFilter]) -> HookDecorator:
"""Register decorated function as listener for the given event."""
return self._hooks.after(event)

def on_init(self, func: CliEventHook) -> CliEventHook:
"""Register function to be called before the bot starts serving requests.
Expand Down
16 changes: 7 additions & 9 deletions examples/echobot_advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ def log_event(bot, accid, event):
bot.rpc.send_msg(accid, chatid, reply)


@cli.on(events.NewMessage(is_info=True))
def delete_info_msgs(bot, accid, event):
bot.rpc.delete_messages(accid, [event.msg.id])
@cli.on(events.NewMessage(command="/help"))
def _help(bot, accid, event):
msg = event.msg
bot.rpc.send_msg(accid, msg.chat_id, MsgData(text="I will repeat anything you say to me"))


@cli.on(events.NewMessage(is_info=False))
Expand All @@ -54,14 +55,11 @@ def echo(bot, accid, event):
return
msg = event.msg
bot.rpc.send_msg(accid, msg.chat_id, MsgData(text=msg.text))
bot.rpc.delete_messages(accid, [msg.id])


@cli.on(events.NewMessage(command="/help"))
def _help(bot, accid, event):
msg = event.msg
bot.rpc.send_msg(accid, msg.chat_id, MsgData(text="I will repeat anything you say to me"))
bot.rpc.delete_messages(accid, [msg.id])
@cli.after(events.NewMessage)
def delete_msgs(bot, accid, event):
bot.rpc.delete_messages(accid, [event.msg.id])


def test(_cli, bot, args):
Expand Down
2 changes: 1 addition & 1 deletion pylama.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[pylama]
linters=mccabe,pyflakes,pylint,isort,mypy
ignore=C0116,R0902,R0913,W1203,W0718
skip=.*,build/*,tests/*,*/flycheck_*
skip=.*,build/*,tests/*,*/_version.py,*/flycheck_*
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ classifiers = [
"License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)",
]
dependencies = [
"deltachat2[full]>=0.4.0",
"deltachat2[full]>=0.5.0",
"appdirs>=1.4.4",
"rich>=12.6.0",
"qrcode>=7.4.2",
Expand Down

0 comments on commit 859c330

Please sign in to comment.