Last active
August 22, 2016 21:15
-
-
Save holysugar/1984310e0f6df3942c64ce5b1fab2527 to your computer and use it in GitHub Desktop.
gbf proto-bahamuto call notification
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 'slack-notifier' | |
require 'tweetstream' | |
SLACK_WEBHOOK_URL = 'https://hooks.slack.com/services/XXXXXXXXXXXXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX' | |
TweetStream.configure do |config| | |
config.consumer_key = 'XXXXXXXXXXXXXXXXXXXXXXXXX' | |
config.consumer_secret = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' | |
config.oauth_token = 'XXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' | |
config.oauth_token_secret = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' | |
config.auth_method = :oauth | |
end | |
words = [ | |
'プロトバハムート', | |
'ジ・オーダー・グランデ', | |
'ティアマト・マグナ=エア', | |
'ユグドラシル・マグナ', | |
# 'シュヴァリエ・マグナ', | |
# 'セレスト・マグナ', | |
] | |
class ProtobahamutoCall | |
def initialize(url, name = 'protobahamutocall') | |
@notifier = Slack::Notifier.new(url) | |
@name = name | |
@notifier.username = @name | |
end | |
def watch(words) | |
_watch(words) | |
rescue SignalException | |
@notifier.username = @name | |
@notifier.ping('bye :)') | |
raise | |
end | |
def _watch(words) | |
@notifier.ping("Started. Picking words: #{words.join(',')}") | |
TweetStream::Client.new.track(words) do |status| | |
status.text.scan(/参戦ID:([0-9A-F]{8})/) do |m| | |
status.text.scan(/(^Lv1.*)$/) do |character| | |
p "#{m.first}:#{character.first}\n#{status.text}" | |
@notifier.username = character.first | |
@notifier.ping(m.first) | |
end | |
end | |
end | |
end | |
end | |
ProtobahamutoCall.new(SLACK_WEBHOOK_URL).watch(words) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment