Last active
December 19, 2015 17:19
-
-
Save RoxasShadow/5990649 to your computer and use it in GitHub Desktop.
Crunchyroll bot for IRC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
# Version 2, December 2004 | |
# | |
# Everyone is permitted to copy and distribute verbatim or modified | |
# copies of this license document, and changing it is allowed as long | |
# as the name is changed. | |
# | |
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
# | |
# 0. You just DO WHAT THE FUCK YOU WANT TO. | |
## | |
require 'cinch' | |
require 'cinch/plugins/login' | |
require 'open-uri' | |
require 'nokogiri' | |
require 'date' | |
class DateTime | |
def time_left(date) | |
a = self.to_time - 1*60*60 | |
secs = (a - date.to_time).to_int | |
mins = secs / 60 | |
hours = mins / 60 | |
days = hours / 24 | |
"#{days} days, #{hours % 24} hours, #{mins % 60} minutes and #{secs % 60} seconds" | |
end | |
def date_of_next | |
delta = self > DateTime.now ? 0 : 7 | |
self + delta | |
end | |
end | |
class Fixnum | |
def fix | |
self > 9 ? self.to_s : "0#{self}" | |
end | |
end | |
class String | |
def to_ita | |
day_eng = [ 'Sundays', 'Mondays', 'Tuesdays', 'Wednesdays', 'Thursdays', 'Fridays', 'Saturdays' ] | |
day_ita = [ 'Domenica', 'Lunedì', 'Martedì', 'Mercoledì', 'Giovedì', 'Venerdì', 'Sabato' ] | |
tim_eng = [ 'days', 'hours', 'minutes', 'seconds' ] | |
tim_ita = [ 'giorni', 'ore', 'minuti', 'secondi' ] | |
self.tap { |s| | |
0.upto(6) { |i| s.gsub! day_eng[i], day_ita[i] } | |
0.upto(3) { |i| s.gsub! tim_eng[i], tim_ita[i] } | |
s.gsub! 'and', 'e' | |
} | |
end | |
end | |
Cinch::Bot.new { | |
configure { |c| | |
c.nick = 'Crunchyroll`' | |
c.realname = 'Crunchyroll`' | |
c.user = 'Crunchyroll`' | |
c.server = 'irc.rizon.net' | |
c.channels = ['#aggvistnurummor'] | |
c.plugins.plugins = [Cinch::Plugins::Login] | |
c.plugins.options[Cinch::Plugins::Login] = { :password => 'dat_password' } | |
} | |
on :message, /^.cr (.+)$/i do |m, name| | |
begin | |
url = '' | |
title = '' | |
cr = 'http://www.uswebproxy.com/index.php?q=aHR0cDovL3d3dy5jcnVuY2h5cm9sbC5jb20vbGluZXVw&hl=3ed' | |
Nokogiri::HTML(open(cr)).xpath('//div[@class="anime-grid-item"]').each { |r| | |
tmp = r.xpath('.//a/div/text()').to_s | |
if tmp.downcase.include? name.downcase | |
title = r.xpath('.//a/div/text()').to_s | |
url = r.xpath('.//a/@href') .to_s | |
break | |
end | |
} | |
raise 'Anime not found' if title.empty? || url.empty? | |
air = Nokogiri::HTML(open(url)).xpath('//ul[@id="sidebar_elements"]/li')[1].xpath('.//p')[0].text | |
day_literal = air.split('Simulcast on ')[1].split(' ')[0] | |
date = DateTime.parse(air.split('Simulcast on ')[1]).date_of_next | |
# m.reply "#{Format(:red, title)} is a series airing on #{Format(:red, 'Crunchyroll')} at #{Format(:red, day_literal)} #{Format(:red, date.hour.fix)}:#{Format(:red, date.min.fix)} which is in #{Format(:red, date.time_left(DateTime.now))}." | |
m.reply "#{Format(:red, title)} è una serie trasmessa da #{Format(:red, 'Crunchyroll')} il #{Format(:red, day_literal.to_ita)} alle #{Format(:red, date.hour.fix)}:#{Format(:red, date.min.fix)}, cioè tra #{Format(:red, date.time_left(DateTime.now).to_ita)}." | |
rescue | |
# m.reply Format(:red, 'Anime not found') | |
m.reply Format(:red, 'Anime non trovato') | |
end | |
end | |
}.start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment