Advertisement
Shiny_

Untitled

Apr 21st, 2014
2,577
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. require "cinch"
  2. require "open-uri"
  3. require "nokogiri"
  4. require "cgi"
  5. require "wolfram"
  6.  
  7. Wolfram.appid    = "CHUJ CI DO TEGO, ZAPYTAĆ SIĘ MOŻESZ"
  8. ADMIN            = "Linux_Shines"
  9. TESTING          = false
  10. BOT_NICK         = "Lunux_"
  11. BOT_REALNAME     = "Jean Paul Secundo"
  12. BOT_USER         = "Lunux_"
  13. PASSWORD         = "HASŁO"
  14. HOP_REGEX        = /^!hop (.+)/i
  15. LENNYFACE        = "( ͡° ͜ʖ ͡°)"
  16. WOLFRAM_REGEX    = /\A% (?<query>.*)\z/i
  17. WYKOP_REGEX      = /^wykop(.+)/i
  18. SERVER_NAME      = "irc.pirc.pl"
  19.                                         if TESTING == false
  20. CHANNEL_NAME  = "#mirkofm"
  21.                                         elsif TESTING == true
  22. CHANNEL_NAME  = "#testingchannel"
  23.                                         end
  24. GOOGLE_REGEX  = /^!g (.+)/i
  25.  
  26. bot = Cinch::Bot.new do
  27.     helpers do
  28.         def is_admin?(user)
  29.             true if user.nick == ADMIN
  30.         end
  31.         def google(query)
  32.             url = "http://www.google.pl/search?q=#{CGI.escape(query)}"
  33.             res = Nokogiri::HTML(open(url)).at("h3.r")
  34.  
  35.             title = res.text
  36.             link = res.at('a')[:href]
  37.             desc = res.at("./following::div").children.first.text
  38.             rescue
  39.                 "Nie znaleziono żadnych wyników."
  40.             else
  41.                 CGI.unescape_html(CGI.unescape("#{title} - #{desc} (#{link})")).force_encoding("ISO-8859-2").encode("UTF-8")
  42.                 #"#{title} - #{desc} (#{link})")
  43.                 #.force_encoding('ISO-8859-2').encode('UTF-8')
  44.         end
  45.     end
  46.    
  47.     configure do |c|
  48.         c.server            = SERVER_NAME
  49.         c.channels          = [CHANNEL_NAME]
  50.         c.nick              = BOT_NICK
  51.         c.realname          = BOT_REALNAME
  52.         c.user              = BOT_USER
  53.         c.password          = PASSWORD
  54.     end
  55.  
  56.     on :join do
  57.         bot.irc.send "MODE " + BOT_NAME + " +B"
  58.         # m.reply("A po szkole chodziliśmy na... dziwki. ( ͡° ͜ʖ ͡°)\n~Jean Paul Secundo")
  59.         bot.Channel(CHANNEL_NAME).send("A po szkole chodziliśmy na... dziwki. ( ͡° ͜ʖ ͡°)\n~Jean Paul Secundo")
  60.     end
  61.    
  62.     on :kick do
  63.         bot.Channel(CHANNEL_NAME).join
  64.     end
  65.    
  66.     on :ban do
  67.         bot.irc.send("MSG CHANSERV unban #{CHANNEL_NAME} #{BOT_NAME}")
  68.     end
  69.  
  70. # if TESTING == true
  71.     on :message, "test" do |m|
  72.         m.reply("Testowana wiadomość skierowana do użytkownika #{m.user.nick}")
  73.     end
  74. # end
  75.        
  76.     on :message, WOLFRAM_REGEX do |m|
  77.         query = WOLFRAM_REGEX.match(m.message)[:query]
  78.         result = Wolfram.fetch(query)
  79.         # puts result
  80.         hash = Wolfram::HashPresenter.new(result).to_hash
  81.         # puts hash
  82.         m.reply(hash[:pods]['Result'][0] || "Nie.", true)
  83.     end
  84.    
  85.     on :message, GOOGLE_REGEX do |m, query|
  86.         m.reply google(query)
  87.     end
  88.    
  89.     on :message, "wykop" do |m|
  90.         m.reply("Obraża papieża.")
  91.     end
  92.    
  93.     on :message, LENNYFACE do |m|
  94. if ADMIN == "Linux_Shines"
  95.         m.reply("( ͡° ͜ʖ ͡°)")
  96. elsif # czemu kurwa to nie działa :<
  97.         m.reply("NIE DLA PSA LENNYFACE. ( ͡° ͜ʖ ͡°)")
  98. end
  99.     end
  100.  
  101.     on :message, "lennyface" do |m|
  102. if ADMIN == "Linux_Shines"
  103.         m.reply("( ͡° ͜ʖ ͡°)")
  104. elsif # czemu kurwa to nie działa :<
  105.         m.reply("NIE DLA PSA LENNYFACE. ( ͡° ͜ʖ ͡°)")
  106. end
  107.     end
  108.    
  109.     on :message, HOP_REGEX do |m|
  110.         m.reply("sam se kurna skacz")
  111.     end
  112.    
  113.     on :message, WYKOP_REGEX do |m|
  114.         m.reply("Więc to tutaj obraża się papieża!")
  115.     end
  116. end
  117. bot.start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement