|
Revision 761, 1.3 kB
(checked in by vkgtaro, 5 months ago)
|
twitter からの reply を irc に post するとき、その url もつけるように変更
|
| Line | |
|---|
| 1 |
#!/usr/bin/env ruby |
|---|
| 2 |
# encoding: utf-8 |
|---|
| 3 |
|
|---|
| 4 |
$LOAD_PATH << "lib" |
|---|
| 5 |
|
|---|
| 6 |
require 'rubygems' |
|---|
| 7 |
require 'net/irc' |
|---|
| 8 |
require 'observer' |
|---|
| 9 |
require 'lazysan' |
|---|
| 10 |
require 'yaml' |
|---|
| 11 |
|
|---|
| 12 |
class LazySan::IRC < Net::IRC::Client |
|---|
| 13 |
|
|---|
| 14 |
def initialize(config) |
|---|
| 15 |
@channel = config[:irc][:opts][:channel] |
|---|
| 16 |
|
|---|
| 17 |
@lazysan = LazySan::Twitter.new(config[:twitter][:user], config[:twitter][:pass]) |
|---|
| 18 |
|
|---|
| 19 |
super( |
|---|
| 20 |
config[:irc][:host], |
|---|
| 21 |
config[:irc][:port], |
|---|
| 22 |
config[:irc][:opts] |
|---|
| 23 |
) |
|---|
| 24 |
end |
|---|
| 25 |
|
|---|
| 26 |
def on_rpl_welcome(m) |
|---|
| 27 |
post JOIN, @channel |
|---|
| 28 |
run_observe_twitter() |
|---|
| 29 |
end |
|---|
| 30 |
|
|---|
| 31 |
def run_observe_twitter() |
|---|
| 32 |
@message_thread = Thread.new do |
|---|
| 33 |
loop do |
|---|
| 34 |
begin |
|---|
| 35 |
@lazysan.auto_follow |
|---|
| 36 |
@lazysan.replies.each {|status| |
|---|
| 37 |
post NOTICE, @channel, "@#{status['user']['screen_name']}: #{status['text']} http://twitter.com/#{status['user']['screen_name']}/status/#{status['id']}" |
|---|
| 38 |
} |
|---|
| 39 |
rescue |
|---|
| 40 |
# TODO: Net::IRC の log |
|---|
| 41 |
end |
|---|
| 42 |
sleep 300 |
|---|
| 43 |
end |
|---|
| 44 |
end |
|---|
| 45 |
end |
|---|
| 46 |
|
|---|
| 47 |
def on_privmsg(m) |
|---|
| 48 |
if match = m[1].match(/^lazy_san:\s*(.*)/) |
|---|
| 49 |
begin |
|---|
| 50 |
@lazysan.update(match[1]) |
|---|
| 51 |
post NOTICE, @channel, "#{m.prefix.nick}: #{match[0]}" |
|---|
| 52 |
rescue |
|---|
| 53 |
post NOTICE, @channel, "投稿ミスった >_<" |
|---|
| 54 |
end |
|---|
| 55 |
end |
|---|
| 56 |
end |
|---|
| 57 |
|
|---|
| 58 |
end |
|---|
| 59 |
|
|---|
| 60 |
config = YAML.load_file('lazysan.yaml') |
|---|
| 61 |
|
|---|
| 62 |
lazy_san = LazySan::IRC.new(config) |
|---|
| 63 |
|
|---|
| 64 |
lazy_san.start |
|---|