Created
April 8, 2015 11:28
-
-
Save mattn/2df4638ba0f82914f35b to your computer and use it in GitHub Desktop.
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
diff --git a/app.rb b/app.rb | |
index fcb7113..7c08ac0 100644 | |
--- a/app.rb | |
+++ b/app.rb | |
@@ -104,45 +104,47 @@ class Bot < Sinatra::Base | |
end | |
def handle_message message | |
- response = | |
- case message['text'] | |
- when /^ping$/ | |
- 'pong' | |
- when %r`(http://(?:www\.nicovideo\.jp/watch|nico\.ms)/((?:sm|nm)?\d+))` | |
- nicovideo($1, $2) | |
- when %r`http://live\.nicovideo\.jp/gate/(lv\d+)` | |
- nicolive_gate($1) | |
- # when %r`http://(?:www|touch)?\.pixiv\.net/member\.php\?id=(\d+)` | |
- # pixiv_member($1) | |
- when %r`https?://(?:mobile\.)?twitter\.com/[^\/]+/status(?:es)?/(\d+)(?:\/photo\/\d+)?$` | |
- twitter_content($1.to_i) | |
- when %r`http://d\.pr/i/(\w+)$` | |
- droplr_raw_url($1) | |
- when %r`http://seiga\.nicovideo\.jp/seiga/im(\d+)` | |
- nicoseiga_image_url($1.to_i) | |
- when %r`(http://seiga\.nicovideo\.jp/watch/mg\d+)` | |
- nicoseiga_comic_thumb_url($1) | |
- when %r`(http://seiga\.nicovideo\.jp/comic/\d+)` | |
- nicoseiga_comic_main_url($1) | |
- when %r`(http://gyazo\.com/\w+)$` | |
- gyazo_raw_url($1) | |
- when %r`http://ow\.ly/i/(\w+)` | |
- owly_raw_url($1) | |
- when %r`(http://\w+\.\w.yimg.jp/.+)` | |
- append_extension $1 | |
- when %r`(http://.+-origin\.fc2\.com/.+\.(?:jpe?g|gif|png))$` | |
- fc2_blog_url $1 | |
- when %r`(https?://b.hatena.ne.jp/entry/\d+/comment/[^\s]+)$` | |
- hatenabookmark_comment $1 | |
- when %r`(https?://ask.fm/.+/answer/\d+)` | |
- askfm $1 | |
- when %r`https?://p.twipple.jp/(\w+)` | |
- twipple_photo $1 | |
- when %r`(https?://[^\s]+)` | |
- title_for_url $1 | |
- end | |
- say message['room'], response if response | |
- puts "Didn't match." unless response | |
+ message.split("\n").each do |x| | |
+ response = | |
+ case message['text'] | |
+ when /^ping$/ | |
+ 'pong' | |
+ when %r`(http://(?:www\.nicovideo\.jp/watch|nico\.ms)/((?:sm|nm)?\d+))` | |
+ nicovideo($1, $2) | |
+ when %r`http://live\.nicovideo\.jp/gate/(lv\d+)` | |
+ nicolive_gate($1) | |
+ # when %r`http://(?:www|touch)?\.pixiv\.net/member\.php\?id=(\d+)` | |
+ # pixiv_member($1) | |
+ when %r`https?://(?:mobile\.)?twitter\.com/[^\/]+/status(?:es)?/(\d+)(?:\/photo\/\d+)?$` | |
+ twitter_content($1.to_i) | |
+ when %r`http://d\.pr/i/(\w+)$` | |
+ droplr_raw_url($1) | |
+ when %r`http://seiga\.nicovideo\.jp/seiga/im(\d+)` | |
+ nicoseiga_image_url($1.to_i) | |
+ when %r`(http://seiga\.nicovideo\.jp/watch/mg\d+)` | |
+ nicoseiga_comic_thumb_url($1) | |
+ when %r`(http://seiga\.nicovideo\.jp/comic/\d+)` | |
+ nicoseiga_comic_main_url($1) | |
+ when %r`(http://gyazo\.com/\w+)$` | |
+ gyazo_raw_url($1) | |
+ when %r`http://ow\.ly/i/(\w+)` | |
+ owly_raw_url($1) | |
+ when %r`(http://\w+\.\w.yimg.jp/.+)` | |
+ append_extension $1 | |
+ when %r`(http://.+-origin\.fc2\.com/.+\.(?:jpe?g|gif|png))$` | |
+ fc2_blog_url $1 | |
+ when %r`(https?://b.hatena.ne.jp/entry/\d+/comment/[^\s]+)$` | |
+ hatenabookmark_comment $1 | |
+ when %r`(https?://ask.fm/.+/answer/\d+)` | |
+ askfm $1 | |
+ when %r`https?://p.twipple.jp/(\w+)` | |
+ twipple_photo $1 | |
+ when %r`(https?://[^\s]+)` | |
+ title_for_url $1 | |
+ end | |
+ say message['room'], response if response | |
+ puts "Didn't match." unless response | |
+ end | |
end | |
def say room_id, message |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment