Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions docs/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -1105,9 +1105,10 @@ with the same `{placeholders}`; every Spanish string containing `?` also contain
user_id=<bot id>)`; either one (privacy mode off, or status `administrator`/`creator`) turns on the
privacy-off rule (4.3), and the log line says which.
- After the menu, a version the KV's `announced_version` does not hold yet is announced in private to
each admin of the profile (the group when it names none): «Nueva versión en marcha: 0.6.0 (antes
0.5.0).». The version is stored once Telegram took at least one of those messages, so a failed send
is tried again at the next start and a restart on the same version says nothing.
each admin of the profile: «Nueva versión en marcha: 0.6.0 (antes 0.5.0).». It goes to the group
when the profile names no admin or Telegram refuses every private message (403 for an admin who never
opened a private chat with the bot). The version is stored once Telegram took a message, so a failed
send is tried again at the next start and a restart on the same version says nothing.
- `download(file_path, limit)` fetches a file `getFile` returned from
`https://api.telegram.org/file/bot<token>/<file_path>`. Like `call`, its errors are
`TelegramError("download", code, description)` with no URL in them; more than `limit` bytes raises
Expand Down
2 changes: 1 addition & 1 deletion supercycletracker/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""SuperCycleTracker: a menstrual cycle tracker that lives in a Telegram group."""

__version__ = "0.6.0"
__version__ = "0.6.1"
14 changes: 8 additions & 6 deletions supercycletracker/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,19 +641,21 @@ def group_admin(self) -> bool:
return isinstance(member, Mapping) and member.get("status") in ADMIN_STATUSES

def announce_version(self, version: str = __version__) -> None:
"""Tell the admins in private, or the group when the profile names none, that a new
version runs. The version is kept in the KV only once Telegram took at least one message,
so a failed send is tried again at the next start and a restart on the same version
says nothing."""
"""Tell the admins in private that a new version runs, or the group when the profile
names none or Telegram refuses every private message (an admin who never opened a
private chat with the bot gets 403). The version is kept in the KV only once Telegram
took a message, so a failed send is tried again at the next start and a restart on the
same version says nothing."""
previous = self.kv.get("announced_version")
if previous == version:
return
if previous:
text = self.t("version_new_from", version=version, previous=previous)
else:
text = self.t("version_new", version=version)
chats = list(self.profile.admins) or [self.chat_id]
sent = [c for c in chats if c is not None and self.post(c, text) is not None]
sent = [a for a in self.profile.admins if self.post(a, text) is not None]
if not sent and self.chat_id is not None and self.post(self.chat_id, text) is not None:
sent = [self.chat_id]
if sent:
self.kv.set("announced_version", version)
log.info("version %s announced to %d chat(s)", version, len(sent))
Expand Down
11 changes: 10 additions & 1 deletion tests/test_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1412,10 +1412,19 @@ def test_a_new_version_names_the_one_before(make_bot):
def test_a_failed_announcement_is_not_stored_and_goes_out_at_the_next_start(make_bot):
bot = make_bot()
bot.tg.fail_next("sendMessage", 403, "Forbidden: bot can't initiate conversation with a user")
bot.tg.fail_next("sendMessage", 502, "Bad Gateway")
bot.announce_version("1.2.3")
assert bot.kv.get("announced_version") is None
bot.announce_version("1.2.3")
assert bot.tg.texts() == ["Nueva versión en marcha: 1.2.3."] * 2 # refused, then taken
assert [m["chat_id"] for m in bot.tg.of("sendMessage")] == [ADMIN, GROUP, ADMIN]
assert bot.kv.get("announced_version") == "1.2.3"


def test_an_admin_the_bot_cannot_reach_in_private_gets_it_in_the_group(make_bot):
bot = make_bot()
bot.tg.fail_next("sendMessage", 403, "Forbidden: bot can't initiate conversation with a user")
bot.announce_version("1.2.3")
assert [m["chat_id"] for m in bot.tg.of("sendMessage")] == [ADMIN, GROUP]
assert bot.kv.get("announced_version") == "1.2.3"


Expand Down
Loading