From ec24d142635c96beee716e7f1bccc95e8c0df0ff Mon Sep 17 00:00:00 2001 From: adbenitez Date: Fri, 21 Oct 2022 02:32:18 -0400 Subject: [PATCH] make /sub and /unsub usable by non-admins by default --- README.rst | 4 ---- simplebot_tgchan/__init__.py | 5 +++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/README.rst b/README.rst index d1f41eb..579cd71 100644 --- a/README.rst +++ b/README.rst @@ -39,10 +39,6 @@ and get them then configure the bot:: simplebot -a bot@example.com db -s simplebot_tgchan/api_id "12345" simplebot -a bot@example.com db -s simplebot_tgchan/api_hash "0123456789abcdef0123456789abcdef" -Add your e-mail address as the bot administrator so you have access to the administration commands:: - - simplebot -a bot@example.com admin -a me@example.com - Then you must provide a phone number for the bot to use, to start session in Telegram:: simplebot -a bot@example.com login diff --git a/simplebot_tgchan/__init__.py b/simplebot_tgchan/__init__.py index 149890b..33bc9f2 100644 --- a/simplebot_tgchan/__init__.py +++ b/simplebot_tgchan/__init__.py @@ -30,6 +30,9 @@ def deltabot_init(bot: DeltaBot) -> None: getdefault(bot, "api_hash", "") getdefault(bot, "delay", str(60 * 5)) getdefault(bot, "max_size", str(1024**2 * 5)) + allow_sub = getdefault(bot, "allow_subscriptions", "1") == "1" + bot.commands.register(func=sub, admin=not allow_sub) + bot.commands.register(func=unsub, admin=not allow_sub) @simplebot.hookimpl @@ -60,7 +63,6 @@ def deltabot_member_removed( session.delete(channel) -@simplebot.command(admin=True) def sub(bot: DeltaBot, payload: str, message: Message, replies: Replies) -> None: """Subscribe chat to the given Telegram channel.""" if not getdefault(bot, "session"): @@ -112,7 +114,6 @@ async def _sub(bot: DeltaBot, payload: str, message: Message, replies: Replies) await client.disconnect() -@simplebot.command(admin=True) def unsub(bot: DeltaBot, payload: str, message: Message, replies: Replies) -> None: """Unsubscribe chat from the given Telegram channel.