Skip to content

Conversation

@OoLunar
Copy link
Contributor

@OoLunar OoLunar commented Aug 10, 2022

Closes #1374. Untested.

@Erisa
Copy link
Contributor

Erisa commented Aug 10, 2022

The attribute for this was lazily copied as CooldownAttribute rather than the expected SlashCooldownAttribute, as well as CooldownBucketType.

This lead to me having to avoid ambiguity by doing the following:

[DSharpPlus.SlashCommands.Attributes.Cooldown(1, 10, DSharpPlus.SlashCommands.Attributes.CooldownBucketType.User)]

Even doing that, it does not work.

I traced through the stack and found out that the this._buckets was being recreated every time the command is called, likely from the following line:

this._buckets = new ConcurrentDictionary<string, CommandCooldownBucket>();

I tried fixing this myself for a while, but it seems I'm in over my head so I don't have any solution for it. this._buckets is still empty every time the ExecuteCheckAsync is called. It contains no values and thus a new bucket is created each call, resulting in nothing happening.

Copy link
Contributor

@Erisa Erisa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to work now.

When you use commands faster than the cooldown it throws DSharpPlus.SlashCommands.SlashExecutionChecksFailedException and shows "The application did not respond." in Discord - I assume we are expected to handle this exception ourselves, like with others.

Every piece works as expected from my pov.

@OoLunar
Copy link
Contributor Author

OoLunar commented Aug 10, 2022

Yeah the user is expected to handle that failed check

Copy link
Member

@akiraveliara akiraveliara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generally, looks good to me.
there are a few things somewhat bothering me (such as null1 and null2 as variable names - or whatever is happening name-wise in ExecuteChecksAsync, for that matter), and of course, this is currently not applicable to context menu commands, something we might want to tackle in the slashie cleanup branch.

@OoLunar OoLunar merged commit eba2fba into master Aug 15, 2022
@OoLunar OoLunar deleted the feature/v4/slash/cooldown-attribute branch August 15, 2022 18:13
@Nenkai
Copy link

Nenkai commented Aug 15, 2022

This PR disregards different commands entirely;

Setting a command with a cooldown i.e with [SlashCooldown(1, 20, SlashCooldownBucketType.Guild)] then using another command with the same cooldown within the time span of the first command will fail the check. Is this intended?

@OoLunar
Copy link
Contributor Author

OoLunar commented Aug 15, 2022

Uh oh. Could you create an issue with a repro?

VelvetToroyashi pushed a commit that referenced this pull request Jan 28, 2023
* Change GuildMemberUpdatedEventArgs to contain before and after DiscordMember objects (#1359)

* Fix #1325 - WebhookBuilder Throws Bad Request (#1363)

* use DiscordMentions on RestWebhookPayloads

* keep null value when null

* remove null check from discordmentions arg

* Implemented PATCH /guilds/:guild_id/roles (tested) (#1311)

* Fix compile errors caused by #1333

* Update hosting.md

* Remove unused DSharpPlus.MSTest folder

* Cache threads upon thread creation (#1366)

* categorization for the cnext default help command (#1371)

* Fix memberBefore missing roles in GuildMemberUpdateEventArgs when not… (#1364)

* Fix memberBefore missing roles in GuildMemberUpdateEventArgs when not in cache

* Update cached guild member in OnGuildMemberUpdateEventAsync internal event handler

* Update DiscordClient.Dispatch.cs

Co-authored-by: Lunar Starstrum <lunar@forsaken-borders.net>

* Ported CommandsNext cooldown attribute to Slash Commands (#1375)

* Ported CommandsNext cooldown attribute to Slash Commands; Fixed compiler warnings and suggestions

* Still untested; Attempted to resolve @Erisa's review

* Made all exceptions inherit from ApplicationCommandExecutionChecksFailedException (previously Exception)

* Start on converters

* Added custom converter support:

- No, I did not implement the checks in the converters. I felt that should be done in a separate area of code
- Yes, I did break my Enter, Backspace, D and Apostrophe keys because of this PR. Don't ask how.

* Fixed startup errors; Added DiscordMessageArgumentConverter; Added (un)register converter methods (untested).

* Fix registering converters

* (untested) Add number converters; Fix enums not registering choices correctly

* Add DiscordMember converter; Switch from ArgumentException to new MissingArgumentConverterException

* Actually fix Nullable and update TimeSpan converter to match with CNext

* Add params/array support

* Boundry checks

* [ci-skip] Resolve naming errors

* "One less variable allocation"

* Remove unsupport NETSTANDARD1_3 support; Un-Emziware those variable names

* Remove unused property

* Extra parameter limit attribute check

* Remove UnregisterConverter(s) methods

* Changed BCL types to use framework names

* Pass InnerException to prevent passing TargetInvocationException

* Fix enum support (again)

---------

Co-authored-by: Bob Loblaw <razvanmandache@gmail.com>
Co-authored-by: waffle-lord <76401815+waffle-lord@users.noreply.github.com>
Co-authored-by: Iris Féanorá <61018569+ExaInsanity@users.noreply.github.com>
OoLunar added a commit that referenced this pull request Oct 3, 2024
* Ported CommandsNext cooldown attribute to Slash Commands; Fixed compiler warnings and suggestions

* Still untested; Attempted to resolve @Erisa's review
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Slash Commands Cooldown

4 participants