Created
January 27, 2010 13:55
-
-
Save ssig33/287842 to your computer and use it in GitHub Desktop.
This file contains 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 'net/http' | |
@screen_name = "" | |
@password = "" | |
module Misuzilla::IronRuby | |
module TypableMap | |
include Misuzilla::Applications::TwitterIrcGateway::AddIns::TypableMap | |
@@commands = [] | |
def self.setup | |
@@typablemap_proc = Session.AddInManager.GetAddIn(Misuzilla::Applications::TwitterIrcGateway::AddIns::TypableMapSupport.to_clr_type).TypableMapCommands | |
# スクリプトアンロード時にコマンドを削除する | |
Session.AddInManager.GetAddIn(Misuzilla::Applications::TwitterIrcGateway::AddIns::DLRIntegration::DLRIntegrationAddIn.to_clr_type).BeforeUnload do |sender, e| | |
@@commands.each do |command| | |
@@typablemap_proc.RemoveCommand(command) | |
end | |
end | |
end | |
def self.register(command, desc, &proc_cmd) | |
@@commands << command | |
@@typablemap_proc.AddCommand(command, desc, ProcessCommand.new{|p, msg, status, args| | |
proc_cmd.call(p, msg, status, args) | |
}) | |
end | |
setup | |
end | |
end | |
# TypableMap: test コマンドを追加する | |
Misuzilla::IronRuby::TypableMap.register("test", "Test Command") do |p, msg, status, args| | |
System::Diagnostics::Trace.WriteLine("Test: #{status.to_string}") | |
true # true を返すとハンドルしたことになりステータス更新処理は行われない | |
end | |
# TypableMap: rt コマンドを追加する | |
Misuzilla::IronRuby::TypableMap.register("rt", "ReTweet Command") do |p, msg, status, args| | |
System::Diagnostics::Trace.WriteLine("RT: #{status.to_string}") | |
Session.RunCheck(Misuzilla::Applications::TwitterIrcGateway::Procedure.new{ | |
Net::HTTP.version_1_2 | |
req = Net::HTTP::Post.new("/statuses/retweet/#{status.id}.json") | |
req.basic_auth @screen_name, @password | |
Net::HTTP.start('twitter.com') {|http| | |
response = http.request(req) | |
} | |
}, System::Action[System::Exception].new{|ex| | |
Session.send_channel_message(msg.receiver, Server.server_nick, "メッセージ送信に失敗しました", false, false, true) | |
}) | |
true # true を返すとハンドルしたことになりステータス更新処理は行われない | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment