Show
Ignore:
Timestamp:
10/20/09 01:21:35 (5 months ago)
Author:
vkgtaro
Message:
  • コンフィグにシンボルを使用するように変更
  • lazy_san にあわせるように変更
  • notify_observers で失敗しても言いようにエラーハンドリング追加
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • project/lazy-people/thanksbot/thanksbot.rb

    r762 r763  
    1616  include Observable 
    1717 
    18   def initialize(*args) 
    19     p args 
    20     @channel = args[2] 
    21     args.delete_at 2 
    22     super 
     18  def initialize(config) 
     19    @channel = config[:irc][:opts][:channel] 
     20 
     21    super( 
     22      config[:irc][:host], 
     23      config[:irc][:port], 
     24      config[:irc][:opts] 
     25    ) 
    2326  end 
    2427 
     
    3033    if match = m[1].match(/^thanksbot:\s*(.*)/) 
    3134      changed 
    32       notify_observers('', match[1]) 
    33       post NOTICE, m[0], "#{m.prefix.nick}: #{match[1]}" 
     35      begin 
     36        notify_observers(match[1]) 
     37        post NOTICE, m[0], "#{m.prefix.nick}: #{match[1]}" 
     38      rescue 
     39        post NOTICE, m[0], "ごめん、失敗したかも" 
     40      end 
    3441    end 
    3542  end 
     
    3744 
    3845class ThanksDB < WedataDatabase 
    39   def update(name, message) 
    40     create_item(name, { 'message' => message }) 
     46  def update(message) 
     47    create_item('thanksbot', { 'message' => message }) 
    4148  end 
    4249end 
     
    4451config = YAML.load_file('thanksbot.yaml') 
    4552 
    46 thanksbot = ThanksBot.new( 
    47   config['irc']['host'], 
    48   config['irc']['port'], 
    49   config['irc']['channel'], 
    50   config['irc']['nicks'] 
    51 
     53thanksbot = ThanksBot.new(config) 
    5254 
    53 thanksdb = ThanksDB.new('thanks', config['wedata_api']) 
     55thanksdb = ThanksDB.new('thanks', config[:wedata_api]) 
    5456lazysan  = LazySan::Twitter.new(config[:twitter][:user], config[:twitter][:pass]) 
    5557