RISCfuture / autumn

Easy, fresh, feature-rich IRC bots in Ruby
222 stars 33 forks source link

Username starting with _ (underscore) raises exception on command #25

Closed alolis closed 13 years ago

alolis commented 13 years ago

Hello

I just discovered a weird problem. If a username which starts with _ executes a !command then an exception is raised. More specifically:

i have implemented in my controller did_receive_channel_message and one command, test_command, and everytime the user with underscore in front types !test, the sender parameter in leaf.rb, line 614 is nil. The problem i think starts in stem.rb however, line 490, were args[1] is nil as well.

Debug log shows the following:

undefined method merge' for nil:NilClass testbot/libs/leaf.rb:621:incommand_parse' testbot/libs/leaf.rb:220:in block in irc_privmsg_event' testbot/libs/leaf.rb:317:indatabase' testbot/libs/leaf.rb:218:in irc_privmsg_event' /home/tester/.rvm/gems/ruby-1.9.2-p136/gems/facets-2.8.4/lib/core/facets/kernel/respond.rb:18:inrespond' testbot/libs/stem.rb:490:in block (2 levels) in broadcast' undefined methodmerge' for nil:NilClass testbot/libs/leaf.rb:621:in command_parse' testbot/libs/leaf.rb:220:inblock in irc_privmsg_event' /home/tester/.rvm/gems/ruby-1.9.2-p136/gems/dm-core-1.0.2/lib/dm-core.rb:299:in block in repository' /home/tester/.rvm/gems/ruby-1.9.2-p136/gems/dm-core-1.0.2/lib/dm-core/repository.rb:114:inscope' /home/tester/.rvm/gems/ruby-1.9.2-p136/gems/dm-core-1.0.2/lib/dm-core.rb:299:in repository' /home/tester/.rvm/gems/ruby-1.9.2-p136/gems/dm-core-1.0.2/lib/dm-core/core_ext/kernel.rb:8:inrepository' testbot/libs/leaf.rb:315:in database' testbot/libs/leaf.rb:218:inirc_privmsg_event' /home/tester/.rvm/gems/ruby-1.9.2-p136/gems/facets-2.8.4/lib/core/facets/kernel/respond.rb:18:in respond' testbot/libs/stem.rb:490:inblock (2 levels) in broadcast'

RISCfuture commented 13 years ago

The reason for this is that nicks starting with an underscore are not strictly allowed under the IRC specs. Of course, many IRC servers are more lenient. To solve this problem, specify a custom nick_regex in your stems.yml file:

Example: 
  nick: MyIRCBot
  nick_regex: [a-zA-Z_][a-zA-Z0-9\\-_\\[\\]\\{\\}\\\\|`\\^]+
alolis commented 13 years ago

Thanks. The IRCd is Unreal latest by the way in case you were wondering.

alolis commented 13 years ago

I added the following to my stems.yml

nickregex: "[a-zA-Z][a-zA-Z0-9-_[]{}\|`\^]+<"

And now the bot doesn't respond to any command, not even from normal usernames :(

RISCfuture commented 13 years ago

GitHub treated your regex as formatted so I can't tell what it was originally, but I just used the following regex and it worked fine:

nick_regex: "[a-zA-Z_][a-zA-Z0-9\\-_\\[\\]\\{\\}\\\\|`\\^]+"
RISCfuture commented 13 years ago

Although, maybe delete the angle bracket at the end of your regex.

alolis commented 13 years ago

Thanks, it seems that "<" was added on the regex when i copy pasted and messed it up.

alolis commented 13 years ago

Hello, it seems that i am having a similar problem again but with usernames which look like this:

|USERNAME|

Can you please update the above regex so i can make that work too?

alolis commented 13 years ago

It seems that there is a problem with one letter usernames as well. Basically, whats the regex to accept any username?

RISCfuture commented 13 years ago

You should be able to write out your own regexes, but I'll get you started ...

.+? should match all usernames, but I haven't tested it.

alolis commented 13 years ago

Ah ok i will work it out no worries, thanks :)