Commits

firefly  committed 7b6b662 Merge

Merge with 047bf4b5b8af

  • Participants
  • Parent commits 23509ec, 047bf4b

Comments (0)

Files changed (4)

File backends/node-bindings.js

 
 		var userAgent = 'Mozilla/4.0 (compatible; node.js; ' +
 				'see <http://bitbucket.org/firefly/eldis4>) Eldis/4.0'
-	//	var userAgent = 'Mozilla/4.0 (compatible; node.js; ' +
-	//			'see <http://bitbucket.org/firefly/eldis4>) Eldis/4.0'
+	//	'User-Agent': 'Eldis/4.0 (node.js; see <http://bitbucket.org/firefly/eldis4>)'
 
 		;(useSsl ? https : http).get({
 			host: matches[1],
 			path: '/' + matches[2] + firstSep + extraGets.join("&"),
 			headers: { 'User-Agent':userAgent }
 		}, function handleResult(res) {
-			if (res.statusCode == 301) { // Moved permanently
+			if (res.statusCode == 301 || res.statusCode == 302) { // Moved permanently
+				var matches = res.headers["location"].match(/^\w+:\/\/([^\/]+)\/(.*)/)
+ //res.headers["location"].replace(/^\w+:\/\/[^\/]+/, ''),
 				(useSsl ? https : http).get({
 					host: matches[1],
 					port: (useSsl ? 443 : 80),

File modules/05-commands.coffee

 vm         = require 'vm'
 fs         = require 'fs'
 os         = require 'os'
-sys        = require 'sys'
 util       = require 'util'
 htmlparser = require 'htmlparser'
 {exec}     = require 'child_process'
 		unsafe: {$eq: true}
 	
 	exec: (data) ->
-		result = sys.inspect eval data.line
+		result = util.inspect eval data.line
 		@reply escapeString result
 
 bot.triggers.command.add 'eval-coffee',
 	exec: (data) ->
 		{compile} = require 'coffee-script'
 		
-		result = sys.inspect eval (compile data.line, bare: true)
+		result = util.inspect eval (compile data.line, bare: true)
 		@reply escapeString result
 
 
 			@reply "Too short search query."
 			return
 		
-		query    = encodeURIComponent data.line
+		query    = encodeURIComponent data.line.trim()
 		shorturl = require 'shorturl'
 		
 		backend.net.get 'ajax.googleapis.com/ajax/services/search/web', {
 		
 		if chain.length == 0		# Print properties
 			# TODO: Pretty-print.
-			json = (sys.inspect rights).replace /\s+/g, " "
+			json = (util.inspect rights).replace /\s+/g, " "
 			@send data.target, "Rights: #{json}"
 		else if chain.length >= 2	# Set 
 			keyvalues = ["true", "false"]

File modules/05-unicode-lookup/index.js

 
 bot.triggers.command.add('char', {
 	help: "Looks up information about a unicode character.",
-	exec: function(data, chr) {
+	exec: function(data) {
 		var self = this
 		  , match
+		  , chr = data.line
 
 		if (!chr) {
 			self.send(data.target, "Error: usage: 'char <character>' or"
 
 		if (match = chr.match(/^U\+([\dA-F]+)$/i)) {
 			chr = String.fromCharCode(parseInt(match[1], 16))
+		} else if (chr.match(/^U\+/)) {
+			self.send(data.target, "Error: invalid U+ codepoint.")
+			return
 		} else if (chr.length != 1) {
-			throw new Error("Must check exactly one character!")
+			self.send(data.target, "Error: Must check exactly one character!")
+			return
 		}
 
 		lookup(chr, function(err, charinfo) {
 			}
 
 			console.log("TEST", charinfo, charinfo.name, charinfo.type)
-			self.reply(util.format("%s: U+%s %s (%s, %s)", chr, codepoint,
-					charinfo.name, charinfo.type, charinfo.directionality))
+			self.reply(util.format("%s: U+%s %s (%s)", chr, codepoint,
+					charinfo.name, charinfo.type))
 		})
 	}
 })

File modules/05-wikipedia/index.js

   exec: function(data) {
     var self = this
 
-    var encodedTitle = encodeTitle(data.line)
-    console.log("Fetching %s...", encodedTitle)
+    var title = data.line
+      , subdomain
+
+    // Handle interwiki prefixes; either two- or three-char language code or
+    // one of a number of special prefixes.
+    if (match = title.match(/^([a-z]{2,3}|simple):(.*)/i)) {
+        subdomain= match[1].toLowerCase()
+        title     = match[2]
+    } else {
+        subdomain = 'en'
+    }
+
+    var encodedTitle = encodeURIComponent(title).replace(/%20/g, '_')
+
+    console.log("Fetching %s from %s...", encodedTitle, subdomain)
+
+    backend.net.get(subdomain + ".wikipedia.org/w/index.php",
+        { "action" : "raw"
+        , "title"  : encodedTitle
+        }, function(err, data, done) {
+            if (!done) return
+            if (err) throw err
 
     backend.net.get("en.wikipedia.org/w/index.php",
       { "action" : "raw"
           , match    = result.match(/^(?:[^.]|\.(?! ))+\./)
           , response = match ? match[0] : result
 
+        // Replace newlines
+        response = response.replace(/\n/g, " ")
+
         // Make sure that the response isn't too long...
         if (response.length > 200) {
           response = response.slice(0, 199) + "\u2026" // Ellipsis