cinchrb / cinch

The IRC Bot Building Framework
http://www.rubydoc.info/gems/cinch
MIT License
1k stars 180 forks source link

Initial support for IRC v3.2 tags #232

Closed Defman21 closed 7 years ago

Defman21 commented 8 years ago

Fixes #217 #201

Defman21 commented 8 years ago

Note: the regex has been changed to provide compatibility with older versions of IRC (which doesn't have tags supported). I've tested it using Twitches IRC PRIVMSG without tags enabled (which makes Twitch IRC responds without IRC3.2 tags) and it works fine.

dominikh commented 8 years ago

Hey, thanks for the PR. I'm currently swamped with other work, but I'll try to take a look at it soon.

bougyman commented 7 years ago

The regex + match = @raw.match(/(?:^@([^:]+))?(?::?(\S+) )?(\S+)(.*)/) will not work the way you expect. I think we need some code logic here and not try to stuff everything into one regex. If there's no first capture, @tags will get the 2nd capture, etc.

Defman21 commented 7 years ago

If there's no first capture, @tags will be {}. (because tags is nil and parse_tags(nil) returns {} if the argument is nil)

match = "bye world".match(%r/(hello)? (world)/) # => #<MatchData " world" 1:nil 2:"world">
hello, world = match.captures # => [nil, "world"]
bougyman commented 7 years ago

Thanks for the info. I've been bitten by this before, but your method looks safe from this.