Advertisement
Shiny_

dunno lol

Dec 31st, 2017
473
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 7.79 KB | None | 0 0
  1. require "cgi"
  2. require "cinch"
  3. require "nokogiri"
  4. require "open-uri"
  5. require "wolfram"
  6.  
  7. if not defined?(Ocra)
  8.     Wolfram.appid    = "APP_ID"
  9.     ADMIN            = "ADMIN_NAME"
  10.     TESTING          = false
  11.     USE_MY_NICK      = false
  12.     if USE_MY_NICK == true
  13.         PORT             = 5000
  14.         BOT_NICK         = ADMIN
  15.         BOT_REALNAME     = ADMIN
  16.         SERVER_NAME      = "SERWER"
  17.     elsif USE_MY_NICK == false
  18.         PORT             = 6667
  19.         BOT_NICK         = "nrq"
  20.         BOT_REALNAME     = BOT_NICK
  21.         SERVER_NAME      = "irc.pirc.pl"
  22.     end
  23.     BOT_USER         = BOT_REALNAME
  24.     PASSWORD         = "PASS"
  25.     HOP_REGEX        = /^!hop (.+)/i
  26.     LENNYFACE        = "( ͡° ͜ʖ ͡°)"
  27.     RAT_REGEX        = /\b[ImgInfo]?\b/i
  28.     SAY_REGEX        = /\Asay (?<msg>.*)\z/i
  29.     BASH_REGEX       = /^!bash/i
  30.     RAT_REGEX_2      = /\b[YouTube]?\b/i
  31.     LENNY_REGEX      = /\blenny(face)?\b/i
  32.     LUNUX_REGEX      = /\l(n|unu)x( pls| plz)?\b/i
  33.     NIGGA_REGEX      = /\bn(i|y)(g|gg)a?\b/i
  34.     WYKOP_REGEX      = /^*wykop(.+)/i
  35.     GOOGLE_REGEX     = /^!g (.+)/i
  36.     WOLFRAM_REGEX    = /\A% (?<query>.*)\z/i
  37.     DELETE_ACCOUNT   = /\busu[]\s+k(?:on|ą)to\b/
  38.     if TESTING == false
  39.         CHANNEL_NAME  = "#mirkofm"
  40.     elsif TESTING == true
  41.         CHANNEL_NAME  = "#testingchannel"
  42.     end
  43.  
  44.     bot = Cinch::Bot.new do
  45.         helpers do
  46.             def google(query)
  47.                 url = "http://www.google.pl/search?q=#{CGI.escape(query)}"
  48.                 res = Nokogiri::HTML(open(url)).at("h3.r")
  49.  
  50.                 title = res.text
  51.                 link = res.at('a')[:href]
  52.                 desc = res.at("./following::div").children.first.text
  53.                 rescue "Nie znaleziono żadnych wyników."
  54.                 else CGI.unescape_html(CGI.unescape("#{title} - #{desc} (#{link})")).force_encoding("ISO-8859-2").encode("UTF-8")
  55.                     .gsub("Âą", "ą")
  56.                     .gsub("ĂŚ", "ć")
  57.                     .gsub("ĂŞ", "ę")
  58.                     .gsub("Âł", "ł")
  59.                     .gsub("Ăą", "ń")
  60.                     .gsub("Ăł", "ó")
  61.                     .gsub("Âś", "ś")
  62.                     .gsub("Âź", "ź")
  63.                     .gsub("Âż", "ż")
  64.                     .gsub("–", "-")
  65.                     .gsub(/\Podobne+/, "")
  66.                     .gsub("‎Kopia", "")
  67.                     .gsub("‎KopiaPodobne ", "")
  68.                     .gsub("►", "")
  69.                     .gsub(/\(\/url\?q=/, "Link: ")
  70.                     .gsub(/\(\/images\?q=/, "Obrazek: ")
  71.                     .gsub(/\/&sa=.+/, "")
  72.                     # .gsub(/\(\/url\?q=.+/, /\.+/)
  73.                     # .gsub("(/q=" " Oryginalny URL: ")
  74.                     #"#{title} - #{desc} (#{link})")
  75.                     #.force_encoding('ISO-8859-2').encode('UTF-8')
  76.             end
  77.            
  78.             class Bash
  79.                 def self.Random_Quote
  80.                     Get_Quote("random")
  81.                 end
  82.             private
  83.                 def self.Get_Quote(params)
  84.                     result = Bash_Request(params)
  85.                     result.first.text
  86.                 end            
  87.                 def self.Bash_Request(params)
  88.                     result = Nokogiri::HTML(open("http://bash.org.pl/#{params}"))
  89.                     result.xpath("//div[@class = 'quote post-content post-body']")
  90.                 end
  91.             end
  92.         end
  93.        
  94.         configure do |c|
  95.             c.server            = SERVER_NAME
  96.             c.port              = PORT
  97.             c.channels          = [CHANNEL_NAME]
  98.             c.nick              = BOT_NICK
  99.             c.realname          = BOT_REALNAME
  100.             c.user              = BOT_USER
  101.             c.password          = PASSWORD
  102.         end
  103.  
  104.         on :join do |m|
  105.             if USE_MY_NICK == false
  106.                 bot.irc.send "MODE " + BOT_NICK + " +x"
  107.                 # if m.user.to_s.downcase == BOT_NICK.downcase
  108.                     # bot.Channel(CHANNEL_NAME).send("Po maturze chodziliśmy na... dziwki. ( ͡° ͜ʖ ͡°)\n   ~Jean Paul Secundo")
  109.                     # bot.User(m.user.to_s).send("A po szkole chodziliśmy na... dziwki. ( ͡° ͜ʖ ͡°)\n~Jean Paul Secundo")
  110.                 # end
  111.             end
  112.         end
  113.        
  114.         on :kick do
  115.             bot.Channel(CHANNEL_NAME).join
  116.         end
  117.        
  118.         on :ban do
  119.             bot.irc.send("MSG CHANSERV unban #{CHANNEL_NAME} #{BOT_NICK}")
  120.         end
  121.  
  122.     if TESTING == true
  123.         on :message, "test" do |m|
  124.             m.reply("Testowana wiadomość skierowana do użytkownika #{m.user.nick}")
  125.         end
  126.     end
  127.    
  128.         on :message, SAY_REGEX do |m|
  129.             if m.user.to_s.downcase == ADMIN.downcase
  130.                 msg = SAY_REGEX.match(m.message)[:msg]
  131.                 bot.Channel(CHANNEL_NAME).msg msg
  132.             end
  133.         end
  134.        
  135.         # on :message, WOLFRAM_REGEX do |m|
  136.             # query = WOLFRAM_REGEX.match(m.message)[:query]
  137.             # result = Wolfram.fetch(query)
  138.             ## puts result
  139.             # hash = Wolfram::HashPresenter.new(result).to_hash
  140.             ## puts hash
  141.             # m.reply(hash[:pods]['Result'][0])
  142.         # end
  143.        
  144.         on :message, WOLFRAM_REGEX do |m|
  145.             query = WOLFRAM_REGEX.match(m.message)[:query]
  146.             result = Wolfram.fetch(query)
  147.             sprintf "%s", result
  148.             gsub(" Clash  - Input nterpretation: ", "")
  149.             m.reply result.inspect[0 .. 300]
  150.                 .gsub("a:", "answer:")
  151.                 .gsub("Math\n", "")
  152.                 .gsub(/\bAdministrativeDivision,|Airport,|City,|MetropolitanArea,|Ocean \(|assumptions: |Clash, |SubCategory|\)|Input*interpretation:*?\b\i/, "")
  153.                 .gsub("\n", "")
  154.                 .gsub(/\banswer:*|   - Input: [\d\(\)\+\-\*\/\.][\d\(\)\+\-\*\/\.][\d\(\)\+\-\*\/\.]   - |\b\i/, "")
  155.                 # .gsub(/\b(Clash|City)  - Input nterpretation:[ ]|\b\i/, "")
  156.                 # .gsub(/\banswer:  answer:  \b\i/, "answer: ")
  157.                 # .gsub("\n", "|")
  158.             #result.inspect[0 .. 256].gsub("\n", "|")
  159.             #.subpods[0].plaintext
  160.             #result.assumptions[0][1].requery.fetch
  161.             #result.inspect.to_s#
  162.             #[0 .. 256].gsub("\n", " | ")
  163.         end
  164.        
  165.         on :message, GOOGLE_REGEX do |m, params|
  166.             m.reply google(params)
  167.         end
  168.    
  169.         on :message, BASH_REGEX do |m|
  170.             m.reply Bash.Random_Quote.gsub(/</, "\n<").gsub("\n", "")
  171.         end
  172.        
  173.         # on :message, WIKIPEDIA_REGEX do |m, query|
  174.             # m.reply wikipedia(query)
  175.         # end
  176.        
  177.         # on :message, "wykop" do |m|
  178.             # m.reply("Obraża papieża.")
  179.         # end
  180.        
  181.         on :message, ":lenny:" do |m|
  182.             if m.user.to_s.downcase == /\bCy(c|s)io(land)\i/
  183.                 m.reply("NOPE.")
  184.             else
  185.                 m.reply("( ͡° ͜ʖ ͡°)")
  186.             end
  187.         end
  188.            
  189.         on :message, LENNYFACE do |m|
  190.             if m.user.to_s.downcase == ADMIN.downcase
  191.                 m.reply("( ͡° ͜ʖ ͡°)")
  192.             else
  193.                 m.reply("NIE DLA PSA LENNYFACE. ( ͡° ͜ʖ ͡°)")
  194.                 bot.irc.send("kick #{CHANNEL_NAME} #{m.user.nick} #{m.user.nick} pls: NIE DLA PSA LENNYFACE. ( ͡° ͜ʖ ͡°)")
  195.             end
  196.         end
  197.  
  198.         on :message, NIGGA_REGEX do |m|
  199.             m.reply("https://www.youtube.com/watch?v=LsR2dKu5NYM&feature=youtu.be&t=7m4s")
  200.         end
  201.        
  202.         # on :message, LENNY_REGEX do |m|
  203.             # if m.user.to_s.downcase == ADMIN.downcase
  204.                 # m.reply("( ͡° ͜ʖ ͡°)")
  205.             # else
  206.                 # m.reply("NIE DLA PSA LENNYFACE. ( ͡° ͜ʖ ͡°)")
  207.                 # bot.irc.send("kick #{CHANNEL_NAME} #{m.user.nick} #{m.user.nick} pls: NIE DLA PSA LENNYFACE. ( ͡° ͜ʖ ͡°)")
  208.             # end
  209.         # end
  210.        
  211.         on :message, HOP_REGEX do |m|
  212.             m.reply("sam se kurna skacz")
  213.         end
  214.        
  215.         # on :message, WYKOP_REGEX do |m|
  216.             # m.reply("Więc to tutaj obraża się papieża!")
  217.         # end
  218.        
  219.         on :message, DELETE_ACCOUNT do |m|
  220.             m.reply("sam se usuń")
  221.             bot.irc.send("kick #{CHANNEL_NAME} #{m.user.nick} sam se usuń")
  222.         end
  223.        
  224.         # on :message, LUNUX_REGEX do |m|
  225.             # if m.user.to_s.downcase != "nvll".downcase
  226.                 # m.reply("#{m.user.nick} pls")
  227.                 # bot.irc.send("kick #{CHANNEL_NAME} #{m.user.nick} #{m.user.nick} pls")
  228.             # end
  229.         # end
  230.     end
  231.     bot.start
  232. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement