Skip to content

Commit

Permalink
InstantCommands version 1.2 (#78)
Browse files Browse the repository at this point in the history
* Read command content from context

* Add redbot and asyncio to env

* Edit docs with new env values

Resolves #76

* Make Listener objects callable

They will call their own function

* Bump to version 1.2.0
  • Loading branch information
laggron42 committed Jun 16, 2020
1 parent cfbc708 commit fc4a405
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
18 changes: 6 additions & 12 deletions docs/instantcommands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,23 +109,17 @@ It can be a command (you will need to add the ``commands`` decorator) or a liste

* ``discord``

* ``ext.commands``

* ``asyncio``

* ``inspect``

* ``traceback``

* ``random``
* ``redbot``

* ``redbot.core``

* ``checks``
* ``.core.commands``
* ``.core.checks``

* ``Config``
* ``.core.Config``

* ``utils.chat_formatting.pagify``
* ``.core.utils.chat_formatting.pagify``

It isn't recommanded to use the ``Config`` value for now.
A future release should give a ready ``Config.Config`` object.
Expand Down
18 changes: 14 additions & 4 deletions instantcmd/instantcmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import logging
import os
import sys
import redbot

from redbot.core import commands
from redbot.core import checks
Expand Down Expand Up @@ -69,13 +70,20 @@ def __init__(self, bot):
self.listeners = {}

# these are the availables values when creating an instant cmd
self.env = {"bot": self.bot, "discord": discord, "commands": commands, "checks": checks}
self.env = {
"bot": self.bot,
"discord": discord,
"commands": commands,
"checks": checks,
"asyncio": asyncio,
"redbot": redbot,
}
# resume all commands and listeners
bot.loop.create_task(self.resume_commands())
self._init_logger()

__author__ = ["retke (El Laggron)"]
__version__ = "1.1.2"
__version__ = "1.2.0"

def _init_logger(self):
log_format = logging.Formatter(
Expand Down Expand Up @@ -207,13 +215,13 @@ async def instantcmd(self, ctx):
pass

@instantcmd.command(aliases=["add"])
async def create(self, ctx):
async def create(self, ctx, *, command: str = None):
"""
Instantly generate a new command from a code snippet.
If you want to make a listener, give its name instead of the command name.
You can upload a text file if the command is too long, but you should consider coding a\
cog at this point.
cog at this point.
"""

async def read_from_file(msg: discord.Message):
Expand All @@ -231,6 +239,8 @@ async def read_from_file(msg: discord.Message):

if ctx.message.attachments:
function_string = await read_from_file(ctx.message)
elif command:
function_string = self.cleanup_code(command)
else:
await ctx.send(
"You're about to create a new command. \n"
Expand Down
3 changes: 3 additions & 0 deletions instantcmd/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ def __init__(self, function: Callable, name: str):
self.name = name
self.id = id(function)

def __call__(self, *args, **kwargs):
self.func(*args, **kwargs)


def listener(name: str = None):
"""
Expand Down

0 comments on commit fc4a405

Please sign in to comment.