nexy7574 / nio-bot

Matrix bot library based on matrix-nio, similar in design to discord.py
https://docs.nio-bot.dev/
GNU Lesser General Public License v3.0
28 stars 5 forks source link

[BUG] Incorrect keyword-only argument parsing #29

Open nexy7574 opened 6 days ago

nexy7574 commented 6 days ago

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.

nexy7574 commented 6 days ago

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")