# HG changeset patch # User David Demelier # Date 1463682859 -7200 # Node ID 2ce88e3a4759c26e67a03259019c4bfeff929f2d # Parent 5cde682ce9dbb80ea2cc8082c5c922939320be33 Plugin hangman: use new format section, #410 diff -r 5cde682ce9db -r 2ce88e3a4759 plugins/hangman/hangman.js --- a/plugins/hangman/hangman.js Thu May 19 20:21:50 2016 +0200 +++ b/plugins/hangman/hangman.js Thu May 19 20:34:19 2016 +0200 @@ -16,7 +16,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* Modules */ +// Modules. var Logger = Irccd.Logger; var File = Irccd.File; var Plugin = Irccd.Plugin; @@ -24,7 +24,7 @@ var Unicode = Irccd.Unicode var Util = Irccd.Util; -/* Plugin information */ +// Plugin information. info = { author: "David Demelier ", license: "ISC", @@ -32,9 +32,22 @@ version: "@IRCCD_VERSION@" }; -/* Default options */ +// Default options. Plugin.config["collaborative"] = "true"; +// Formats. +Plugin.format = { + "asked": "#{nickname}, '#{letter}' was already asked.", + "dead": "#{nickname}, fail the word was: #{word}.", + "found": "#{nickname}, nice! the word is now #{word}", + "running": "#{nickname}, the game is already running.", + "start": "#{nickname}, the game is started, the word to find is: #{word}", + "win": "#{nickname}, congratulations, the word is #{word}.", + "wrong-word": "#{nickname}, this is not the word.", + "wrong-player": "#{nickname}, please wait until someone else proposes.", + "wrong-letter": "#{nickname}, there is no '#{letter}'." +}; + function Hangman(server, channel) { this.server = server; @@ -54,21 +67,6 @@ Hangman.words = []; /** - * Formats for writing. - */ -Hangman.formats = { - "asked": "#{nickname}, '#{letter}' was already asked.", - "dead": "#{nickname}, fail the word was: #{word}.", - "found": "#{nickname}, nice! the word is now #{word}", - "running": "#{nickname}, the game is already running.", - "start": "#{nickname}, the game is started, the word to find is: #{word}", - "win": "#{nickname}, congratulations, the word is #{word}.", - "wrong-word": "#{nickname}, this is not the word.", - "wrong-player": "#{nickname}, please wait until someone else proposes.", - "wrong-letter": "#{nickname}, there is no '#{letter}'." -}; - -/** * Search for an existing game. * * @param server the server object @@ -157,7 +155,16 @@ */ Hangman.loadFormats = function () { - for (var key in Hangman.formats) { + // --- DEPRECATED ------------------------------------------ + // + // This code will be removed. + // + // Since: 2.1.0 + // Until: 3.0.0 + // Reason: new [format] section replaces it. + // + // ---------------------------------------------------------- + for (var key in Plugin.format) { var optname = "format-" + key; if (typeof (Plugin.config[optname]) !== "string") @@ -166,7 +173,7 @@ if (Plugin.config[optname].length === 0) Logger.warning("skipping empty '" + optname + "' format"); else - Hangman.formats[key] = Plugin.config[optname]; + Plugin.format[key] = Plugin.config[optname]; } } @@ -242,17 +249,15 @@ if (this.table[ch]) { this.tries -= 1; status = "asked"; - } else { + } else this.table[ch] = true; - } } } else { if (this.word != ch) { this.tries -= 1; status = "wrong-word"; - } else { + } else status = "win"; - } } /* Check if dead */ @@ -299,21 +304,21 @@ switch (st) { case "found": kw.word = game.formatWord(); - server.message(channel, Util.format(Hangman.formats["found"], kw)); + server.message(channel, Util.format(Plugin.format["found"], kw)); break; case "wrong-letter": case "wrong-player": case "wrong-word": case "asked": kw.letter = String.fromCharCode(proposition); - server.message(channel, Util.format(Hangman.formats[st], kw)); + server.message(channel, Util.format(Plugin.format[st], kw)); break; case "dead": case "win": kw.word = game.word; - server.message(channel, Util.format(Hangman.formats[st], kw)); + server.message(channel, Util.format(Plugin.format[st], kw)); - /* Remove the game */ + // Remove the game. Hangman.remove(game); break; default: @@ -336,9 +341,9 @@ if (game) { var list = message.split(" \t"); - if (list.length === 0 || String(list[0]).length === 0) { - server.message(channel, Util.format(Hangman.formats["running"], kw)); - } else { + if (list.length === 0 || String(list[0]).length === 0) + server.message(channel, Util.format(Plugin.format["running"], kw)); + else { var word = String(list[0]); if (Hangman.isWord(word)) @@ -347,7 +352,7 @@ } else { game = Hangman.create(server, channel); kw.word = game.formatWord(); - server.message(channel, Util.format(Hangman.formats["start"], kw)); + server.message(channel, Util.format(Plugin.format["start"], kw)); } } diff -r 5cde682ce9db -r 2ce88e3a4759 plugins/hangman/hangman.md --- a/plugins/hangman/hangman.md Thu May 19 20:21:50 2016 +0200 +++ b/plugins/hangman/hangman.md Thu May 19 20:34:19 2016 +0200 @@ -51,20 +51,34 @@ ## Configuration -The **hangman** plugin can be configured to show different messages. - The following options are available under the `[plugin.hangman]` section: - **file**: (string) the path to the database file (Optional, default: configuration directory), - **collaborative**: (bool) set to true to enable collaborative mode, a player can't propose two consecutives proposals (Optional, default: true), - - **format-asked**: (string) when a letter has been already asked but present in the word (Optional), - - **format-dead**: (string) when the man was hung (Optional), - - **format-found**: (string) when a correct letter has been placed (Optional), - - **format-running**: (string) when a game is requested but it's already running (Optional), - - **format-start**: (string) when the game starts (Optional), - - **format-win**: (string) when the game succeeded (Optional), - - **format-wrong-word**: (string) when a word proposal is wrong (Optional), - - **format-wrong-letter**: (string) when a letter proposal is wrong (Optional). + +**Deprecated in irccd 2.1.0:** + + - **format-asked**: Use `[format.hangman] asked` instead, + - **format-dead**: Use `[format.hangman] dead` instead, + - **format-found**: Use `[format.hangman] found` instead, + - **format-running**: Use `[format.hangman] running` instead, + - **format-start**: Use `[format.hangman] start` instead, + - **format-win**: Use `[format.hangman] win` instead, + - **format-wrong-word**: Use `[format.hangman] wrong-word` instead, + - **format-wrong-letter**: Use `[format.hangman] wrong-letter` instead. + +## Formats + +The **hangman** plugin supports the following formats in `[format.hangman]` section: + + - **asked**: (string) when a letter has been already asked but present in the word (Optional), + - **dead**: (string) when the man was hung (Optional), + - **found**: (string) when a correct letter has been placed (Optional), + - **running**: (string) when a game is requested but it's already running (Optional), + - **start**: (string) when the game starts (Optional), + - **win**: (string) when the game succeeded (Optional), + - **wrong-word**: (string) when a word proposal is wrong (Optional), + - **wrong-letter**: (string) when a letter proposal is wrong (Optional). ### Keywords supported @@ -73,13 +87,13 @@ | Format | Keywords | Notes | |-------------------------|----------------------------------------------------|---------------------------------| | (any) | channel, command, nickname, origin, plugin, server | all formats | -| **format-asked** | letter | the letter proposal | -| **format-dead** | word | the word to find | -| **format-found** | word | the hidden word | -| **format-start** | word | the hidden word | -| **format-win** | word | the word to find | -| **format-wrong-word** | word | the invalid word proposal | -| **format-wrong-letter** | letter | the letter proposal | +| **asked** | letter | the letter proposal | +| **dead** | word | the word to find | +| **found** | word | the hidden word | +| **start** | word | the hidden word | +| **win** | word | the word to find | +| **wrong-word** | word | the invalid word proposal | +| **wrong-letter** | letter | the letter proposal | Example: @@ -87,9 +101,9 @@
~/.config/irccd/irccd.conf
````ini -[plugin.hangman] -format-win = "nice job, the word was #{word}!" -format-wrong-letter = "please try again, there is no #{letter}" +[format.hangman] +win = "nice job, the word was #{word}!" +wrong-letter = "please try again, there is no #{letter}" ````