Commits

firefly committed e52e694

Merge.

  • Participants
  • Parent commits a6675b5

Comments (0)

Files changed (6)

File modules/01-additional-triggers.coffee

 callbackPairs = []
 
 bot.register 'join',
-	match: (text) -> false
+	match: (conn, text) -> false
 	call: (conn, msg) ->
 		for [url, callback] in callbackPairs
 			index = msg.message.indexOf url

File modules/01-command-trigger.coffee

 		return prefix if startsWith msg, prefix
 
 commandTrigger =
-	match: (line) ->
+	match: (conn, line) ->
 		(getPrefix line)?
 
 	call: (conn, msg) ->

File modules/01-markov-trigger/index.js

 var modulePrefix = 'modules/01-markov-trigger/'
 
-//delete require.cache['/home/firefly/prog/eldis4/modules/05-wikipedia/substitutors.js']
-
 var markov  = require(modulePrefix + 'markov/model').markov
   , digraph = require(modulePrefix + 'fileLoader').digraph
 
 }
 
 var trigger = {
-  match: function (line) {
-    return line.indexOf("Eldis4")  >= 0 &&
-           line.indexOf("Eldis4>") == -1
+  match: function (conn, line) {
+    var nick = conn.options.nickname
+    return line.indexOf(nick)       >= 0 &&
+           line.indexOf(nick + ">") == -1
   },
 
   call: function (conn, msg) {

File modules/01-markov-trigger/markov/test.js

+var markov = require('./model').markov
+
+console.warn("Reading markov data...")
+var map = JSON.parse(require('fs').readFileSync('./markov-map.json'))
+console.warn("Done!")
+
+var fallbackPhrases = [ "så att",
+                        "jag är",
+                        "då jag",
+                        "det är" ].map(markov.parse.bind(markov))
+
+function generateSequence(input, count, threshold) {
+  var tokens = markov.parse(input)
+    , n = markov.opts.n
+
+  // Try to generate a sequence based on the input...
+  for (var i=0; i<tokens.length - n + 1; i++) {
+    var ngram = tokens.slice(i, i + n)
+      , reply = markov.generate(ngram, map, 100)
+
+    var candidate = markov.stringify(ngram.concat(reply))
+
+    if (candidate.length > threshold) {
+      return candidate
+    }
+  }
+
+  // Oops, didn't succeed.  Fallback to one of a fixed set of predefined
+  // prefixes.
+  var tokens = randomElementOf(fallbackPhrases).slice(-n)
+    , reply  = markov.generate(tokens, map, 100)
+
+  return markov.stringify(tokens.concat(reply))
+
+  function randomElementOf(arr) {
+    return arr[Math.random() * arr.length | 0]
+  }
+}
+
+function tryToGenerate(input, count, threshold) {
+  for (var i=0; i<count; i++) {
+    var attempt = generateSequence(input, 10, threshold)
+
+    if (attempt.length > threshold) {
+      return attempt
+    }
+  }
+
+  // Return the last attempt anyway
+  return attempt
+}
+
+
+var input = process.argv.slice(2).join(" ")
+
+for (var i=0; i<30; i++) {
+  console.log(tryToGenerate(input, 10, 40))
+}

File src/eldis4.js

 
     if (trig.match.constructor.name == 'RegExp') {
       isMatch = trig.match.exec(msg.message)
+
     } else if (typeof trig.match == 'function') {
-      isMatch = trig.match(msg.message)
+      isMatch = trig.match(conn, msg.message)
     }
 
     if (isMatch) {