Last active
March 31, 2021 23:22
-
-
Save donpdonp/5b0e2ed95ae9055dc3f26c178ef8f8ce to your computer and use it in GitHub Desktop.
gluon emoji
This file contains hidden or 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
(function(){ | |
return {name: "emoji"} | |
}) | |
function go(msg) { | |
if(msg.method == "irc.privmsg") { | |
var match = /!emoji\s+(.*)/.exec(msg.params.message) | |
if(match) { | |
var term = match[1] | |
var emoji = emojipedia(term) | |
if(emoji) { | |
bot.say(msg.params.channel, "emoji "+emoji) | |
} else { | |
bot.say(msg.params.channel, "emoji not found for "+term) | |
} | |
} | |
var parts = msg.params.message.split(':') | |
if(parts.length > 0) { | |
var say = "" | |
var inside = false | |
parts.forEach(function(part, idx){ | |
bot.say(bot.admin_channel, JSON.stringify([part, idx])) | |
if (inside) { | |
bot.say(bot.admin_channel, "part "+idx+" "+JSON.stringify(part)) | |
var term = part.match(/([^:]*?):([a-zA-Z][^:]*):/) | |
var emoji = emojipedia(term[2]) | |
if(emoji) say += term[1] + emoji | |
inside = false // future optional | |
} else { inside = true } | |
}) | |
if(say.length > 0) { | |
bot.say(bot.admin_channel, "say: "+say) | |
//bot.say(msg.params.channel, say) | |
} | |
} | |
} | |
} | |
function emojipedia(term) { | |
var html = http.get("https://emojipedia.org/search/?q="+encodeURIComponent(term))//.replace(/(\r\n|\n|\r)/gm, ''); | |
// <h2><a href="/jack-o-lantern/"><span class="emoji">🎃</span> Jack-O-Lantern</a></h2> | |
var no_results = /No results found/.exec(html) | |
if (!no_results) { | |
var uc = /h2.*\"emoji\"\>([^<>]*)\<\/span\>/.exec(html) | |
if (uc) { | |
return uc[1] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment