Skip to content

TypedSayCommand does not accept the colon character #244

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

Closed
p-hennessy opened this issue Mar 27, 2018 · 6 comments
Closed

TypedSayCommand does not accept the colon character #244

p-hennessy opened this issue Mar 27, 2018 · 6 comments
Labels

Comments

@p-hennessy
Copy link

p-hennessy commented Mar 27, 2018

Game: Team Fortress 2
Input in chat: !mapdl http://test.com/test.bsp
Code in question:

from commands.typed import TypedSayCommand

@TypedSayCommand('!mapdl')
def on_mapdl(command_info, map_url: str):
    print(map_url)

Error:

Too many arguments:
  !mapdl <map_url:str>

Works fine without the colon character. Not sure if this is just a parse issue or deliberately there? It also looks like it truncates everything after the colon, even if i did a *args: ('http', ':')

@Ayuto
Copy link
Member

Ayuto commented Mar 27, 2018

Have you tried passing the URL in quotation marks?

@p-hennessy
Copy link
Author

Yes, single and double quotes are no dice.

It only appears to be when coming from chat commands; it works fine as a server console command (though that needs quotes)

@Ayuto
Copy link
Member

Ayuto commented Apr 1, 2018

Looks like we need to split the arguments on our own instead of relying on CCommand.

@Ayuto Ayuto added the bug label Apr 1, 2018
@Cheaterman
Copy link

FWIW, the single quote doesn't seem to work either (dunno why anyone would want that, in my case I wanted a hidden command for godmode when people said I'M JOHN CENA in the chat, I settled on I AM JOHN CENA instead).

@jordanbriere
Copy link
Contributor

The Tokenize class I posted back in 2013 seems to have the desired outputs here: https://forums.sourcepython.com/viewtopic.php?p=1221#p1221

from re import compile

class Tokenize(list):
    _pattern = compile('"[^"]*"|[^ ]+')

    def __init__(self, given_string, comment_prefix=None):
        self.string = given_string

        for token_match in self._pattern.finditer(self.string):
            token_string = token_match.group()

            if comment_prefix and token_string.startswith(comment_prefix):
                self.string = self.string[:token_match.start()]
                break

            self.append(token_string.strip('"'))

    def __str__(self):
        return self.string

print(repr(Tokenize('!mapdl http://test.com/test.bsp')))

# Result:  ['!mapdl', 'http://test.com/test.bsp']

print(repr(Tokenize("I'M JOHN CENA")))

# Result: ["I'M", 'JOHN', 'CENA']

@Cheaterman
Copy link

Cheaterman commented May 27, 2018

Le Québec invincible gagne encore! :-)

I'm going to try monkey-patching the standard Tokenize with your regexp and see if it doesn't break anything in my code.

If it works for everyone else, can we expect a PR from you, @invincibleqc ?

EDIT: Actually, can't seem to find Tokenize anywhere, at least not on the Python side, and I'm not quite sure what CCommand.Tokenize() refers to in the code... Could someone please give me a summary of the codepath for command parsing? Thanks in advance! Also FWIW I can't access the forum post you referenced, it's probably in an admin-only section or something?

jordanbriere added a commit that referenced this issue Dec 3, 2021
Added core.Tokenize and core.ConfigFile helper classes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants