summaryrefslogtreecommitdiff
path: root/bucky/db/fortune.js
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2017-12-08 02:18:49 +0100
committerJules Laplace <julescarbon@gmail.com>2017-12-08 02:18:49 +0100
commitbbbd8bbab8737f5067c85376daf79cd8a5a9c4cb (patch)
tree844d1385d7b88623eee3c2ea2c420280006ad349 /bucky/db/fortune.js
parente4e0cf21a31b74d5ee1e6d45b343ea60ed44f372 (diff)
parentdf674eef8e20c43426c0af5aa3d1a09b5e24c58a (diff)
merge
Diffstat (limited to 'bucky/db/fortune.js')
-rw-r--r--bucky/db/fortune.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/bucky/db/fortune.js b/bucky/db/fortune.js
new file mode 100644
index 0000000..7adba5a
--- /dev/null
+++ b/bucky/db/fortune.js
@@ -0,0 +1,28 @@
+function choice (a){ return a[ Math.floor(Math.random()*a.length) ] }
+
+var fs = require("fs"), path = require("path")
+var fortunes = {}
+var dir = "fortune"
+
+fs.readdirSync(path.resolve(dir)).forEach(function(fn){
+
+ var file = dir + '/' + fn
+ var stat = fs.statSync(file)
+
+ if (stat && ! stat.isDirectory()) {
+ fortunes[fn] = fs.readFileSync(file)
+ .toString()
+ .split("\n")
+ .filter(function(s){ return !! s })
+ }
+
+})
+
+module.exports = function(tag){
+ if (tag in fortunes) {
+ return choice(fortunes[tag])
+ }
+ else {
+ return "bucky"
+ }
+} \ No newline at end of file