Skip to content

Easy to use python module to create private telegram bots.

License

Notifications You must be signed in to change notification settings

timofurrer/ownbot

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ownbot

Build Status Coverage Status PyPI version

Easy to use python module to create private telegram bots.

Ownbot provides some cool decorators to protect your command handler functions from unauthorized users!

Install

pip install ownbot

Get Started

  • The assign_first_to decorator adds the first user who invokes the handler method to the specified group.
  • The second decorator requires_usergroup lets you define which usergroups will have permission to access the handler command.
from ownbot.auth import requires_usergroup, assign_first_to
(...)

@assign_first_to("admin")
@requires_usergroup("user")
def start_handler(bot, update):
    bot.sendMessage(chat_id=update.message.chat_id, text="Hello World")

Obviously if a user is in the admin group he has also access to functions which are protected with the @requires_usergroup("user") decorator. If a group passed to this decorator does not already exist, it will be automatically created.

How It Works

Ownbot saves new users added by Telegram username as unverified users. On first contact, when the user sends his first message to the bot, ownbot will store the user with his unique id as a verified user. A verified user will from now on always have access to his group even if he changes his username. The authorization checks are done only on the unique Telegram user_id! Sounds good right?

Admin Commands

The admin commands can be enabled by simply instantiating the AdminCommands class and passing over the bot's dispatcher.

from ownbot.admincommands import AdminCommands
(...)
updater = Updater(TOKEN)
dispatcher = updater.dispatcher
AdminCommands(dispatcher)

If the admin commands are enabled, a user who is in the admin group is able to perform the following actions:

Command Arguments Description
/adminhelp - Shows a list of available commands.
/users - Shows all registered users.
/adduser user group Adds a user to a group.
/rmuser user group Removes a user from a group.

Work in progress ...

About

Easy to use python module to create private telegram bots.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%