Last active
December 10, 2015 15:08
-
-
Save siyo/4452030 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
| # -*- coding: utf-8 -*- | |
| # boxer tweet | |
| # | |
| # e.g. :boxer $aa => hoge (^ω゚(o-('-'o イェイ! | |
| # :boxer user => foo (^ω゚(6('-'o) | |
| # | |
| class String | |
| def punch | |
| arms = ["=≡-","-","-=≡","≡","=","~"] | |
| lface = ["(o'-')","o'-')","イェイ! o'-')"].sample | |
| rface = ["('-'o)","('-'o","('-'o イェイ!"].sample | |
| lrgxp = /^[^((\{]*[((\{]\s*\*?\s*(?:(?:´[・・])|(?:`[・・])|(?:கு)|[ ̄¦☉'´ு``◕´◕゚^^・。◠著])/ | |
| rrgxp = /(?:(?:´[・・])|(?:`[・・])|(?:கு)|[ ̄¦☉'´ு``◕´◕゚^^・。◠=〓権≦])\s*\*?\s*[\}))][^))\}]*$/ | |
| self.split("\n").inject(""){|sub, l| | |
| a = l.scan(rrgxp) | |
| sub << if a.size > 0 | |
| l.sub(a[0],'゚(' + arms.map{|e| 'o' + e}.concat(['6','6']).sample + rface) + "\n" | |
| else | |
| a = l.scan(lrgxp) | |
| s = a.size > 0 ? l.sub(a[0],lface + arms.map{|e| e + 'o'}.concat(['9','9','∂']).sample + ')゚') : l | |
| s + "\n" | |
| end | |
| } | |
| end | |
| end | |
| module Earthquake::Input | |
| def recent_status_id(name,index = -1) | |
| a = ("aa".."zz").to_a.inject([]){|s,v| | |
| break s unless id = var2id("$#{v}"); | |
| next s unless st = cache.read("status:#{id}"); | |
| s << id if st["user"]["screen_name"] && st["user"]["screen_name"] == name | |
| s | |
| } | |
| a.empty? ? nil : a.sort[index] | |
| end | |
| end | |
| Earthquake.init do | |
| command %r|^:boxer\s+(.+)$|, :as => :boxer do |m| | |
| txt = (st = cache.read("status:#{m[1].to_i}")) ? st["text"] : nil | |
| txt ||= (id = recent_status_id(m[1])) ? cache.read("status:#{id}")["text"] : nil; | |
| if txt | |
| s = txt.punch | |
| if confirm(s) | |
| twitter.update s | |
| end | |
| else | |
| puts "Not found tweet." | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment