changeset 272:8fb6bd57878c

Plugin hangman: allow usage in query, closes #424
author David Demelier <markand@malikania.fr>
date Wed, 28 Sep 2016 13:00:38 +0200
parents 3d37e1afec54
children 7069219bf764
files plugins/hangman/hangman.js tests/plugin-hangman/main.cpp
diffstat 2 files changed, 28 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/hangman/hangman.js	Fri Sep 23 18:20:08 2016 +0200
+++ b/plugins/hangman/hangman.js	Wed Sep 28 13:00:38 2016 +0200
@@ -234,7 +234,7 @@
     var status = "found";
 
     // Check for collaborative mode.
-    if (Plugin.config["collaborative"] === "true") {
+    if (Plugin.config["collaborative"] === "true" && !this.query) {
         if (this.last !== undefined && this.last === nickname)
             return "wrong-player";
 
@@ -355,6 +355,8 @@
         kw.word = game.formatWord();
         server.message(channel, Util.format(Plugin.format["start"], kw));
     }
+
+    return game;
 }
 
 function onMessage(server, origin, channel, message)
@@ -367,3 +369,13 @@
     if (message.length === 1 && Unicode.isLetter(message.charCodeAt(0)))
         propose(server, channel, origin, game, message.charCodeAt(0));
 }
+
+function onQueryCommand(server, origin, message)
+{
+    onCommand(server, origin, Util.splituser(origin), message).query = true;
+}
+
+function onQuery(server, origin, message)
+{
+    onMessage(server, origin, Util.splituser(origin), message);
+}
--- a/tests/plugin-hangman/main.cpp	Fri Sep 23 18:20:08 2016 +0200
+++ b/tests/plugin-hangman/main.cpp	Wed Sep 28 13:00:38 2016 +0200
@@ -199,6 +199,21 @@
     ASSERT_EQ("#hangman:found=hangman:!hangman:test:#hangman:francis!francis@localhost:francis:s k _", m_server->last());
 }
 
+TEST_F(HangmanTest, query)
+{
+    load();
+
+    // Query mode is never collaborative.
+    m_plugin->onQueryCommand(m_irccd, QueryEvent{m_server, "jean!jean@localhost", ""});
+    ASSERT_EQ("jean:start=hangman:!hangman:test:jean:jean!jean@localhost:jean:_ _ _", m_server->last());
+    m_plugin->onQuery(m_irccd, QueryEvent{m_server, "jean!jean@localhost", "s"});
+    ASSERT_EQ("jean:found=hangman:!hangman:test:jean:jean!jean@localhost:jean:s _ _", m_server->last());
+    m_plugin->onQuery(m_irccd, QueryEvent{m_server, "jean!jean@localhost", "k"});
+    ASSERT_EQ("jean:found=hangman:!hangman:test:jean:jean!jean@localhost:jean:s k _", m_server->last());
+    m_plugin->onQueryCommand(m_irccd, QueryEvent{m_server, "jean!jean@localhost", "sky"});
+    ASSERT_EQ("jean:win=hangman:!hangman:test:jean:jean!jean@localhost:jean:sky", m_server->last());
+}
+
 int main(int argc, char **argv)
 {
     path::setApplicationPath(argv[0]);