Created
December 28, 2016 22:12
-
-
Save html5cat/d52c2d3c64952319bf9572db43ea9343 to your computer and use it in GitHub Desktop.
morbotron.com other.chat feature
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
const {fetch, Feature} = require('other') | |
const feature = new Feature({ | |
name: 'Morbotron', | |
version: '0.0.1', | |
dependencies: { | |
otherjs: '^3.2.x', | |
}, | |
}) | |
feature.listen({ | |
to: {words: ['morbo']}, | |
on({word, rest}) { | |
const query = encodeURIComponent(rest.replace(word, '').trim()) | |
const url = `https://morbotron.com/api/search?q=${query}&format=json` | |
return fetch(url).then((response) => response.json()).then((json) => { | |
if (!json.data) return null | |
const chatCompletions = json.data.map((d) => { | |
return {media: { | |
type: 'image', | |
url: 'https://morbotron.com/img/' + d.Episode + '/' + d.Timestamp + '/small.jpg', | |
size: {height: 90, width: 160} | |
} | |
} | |
}) | |
return {chatCompletions} | |
}) | |
}, | |
}) | |
module.exports = feature |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment