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

Tokenising multiple words to multiple arguments #450

Open
chillymosh opened this issue May 13, 2024 Discussed in #449 · 1 comment
Open

Tokenising multiple words to multiple arguments #450

chillymosh opened this issue May 13, 2024 Discussed in #449 · 1 comment
Assignees
Labels
2.0 TwitchIO 2.0 Addressed in next release This issue will be closed when the next release is created bug EXT: commands

Comments

@chillymosh
Copy link
Collaborator

chillymosh commented May 13, 2024

Discussed in #449

Originally posted by DennisMinn May 13, 2024
I want to pass multiple arguments enclosed in either ' or ", but on the first argument is properly formatted, while the second argument is cut off. Is there a way to modify how the arguments is parsed?

class Bot(commands.Bot):
    def __init__(self):
        super().__init__(token='<access token>', prefix='!', initial_channels = ['<initial channel>'])

    @commands.command(name='addQA')
    async def add_qa(self, context: commands.Context, question: str, answer: str):
        print(question, answer)

Input from <initial channel> chatroom

!addQA "this is a question" "this is the answer"

Current Output

this is a question "this

Desired Output

this is a question this is the answer
@chillymosh
Copy link
Collaborator Author

chillymosh commented May 13, 2024

Potential fix that needs to be tested - ext.commands.stringparser.py

    def process_string(self, msg: str) -> Dict[int, str]:
        while self.count < len(msg):
            loc = msg[self.count]

            if loc == '"' and not self.ignore:
                self.ignore = True
                self.start = self.count + 1
            elif loc == '"' and self.ignore:
                self.words[self.index] = msg[self.start:self.count]
                self.index += 1
                self.ignore = False
                self.start = self.count + 1
            elif loc.isspace() and not self.ignore:
                if self.start != self.count:
                    self.words[self.index] = msg[self.start:self.count]
                    self.index += 1
                self.start = self.count + 1

            self.count += 1

        if self.start < len(msg) and not self.ignore:
            self.words[self.index] = msg[self.start:len(msg)].strip()

        return self.words

@IAmTomahawkx IAmTomahawkx added the Addressed in next release This issue will be closed when the next release is created label Jun 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.0 TwitchIO 2.0 Addressed in next release This issue will be closed when the next release is created bug EXT: commands
Projects
None yet
Development

No branches or pull requests

2 participants