summaryrefslogtreecommitdiff
path: root/bucky/db/fortune.js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2015-09-25 17:36:53 -0400
committerJules Laplace <jules@okfoc.us>2015-09-25 17:36:53 -0400
commit3aa171fbaf05d0ee5b82673443da51ed43719475 (patch)
tree291426c3102cffff23f8b202ec14cd03df91e799 /bucky/db/fortune.js
parentccd2a51e9206aa858313ae97550b09b9bf8476db (diff)
moving things around
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