Commits

firefly  committed bdb7516

Merge with 7b6b662b1dff

  • Participants
  • Parent commits 7b6b662

Comments (0)

Files changed (3)

File backends/node-bindings.js

 			headers: { 'User-Agent':userAgent }
 		}, function handleResult(res) {
 			if (res.statusCode == 301 || res.statusCode == 302) { // Moved permanently
-				var matches = res.headers["location"].match(/^\w+:\/\/([^\/]+)\/(.*)/)
+				var matches = (res.headers["location"] || "").match(/^\w+:\/\/([^\/]+)\/(.*)/)
+
+				if (!matches) {
+					callback(new Error("Invalid 'location' header."))
+					return
+				}
+
  //res.headers["location"].replace(/^\w+:\/\/[^\/]+/, ''),
 				(useSsl ? https : http).get({
 					host: matches[1],

File modules/05-cmd-markov.coffee

 fs = require 'fs'
 
 filenameMap =
-	"bible"        : '/home/firefly/tmp/b/short-bible'
+#	"bible"        : '/home/firefly/tmp/b/short-bible'
 	"zelda-la"     : '/home/firefly/annat/texts/zelda-la.txt'
-	"pkmn-red"     : '/home/firefly/tmp/b/dred.txt'
-	"kinginyellow" : '/home/firefly/tmp/b/kinginyellow'
-	"portal2"      : '/tmp/portal2-subtitles'
-	"lagtext"      : '/home/firefly/tmp/b/lagtext'
-	"raytracer"    : '/tmp/raytracer'
-	"wp-sweden"    : '/home/firefly/tmp/b/wp-sweden'
+#	"pkmn-red"     : '/home/firefly/tmp/b/dred.txt'
+#	"kinginyellow" : '/home/firefly/tmp/b/kinginyellow'
+	"portal2"      : '/home/firefly/annat/texts/portal2-subtitles'
+#	"lagtext"      : '/home/firefly/tmp/b/lagtext'
+	"raytracer"    : '/home/firefly/annat/texts/raytracer'
+#	"wp-sweden"    : '/home/firefly/tmp/b/wp-sweden'
 	"communist"    : '/home/firefly/annat/texts/communist-manifest.txt'
 	"art-of-war"   : '/home/firefly/annat/texts/art-of-war.txt'
 	"datalogi"     : '/home/firefly/annat/texts/datalogi-a.txt'
 				@reply "No such wordset available. :( (see 'markov' for available wordsets.)"
 				return
 			
-			@reply getOutputText getChainMap setName
+			@reply getOutputText getChainMap setName

File modules/05-commands.coffee

 		result = util.inspect eval (compile data.line, bare: true)
 		@reply escapeString result
 
+<<<<<<< local
+#### ~js & friends ####
+# @optdepends jsdom - DOM support in the JS context.
+fetchJsContext = (storage) ->
+	ctx = (storage['js-context'] ?= {})
+	
+	console.log "Fetching jsContext!"
+	
+	if 'console' not of ctx?.g
+		console.log "Initing magics!"
+		ctx.g = {}
+		
+		createMagic = (prop, value) ->
+			try
+				Object.defineProperty ctx.g, prop,
+					value      : value
+					enumerable : false
+					writable   : false
+
+				ctx[prop] = ctx.g[prop]
+				console.log "Defined #{prop}!"
+			
+			catch err
+				console.log "### Failed to define #{prop}!", err.message
+		
+		#modules = ['util']
+		#(createMagic name, require name) for name in modules
+		
+		output = []
+		createMagic 'console', myConsole = {
+			log: ->
+				Array::push.apply output, arguments
+				return
+
+			getOutput: ->
+				res = output.map(jsPrettify).join ", "
+				output.length = 0
+				res
+		}
+		
+	ctx
+
+jsPrettify = require('util').inspect
+
+bot.triggers.command.add 'js',
+	help: "Evaluates a single line of JavaScript code."
+	exec: (data) ->
+		context = fetchJsContext data.storage
+		
+		try
+			result = vm.runInNewContext data.line, context, 'input'
+
+		catch err
+			@send data.target, "#{err.name}: #{err.message}"
+			return
+
+		output = jsPrettify result
+
+		#consoleOutput = context.g.console.getOutput()
+		consoleOutput = context.console.getOutput()
+		if consoleOutput.length > 0
+			output += "; console: #{consoleOutput}"
+
+		@reply escapeString output
+
+# TODO: Unify this and ~js (above)
+bot.triggers.command.add 'coffee',
+	help: "Evaluates a single line of CoffeeScript code."
+	exec: (data) ->
+		context = fetchJsContext bot.triggers.command.getStorage 'js'
+		
+		{compile} = require 'coffee-script'
+		
+		try
+			jsCode = compile data.line, bare: true
+			result = vm.runInNewContext jsCode, context, 'input'
+			@reply escapeString jsPrettify result
+		catch err
+			@send data.target, "#{err.name}: #{err.message}"
+
+bot.triggers.command.add 'python',
+	help: "Evaluates a single line of Python code."
+	requires:
+		unsafe: $eq: true
+	exec: (data) ->
+		command = data.line.replace /'/g, "\\'"
+		options = timeout: 2000, killSignal: 'SIGINT'
+		
+		command = "fakechroot chroot sandbox python -c '#{command}'"
+		
+		exec command, options, (err, stdout, stderr) =>
+			if err
+				if err.signal == 'SIGINT'
+					@send data.target, "#{data.nick}: Timed out."
+				else
+					@send data.target, "#{data.nick}: (returned #{err.code}): " +
+									   "#{escapeString stderr}"
+			else
+				@send data.target, "#{data.nick}: #{escapeString stdout}"
+
+# Assumes stuff/migol.jar exists and is a proper executable Migol jar.
+bot.triggers.command.add 'migol',
+	help: "Evaluates a Migol program."
+	exec: (data) ->
+		command = data.line.replace /'/g, "\\'"
+		options = timeout: 2000, killSignal: 'SIGINT'
+		
+		fs.writeFile "/tmp/tmp-eldis4-migol", data.line, (err) =>
+			if err
+				@send data.target, "Error: #{err}"
+				return
+			
+			command = "java -jar stuff/migol.jar /tmp/tmp-eldis4-migol"
+			
+			exec command, options, (err, stdout, stderr) =>
+				if err
+					if err.signal == 'SIGINT'
+						@send data.target, "#{data.nick}: Timed out."
+					else
+						@send data.target, "#{data.nick}: (returned #{err.code}): " +
+										   "#{escapeString stderr}"
+				else
+					@send data.target, "#{data.nick}: #{escapeString stdout}"
+				
+				fs.unlink "/tmp/tmp-eldis4-migol", (err) ->
+					throw err if err
+=======
+>>>>>>> other
 
 ##### Beginning of literals code #####
 literals = (bot.triggers.command.getStorage('literal')?.literals ?= {})
 				
 				@reply "#{beautify lhs} = #{beautify rhs}"
 
+
 # @depends shorturl
 bot.triggers.command.add 'g',
 	help: "Searches the web for a given string, through the Google search engine."