Skip to content

Instantly share code, notes, and snippets.

@mayuki
Created April 20, 2009 10:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mayuki/98472 to your computer and use it in GitHub Desktop.
Save mayuki/98472 to your computer and use it in GitHub Desktop.
module Misuzilla::IronRuby
module Hatetter
require 'rexml/document'
require 'open-uri'
@@channel = "#Hatetter"
@@interval = 360
@@endpoint = 'http://hatetter.blogdb.jp/mayuki/statuses/friends_timeline.xml'
@@ids = {}
@@thread = nil
@@group = nil
@@first_time = true
def self.setup
# チャンネル
if Session.Groups.contains_key(@@channel)
@@group = Session.Groups[@@channel.to_clr_string]
else
@@group = Misuzilla::Applications::TwitterIrcGateway::Group.new(@@channel)
Session.Groups.Add(@@channel, @@group)
end
@@group.is_special = true
@@group.is_joined = true
Session.send_server(Misuzilla::Net::Irc::JoinMessage.new(@@channel, ""))
@@thread = Thread.new do
dlr_addin = Session.AddInManager.GetAddIn(Misuzilla::Applications::TwitterIrcGateway::AddIns::DLRIntegration::DLRIntegrationAddIn.to_clr_type)
dlr_addin.BeforeUnload do |sender, e|
@@thread.kill
end
while true do
fetch
sleep @@interval
end
end
@@thread.run
end
def self.fetch
return unless @@group.is_joined
System::Diagnostics::Trace.WriteLine("Fetch: #{@@endpoint} / IsFirstTime: #{@@first_time}")
REXML::Document.new(open(@@endpoint)).root.elements.each do |e|
unless @@ids[e.elements['id'].text]
text = e.elements['text'].text
screen_name = e.elements['user'].elements['screen_name'].text
# 初回は流さない
unless @@first_time
notice_msg = Misuzilla::Net::Irc::PrivMsgMessage.new(@@channel, text)
notice_msg.sender_nick = screen_name
Session.send(notice_msg)
end
@@ids[e.elements['id'].text] = 1
end
end
@@first_time = false
end
# 開始
setup
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment