1. firefly
  2. Eldis4

Commits

firefly  committed 75c36e0

Various minor fixes for commands.

  • Participants
  • Parent commits 35ac625
  • Branches default

Comments (0)

Files changed (6)

File modules/01-command-trigger.js

View file
       var args = [obj].concat((line.split(" ")).slice(1))
 
       function handleError(err) {
+        if (!(err instanceof Error)) err = { name: "", message: err, stack: "", toString: function () { return this.err } }
         var matches = err.stack.match(/^([^\n]+)+\s*([^\n]+)/)
         if (matches) {
           var name    = matches[1]
       }
 
       var ctx = { error: function () { return handleError.apply(conn, arguments) },
-                  reply: function (str) { return conn.send(msg.target, "" + msg.nick + ": " + str) } }
+                  reply: function (str) {
+                           return conn.send(msg.target, msg.nick + ": " + str.replace(/\n/g, ''))
+                         } }
 
       for (var key in conn) {
         if (ctx[key] == null && typeof conn[key] == 'function') {

File modules/05-alias.js

View file
 
 function registerAlias(name, target, boundArgs) {
   bot.triggers.command.add(name, {
-    help: "Alias for '#{[target].concat(boundArgs).join ' '}'.",
+    help: "Alias for '" + [target].concat(boundArgs).join(" ") + "'.",
     type: "alias",
     exec: function (data /*...*/) {
       var rest = Array.prototype.slice.call(arguments, 1)

File modules/05-commands.js

View file
   var deentify = function (x) { return x }
 }
 
+/*
 bot.triggers.command.add('gcalc', {
   help: "Calculates an expression using the Google Calc API.",
   exec: function (data) {
         json = json.replace(/(\w+): /g, '"$1": ')
         json = json.replace(/\\x([\da-f]{2})/g, '\\u00$1')
 
-        var data  = JSON.parse(data)
+        // Invalid JSON
+        try { JSON.parse(json) }
+        catch (err) { console.warn(json) }
+
+        var data  = JSON.parse(json)
           , lhs   = data.lhs
           , rhs   = data.rhs
           , error = data.error
 
         console.log("Data:", data)
 
-        if (error) { return this.reply("Error: " + error) }
+        if (error) { return self.reply("Error: " + error) }
 
         var supDigitsMap = ("\u2070\u00b9\u00b2\u00b3\u2074\u2075\u2076" +
                             "\u2077\u2078\u2079").split("")
           // Replace <sup>
           str = str.replace(/<sup>([^<]+)<\/sup>/g, function (_, value) {
             return /^-?\d+$/.test(value)?  value.replace(/./g, supChar)
-                 : /*else*/                "^" + value
+                 :                         "^" + value
 
             function supChar(chr) { return supDigitsMap[chr] }
           })
           // Replace <sub>
           str = str.replace(/<sub>([^<]+)<\/sub>/g, function (_, value) {
             return /^-?\d+$/.test(value)?  value.replace(/./g, subChar)
-                 : /*else*/                "_" + value
+                 :                         "_" + value
 
             function subChar(chr) { return subDigitsMap[chr] }
           })
           return deentify(str)
         }
 
-        this.reply(beautify(lhs) + " = " + beautify(rhs))
+        self.reply(beautify(lhs) + " = " + beautify(rhs))
       })
   }
 })
+*/
 
 // @depends shorturl
 bot.triggers.command.add('g', {
           , hits     = response["responseData"]["results"]
 
         if (hits.length < 1) {
-          return this.reply("No result. :(")
+          return self.reply("No result. :(")
         }
 
         var titleNoFormatting = hits[0].titleNoFormatting

File modules/05-interpreters.js

View file
 
 // Assumes stuff/migol.jar exists and is a proper executable Migol interpreter.
 bot.triggers.command.add('migol', {
-  help: "Evaluates a Migol program.",
+  help: "Evaluates a Migol 09 program.",
   exec: function(data) {
     var self    = this
       , options = {timeout:15000, killSignal:'SIGKILL'}
 
 
 //-- '~hs' for haskell eval -------------------------------
+/*
 bot.triggers.command.add('hs', {
   help: "Evaluates a Haskell snippet.",
   exec: function(data) {
     }
   }
 })
+*/
 

File modules/05-literals.js

View file
-var storage = bot.triggers.command.getStorage('alias')
+var storage = bot.triggers.command.getStorage('literal')
 if (!storage.literals) storage.literals = {}
 var literals = storage.literals
 
         if (suffix == "+") { joiner = " " }
 
         if (! +command) {
-          throw new Error("Syntax error in literal: " + command + " has a suffix.")
+          throw new Error("Syntax error in literal: $" + command + " has a suffix.")
         }
       }
 
         break
 
       case 'show':
+        if (!(name in literals)) {
+          return this.send(data.target, "Error: No such literal: '" + name + "'.")
+        }
+
         var lit = literals[name]
-        this.reply("Literal '" + lit.name + "' contains: " + lit.content)
+        this.reply("Literal '" + name + "' contains: " + lit.content)
         break
 
       default: this.reply("Unknown command 'literal " + command + "'")

File modules/05-wikipedia/index.js

View file
     var title     = ident.title
       , subdomain = ident.namespace
 
-    var encodedTitle = encodeURIComponent(title).replace(/%20/g, '_')
+ // var encodedTitle = encodeURIComponent(title).replace(/%20/g, '_')
+    var encodedTitle = encodeTitle(title)
 
     console.log("Fetching %s from %s...", encodedTitle, subdomain)
 
 
     // Encodes a title to be part of a mediawiki URL
     function encodeTitle(str) {
-      return encodeURIComponent(str).replace(/%20/g, '_')
-                                    .replace(/[()]/g, urlEscape)
+      return str.replace(/[() \/]/g, wikiEscape)
+   // return encodeURIComponent(str).replace(/%20/g, '_')
+   //                               .replace(/[()]/g, urlEscape)
 
+      function wikiEscape(chr) {
+        if (chr == " ") return "_"
+        var hex = chr.charCodeAt().toString(16)
+        if (hex.length == 1) hex = "0" + hex
+        return "." + hex
+      }
       function urlEscape(chr) {
         var hex = chr.charCodeAt().toString(16)
         if (hex.length == 1) hex = "0" + hex