Skip to content

Instantly share code, notes, and snippets.

@luser
Created April 10, 2015 17:31
Show Gist options
  • Save luser/b177a865341005981f5e to your computer and use it in GitHub Desktop.
Save luser/b177a865341005981f5e to your computer and use it in GitHub Desktop.
IRCCloud /gif command
function getGIF(words) {
return new Promise(function(resolve, reject) {
var req = new XMLHttpRequest();
req.responseType = "json";
req.onload = function() {
if (req.response.meta.status != 200 ||
!req.response.data.hasOwnProperty('images')) {
reject("Failed");
} else {
resolve(req.response.data.images.downsized.url);
}
};
req.onerror = function(e) {
reject(e);
};
req.open('GET', 'https://api.giphy.com/v1/gifs/translate?s=' + encodeURIComponent(words) + '&api_key=dc6zaTOxFJmzC', true);
req.send();
});
}
var _COMMANDS = {
gif: getGIF
};
var _oldsay = SESSIONVIEW.mainArea.current.input.__proto__.say;
SESSIONVIEW.mainArea.current.input.__proto__.say = function(m) {
var cmd = m.split(' ')[0].substr(1);
if (m.startsWith('/') && _COMMANDS.hasOwnProperty(cmd)) {
this.clear();
_COMMANDS[cmd](m.substr(cmd.length + 2)).then((newmsg) => {
_oldsay.apply(this, [newmsg]);
});
} else {
_oldsay.apply(this, [m]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment