Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require "cinch"
- require "open-uri"
- require "nokogiri"
- require "cgi"
- require "wolfram"
- Wolfram.appid = "APP_ID"
- ADMIN = "Linux_Shines"
- TESTING = false
- HOP_REGEX = /^!hop (.+)/i
- LENNYFACE = /^( ͡° ͜ʖ ͡°)(.+)/i
- CALC_REGEX = /\A% (?<query>.*)\z/i
- WYKOP_REGEX = /^*wykop*(.+)/i
- GOOGLE_REGEX = /^!g (.+)/i
- bot = Cinch::Bot.new do
- helpers do
- def is_admin?(user)
- true if user.nick == ADMIN
- end
- def google(query)
- url = "http://www.google.pl/search?q=#{CGI.escape(query)}"
- res = Nokogiri::HTML(open(url)).at("h3.r")
- title = res.text
- link = res.at('a')[:href]
- desc = res.at("./following::div").children.first.text
- rescue
- "Nie znaleziono żadnych wyników."
- else
- CGI.unescape_html(CGI.unescape("#{title} - #{desc} (#{link})")).force_encoding("ISO-8859-2").encode("UTF-8")
- #"#{title} - #{desc} (#{link})")
- #.force_encoding('ISO-8859-2').encode('UTF-8')
- end
- end
- configure do |c|
- c.server = "irc.pirc.pl"
- if TESTING == true
- c.channels = [ "#testingchannel" ]
- elsif TESTING == false
- c.channels = [ "#mirkofm" ]
- end
- c.nick = "Lunux_"
- c.password = "HASŁO"
- c.plugins.plugins = [Lunux_]
- end
- # if TESTING == true
- on :message, "test" do |m|
- m.reply("Testowana wiadomość skierowana do użytkownika #{m.user.nick}")
- end
- # end
- on :message, CALC_REGEX do |m|
- query = CALC_REGEX.match(m.message)[:query]
- result = Wolfram.fetch(query)
- # puts result
- hash = Wolfram::HashPresenter.new(result).to_hash
- # puts hash
- m.reply(hash[:pods]['Result'][0] || "Nie.", true)
- end
- on :message, GOOGLE_REGEX do |m, query|
- m.reply google(query)
- end
- on :message, "wykop" do |m|
- m.reply("Obraża papieża.")
- end
- on :message, LENNYFACE do |m|
- m.reply(LENNYFACE)
- end
- on :message, HOP_REGEX do |m|
- m.reply("sam se kurna skacz")
- end
- on :message, WYKOP_REGEX do |m|
- m.reply("Więc to tutaj obraża się papieża!")
- end
- end
- bot.start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement