Skip to main content

RegEx based command mapping discord BOT framework with authorization

Project description

Latest version on PyPi Supported Python versions Documentation status Code style: black discord-rebot logo

Welcome to discord-rebot (py)

discordRebot is a RegEx based command mapping discord BOT framework with authorization.


Why discordRebot?

discordRebot is easy to use, minimal, and async ready framework using discord.py

Most of the bots uses a single prefix, string to match command and args split by spaces, example !cmd arg1 arg2.

But discordRebot uses RegEx for both matching the command and capturing the arguments. It gives more control over both matching the command and parsing arguments.

Also, it provides authorization to authorize the author of the message before executing the command.

Basic Example

A minimal bot with echo command

from discordRebot import *

client = discord.Client()
key = Mapper()

@key(re.compile(r"^!echo (.*)$")) # Eg: '!echo hello' -> 'hello'
def echo(msg, string):
    return string
echo.auth = None

client.event(Manager(key).on_message)
import os; client.run(os.environ["DBToken"])

You can find more examples in the examples directory.

Features

  • It also supports

    Example:
    @key(re.compile(r"^!ticker (\d*) (\d*)$"))
    async def ticker(msg, delay, to):
        delay, to = int(delay), int(to)
        for i in range(to):
            yield i
            await asyncio.sleep(delay)
    
  • Authorizes the message author
    based on

    • user_id example:1234567890
    • user_name example:'user#1234'
    • roles server (not applicable for DM)
    • permissions of members in server (not applicable for DM)
    • custom Callable[[author], bool]
    Example:
    @key("am i authorized ?")
    def amiauthorized(msg):
        return "Authorized"
    amiauthorized.auth = {1234567890, 'user#1234'}
    # only executable by user1 (with id 1234567890) and user2 (with username 'user#1234')
    
  • Can match multiple commands with a message

    Example:
    @key(re.compile(r"^([\s\S]*)$"))
    def printmsg(msg, content):
        print(f"@{msg.author}:")
        print(content)
    
    @key("whereami")
    def whereami(msg):
        if msg.guild:
            return msg.guild.name
        else:
            return "DM"
    

Links



discordpy-ext-rebot comming soon (for full featured Discord Bot with RegEx based argparser)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

discord-rebot-0.0.2.tar.gz (13.3 kB view hashes)

Uploaded Source

Built Distribution

discord_rebot-0.0.2-py3-none-any.whl (13.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page