Created
May 1, 2012 17:09
-
-
Save no6v/2569701 to your computer and use it in GitHub Desktop.
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
require "named_emoji" | |
Earthquake.once do | |
::EMOJIMOJI = NamedEmoji::ALL.each_with_object(Hash.new{|h, k| h[k] = {}}) do |(key, value), hash| | |
hash[value.size].update(value => ":#{key}:") if value | |
end | |
::EMOJI_RE = ::EMOJIMOJI.inject({}) do |regexps, (size, hash)| | |
re = case size | |
when 1 | |
Regexp.new("[" + hash.keys.join + "]") | |
else | |
Regexp.union(hash.keys) | |
end | |
regexps.update(size => re) | |
end | |
end | |
Earthquake.init do | |
command :emojimoji do |m| | |
text = twitter.status(m[1])["text"].u | |
::EMOJIMOJI.keys.sort.reverse_each do |size| | |
text.gsub!(::EMOJI_RE[size], ::EMOJIMOJI[size]) | |
end | |
puts text | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment