Last active
August 29, 2015 14:20
-
-
Save tnraro/c2b09598a9476506a105 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var plugin = { | |
name: 'shortly.me', | |
name_ko: '나를 짧게', | |
name_jp: '私を短く', | |
author: 'admin@tnraro.com', | |
version: '0.1.0', | |
description: '나를 짧게 해줍니다.', | |
alias: ['짧게'], | |
depends: ['Command'], | |
init: init, | |
destroy: destroy | |
} | |
var config = { | |
host: "http://shortly.me/shorten?url=" | |
}; | |
var request, async; | |
try{ | |
request = require('request'); | |
async = require('async'); | |
}catch(e){ | |
console.error('plz try "npm install ."'); | |
throw "Node modules not found"; | |
} | |
function init(bot, callback){ | |
console.log('hi'); | |
bot.registerCommand('shortly', plugin.description, '<url>', cmd, 0, plugin.alias); | |
callback(); | |
} | |
function cmd(bot, message, command, args){ | |
args.shift(); | |
var parallel = []; | |
args.forEach(function(url, i){ | |
if(url.match(/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w\.-]*)*\/?$/) !== null){ | |
parallel.push(function(callback){ | |
if(url.match(/^(https?:\/\/)/) === null){ | |
url = 'http://' + url; | |
} | |
request(config.host + encodeURIComponent(url), function(err, res, body){ | |
if(!err && res.statusCode === 200){ | |
bot.session.sendText(message.chatRoom, body); | |
} | |
}); | |
}); | |
} | |
}); | |
async.parallel(parallel, function(err, results){ | |
if(err){ | |
console.error(err); | |
throw err; | |
} | |
console.log(results); | |
}); | |
} | |
function destroy(bot, callback){ | |
console.log('hi'); | |
bot.unregisterCommand('shortly'); | |
callback(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from urllib.parse import quote | |
from urllib.request import urlopen | |
import sys | |
argv = sys.argv[1:] | |
host = "http://shortly.me/shorten?url=" | |
for url in argv: | |
after = urlopen(host+quote(url)).read().decode('utf-8') | |
print("\""+url+"\" -> "+after) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment