Skip to content
This repository was archived by the owner on Jan 21, 2023. It is now read-only.

Commit 753c2b8

Browse files
committed
add echo filter
1 parent d2fcc26 commit 753c2b8

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

CHANGELOG.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
Changelog
22
=========
33

4+
`1.1.0`_
5+
--------
6+
7+
- add filter to echo text received in private.
8+
- improve ``/echo`` command's help.
9+
410
1.0.0
511
-----
612

713
- initial release
814

15+
16+
.. _Unreleased: https://github.com/simplebot-org/simplebot_echo/compare/v1.1.0...HEAD
17+
.. _1.1.0: https://github.com/simplebot-org/simplebot_echo/compare/v1.0.0...v1.1.0

simplebot_echo.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Plugin's commands definition."""
22

33
import simplebot
4+
from deltachat import Message
45
from pkg_resources import DistributionNotFound, get_distribution
56
from simplebot.bot import Replies
67

@@ -11,12 +12,19 @@
1112
__version__ = "0.0.0.dev0-unknown"
1213

1314

15+
@simplebot.filter
16+
def echo_filter(message: Message, replies: Replies) -> None:
17+
"""I will echo back any text message you send me in private."""
18+
if not message.chat.is_group() and message.text:
19+
replies.add(text=message.text)
20+
21+
1422
@simplebot.command
1523
def echo(payload: str, replies: Replies) -> None:
16-
"""Echoes back received text.
24+
"""Echo back received text.
1725
18-
To use it you can simply send a message starting with
19-
the command '/echo'. Example: `/echo hello world`
26+
To use it send a message like:
27+
/echo hello world
2028
"""
2129
replies.add(text=payload or "echo")
2230

@@ -30,3 +38,10 @@ def test_echo(self, mocker):
3038

3139
msg = mocker.get_one_reply("/echo hello world")
3240
assert msg.text == "hello world"
41+
42+
def test_filter(self, mocker):
43+
msg = mocker.get_one_reply("hello world")
44+
assert msg.text == "hello world"
45+
46+
msgs = mocker.get_replies("hello world", group="TestGroup")
47+
assert not msgs

0 commit comments

Comments
 (0)