Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
5794b2f
feat: new Command object
Toricane Jun 28, 2022
7b70df0
fix: import error
Toricane Jun 28, 2022
4eef731
feat: option decorator
Toricane Jun 29, 2022
b074c48
fix: attempt to fix circular import
Toricane Jun 29, 2022
4678cd8
fix: circular import
Toricane Jun 29, 2022
1c0cf11
refactor: replace errors with LibraryException
Toricane Jun 29, 2022
448d552
refactor: few small refactors
Toricane Jun 29, 2022
5c5ecf3
refactor: test
Toricane Jun 29, 2022
98c21a4
feat: implement Command obj in decorators
Toricane Jun 30, 2022
45e6913
feat: working subcommand system
Toricane Jun 30, 2022
ce7edf3
feat: more customizable subcommand system
Toricane Jun 30, 2022
d12883b
feat: working Command system in Extensions
Toricane Jun 30, 2022
4c06e6c
refactor: add a TODO
Toricane Jun 30, 2022
eb8c379
refactor: tidy up the code, improve coro calling
Toricane Jul 1, 2022
26de2fd
refactor: rename Command.base to Command.name
Toricane Jul 1, 2022
d243756
feat: better group behavior
Toricane Jul 1, 2022
8533cf5
Merge branch 'unstable' into unstable
Toricane Jul 1, 2022
b5ab857
refactor: replace a few more base= with name=, tidy up code
Toricane Jul 1, 2022
e476f84
refactor: remove client field from Command and properly teardown comm…
Toricane Jul 2, 2022
7db851e
refactor: different method of looping
Toricane Jul 2, 2022
08eaf87
feat: implement default_scope functionality
Toricane Jul 2, 2022
62c8fa7
refactor: remove options param from Command.group()
Toricane Jul 2, 2022
0b39f85
refactor: make autocomplete work, change typehints, make user and mes…
Toricane Jul 6, 2022
7f41eba
feat: implement autodefer and spread_to_rows
Toricane Jul 6, 2022
ec3287f
fix: commands and autocomplete with self not passed when inside Exten…
Toricane Jul 7, 2022
e2ac9b7
style: add typehints
Toricane Jul 7, 2022
009a936
refactor: tweak default scope setting
Toricane Jul 7, 2022
b277ecc
docs: some docstrings filled in
Toricane Jul 7, 2022
c31925d
docs: more docstrings, organization of code
Toricane Jul 9, 2022
9e131b9
refactor: move resolving commands outside of __sync
Toricane Jul 9, 2022
446526e
refactor: change __all__ from list to tuple
Toricane Jul 9, 2022
180a791
fix: subcommands error with variables
Toricane Jul 9, 2022
682dec0
fix: incorrect error
Toricane Jul 9, 2022
dc693bd
docs: utils.py docstrings
Toricane Jul 9, 2022
ba585c4
feat: new way of creating an ActionRow (pun intended)
Toricane Jul 9, 2022
1b4f58f
Merge branch 'unstable' into unstable
Toricane Jul 9, 2022
29b6239
refactor: make option decorator better
Toricane Jul 10, 2022
2ae9c3e
refactor: change Command.self to Command.extension
Toricane Jul 10, 2022
6a7dce0
docs: fix incorrect typehint
Toricane Jul 10, 2022
83c560f
docs: modify docstring
Toricane Jul 10, 2022
0401317
docs: new docs page
Toricane Jul 10, 2022
bb5410f
docs: add doc file
Toricane Jul 10, 2022
dfa4ac1
docs: move line
Toricane Jul 10, 2022
e12906d
docs: modify docstring of spread_to_rows
Toricane Jul 10, 2022
3932438
refactor: rename variables
Toricane Jul 10, 2022
e393742
feat: implement Command.error decorator
Toricane Jul 10, 2022
a8da923
fix: typehint
Toricane Jul 10, 2022
a7cdb3b
docs: attempt to fix parameters of Client docstring
Toricane Jul 10, 2022
52e1369
ci: correct from checks.
pre-commit-ci[bot] Jul 10, 2022
a792fe7
docs: fix docstring
Toricane Jul 10, 2022
30a753a
style: delete a blank line
Toricane Jul 10, 2022
8fa993d
chore: merge branch 'unstable' of https://github.com/Toricane/library…
Toricane Jul 10, 2022
cab01f9
docs: update quickstart
Toricane Jul 10, 2022
922eb32
ci: correct from checks.
pre-commit-ci[bot] Jul 10, 2022
7269e98
docs: modify quickstart
Toricane Jul 10, 2022
a303271
Merge branch 'unstable' of https://github.com/Toricane/library into u…
Toricane Jul 10, 2022
186941a
docs: document new features
Toricane Jul 11, 2022
303bab8
docs: testing
Toricane Jul 11, 2022
e837510
docs: testing
Toricane Jul 11, 2022
35e9c12
docs: make it look good
Toricane Jul 11, 2022
90c9583
docs: fix formatting
Toricane Jul 11, 2022
103a287
docs: add migration docs
Toricane Jul 11, 2022
a4a859e
Merge branch 'unstable' into unstable
Toricane Jul 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions docs/migration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,116 @@ portal and add the intent to your current intents when connecting:
from interactions import Client, Intents

bot = Client("TOKEN", intents=Intents.DEFAULT | Intents.GUILD_MESSAGE_CONTENT)

4.1.0 → 4.3.0
~~~~~~~~~~~~~~~

``4.3.0`` introduces a new method of creating commands, subcommands, and options.
There are also numerous new features, such as a default scope and utilities.

The following example shows and explains how to create commands effortlessly and use new features mentioned above:

.. code-block:: python

import interactions

bot = interactions.Client("TOKEN", default_scope=1234567890)
# the default scope will be applied to all commands except for those
# that disable the feature in the command decorator via: `default_scope=False`

@bot.command()
async def command_name(ctx):
"""Command description"""
... # do something here.
# the name of the command is the coroutine name.
# the description is the first line of the docstring or "No description set".

@bot.command(default_scope=False)
@interactions.option(str, name="opt1") # description is optional.
@interactions.option(4, name="opt2", description="This is an option.")
@interactions.option(interactions.Channel, name="opt3", required=True)
async def command_with_options(
ctx, opt1: str, opt2, int, opt3: interactions.Channel = None
):
... # do something here.
# the default scope is disabled for this command, so this is a global command.
# the option type is positional only, and can be a python type, an integer,
# or supported interactions.py objects.
# all other options are keyword only arguments.
# the type amd name of the option are required, the rest are optional.

# Subcommand system:
@bot.command()
async def base_command(ctx):
... # do something here.
# this is the base command of the subcommand system.

@base_command.subcommand()
async def subcommand1(ctx, base_res: interactions.BaseResult):
... # do something here.
# this is a subcommand of the base command.
# the base result is the result of the base command, it is optional to have.
# /base_command subcommand1

# create subcommands *before* creating groups!

@base_command.group()
async def group1(ctx, base_res: interactions.BaseResult):
... # do something here.
# this symbolizes a group for subcommands.

@group.subcommand()
async def subcommand2(ctx, group_res: interactions.GroupResult):
raise Exception("pretend an error happened here")
# this is a subcommand of the group.
# the group result is the result of the group, it is optional to have.
# /base_command group1 subcommand2

@base_command.group()
async def group2(ctx):
# this symbolizes a group for subcommands.
# here, we will intentionally return StopCommand:
return interactions.StopCommand
# if this is returned, any callbacks afterwards in the same
# command will not be executed.
# for example, subcommand3 will not be executed.

@group2.subcommand()
async def subcommand3(ctx):
... # do something here.
# this is a subcommand of the group.
# this will NOT be executed.
# /base_command group2 subcommand3

@base_command.error
async def base_command_error(ctx, error):
... # do something here.
# remember the exception in subcommand2?
# here, you can handle any errors that occur in the base command.
# this is the error handler for the base command.
# the error is the exception raised by the command.
# you can have optional res, *args, and **kwargs
# if your command is a subcommand or
# there are options that you want to access.

# utilities
@bot.command()
@interactions.autodefer() # configurable
async def autodefer_command(ctx):
# it will automatically defer the command if the command is not
# executed within the configured `delay` in the autodefer decorator.

# ActionRow.new() utility:
b1 = Button(style=1, custom_id="b1", label="b1")
b2 = Button(style=1, custom_id="b2", label="b2")
b3 = Button(style=1, custom_id="b3", label="b3")
b4 = Button(style=1, custom_id="b4", label="b4")

await ctx.send("Components:", components=interactions.ActionRow.new(b1, b2, b3, b4))
# instead of the cumbersome ActionRow(components=[b1, b2, b3, b4])

# spread_to_rows utility:
await ctx.send("Components:", components=interactions.spread_to_rows(b1, b2, b3, b4, max_in_row=2))
# configurable

bot.start()
1 change: 1 addition & 0 deletions docs/models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ Interaction Models
models.command.rst
models.component.rst
models.misc.rst
models.utils.rst
8 changes: 8 additions & 0 deletions docs/models.utils.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.. currentmodule:: interactions

Utilities
==========================

.. automodule:: interactions.client.models.utils
:members:
:noindex:
Loading