changeset 149:19df514cb61c

Plugin ask: add optional file parameter, #504
author David Demelier <markand@malikania.fr>
date Fri, 20 May 2016 12:52:47 +0200
parents 1f61fc0566f2
children 81dd79ec1e99
files plugins/ask/ask.js plugins/ask/ask.md
diffstat 2 files changed, 24 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/ask/ask.js	Fri May 20 12:49:05 2016 +0200
+++ b/plugins/ask/ask.js	Fri May 20 12:52:47 2016 +0200
@@ -16,13 +16,7 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* Modules */
-var File	= Irccd.File;
-var Logger	= Irccd.Logger;
-var Plugin	= Irccd.Plugin;
-var Util	= Irccd.Util;
-
-/* Plugin information */
+// Plugin information.
 info = {
 	author: "David Demelier <markand@malikania.fr>",
 	license: "ISC",
@@ -30,6 +24,12 @@
 	version: "@IRCCD_VERSION@"
 };
 
+// Modules.
+var File = Irccd.File;
+var Logger = Irccd.Logger;
+var Plugin = Irccd.Plugin;
+var Util = Irccd.Util;
+
 /* List of answers */
 var answers = [
 	"Yes",
@@ -39,15 +39,20 @@
 function onLoad()
 {
 	try {
-		var path = Plugin.configPath + "answers.conf";
+		// User specified file?
+		if (Plugin.config["file"])
+			path = Plugin.config["file"];
+		else
+			path = Plugin.configPath + "answers.conf";
+
 		var file = new File(path, "r");
 		var line;
 
-		/* Reset */
+		// Reset.
 		answers = [];
 
 		while ((line = file.readline()))
-			/* Skip empty lines */
+			// Skip empty lines.
 			if (line.length > 0)
 				answers.push(line);
 	} catch (e) {
--- a/plugins/ask/ask.md	Fri May 20 12:49:05 2016 +0200
+++ b/plugins/ask/ask.md	Fri May 20 12:52:47 2016 +0200
@@ -25,10 +25,10 @@
 irccd: markand, No.
 ````
 
-## Configuration
+## File
 
-By default, **ask** will only answer yes or no. It's possible to add any answers you want in the file **answers.conf**
-located in the ask configuration directory.
+By default, **ask** will only answer yes or no. It's possible to add any answers you want in the file **answers.conf** located in the ask
+configuration directory.
 
 Just add one line per answer like this:
 
@@ -42,3 +42,9 @@
 ````
  </div>
 </div>
+
+## Configuration
+
+The following options are available under the `[plugin.ask]` section:
+
+  - **file**: (string) the path to the database file (Optional, default: **answers.conf** in configuration directory).