Skip to content

Commit

Permalink
make /sub and /unsub usable by non-admins by default
Browse files Browse the repository at this point in the history
  • Loading branch information
adbenitez committed Oct 21, 2022
1 parent 7f3850c commit ec24d14
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
4 changes: 0 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ and get them then configure the bot::
simplebot -a [email protected] db -s simplebot_tgchan/api_id "12345"
simplebot -a [email protected] 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 [email protected] admin -a [email protected]

Then you must provide a phone number for the bot to use, to start session in Telegram::

simplebot -a [email protected] login
Expand Down
5 changes: 3 additions & 2 deletions simplebot_tgchan/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"):
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit ec24d14

Please sign in to comment.