From ab50202c59cbbdae80fdeefd95fa00ecc4d651dd Mon Sep 17 00:00:00 2001 From: Vioshim Date: Sat, 18 Dec 2021 02:16:45 -0500 Subject: [PATCH 01/27] Compatibility with OptionChoices in autocomplete --- discord/commands/commands.py | 3 ++- discord/utils.py | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/discord/commands/commands.py b/discord/commands/commands.py index fc6ddba9b2..d2b25c8cbc 100644 --- a/discord/commands/commands.py +++ b/discord/commands/commands.py @@ -565,7 +565,8 @@ async def invoke_autocomplete_callback(self, ctx: AutocompleteContext): result = await result choices = [ - o if isinstance(o, OptionChoice) else OptionChoice(o) + o if isinstance(o, OptionChoice) + else (OptionChoice(*o) if isinstance(o, tuple) else OptionChoice(o)) for o in result ][:25] return await ctx.interaction.response.send_autocomplete_result(choices=choices) diff --git a/discord/utils.py b/discord/utils.py index 1d1af3b1fb..53ddef25b9 100644 --- a/discord/utils.py +++ b/discord/utils.py @@ -1111,7 +1111,26 @@ async def autocomplete_callback(ctx: AutocompleteContext) -> V: if asyncio.iscoroutine(_values): _values = await _values - gen = (val for val in _values if str(val).lower().startswith(str(ctx.value or "").lower())) + def check(item: Any) -> bool: + """Comparator method + + Parameters + ---------- + x : str + parameter + + Returns + ------- + bool + if valid + """ + if isinstance(item, tuple): + item, _ = item + if hasattr(item, "to_dict"): + item = item.to_dict()["name"] + return str(item).lower().startswith(str(ctx.value or "").lower()) + + gen = (val for val in _values if check(val)) return iter(itertools.islice(gen, 25)) return autocomplete_callback From 460a8adabbf21c3ebdd8212710bbb547c627693f Mon Sep 17 00:00:00 2001 From: Vioshim Date: Sat, 18 Dec 2021 02:22:13 -0500 Subject: [PATCH 02/27] Documentation changes --- discord/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/discord/utils.py b/discord/utils.py index 53ddef25b9..ace99b8cb4 100644 --- a/discord/utils.py +++ b/discord/utils.py @@ -1094,13 +1094,13 @@ async def autocomplete(ctx): Parameters ----------- - values: Union[Union[Iterable[:class:`str`], Iterable[:class:`int`], Iterable[:class:`float`]], Callable[[:class:`AutocompleteContext`], Union[Union[Iterable[:class:`str`], Iterable[:class:`int`], Iterable[:class:`float`]], Awaitable[Union[Iterable[:class:`str`], Iterable[:class:`int`], Iterable[:class:`float`]]]]], Awaitable[Union[Iterable[:class:`str`], Iterable[:class:`int`], Iterable[:class:`float`]]]] + values: Union[Union[Iterable[:class:`tuple`], Iterable[:class:`OptionChoice`], Iterable[:class:`str`], Iterable[:class:`int`], Iterable[:class:`float`]], Callable[[:class:`AutocompleteContext`], Union[Union[Iterable[:class:`str`], Iterable[:class:`int`], Iterable[:class:`float`]], Awaitable[Union[Iterable[:class:`str`], Iterable[:class:`int`], Iterable[:class:`float`]]]]], Awaitable[Union[Iterable[:class:`str`], Iterable[:class:`int`], Iterable[:class:`float`]]]] Possible values 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`. Returns -------- - Callable[[:class:`AutocompleteContext`], Awaitable[Union[Iterable[:class:`str`], Iterable[:class:`int`], Iterable[:class:`float`]]]] + Callable[[:class:`AutocompleteContext`], Awaitable[Union[Iterable[:class:`tuple`], Iterable[:class:`OptionChoice`], Iterable[:class:`str`], Iterable[:class:`int`], Iterable[:class:`float`]]]] A wrapped callback for the autocomplete. """ async def autocomplete_callback(ctx: AutocompleteContext) -> V: From d6cdbaacd4c4cd77245bd061b4c47ca6199fe769 Mon Sep 17 00:00:00 2001 From: Vioshim <63890837+Vioshim@users.noreply.github.com> Date: Sat, 18 Dec 2021 02:34:36 -0500 Subject: [PATCH 03/27] Fixed typos --- discord/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/utils.py b/discord/utils.py index ace99b8cb4..cf38f6ccf1 100644 --- a/discord/utils.py +++ b/discord/utils.py @@ -1116,7 +1116,7 @@ def check(item: Any) -> bool: Parameters ---------- - x : str + item : Any parameter Returns From e6b49ae5480d2348beb3eaf1ef0e1c14c238ee81 Mon Sep 17 00:00:00 2001 From: Vioshim <63890837+Vioshim@users.noreply.github.com> Date: Sun, 19 Dec 2021 02:38:28 -0500 Subject: [PATCH 04/27] removing tuple usage removing tuple usage --- discord/utils.py | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/discord/utils.py b/discord/utils.py index cf38f6ccf1..8f2cea63a8 100644 --- a/discord/utils.py +++ b/discord/utils.py @@ -1094,13 +1094,13 @@ async def autocomplete(ctx): Parameters ----------- - values: Union[Union[Iterable[:class:`tuple`], Iterable[:class:`OptionChoice`], Iterable[:class:`str`], Iterable[:class:`int`], Iterable[:class:`float`]], Callable[[:class:`AutocompleteContext`], Union[Union[Iterable[:class:`str`], Iterable[:class:`int`], Iterable[:class:`float`]], Awaitable[Union[Iterable[:class:`str`], Iterable[:class:`int`], Iterable[:class:`float`]]]]], Awaitable[Union[Iterable[:class:`str`], Iterable[:class:`int`], Iterable[:class:`float`]]]] + values: Union[Union[Iterable[:class:`OptionChoice`], Iterable[:class:`str`], Iterable[:class:`int`], Iterable[:class:`float`]], Callable[[:class:`AutocompleteContext`], Union[Union[Iterable[:class:`str`], Iterable[:class:`int`], Iterable[:class:`float`]], Awaitable[Union[Iterable[:class:`str`], Iterable[:class:`int`], Iterable[:class:`float`]]]]], Awaitable[Union[Iterable[:class:`str`], Iterable[:class:`int`], Iterable[:class:`float`]]]] Possible values 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`. Returns -------- - Callable[[:class:`AutocompleteContext`], Awaitable[Union[Iterable[:class:`tuple`], Iterable[:class:`OptionChoice`], Iterable[:class:`str`], Iterable[:class:`int`], Iterable[:class:`float`]]]] + Callable[[:class:`AutocompleteContext`], Awaitable[Union[Iterable[:class:`OptionChoice`], Iterable[:class:`str`], Iterable[:class:`int`], Iterable[:class:`float`]]]] A wrapped callback for the autocomplete. """ async def autocomplete_callback(ctx: AutocompleteContext) -> V: @@ -1112,20 +1112,6 @@ async def autocomplete_callback(ctx: AutocompleteContext) -> V: _values = await _values def check(item: Any) -> bool: - """Comparator method - - Parameters - ---------- - item : Any - parameter - - Returns - ------- - bool - if valid - """ - if isinstance(item, tuple): - item, _ = item if hasattr(item, "to_dict"): item = item.to_dict()["name"] return str(item).lower().startswith(str(ctx.value or "").lower()) From b1b99481a2ee14f0dcf9ef8ff81980cbc489a7bb Mon Sep 17 00:00:00 2001 From: Vioshim <63890837+Vioshim@users.noreply.github.com> Date: Sun, 19 Dec 2021 02:39:24 -0500 Subject: [PATCH 05/27] removing tuple usage removing tuple usage --- discord/commands/commands.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/discord/commands/commands.py b/discord/commands/commands.py index d2b25c8cbc..fc6ddba9b2 100644 --- a/discord/commands/commands.py +++ b/discord/commands/commands.py @@ -565,8 +565,7 @@ async def invoke_autocomplete_callback(self, ctx: AutocompleteContext): result = await result choices = [ - o if isinstance(o, OptionChoice) - else (OptionChoice(*o) if isinstance(o, tuple) else OptionChoice(o)) + o if isinstance(o, OptionChoice) else OptionChoice(o) for o in result ][:25] return await ctx.interaction.response.send_autocomplete_result(choices=choices) From 7211b298d2288ae985d24eb95bc70c4d6af15ace Mon Sep 17 00:00:00 2001 From: HyperGH <46067571+HyperGH@users.noreply.github.com> Date: Sat, 25 Dec 2021 20:29:53 +0100 Subject: [PATCH 06/27] Add a note about using ctx.respond --- examples/app_commands/slash_basic.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/app_commands/slash_basic.py b/examples/app_commands/slash_basic.py index b85ab0d24e..f66ab8bbe5 100644 --- a/examples/app_commands/slash_basic.py +++ b/examples/app_commands/slash_basic.py @@ -14,6 +14,8 @@ async def hello(ctx): """Say hello to the bot""" # the command description can be supplied as the docstring await ctx.respond(f"Hello {ctx.author}!") + # Please note that you MUST either use ctx.respond() or ctx.defer() in your + # slash command code, otherwise the interaction will fail. @bot.slash_command( From 69f656398b618281df09be9c334abc475533ecc7 Mon Sep 17 00:00:00 2001 From: HyperGH <46067571+HyperGH@users.noreply.github.com> Date: Sat, 25 Dec 2021 21:59:37 +0100 Subject: [PATCH 07/27] Clarify wording --- examples/app_commands/slash_basic.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/app_commands/slash_basic.py b/examples/app_commands/slash_basic.py index f66ab8bbe5..50df3b9db4 100644 --- a/examples/app_commands/slash_basic.py +++ b/examples/app_commands/slash_basic.py @@ -14,8 +14,8 @@ async def hello(ctx): """Say hello to the bot""" # the command description can be supplied as the docstring await ctx.respond(f"Hello {ctx.author}!") - # Please note that you MUST either use ctx.respond() or ctx.defer() in your - # slash command code, otherwise the interaction will fail. + # Please note that you MUST use ctx.respond(), ctx.defer(), or any other interaction response + # in your slash command code, otherwise the interaction will fail. @bot.slash_command( From c9fc04c7be1a45e16f8feb680977a21f17ee4b52 Mon Sep 17 00:00:00 2001 From: HyperGH <46067571+HyperGH@users.noreply.github.com> Date: Sat, 25 Dec 2021 23:02:25 +0100 Subject: [PATCH 08/27] Add timeout notice --- examples/app_commands/slash_basic.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/app_commands/slash_basic.py b/examples/app_commands/slash_basic.py index 50df3b9db4..17b0b512db 100644 --- a/examples/app_commands/slash_basic.py +++ b/examples/app_commands/slash_basic.py @@ -14,8 +14,9 @@ async def hello(ctx): """Say hello to the bot""" # the command description can be supplied as the docstring await ctx.respond(f"Hello {ctx.author}!") - # Please note that you MUST use ctx.respond(), ctx.defer(), or any other interaction response - # in your slash command code, otherwise the interaction will fail. + # Please note that you MUST respond with ctx.respond(), ctx.defer(), or any other + # interaction response within 3 seconds in your slash command code, otherwise the + # interaction will fail. @bot.slash_command( From 0c1f30c364712d9108026c2f32f04d9f773a8524 Mon Sep 17 00:00:00 2001 From: Dorukyum Date: Sun, 26 Dec 2021 21:38:54 +0300 Subject: [PATCH 09/27] Fix converters --- discord/commands/commands.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/discord/commands/commands.py b/discord/commands/commands.py index 1b1b80359d..ebbdcbb2d8 100644 --- a/discord/commands/commands.py +++ b/discord/commands/commands.py @@ -529,8 +529,8 @@ async def _invoke(self, ctx: ApplicationContext) -> None: if arg is None: arg = ctx.guild.get_role(arg_id) or arg_id - elif op.input_type == SlashCommandOptionType.string and op._converter is not None: - arg = await op._converter.convert(ctx, arg) + elif op.input_type == SlashCommandOptionType.string and (converter := op.converter) is not None: + arg = await converter.convert(converter, ctx, arg) kwargs[op._parameter_name] = arg @@ -626,11 +626,11 @@ def __init__( ) -> None: self.name: Optional[str] = kwargs.pop("name", None) self.description = description or "No description provided" - self._converter = None + self.converter = None self.channel_types: List[SlashCommandOptionType] = kwargs.pop("channel_types", []) if not isinstance(input_type, SlashCommandOptionType): if hasattr(input_type, "convert"): - self._converter = input_type + self.converter = input_type input_type = SlashCommandOptionType.string else: _type = SlashCommandOptionType.from_datatype(input_type) From d795f10852f67ffcec38afb5a0606c19011ba506 Mon Sep 17 00:00:00 2001 From: Vincent Date: Sun, 26 Dec 2021 22:34:09 -0800 Subject: [PATCH 10/27] feat: commit styling guide --- .github/CONTRIBUTING.md | 78 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 69 insertions(+), 9 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 42001e6dd6..f43785c599 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -43,12 +43,72 @@ deciding to ignore type checking warnings. By submitting a pull request, you agree that; 1) You hold the copyright on all submitted code inside said pull request; 2) You agree to transfer all rights to the owner of this repository, and; 3) If you are found to be in fault with any of the above, we shall not be held responsible in any way after the pull request has been merged. -### Git Commit Guidelines - -- Use present tense (e.g. "Add feature" not "Added feature") -- Limit all lines to 72 characters or less. -- Reference issues or pull requests outside of the first line. - - Please use the shorthand `#123` and not the full URL. -- Commits regarding the commands extension must be prefixed with `[commands]` - -If you do not meet any of these guidelines, don't fret. Chances are they will be fixed upon rebasing but please do try to meet them to remove some of the workload. +## Git Commit Styling + +Not following this guideline could lead to your pull being squashed for a cleaner commit history + +This style guide is most based of the [conventional commits](https://www.conventionalcommits.org/) style guide, in where it follows following guidelines: +```txt +type(scope): +``` +different with conventional commits is that we are gonna be defining the types you can use. + +### Normal Types + +These here are some types normally used without the library + +#### Feature Types: +``` +feat: +feature: +addition: +creation: +``` +#### Bug Fix Types: +``` +fix: +bug: +bug-fix: +``` +#### Fixing Grammar Mistakes: +``` +typo: +grammar: +nit: +``` +#### When refactoring or efficientizing code: +``` +speed: +refactor: +efficent: +``` + +### Extension Types + +Some types used in the `ext`'s + +#### ommands Types: +``` +ext.commands: +commands.Bot +checks: +cogs: +cooldowns: +``` +#### ages Types: +``` +ext.pages: +pages: +paginator: +``` +Tasks Types: +``` +ext.tasks: +tasks: +``` + +### Displaying breaking changes or closing issues in a commit +When closing issues or displaying a breaking change just add the following to your extended description: +``` +BREAKING CHANGE: +CLOSES: # From 04037d11aad342c7d2fd365054a2a9ba8df8e0e5 Mon Sep 17 00:00:00 2001 From: Dorukyum Date: Mon, 27 Dec 2021 09:35:06 +0300 Subject: [PATCH 11/27] Implement ApplicationContext.invoke --- discord/commands/commands.py | 16 ++++++++++++--- discord/commands/context.py | 39 +++++++++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/discord/commands/commands.py b/discord/commands/commands.py index 1b1b80359d..bc278c58f7 100644 --- a/discord/commands/commands.py +++ b/discord/commands/commands.py @@ -31,7 +31,8 @@ import re import types from collections import OrderedDict -from typing import Any, Callable, Dict, List, Optional, Type, Union, TYPE_CHECKING +from typing import Any, Callable, Dict, Generic, List, Optional, Type, TypeVar, Union, TYPE_CHECKING +from typing_extensions import ParamSpec from .context import ApplicationContext, AutocompleteContext from .errors import ApplicationCommandError, CheckFailure, ApplicationCommandInvokeError @@ -61,9 +62,18 @@ "MessageCommand", ) -if TYPE_CHECKING: +if TYPE_CHECKING: + from ..cog import Cog from ..interactions import Interaction +T = TypeVar('T') +CogT = TypeVar('CogT', bound='Cog') + +if TYPE_CHECKING: + P = ParamSpec('P') +else: + P = TypeVar('P') + def wrap_callback(coro): @functools.wraps(coro) async def wrapped(*args, **kwargs): @@ -97,7 +107,7 @@ async def wrapped(arg): class _BaseCommand: __slots__ = () -class ApplicationCommand(_BaseCommand): +class ApplicationCommand(_BaseCommand, Generic[CogT, P, T]): cog = None def __repr__(self): diff --git a/discord/commands/context.py b/discord/commands/context.py index 0fd332ae88..e956eff20b 100644 --- a/discord/commands/context.py +++ b/discord/commands/context.py @@ -24,11 +24,13 @@ """ from __future__ import annotations -from typing import TYPE_CHECKING, Optional, Union +from typing import Callable, TYPE_CHECKING, Optional, TypeVar, Union import discord.abc if TYPE_CHECKING: + from typing_extensions import ParamSpec + import discord from discord import Bot from discord.state import ConnectionState @@ -42,6 +44,15 @@ from ..message import Message from ..user import User from ..utils import cached_property +from ..webhook import Webhook + +T = TypeVar('T') +CogT = TypeVar('CogT', bound="Cog") + +if TYPE_CHECKING: + P = ParamSpec('P') +else: + P = TypeVar('P') __all__ = ( "ApplicationContext", @@ -81,6 +92,32 @@ def __init__(self, bot: Bot, interaction: Interaction): async def _get_channel(self) -> discord.abc.Messageable: return self.channel + async def invoke(self, command: ApplicationCommand[CogT, P, T], /, *args: P.args, **kwargs: P.kwargs) -> T: + r"""|coro| + Calls a command with the arguments given. + This is useful if you want to just call the callback that a + :class:`.ApplicationCommand` holds internally. + .. note:: + This does not handle converters, checks, cooldowns, pre-invoke, + or after-invoke hooks in any matter. It calls the internal callback + directly as-if it was a regular function. + You must take care in passing the proper arguments when + using this function. + Parameters + ----------- + command: :class:`.ApplicationCommand` + The command that is going to be called. + \*args + The arguments to use. + \*\*kwargs + The keyword arguments to use. + Raises + ------- + TypeError + The command argument to invoke is missing. + """ + return await command(self, *args, **kwargs) + @cached_property def channel(self): return self.interaction.channel From f36183491529a4c431e955d29b31e3fa8b28a210 Mon Sep 17 00:00:00 2001 From: Vincent Date: Sun, 26 Dec 2021 22:37:37 -0800 Subject: [PATCH 12/27] CONTRIBUTING: Expand Style Guide More --- .github/CONTRIBUTING.md | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index f43785c599..eb727c06c3 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -87,7 +87,7 @@ efficent: Some types used in the `ext`'s -#### ommands Types: +#### Commands Types: ``` ext.commands: commands.Bot @@ -95,20 +95,39 @@ checks: cogs: cooldowns: ``` -#### ages Types: +#### Pages Types: ``` ext.pages: pages: paginator: ``` -Tasks Types: +#### Tasks Types: ``` ext.tasks: tasks: ``` ### Displaying breaking changes or closing issues in a commit + When closing issues or displaying a breaking change just add the following to your extended description: ``` BREAKING CHANGE: CLOSES: # +``` + +### Special Commit Types + +#### Github +``` +git: +github: +actions: +ci: +ci/cd: +CONTRIBUTING: +``` +#### Docs +``` +docs: +sphinx: +``` From 8162e5088e0529ef4c61562fc4e4ec8fe161b2bc Mon Sep 17 00:00:00 2001 From: Vincent Date: Sun, 26 Dec 2021 22:40:13 -0800 Subject: [PATCH 13/27] git: make style guide a checked requirement --- .github/PULL_REQUEST_TEMPLATE.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index a4fa4c0b4c..57290eecfe 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -9,6 +9,7 @@ - [ ] If code changes were made then they have been tested. - [ ] I have updated the documentation to reflect the changes. - [ ] If `type: ignore` comments were used, a comment is also left explaining why +- [ ] This PR follows the commit style on [contributing](https://github.com/pycord-development/pycord/blob/master/.github/CONTRIBUTING.md) - [ ] This PR fixes an issue. - [ ] This PR adds something new (e.g. new method or parameters). - [ ] This PR is a breaking change (e.g. methods or parameters removed/renamed) From cbd2a7d0ed6302b3ee5391fac5b0d8c8dc8dc088 Mon Sep 17 00:00:00 2001 From: Vincent Date: Sun, 26 Dec 2021 22:43:41 -0800 Subject: [PATCH 14/27] typo: didn't put a `:` on the `commands.Bot` type --- .github/CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index eb727c06c3..74e606b683 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -90,7 +90,7 @@ Some types used in the `ext`'s #### Commands Types: ``` ext.commands: -commands.Bot +commands.Bot: checks: cogs: cooldowns: From c83c24c1fe3a1141eb90906c2df4cf5c05cbac01 Mon Sep 17 00:00:00 2001 From: Vincent Date: Sun, 26 Dec 2021 22:57:36 -0800 Subject: [PATCH 15/27] refactor: don't duplicate types --- .github/CONTRIBUTING.md | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 74e606b683..847f3945b9 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -61,26 +61,21 @@ These here are some types normally used without the library ``` feat: feature: -addition: -creation: ``` #### Bug Fix Types: ``` fix: -bug: bug-fix: ``` #### Fixing Grammar Mistakes: ``` typo: -grammar: nit: ``` #### When refactoring or efficientizing code: ``` -speed: +speedup: refactor: -efficent: ``` ### Extension Types @@ -91,15 +86,11 @@ Some types used in the `ext`'s ``` ext.commands: commands.Bot: -checks: -cogs: -cooldowns: ``` #### Pages Types: ``` ext.pages: pages: -paginator: ``` #### Tasks Types: ``` @@ -120,14 +111,11 @@ CLOSES: # #### Github ``` git: -github: actions: ci: -ci/cd: CONTRIBUTING: ``` #### Docs ``` docs: -sphinx: ``` From 4805420fd831a3d052b4b8f8c2cf98601feeb7b6 Mon Sep 17 00:00:00 2001 From: Vincent Date: Sun, 26 Dec 2021 23:00:26 -0800 Subject: [PATCH 16/27] refactor: make `speedup` to `speed` again --- .github/CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 847f3945b9..3dd5837b79 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -74,7 +74,7 @@ nit: ``` #### When refactoring or efficientizing code: ``` -speedup: +speed: refactor: ``` From 11a8b16d6ee75abfd307458a14e7ab8397912181 Mon Sep 17 00:00:00 2001 From: Vincent Date: Sun, 26 Dec 2021 23:02:51 -0800 Subject: [PATCH 17/27] nit: Adding the `Mega Change` Type --- .github/CONTRIBUTING.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 3dd5837b79..3d33aa0c74 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -119,3 +119,10 @@ CONTRIBUTING: ``` docs: ``` + +### Displaying multiple commits + +When displaying multiple commits in one use the type: +``` +Mega Change: +``` From ce16e036693c8e794f34ec103bab3a13edbba8a7 Mon Sep 17 00:00:00 2001 From: Makiyu-py <73825066+Makiyu-py@users.noreply.github.com> Date: Mon, 27 Dec 2021 15:11:45 +0800 Subject: [PATCH 18/27] replace first arg of Paginator.send to be only ctx --- discord/ext/pages/pagination.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/discord/ext/pages/pagination.py b/discord/ext/pages/pagination.py index 9f06e1ccb9..8d49d50b39 100644 --- a/discord/ext/pages/pagination.py +++ b/discord/ext/pages/pagination.py @@ -291,14 +291,14 @@ def update_buttons(self) -> Dict: return self.buttons - async def send(self, messageable: abc.Messageable, ephemeral: bool = False) -> Union[discord.Message, discord.WebhookMessage]: + async def send(self, ctx: Union[ApplicationContext, Context], ephemeral: bool = False) -> Union[discord.Message, discord.WebhookMessage]: """Sends a message with the paginated items. Parameters ------------ - messageable: :class:`discord.abc.Messageable` - The messageable channel to send to. + ctx: Union[:class:`~discord.ext.commands.Context`, :class:`~discord.ApplicationContext`] + The invocation context. ephemeral: :class:`bool` Choose whether the message is ephemeral or not. Only works with slash commands. @@ -308,16 +308,12 @@ async def send(self, messageable: abc.Messageable, ephemeral: bool = False) -> U The message that was sent with the paginator. """ - if not isinstance(messageable, abc.Messageable): - raise TypeError("messageable should be a subclass of abc.Messageable") - page = self.pages[0] - if isinstance(messageable, (ApplicationContext, Context)): - self.user = messageable.author + self.user = ctx.author - if isinstance(messageable, ApplicationContext): - msg = await messageable.respond( + if isinstance(ctx, ApplicationContext): + msg = await ctx.respond( content=page if isinstance(page, str) else None, embed=page if isinstance(page, discord.Embed) else None, view=self, @@ -325,7 +321,7 @@ async def send(self, messageable: abc.Messageable, ephemeral: bool = False) -> U ) else: - msg = await messageable.send( + msg = await ctx.send( content=page if isinstance(page, str) else None, embed=page if isinstance(page, discord.Embed) else None, view=self, From 07750dc67ba16d0dceb137be8bb9d744fc78bf2f Mon Sep 17 00:00:00 2001 From: Vincent Date: Sun, 26 Dec 2021 23:20:16 -0800 Subject: [PATCH 19/27] refactor --- .github/PULL_REQUEST_TEMPLATE.md | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 57290eecfe..a4fa4c0b4c 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -9,7 +9,6 @@ - [ ] If code changes were made then they have been tested. - [ ] I have updated the documentation to reflect the changes. - [ ] If `type: ignore` comments were used, a comment is also left explaining why -- [ ] This PR follows the commit style on [contributing](https://github.com/pycord-development/pycord/blob/master/.github/CONTRIBUTING.md) - [ ] This PR fixes an issue. - [ ] This PR adds something new (e.g. new method or parameters). - [ ] This PR is a breaking change (e.g. methods or parameters removed/renamed) From 31c4aa323ac7ee7c9263e76db945b4712588204d Mon Sep 17 00:00:00 2001 From: Vincent Date: Sun, 26 Dec 2021 23:26:24 -0800 Subject: [PATCH 20/27] refactor a lot --- .github/CONTRIBUTING.md | 84 +++-------------------------------------- 1 file changed, 5 insertions(+), 79 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 3d33aa0c74..630c064fee 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -47,82 +47,8 @@ By submitting a pull request, you agree that; 1) You hold the copyright on all s Not following this guideline could lead to your pull being squashed for a cleaner commit history -This style guide is most based of the [conventional commits](https://www.conventionalcommits.org/) style guide, in where it follows following guidelines: -```txt -type(scope): -``` -different with conventional commits is that we are gonna be defining the types you can use. - -### Normal Types - -These here are some types normally used without the library - -#### Feature Types: -``` -feat: -feature: -``` -#### Bug Fix Types: -``` -fix: -bug-fix: -``` -#### Fixing Grammar Mistakes: -``` -typo: -nit: -``` -#### When refactoring or efficientizing code: -``` -speed: -refactor: -``` - -### Extension Types - -Some types used in the `ext`'s - -#### Commands Types: -``` -ext.commands: -commands.Bot: -``` -#### Pages Types: -``` -ext.pages: -pages: -``` -#### Tasks Types: -``` -ext.tasks: -tasks: -``` - -### Displaying breaking changes or closing issues in a commit - -When closing issues or displaying a breaking change just add the following to your extended description: -``` -BREAKING CHANGE: -CLOSES: # -``` - -### Special Commit Types - -#### Github -``` -git: -actions: -ci: -CONTRIBUTING: -``` -#### Docs -``` -docs: -``` - -### Displaying multiple commits - -When displaying multiple commits in one use the type: -``` -Mega Change: -``` +Some style guides we would recommed using in your pulls: + +The [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) style is a very widely used style and a good style to start with. + +The [gitmoji](https://gitmoji.dev) style guide would make your pull look more lively and different to others. From 6c8eea4eb01c62680ff8e414ec1d2e73903bd82a Mon Sep 17 00:00:00 2001 From: Makiyu <73825066+Makiyu-py@users.noreply.github.com> Date: Mon, 27 Dec 2021 15:50:04 +0800 Subject: [PATCH 21/27] Update docs for Paginator.send's ctx --- discord/ext/pages/pagination.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/ext/pages/pagination.py b/discord/ext/pages/pagination.py index 8d49d50b39..be96e469f1 100644 --- a/discord/ext/pages/pagination.py +++ b/discord/ext/pages/pagination.py @@ -298,7 +298,7 @@ async def send(self, ctx: Union[ApplicationContext, Context], ephemeral: bool = Parameters ------------ ctx: Union[:class:`~discord.ext.commands.Context`, :class:`~discord.ApplicationContext`] - The invocation context. + A command's invocation context. ephemeral: :class:`bool` Choose whether the message is ephemeral or not. Only works with slash commands. From 54a3404b69703609a120f9d3789203c27e4dd47f Mon Sep 17 00:00:00 2001 From: Vincent Date: Tue, 28 Dec 2021 09:53:13 +0800 Subject: [PATCH 22/27] =?UTF-8?q?don=E2=80=99t=20limit=20the=20contributor?= =?UTF-8?q?=20on=20choices?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/CONTRIBUTING.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 630c064fee..9410f0ff0b 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -52,3 +52,5 @@ Some style guides we would recommed using in your pulls: The [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) style is a very widely used style and a good style to start with. The [gitmoji](https://gitmoji.dev) style guide would make your pull look more lively and different to others. + +We dont limit nor deny you using anyother style although, please make sure it is apropriate and makes sense in this library. From 4d254c90d77a9157e76aeed75f9dbbb7a23a3efe Mon Sep 17 00:00:00 2001 From: Lala Sabathil Date: Tue, 28 Dec 2021 19:43:27 +0100 Subject: [PATCH 23/27] Apply suggestions from code review --- .github/CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 9410f0ff0b..a13dff8688 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -53,4 +53,4 @@ The [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) style The [gitmoji](https://gitmoji.dev) style guide would make your pull look more lively and different to others. -We dont limit nor deny you using anyother style although, please make sure it is apropriate and makes sense in this library. +We don't limit nor deny your pulls when you're using another style although, please make sure it is appropriate and makes sense in this library. From e401f4c98ec4d9ee27405d93bc6727d17a958b86 Mon Sep 17 00:00:00 2001 From: Snawe Date: Tue, 28 Dec 2021 19:50:24 +0100 Subject: [PATCH 24/27] Add functionality to update `Paginator` (#658) --- discord/ext/pages/pagination.py | 46 +++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/discord/ext/pages/pagination.py b/discord/ext/pages/pagination.py index 9f06e1ccb9..8aeebe14a1 100644 --- a/discord/ext/pages/pagination.py +++ b/discord/ext/pages/pagination.py @@ -370,3 +370,49 @@ async def respond(self, interaction: discord.Interaction, ephemeral: bool = Fals elif isinstance(msg, discord.Interaction): self.message = await msg.original_message() return self.message + + async def update( + self, + interaction: discord.Interaction, + pages: List[Union[str, discord.Embed]], + show_disabled: Optional[bool] = None, + show_indicator: Optional[bool] = None, + author_check: Optional[bool] = None, + disable_on_timeout: Optional[bool] = None, + custom_view: Optional[discord.ui.View] = None, + timeout: Optional[float] = None + ): + """Updates the paginator. This might be useful if you use a view with :class:`discord.SelectOption` + and you have a different amount of pages depending on the selected option. + + Parameters + ---------- + pages: List[Union[:class:`str`, :class:`discord.Embed`]] + The list of strings and/or embeds to paginate. + show_disabled: Optional[:class:`bool`] + Whether to show disabled buttons. + show_indicator: Optional[:class:`bool`] + Whether to show the page indicator. + author_check: Optional[:class:`bool`] + Whether only the original user of the command can change pages. + disable_on_timeout: Optional[:class:`bool`] + Whether the buttons get disabled when the paginator view times out. + custom_view: Optional[:class:`discord.ui.View`] + A custom view whose items are appended below the pagination buttons. + timeout: Optional[:class:`float`] + Timeout in seconds from last interaction with the paginator before no longer accepting input. + """ + + # Update pages and reset current_page to 0 (default) + self.pages = pages + self.page_count = len(self.pages) - 1 + self.current_page = 0 + # Apply config changes, if specified + self.show_disabled = show_disabled if show_disabled else self.show_disabled + self.show_indicator = show_indicator if show_indicator else self.show_indicator + self.usercheck = author_check if author_check else self.usercheck + self.disable_on_timeout = disable_on_timeout if disable_on_timeout else self.disable_on_timeout + self.custom_view = custom_view if custom_view else self.custom_view + self.timeout = timeout if timeout else self.timeout + + await self.goto_page(interaction, self.current_page) From e9490265be622ad3bd205191305cf06b8d43b05d Mon Sep 17 00:00:00 2001 From: Vioshim <63890837+Vioshim@users.noreply.github.com> Date: Tue, 28 Dec 2021 20:07:56 -0500 Subject: [PATCH 25/27] Update utils.py --- discord/utils.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/discord/utils.py b/discord/utils.py index 8f2cea63a8..19c7754728 100644 --- a/discord/utils.py +++ b/discord/utils.py @@ -1112,8 +1112,7 @@ async def autocomplete_callback(ctx: AutocompleteContext) -> V: _values = await _values def check(item: Any) -> bool: - if hasattr(item, "to_dict"): - item = item.to_dict()["name"] + item = getattr(item, "name", item) return str(item).lower().startswith(str(ctx.value or "").lower()) gen = (val for val in _values if check(val)) From e18099ffc1225d564e30b36758b04ab5eccf1fca Mon Sep 17 00:00:00 2001 From: Sengolda <79252176+Sengolda@users.noreply.github.com> Date: Wed, 29 Dec 2021 13:23:58 +0530 Subject: [PATCH 26/27] Add new `Thread.archive` (#518) Co-authored-by: RPS Co-authored-by: Izhar Ahmad <54180221+nerdguyahmad@users.noreply.github.com> Co-authored-by: Lala Sabathil Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com> --- discord/threads.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/discord/threads.py b/discord/threads.py index e0907a9229..89e01aa849 100644 --- a/discord/threads.py +++ b/discord/threads.py @@ -589,6 +589,36 @@ async def edit( data = await self._state.http.edit_channel(self.id, **payload) # The data payload will always be a Thread payload return Thread(data=data, state=self._state, guild=self.guild) # type: ignore + + async def archive(self, locked: bool = MISSING) -> Thread: + """|coro| + + Archives the thread. This is a shorthand of :meth:`.edit`. + + Parameters + ------------ + locked: :class:`bool` + Whether to lock the thread on archive, Defaults to ``False``. + + + Returns + -------- + :class:`.Thread` + The updated thread. + """ + return await self.edit(archived=True, locked=locked) + + async def unarchive(self) -> Thread: + """|coro| + + Unarchives the thread. This is a shorthand of :meth:`.edit`. + + Returns + -------- + :class:`.Thread` + The updated thread. + """ + return await self.edit(archived=False) async def join(self): """|coro| From 0711ee74553e956f9870d14417b5aa50d738ed3c Mon Sep 17 00:00:00 2001 From: HyperGH <46067571+HyperGH@users.noreply.github.com> Date: Wed, 29 Dec 2021 09:48:55 +0100 Subject: [PATCH 27/27] Add slash command example to quickstart (#639) --- docs/quickstart.rst | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/docs/quickstart.rst b/docs/quickstart.rst index 8b3daeb2ce..86c55f2660 100644 --- a/docs/quickstart.rst +++ b/docs/quickstart.rst @@ -5,13 +5,13 @@ .. currentmodule:: discord Quickstart -============ +========== This page gives a brief introduction to the library. It assumes you have the library installed, if you don't check the :ref:`installing` portion. A Minimal Bot ---------------- +------------- Let's make a bot that responds to a specific message and walk you through it. @@ -40,7 +40,7 @@ It looks something like this: Let's name this file ``example_bot.py``. Make sure not to name it ``discord.py`` as that'll conflict with the library. -There's a lot going on here, so let's walk you through it step by step. +There's a lot going on here, so let's walk you through it step by step: 1. The first line just imports the library, if this raises a `ModuleNotFoundError` or `ImportError` then head on over to :ref:`installing` section to properly install. @@ -77,3 +77,41 @@ On other systems: $ python3 example_bot.py Now you can try playing around with your basic bot. + +A Minimal Bot with Slash Commands +--------------------------------- + +As a continuation, let's create a bot that registers a simple slash command! + +It looks something like this: + +.. code-block:: python3 + + import discord + + bot = discord.Bot() + + @bot.event + async def on_ready(): + print(f"We have logged in as {bot.user}") + + @bot.slash_command(guild_ids=[your, guild_ids, here]) + async def hello(ctx): + await ctx.respond("Hello!") + + bot.run("your token here") + +Let's look at the differences compared to the previous example, step-by-step: + +1. The first line remains unchanged. +2. Next, we create an instance of :class:`.Bot`. This is different from :class:`.Client`, as it supports + slash command creation and other features, while inheriting all the features of :class:`.Client`. +3. We then use the :meth:`.Bot.slash_command` decorator to register a new slash command. + The ``guild_ids`` attribute contains a list of guilds where this command will be active. + If you omit it, the command will be globally available, and may take up to an hour to register. +4. Afterwards, we trigger a response to the slash command in the form of a text reply. Please note that + all slash commands must have some form of response, otherwise they will fail. +6. Finally, we, once again, run the bot with our login token. + + +Congratulations! Now you have created your first slash command!