Limnoria icon indicating copy to clipboard operation
Limnoria copied to clipboard

@scheduler remind should accept human-readable times

Open progval opened this issue 3 years ago • 9 comments

People are used to the @aka remind, that took a nice human-readable time interval definition, eg. 1d 2h; but the new @scheduler remind doesn't , so you have to do @scheduler remind [seconds 1d 2h] foo which isn't a great interface.

@scheduler remind should have this built-in (reusing the code for the @seconds command)

progval avatar Apr 03 '21 07:04 progval

I agree that having a built-in way of allowing the user to input a human-readable time interval argument as mentioned above is a good thing in general and can be used by contributors for any plugin development that needs to deal with time-deltas.

It's actually what made me think of having @scheduler remind in the first place. The issue earlier was permissions. With the current setup I do have an @aka remindme and @aka in which are basically @aka add remindme "remind [seconds $1] $2". This doesn't solve the fact that many people will need to change the @aka remind as they are used to it. But the fact that it can actually be used by everyone without the permissions clash might be well worth the change. The alternative is to use the aka as a default which is again not a clean solution.

I have never looked into messing around with converters but if this isn't super urgent I can try fiddling around and let you know how far I get along.

Also this made me look at the Channel plugin. In the @kban command for example the optional duration argument it takes basically seems to use expiry which again is in seconds. This is how the Chantracker plugin deals with it which is what I think you meant

prdes avatar Apr 04 '21 11:04 prdes

I'm not entirely sure about certain aspects of this. But how far off am I?

This is meant to replace expiry converter. If it's not possible to keep it compatible then I guess a separate converter is in order.

# src/commands.py

# Changing getExpiry() may break dependent code 
# and 3rd party plugins.
# But what if simply providing an integer will revert
# to original behaviour?

# Taken from plugins.Time.seconds
# https://github.com/ncoevoet/ChanTracker/blob/2962c3190b72f432d60a558bb711983a235e7bb9/plugin.py#L1257

def getExpiry(irc, msg, args, state):
    """
    [<years>y] [<weeks>w] [<days>d] [<hours>h] [<minutes>m] [<seconds>s]
    [<seconds>]
    Takes a number of <years>, <weeks>,
    <days>, <hours>, <minutes>, and <seconds> given.  An example usage is
    " 2h 30m", which would return 9000, which is '3600*2 + 30*60'.
    Useful for scheduling events in the future. Additionally using only
    [<seconds>] can replicate the original getExpiry(). 
    """
    now = int(time.time())
    try:
        items = list(args)
    except:
        raise callbacks.ArgumentError
    if len(items) < 1:
        raise callbacks.ArgumentError
    elif len(items) == 1:
        try:
            expires = int(args[0])
            if expires:
                expires += now
                state.args.append(expires)
                del args[0]
        except ValueError:
            state.errorInvalid(_('number of seconds'), args[0])
    else:
        expires = 0
        for arg in items:
            if not arg or arg[-1] not in 'ywdhms':
                raise callbacks.ArgumentError
            (s, kind) = arg[:-1], arg[-1]
            try:
                i = int(s)
            except ValueError:
                raise callbacks.ArgumentError
            if kind == 'y':
                expires += i*31536000
            elif kind == 'w':
                expires += i*604800
            elif kind == 'd':
                expires += i*86400
            elif kind == 'h':
                expires += i*3600
            elif kind == 'm':
                expires += i*60
            elif kind == 's':
                expires += i
# Not clear about this, it's a bit of a blind copy paste
        args.pop(0)
            
        if expires:
            expires += now
        state.args.append(expires)

prdes avatar May 17 '21 15:05 prdes

you don't need to add a new converter, it can be parsed in remind()

progval avatar May 17 '21 16:05 progval

But it's useful in a lot of places. Any form of scheduling events currently uses <seconds> . For example @kban @iban and also if one wishes to write plugins which need to schedule events in the future. For example

Guess the answer to this is to use callbacks ? (I don't yet know how to utilize these easily but it shouldn't be that hard.) I just felt that if you end up having to repeat yourself then maybe you add it to core functionality, hence the attempt at enhancing the expiry converter.

prdes avatar May 17 '21 16:05 prdes

Guess the answer to this is to use callbacks

No, that's the module to manage callbacks/events, not parse command arguments.

The right place for the parser would be in src/utils/

progval avatar May 17 '21 17:05 progval

Even that doesn't seem to work anylonger: @scheduler remind [seconds 1d 2h] foo

The only input it seems to accept right now are integer seconds.

poVoq avatar Jul 19 '21 21:07 poVoq

@poVoq Reset supybot.commands.nested.brackets to [] and/or load the Time plugin.

progval avatar Jul 19 '21 21:07 progval

Seems like I was missing the time plugin indeed.

But something like @scheduler remind 30m foo still doesn't work.

poVoq avatar Jul 19 '21 22:07 poVoq

Yes, that's what this feature request is about

progval avatar Jul 19 '21 22:07 progval