Skip to content

Instantly share code, notes, and snippets.

@kurumigi
Forked from ssig33/rt.rb
Created February 9, 2010 01:56
Show Gist options
  • Save kurumigi/298844 to your computer and use it in GitHub Desktop.
Save kurumigi/298844 to your computer and use it in GitHub Desktop.
(1)username・password・sourceをTwitterIrcGateway本体から取得。 (2)非公式RTと併用できるようにコマンド名を変更。
require 'net/http'
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: ort コマンドを追加する
Misuzilla::IronRuby::TypableMap.register("ort", "Official ReTweet Command") do |p, msg, status, args|
System::Diagnostics::Trace.WriteLine("Officlal RT: #{status.to_string}")
username = Session.Connections[0].UserInfo.UserName
password = Session.Connections[0].UserInfo.Password
source = Session.TwitterService.ClientName
Session.RunCheck(Misuzilla::Applications::TwitterIrcGateway::Procedure.new{
Net::HTTP.version_1_2
req = Net::HTTP::Post.new("/statuses/retweet/#{status.id}.json?source=#{source}")
req.basic_auth username, 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