Advertisement
Shiny_

Untitled

Apr 21st, 2014
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.37 KB | None | 0 0
  1. require "cinch"
  2. require "open-uri"
  3. require "nokogiri"
  4. require "cgi"
  5. require "wolfram"
  6.  
  7. Wolfram.appid = "APP_ID"
  8. ADMIN         = "Linux_Shines"
  9. TESTING       = false
  10. HOP_REGEX     = /^!hop (.+)/i
  11. LENNYFACE     = /^( ͡° ͜ʖ ͡°)(.+)/i
  12. CALC_REGEX    = /\A% (?<query>.*)\z/i
  13. WYKOP_REGEX   = /^*wykop*(.+)/i
  14. GOOGLE_REGEX  = /^!g (.+)/i
  15.  
  16. bot = Cinch::Bot.new do
  17.     helpers do
  18.         def is_admin?(user)
  19.             true if user.nick == ADMIN
  20.         end
  21.         def google(query)
  22.             url = "http://www.google.pl/search?q=#{CGI.escape(query)}"
  23.             res = Nokogiri::HTML(open(url)).at("h3.r")
  24.  
  25.             title = res.text
  26.             link = res.at('a')[:href]
  27.             desc = res.at("./following::div").children.first.text
  28.             rescue
  29.                 "Nie znaleziono żadnych wyników."
  30.             else
  31.                 CGI.unescape_html(CGI.unescape("#{title} - #{desc} (#{link})")).force_encoding("ISO-8859-2").encode("UTF-8")
  32.                 #"#{title} - #{desc} (#{link})")
  33.                 #.force_encoding('ISO-8859-2').encode('UTF-8')
  34.         end
  35.     end
  36.    
  37.     configure do |c|
  38.         c.server            = "irc.pirc.pl"
  39.     if TESTING == true
  40.         c.channels          = [ "#testingchannel" ]
  41.     elsif TESTING == false
  42.         c.channels          = [ "#mirkofm" ]
  43.         end
  44.         c.nick              = "Lunux_"
  45.         c.password          = "HASŁO"
  46.         c.plugins.plugins   = [Lunux_]
  47.     end
  48.    
  49.    
  50. # if TESTING == true
  51.     on :message, "test" do |m|
  52.         m.reply("Testowana wiadomość skierowana do użytkownika #{m.user.nick}")
  53.     end
  54. # end
  55.        
  56.     on :message, CALC_REGEX do |m|
  57.         query = CALC_REGEX.match(m.message)[:query]
  58.         result = Wolfram.fetch(query)
  59.         # puts result
  60.         hash = Wolfram::HashPresenter.new(result).to_hash
  61.         # puts hash
  62.         m.reply(hash[:pods]['Result'][0] || "Nie.", true)
  63.     end
  64.    
  65.     on :message, GOOGLE_REGEX do |m, query|
  66.         m.reply google(query)
  67.     end
  68.    
  69.     on :message, "wykop" do |m|
  70.         m.reply("Obraża papieża.")
  71.     end
  72.    
  73.     on :message, LENNYFACE do |m|
  74.         m.reply(LENNYFACE)
  75.     end
  76.    
  77.     on :message, HOP_REGEX do |m|
  78.         m.reply("sam se kurna skacz")
  79.     end
  80.    
  81.     on :message, WYKOP_REGEX do |m|
  82.         m.reply("Więc to tutaj obraża się papieża!")
  83.     end
  84. end
  85. bot.start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement