Skip to content

Commit

Permalink
v1.0.4
Browse files Browse the repository at this point in the history
Support for commands to be used as functions to call with ButtonType.CALLER
  • Loading branch information
Defxult committed Mar 13, 2021
1 parent be42d54 commit 505d3fe
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Buttons/button types are used when you want to add a reaction to the menu that d
|------|------|---------------|----------
| `name` | `str` |`None` | The name of the button object
| `custom_embed` | `discord.Embed` | `None` | When the reaction is pressed, go to the specifed embed.
| `details` | `function` | `None` | Assigns the function and it's arguments to call when a `Button` with `ButtonType.CALLER is pressed`
| `details` | `function` | `None` | Assigns the function and it's arguments to call when a `Button` with `ButtonType.CALLER` is pressed
---
## Button and ButtonType in detail
* Associated methods
Expand Down Expand Up @@ -161,20 +161,21 @@ menu.add_button(close_menu_button)
Remove all buttons with `menu.clear_all_buttons()`. You can also remove an individual button using its name if you have it set, or the button object itself with `menu.remove_button()`

##### ButtonType methods
At the moment, there is only 1 method in the `ButtonType` class. Class method `caller_details`. This class method is used to setup functions and it's arguments that are later called when the button is pressed. `ButtonType.CALLER` buttons are used to implement your own functionality into the menu. Maybe you want to add a button that creates a text channel or add something to a database. Please note that functions that are registered as commands (`@client.command()`) are not allowed to be used as a caller button type. Only normal functions can be used with `ButtonType.CALLER`
At the moment, there is only 1 method in the `ButtonType` class. Class method `caller_details`. This class method is used to setup functions and it's arguments that are later called when the button is pressed. `ButtonType.CALLER` buttons are used to implement your own functionality into the menu. Maybe you want to add a button that creates a text channel or add something to a database.

>Example
```py
async def add_to_database(name, discord_id, *, country):
@client.command()
async def add_to_database(ctx, name, discord_id, *, country):
# . . .

def car(make, year):
# . . .

menu = ReactionMenu(...)

db_add = Button(emoji='\U000027a1', linked_to=ButtonType.CALLER, details=ButtonType.caller_details(add_to_database, 'Defxult', 123456789, country='U.S'))
db_add = Button(emoji='\U000027a1', linked_to=ButtonType.CALLER, details=ButtonType.caller_details(add_to_database, ctx, 'Defxult', 123456789, country='U.S'))
vehicle = Button(emoji='\U000023ea', linked_to=ButtonType.CALLER, details=ButtonType.caller_details(car, 'Ford', 2021))

menu.add_button(db_add)
Expand Down
2 changes: 1 addition & 1 deletion reactionmenu/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .core import ReactionMenu, Button, ButtonType
__version__ = '1.0.3'
__version__ = '1.0.4'
8 changes: 5 additions & 3 deletions reactionmenu/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ButtonType(Enum):

@classmethod
def caller_details(cls, func, *args, **kwargs) -> tuple:
"""Registers the function to call as well as it's arguments. The 'func' parameter should NOT be a function that is a command ( `@client.command()` ) or event ( `@client.event` ). Only plain functions (including async) are to be used
"""Registers the function to call as well as it's arguments.
Parameter
---------
Expand All @@ -76,9 +76,11 @@ def holiday(location, season, month, *, moto):
```
.. Added v1.0.3
.. Changes :: v1.0.4
- Support for commands to be used as functions to call
"""
if isinstance(func, Command):
raise ReactionMenuException(f'Function {func.callback.__name__!r} cannot be used with ButtonType.CALLER because it is registered as a command. Commands cannot be registered as callers. Only normal functions should be used')
func = func.callback if isinstance(func, Command) else func
return (func, args, kwargs)


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def _get_readme():
author='Defxult#8269',
name='reactionmenu',
description='A package to create a discord.py reaction menu. If your discord.py version is 1.5.0+, intents are required',
version='1.0.3',
version='1.0.4',
url='https://github.com/Defxult',
project_urls=details,
classifiers=classifiers,
Expand Down

0 comments on commit 505d3fe

Please sign in to comment.