Skip to content

Instantly share code, notes, and snippets.

@html5cat
Created December 28, 2016 22:12
Show Gist options
  • Save html5cat/d52c2d3c64952319bf9572db43ea9343 to your computer and use it in GitHub Desktop.
Save html5cat/d52c2d3c64952319bf9572db43ea9343 to your computer and use it in GitHub Desktop.
morbotron.com other.chat feature
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