Skip to content

Instantly share code, notes, and snippets.

@masarakki
Created April 20, 2011 05:43
Show Gist options
  • Save masarakki/930455 to your computer and use it in GitHub Desktop.
Save masarakki/930455 to your computer and use it in GitHub Desktop.
search and quick tweet for earthquake.gem
# -*- coding: utf-8 -*-
#
# Earthquakeを実況モードにするプラグインです
# 普通に起動した後
# :tsunami #K-ON #tbs
# のようにして実況モードに入ります
#
# すると #K-ON (空白区切りで最初のキーワードのみ) で検索した結果が
# リアルタイムに更新されます
#
# つぶやこうとすると つぶやき内容の後ろに #K-ON #tbs が自動で付与されます
#
# 元のモードに戻るには :reconnect のコマンドを実行します
#
module Earthquake
module Tsunami
def tsunami_config(str)
{ :host => 'stream.twitter.com',
:path => '/1.1/statuses/filter.json',
:method => 'POST',
:ssl => true,
:filters => [str]
}
end
def start_tsunami(str)
@old_config = @old_config || config[:api]
config[:api] = tsunami_config(str)
reconnect
end
def stop_tsunami
config[:api] = @old_config
end
end
extend Tsunami
end
Earthquake.init do
command :tsunami do |params|
keywords = params[1]
start_tsunami(keywords.split(/ /).first)
config[:prompt] = "☢ "
@tsunami_mode = keywords
end
command %r|^:(\#.+)$| do |m|
input ":tsunami #{m[1]}"
end
input_filter do |text|
text = "#{text} #{@tsunami_mode}" if text =~ /:update .*/ && !@tsunami_mode.nil?
text
end
input_filter do |text|
if text =~ /^:reconnect$/
@tsunami_mode = nil
stop_tsunami
config[:prompt] = "⚡ "
end
text
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment