dblock / slack-gamebot

Ping pong, chess, pool and other games bot for Slack.
MIT License
129 stars 103 forks source link

Player can lose to themselves #155

Closed kanno41 closed 7 years ago

kanno41 commented 7 years ago

A player can lose to themselves, counting for themselves a win and a loss. The gamebot should prevent losing to yourself.

dblock commented 7 years ago

That's with @bot lost to? That would be bad. I will fix it, unless you want to beat me by sending a PR? (and getting a free bot :))

kanno41 commented 7 years ago

Yep, that's correct. I'm afraid that I am completely unfamiliar with Ruby, however. Thanks for fixing it!

lost.rb seems to be the place where the logic needs to be corrected.

https://github.com/dblock/slack-gamebot/blob/82498bb3cb3c5e6ad1e619a87125aa963609bf6c/slack-gamebot/commands/lost.rb#L41

dblock commented 7 years ago

It could be your first PR into a Ruby project! I can patiently help you :)

Start by going through https://github.com/dblock/slack-gamebot/blob/master/CONTRIBUTING.md and writing a test that reproduces the problem in https://github.com/dblock/slack-gamebot/blob/master/spec/slack-gamebot/commands/lost_spec.rb

kanno41 commented 7 years ago

I want to add this condition to lost.rb, but rubocop complains extensively about it since it makes the function too long! Any ideas?

elsif !(teammates & opponents).empty? client.say(channel: data.channel, text: 'You cannot lose to yourself!', gif: 'loser') logger.info "Cannot lose to yourself: #{client.owner} - #{match}"

dblock commented 7 years ago

Run rubocop -a ; rubocop --auto-gen-config and don't worry about it.