Advertisement
Shiny_

Bot IRC

Apr 23rd, 2014
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.50 KB | None | 0 0
  1. require "cinch"
  2. require "open-uri"
  3. require "nokogiri"
  4. require "cgi"
  5. require "wolfram"
  6.  
  7. if not defined?(Ocra)
  8.     Wolfram.appid    = "IP WOLFRAMA"
  9.     ADMIN            = "Linux_Shines"
  10.     TESTING          = false
  11.     USE_MY_NICK      = true
  12. if USE_MY_NICK == true
  13.     PORT             = 5000
  14.     BOT_NICK         = ADMIN
  15.     BOT_REALNAME     = ADMIN
  16.     SERVER_NAME      = "alldev.eu"
  17. elsif USE_MY_NICK == false
  18.     PORT             = 6667
  19.     BOT_NICK         = "Jean_Paul_Secundo"
  20.     BOT_REALNAME     = "Jean Paul Secundo"
  21.     SERVER_NAME      = "irc.pirc.pl"
  22. end
  23.     BOT_USER         = BOT_REALNAME
  24.     PASSWORD         = "HASEŁKO"
  25.     HOP_REGEX        = /^!hop (.+)/i
  26.     LENNYFACE        = "( ͡° ͜ʖ ͡°)"
  27.     LENNY_REGEX      = /\blenny(face)?\b/i
  28.     WYKOP_REGEX      = /^*wykop(.+)/i
  29.     WOLFRAM_REGEX    = /\A% (?<query>.*)\z/i
  30.     DELETE_ACCOUNT   = /\busu(n|ń konto)?\b/i
  31. if TESTING == false
  32.     CHANNEL_NAME  = "#mirkofm"
  33. elsif TESTING == true
  34.     CHANNEL_NAME  = "#testingchannel"
  35. end
  36.     GOOGLE_REGEX  = /^!g (.+)/i
  37.  
  38.     bot = Cinch::Bot.new do
  39.         helpers do
  40.             def is_admin?(user)
  41.                 true if user.nick == ADMIN
  42.             end
  43.             def google(query)
  44.                 url = "http://www.google.pl/search?q=#{CGI.escape(query)}"
  45.                 res = Nokogiri::HTML(open(url)).at("h3.r")
  46.  
  47.                 title = res.text
  48.                 link = res.at('a')[:href]
  49.                 desc = res.at("./following::div").children.first.text
  50.                 rescue
  51.                     "Nie znaleziono żadnych wyników."
  52.                 else
  53.                     CGI.unescape_html(CGI.unescape("#{title} - #{desc} (#{link})")).force_encoding("ISO-8859-2").encode("UTF-8")
  54.                     #"#{title} - #{desc} (#{link})")
  55.                     #.force_encoding('ISO-8859-2').encode('UTF-8')
  56.             end
  57.         end
  58.        
  59.         configure do |c|
  60.             c.server            = SERVER_NAME
  61.             c.port              = PORT
  62.             c.channels          = [CHANNEL_NAME]
  63.             c.nick              = BOT_NICK
  64.             c.realname          = BOT_REALNAME
  65.             c.user              = BOT_USER
  66.             c.password          = PASSWORD
  67.         end
  68.  
  69.         on :join do |m|
  70.             if USE_MY_NICK == false
  71.                 bot.irc.send "MODE " + BOT_NICK + " +B"
  72.                 if m.user.to_s.downcase == BOT_NICK.downcase
  73.                     bot.Channel(CHANNEL_NAME).send("Po maturze chodziliśmy na... dziwki. ( ͡° ͜ʖ ͡°)\n   ~Jean Paul Secundo")
  74.                 end
  75.             end
  76.         end
  77.        
  78.         on :kick do
  79.             bot.Channel(CHANNEL_NAME).join
  80.         end
  81.        
  82.         on :ban do
  83.             bot.irc.send("MSG CHANSERV unban #{CHANNEL_NAME} #{BOT_NICK}")
  84.         end
  85.  
  86.     if TESTING == true
  87.         on :message, "test" do |m|
  88.             m.reply("Testowana wiadomość skierowana do użytkownika #{m.user.nick}")
  89.         end
  90.     end
  91.            
  92.         on :message, WOLFRAM_REGEX do |m|
  93.             query = WOLFRAM_REGEX.match(m.message)[:query]
  94.             result = Wolfram.fetch(query)
  95.             # puts result
  96.             hash = Wolfram::HashPresenter.new(result).to_hash
  97.             # puts hash
  98.             m.reply(hash[:pods]['Result'][0] || "Nie.", true)
  99.         end
  100.        
  101.         on :message, GOOGLE_REGEX do |m, query|
  102.             m.reply google(query)
  103.         end
  104.        
  105.         on :message, "wykop" do |m|
  106.             m.reply("Obraża papieża.")
  107.         end
  108.        
  109.         on :message, LENNYFACE do |m|
  110.             if m.user.to_s.downcase == ADMIN.downcase
  111.                 m.reply("( ͡° ͜ʖ ͡°)")
  112.             else
  113.                 m.reply("NIE DLA PSA LENNYFACE. ( ͡° ͜ʖ ͡°)")
  114.             end
  115.         end
  116.  
  117.         on :message, LENNY_REGEX do |m|
  118.             if m.user.to_s.downcase == ADMIN.downcase
  119.                 m.reply("( ͡° ͜ʖ ͡°)")
  120.             else
  121.                 m.reply("NIE DLA PSA LENNYFACE. ( ͡° ͜ʖ ͡°)")
  122.             end
  123.         end
  124.        
  125.         on :message, HOP_REGEX do |m|
  126.             m.reply("sam se kurna skacz")
  127.         end
  128.        
  129.         on :message, WYKOP_REGEX do |m|
  130.             m.reply("Więc to tutaj obraża się papieża!")
  131.         end
  132.        
  133.         on :message, DELETE_ACCOUNT do |m|
  134.             # m.reply("sam se usuń")
  135.             m.reply("sam se usuń")
  136.             bot.irc.send("kick #{CHANNEL_NAME} #{m.user.nick} sam se usuń")
  137.         end
  138.     end
  139.     bot.start
  140. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement