Skip to content

Commit

Permalink
Merge branch 'Pycord-Development:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
ThatGenZGamer48 authored Mar 7, 2022
2 parents 9686db4 + a518aaa commit 0aa4cdf
Show file tree
Hide file tree
Showing 43 changed files with 522 additions and 230 deletions.
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ If the bug report is missing this information then it'll take us longer to fix t

## Submitting a Pull Request

Submitting a pull request is fairly simple, just make sure it focuses on a single aspect and doesn't manage to have scope creep and it's probably good to go. It would be incredibly lovely if the style is consistent to that found in the project. This project follows PEP-8 guidelines (mostly) with a column limit of 125.
Submitting a pull request is fairly simple, just make sure it focuses on a single aspect and doesn't manage to have scope creep and it's probably good to go. It would be incredibly lovely if the style is consistent to that found in the project. This project follows PEP-8 guidelines (mostly) with a column limit of 120.

## Use of "type: ignore" comments
In some cases, it might be necessary to ignore type checker warnings for one reason or another.
Expand Down
25 changes: 0 additions & 25 deletions .github/workflows/lint.yaml

This file was deleted.

20 changes: 0 additions & 20 deletions .pre-commit-config.yaml

This file was deleted.

9 changes: 5 additions & 4 deletions discord/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
"""

__title__ = "discord"
__title__ = "pycord"
__author__ = "Pycord Development"
__license__ = "MIT"
__copyright__ = "Copyright 2015-2021 Rapptz & Copyright 2021-present Pycord Development"
__version__ = "2.0.0b4"
__version__ = "2.0.0b5"

__path__ = __import__("pkgutil").extend_path(__path__, __name__)

Expand All @@ -39,6 +39,7 @@
from .file import *
from .flags import *
from .guild import *
from .http import *
from .integrations import *
from .interactions import *
from .invite import *
Expand All @@ -52,7 +53,7 @@
from .raw_models import *
from .reaction import *
from .role import *
from .scheduled_events import ScheduledEvent, ScheduledEventLocation
from .scheduled_events import *
from .shard import *
from .stage_instance import *
from .sticker import *
Expand All @@ -74,6 +75,6 @@ class VersionInfo(NamedTuple):
serial: int


version_info: VersionInfo = VersionInfo(major=2, minor=0, micro=0, releaselevel="beta", serial=4)
version_info: VersionInfo = VersionInfo(major=2, minor=0, micro=0, releaselevel="beta", serial=5)

logging.getLogger(__name__).addHandler(logging.NullHandler())
17 changes: 9 additions & 8 deletions discord/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ async def register_commands(
self,
commands: Optional[List[ApplicationCommand]] = None,
guild_id: Optional[int] = None,
force: bool = False,
force: bool = True,
) -> List[interactions.ApplicationCommand]:
"""|coro|
Expand All @@ -363,9 +363,10 @@ async def register_commands(
If this is set, the commands will be registered as a guild command for the respective guild. If it is not
set, the commands will be registered according to their :attr:`~.ApplicationCommand.guild_ids` attribute.
force: :class:`bool`
Registers the commands regardless of the state of the command on discord, this can take up more API calls
but is sometimes a more foolproof method of registering commands. This also sometimes causes minor bugs
where the command can temporarily appear as an invalid command on the user's side. Defaults to False.
Registers the commands regardless of the state of the command on Discord. This can sometimes cause commands
to be re-registered without changes (The command can temporarily appear as an invalid command on the user's
side) due to a bug in the API, but is a more foolproof method of registering
commands. Defaults to True.
"""
if commands is None:
commands = self.pending_application_commands
Expand Down Expand Up @@ -491,7 +492,7 @@ def register(method: str, *args, **kwargs):
async def sync_commands(
self,
commands: Optional[List[ApplicationCommand]] = None,
force: bool = False,
force: bool = True,
guild_ids: Optional[List[int]] = None,
register_guild_commands: bool = True,
unregister_guilds: Optional[List[int]] = None,
Expand All @@ -518,9 +519,9 @@ async def sync_commands(
commands: Optional[List[:class:`~.ApplicationCommand`]]
A list of commands to register. If this is not set (None), then all commands will be registered.
force: :class:`bool`
Registers the commands regardless of the state of the command on discord, this can take up more API calls
but is sometimes a more foolproof method of registering commands. This also allows the bot to dynamically
remove stale commands. Defaults to False.
Registers the commands regardless of the state of the command on Discord. This can sometimes cause commands
to be re-registered without changes due to a bug in the API, but is sometimes a more foolproof method of
registering commands. Defaults to True.
guild_ids: Optional[List[:class:`int`]]
A list of guild ids to register the commands for. If this is not set, the commands'
:attr:`~.ApplicationCommand.guild_ids` attribute will be used.
Expand Down
9 changes: 7 additions & 2 deletions discord/commands/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,15 @@ def unselected_options(self) -> Optional[List[Option]]:
return self.command.options # type: ignore
return None

@property
def send_modal(self) -> Interaction:
"""Sends a modal dialog to the user who invoked the interaction."""
return self.interaction.response.send_modal

@property
def respond(self) -> Callable[..., Awaitable[Union[Interaction, WebhookMessage]]]:
"""Callable[..., Union[:class:`~.Interaction`, :class:`~.Webhook`]]: Sends either a response
or a followup response depending if the interaction has been responded to yet or not."""
or a followup response depending on if the interaction has been responded to yet or not."""
if not self.interaction.response.is_done():
return self.interaction.response.send_message # self.response
else:
Expand Down Expand Up @@ -290,7 +295,7 @@ class AutocompleteContext:
The option the user is currently typing.
value: :class:`.str`
The content of the focused option.
options :class:`.dict`
options: :class:`.dict`
A name to value mapping of the options that the user has selected before this option.
"""

Expand Down
65 changes: 65 additions & 0 deletions discord/commands/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,58 @@ def __name__(self):


class Option:
"""Represents a selectable option for a slash command.
Examples
--------
Basic usage: ::
@bot.slash_command(guild_ids=[...])
async def hello(
ctx: discord.ApplicationContext,
name: Option(str, "Enter your name"),
age: Option(int, "Enter your age", min_value=1, max_value=99, default=18)
# passing the default value makes an argument optional
# you also can create optional argument using:
# age: Option(int, "Enter your age") = 18
):
await ctx.respond(f"Hello! Your name is {name} and you are {age} years old.")
.. versionadded:: 2.0
Attributes
----------
input_type: :class:`Any`
The type of input that is expected for this option.
description: :class:`str`
The description of this option.
Must be 100 characters or fewer.
name: :class:`str`
The name of this option visible in the UI.
Inherits from the variable name if not provided as a parameter.
choices: Optional[List[Union[:class:`Any`, :class:`OptionChoice`]]]
The list of available choices for this option.
Can be a list of values or :class:`OptionChoice` objects (which represent a name:value pair).
If provided, the input from the user must match one of the choices in the list.
required: Optional[:class:`bool`]
Whether this option is required.
default: Optional[:class:`Any`]
The default value for this option. If provided, ``required`` will be considered ``False``.
min_value: Optional[:class:`int`]
The minimum value that can be entered.
Only applies to Options with an input_type of ``int`` or ``float``.
max_value: Optional[:class:`int`]
The maximum value that can be entered.
Only applies to Options with an input_type of ``int`` or ``float``.
autocomplete: Optional[:class:`Any`]
The autocomplete handler for the option. Accepts an iterable of :class:`str`, a callable (sync or async) that takes a
single argument of :class:`AutocompleteContext`, or a coroutine. Must resolve to an iterable of :class:`str`.
.. note::
Does not validate the input value against the autocomplete results.
"""

def __init__(self, input_type: Any, /, description: str = None, **kwargs) -> None:
self.name: Optional[str] = kwargs.pop("name", None)
self.description = description or "No description provided"
Expand Down Expand Up @@ -139,6 +191,19 @@ def __repr__(self):


class OptionChoice:
"""
Represents a name:value pairing for a selected :class:`Option`.
.. versionadded:: 2.0
Attributes
----------
name: :class:`str`
The name of the choice. Shown in the UI when selecting an option.
value: Optional[Union[:class:`str`, :class:`int`, :class:`float`]]
The value of the choice. If not provided, will use the value of ``name``.
"""

def __init__(self, name: str, value: Optional[Union[str, int, float]] = None):
self.name = name
self.value = value if value is not None else name
Expand Down
7 changes: 4 additions & 3 deletions discord/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"Button",
"SelectMenu",
"SelectOption",
"InputText",
)

C = TypeVar("C", bound="Component")
Expand Down Expand Up @@ -148,8 +149,8 @@ class InputText(Component):
The style of the input text field.
custom_id: Optional[:class:`str`]
The ID of the input text field that gets received during an interaction.
label: Optional[:class:`str`]
The label for the input text field, if any.
label: :class:`str`
The label for the input text field.
placeholder: Optional[:class:`str`]
The placeholder text that is shown if nothing is selected, if any.
min_length: Optional[:class:`int`]
Expand Down Expand Up @@ -181,7 +182,7 @@ def __init__(self, data: InputTextComponentPayload):
self.type = ComponentType.input_text
self.style: InputTextStyle = try_enum(InputTextStyle, data["style"])
self.custom_id = data["custom_id"]
self.label: Optional[str] = data.get("label", None)
self.label: str = data.get("label", None)
self.placeholder: Optional[str] = data.get("placeholder", None)
self.min_length: Optional[int] = data.get("min_length", None)
self.max_length: Optional[int] = data.get("max_length", None)
Expand Down
2 changes: 1 addition & 1 deletion discord/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ class ApplicationType(Enum):


class StagePrivacyLevel(Enum):
# public = 1 Deprecated
# public = 1 (deprecated)
closed = 2
guild_only = 2

Expand Down
4 changes: 4 additions & 0 deletions discord/ext/commands/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,10 @@ class Bot(BotBase, discord.Bot):
This class also subclasses :class:`.GroupMixin` to provide the functionality
to manage commands.
.. note::
Using prefixed commands requires :attr:`discord.Intents.message_content` to be enabled.
Attributes
-----------
command_prefix
Expand Down
Loading

0 comments on commit 0aa4cdf

Please sign in to comment.