japandotorg / Seina-Cogs

My public cogs for red.
https://seina-cogs.readthedocs.io/en/latest/
Other
13 stars 18 forks source link

[Tags] Command block is parsed without consideration of control blocks #38

Closed KohGeek closed 10 months ago

KohGeek commented 10 months ago

Filing this here, unsure if this is a bug or intended. First of all, thank you for forking and continuing the legacy of phen-cogs.

Code in question: {if({args}==): {c:pause} | {c:play {args}}}

Expected behaviour: When argument is empty, the tag runs only pause command. When argument is not empty, it runs the play command with args.

Actual behaviour: Both command runs irregardless of args status.

System: Python 3.11.5 RedBot 3.5.5 Discord.py 2.3.2 Running on Raspberry Pi 4 on Raspberry Pi OS Bullseye 64-bit, headless

cool-aid-man commented 10 months ago

First off: No, this is not a bug. This is an intended behavior.

What you're getting is exactly what the tag script is supposed to do.

Rules

Without going into more technicality, The rectified script would look something like this:

{{if({args(1)}==):c:pause|c:play {args}}}

Changes and Why?

  • I shortened the check from every single argument you'd pass with {if({args}==) to a single 1 argument {if({args(1)}==). Which is what you should be doing as well.
  • I took the curly braces out of the commands ({c:pause} & {c:play}) and placed them in a way where they won't get executed on their own and will only get executed depending on your passing argument.
  • I changed the {c:play} to {c:play {args}} as this is what you're trying to do. To play any song named through your passing arguments. I used args here as your search would be more than just 1 word or, argument.

That's it! As a side note, I'd highly encourage you to go through the documentation.

KohGeek commented 10 months ago

Hi, thank you for the speedy response, and for the listed rules and the sample code. I was staring at this documentation and none of the things you have listed are within this doc. Is the documentation found somewhere else?

Edit: Fixed the link so it wasn't actually just a 404 page of the doc.

cool-aid-man commented 10 months ago

Yep! That's the correct link you've got and about the rules; think of them as a handbook or guide. That's how tagscript works, every block has its own need, and its own set of rules (the way they work). Consider them thumb-rules to make your next custom-command.

I hope it helps and you're very welcome!