Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin API: Add optional message to module.rate() #830

Closed
dgw opened this issue Jun 30, 2015 · 8 comments · Fixed by #2290
Closed

Plugin API: Add optional message to module.rate() #830

dgw opened this issue Jun 30, 2015 · 8 comments · Fixed by #2290
Assignees
Milestone

Comments

@dgw
Copy link
Member

dgw commented Jun 30, 2015

If set, send message as a notice to the calling user if the command was canceled due to rate-limit. Ideally, it would support a placeholder such as {time_left} for the message to tell the user when they can use the command again.

I'd be happy to code it up and PR it; just want to establish that it'd have a chance of being merged first, before putting in that time.

Could also have a third parameter to toggle between using NOTICE and PRIVMSG.

@dgw dgw changed the title [Proposal] Add optional message to willie.module.rate() [Proposal] Add optional message to sopel.module.rate() Dec 11, 2017
@dgw
Copy link
Member Author

dgw commented Dec 11, 2017

If one of the collaborators for this repo feels like assigning this to me, I just came across it while cleaning out my oldest issues in the GitHub dashboard view, and am reminded that this would still be useful to have (since the majority of my Sopel modules use bespoke rate-limiting that includes these features).

@dgw dgw added this to the 7.0.0 milestone Jul 8, 2018
@dgw dgw changed the title [Proposal] Add optional message to sopel.module.rate() Module API: Add optional message to module.rate() Jul 8, 2018
@dgw
Copy link
Member Author

dgw commented Jul 8, 2018

Thanks for the reminder that this exists, @kwaaak. Assigning to Sopel 7 milestone, as it's an API change.

@dgw
Copy link
Member Author

dgw commented May 31, 2019

Hmm, this is not going to be so nice to implement with the rework of @rate from #1065.

Adding another optional msg kwarg would be fine, I guess, but not nearly as elegant as what I originally wanted to do (when there was only one type of rate-limit).

I suppose long-term we could consider splitting @rate into three decorators, but… it's not worth complicating the API like that for such a minor feature.

@dgw dgw modified the milestones: 7.0.0, 7.1.0 Nov 16, 2019
@dgw dgw changed the title Module API: Add optional message to module.rate() Plugin API: Add optional message to module.rate() Nov 16, 2019
@dgw
Copy link
Member Author

dgw commented May 8, 2020

NAK third parameter (OP edited); should always use NOTICE.

@Exirel
Copy link
Contributor

Exirel commented Sep 12, 2020

Still not sure how to do that properly for so many different rate limits:

def rate(user=0, channel=0, server=0, message=None):

Or:

def rate(user=0, channel=0, server=0, user_message=None, channel_message=None, server_message=None):

Or:

def rate(user=0, channel=0, server=0):  # deprecated?
def rate_user(limit, message=None):
def rate_channel(limit, message=None):
def rate_server(limit, message=None):

@dgw any opinion?

@dgw
Copy link
Member Author

dgw commented Oct 30, 2020

Combination of 1 & 3, mostly so there's a way to add more specific messages if necessary:

def rate(user=0, channel=0, server=0, message=None):  # not deprecated
def rate_user(limit, message=None):
def rate_channel(limit, message=None):
def rate_server(limit, message=None):

One consideration: I think it'd be good to implement the new decorators in such a way that they always take precedence over the generic rate values, regardless of the decorator order, just in case. Like this:

@plugin.rate(7, 7, 7, "This must be Vegas!")
@plugin.rate_channel(3, "Little maids from school")
def plugin_thing(bot, trigger):
    """Allowed every 3 seconds per channel, not 7 seconds."""
    pass

Also: What about making both args to the rate_* decorators optional, so a plugin dev could give all the rates in one shorthand @plugin.rate call and override one or two messages with just e.g. @plugin.rate_user(message="I'm different.")?

Would be super cool to allow overriding the message for a rate limit type without even needing the message=, or if e.g. @rate(30, 'It's too soon!') acted like @rate_user(30, 'It's too soon!')—but I know how you feel about "smart" argument handling, especially in complex cases like that second example.

No objection to putting this in 8.0, either, as there's plenty left for 7.1 as it is.

@Exirel Exirel modified the milestones: 7.1.0, 8.0.0 Oct 31, 2020
@Exirel
Copy link
Contributor

Exirel commented Oct 31, 2020

Yeah OK it's getting quite complex and Sopel 8 will handle it, because Sopel 8 is 7.1 but better.

@Exirel Exirel self-assigned this May 28, 2022
@Exirel
Copy link
Contributor

Exirel commented May 28, 2022

Working on that, I already have a working solution, I just need to iron out the tests and the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants