nexy7574/nio-bot

[BUG] Incorrect keyword-only argument parsing

nexy7574 opened this issue · 2 comments

Describe the bug
When providing a *, keyword argument in a command function definition, the library is supposed to make it a "greedy" argument, in that any content unconsumed goes into that variable. Right now, this does not happen.

To Reproduce
Run this simple example:

import niobot

mybot = niobot.NioBot(homeserver="https://example.com", user_id="@example:example.com", command_prefix="!")


@mybot.command()
async def echo(ctx, *, content: str):
    await ctx.respond(content)

Expected behavior
!echo foo bar should respond with foo bar, however, the too many arguments exception is raised

Additional context
Using "quotes" gets around this issue, so the issue may simply just be the command parser being too strict when counting arguments and prematurely raising an error.

This is now fixed in fix/argument-parsing, but be warned, there has not been extensive testing. There are possible regressions relating to optional arguments, positional arguments, argument typing, and even argument parsing. If anyone tests this out, please let me know how it worked out for you ("works for me" is just as valuable as "it didnt work for me")

Will merge soon - no issues have been reported and I have been running this in a stable fashion for 2 weeks with no issues.