Guest User

Untitled

a guest
Apr 8th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. require 'net/http'
  2.  
  3. module Misuzilla::IronRuby
  4. module TypableMap
  5. include Misuzilla::Applications::TwitterIrcGateway::AddIns::TypableMap
  6.  
  7. @@commands = []
  8.  
  9. def self.setup
  10. @@typablemap_proc = Session.AddInManager.GetAddIn(Misuzilla::Applications::TwitterIrcGateway::AddIns::TypableMapSupport.to_clr_type).TypableMapCommands
  11.  
  12. # スクリプトアンロード時にコマンドを削除する
  13. Session.AddInManager.GetAddIn(Misuzilla::Applications::TwitterIrcGateway::AddIns::DLRIntegration::DLRIntegrationAddIn.to_clr_type).BeforeUnload do |sender, e|
  14. @@commands.each do |command|
  15. @@typablemap_proc.RemoveCommand(command)
  16. end
  17. end
  18. end
  19.  
  20. def self.register(command, desc, &proc_cmd)
  21. @@commands << command
  22. @@typablemap_proc.AddCommand(command, desc, ProcessCommand.new{|p, msg, status, args|
  23. proc_cmd.call(p, msg, status, args)
  24. })
  25. end
  26.  
  27. setup
  28. end
  29. end
  30.  
  31. # TypableMap: ort コマンドを追加する
  32. Misuzilla::IronRuby::TypableMap.register("ort", "Official ReTweet Command") do |p, msg, status, args|
  33. System::Diagnostics::Trace.WriteLine("Officlal RT: #{status.to_string}")
  34.  
  35. username = Session.Connections[0].UserInfo.UserName
  36. password = Session.Connections[0].UserInfo.Password
  37. source = Session.TwitterService.ClientName
  38.  
  39. Session.RunCheck(Misuzilla::Applications::TwitterIrcGateway::Procedure.new{
  40. Net::HTTP.version_1_2
  41. req = Net::HTTP::Post.new("/statuses/retweet/#{status.id}.json?source=#{source}")
  42. req.basic_auth username, password
  43. Net::HTTP.start('twitter.com') {|http|
  44. response = http.request(req)
  45. }
  46. }, System::Action[System::Exception].new{|ex|
  47. Session.send_channel_message(msg.receiver, Server.server_nick, "メッセージ送信に失敗しました", false, false, true)
  48. })
  49.  
  50. true # true を返すとハンドルしたことになりステータス更新処理は行われない
  51. end
Add Comment
Please, Sign In to add comment