Last active
December 16, 2015 08:19
-
-
Save hakobe/5405502 to your computer and use it in GitHub Desktop.
前後日に放送の深夜アニメをIRCに通知
This file contains hidden or 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
config.yml | |
vendor | |
*.gem | |
*.rbc | |
.bundle | |
.config | |
coverage | |
InstalledFiles | |
lib/bundler/man | |
pkg | |
rdoc | |
spec/reports | |
test/tmp | |
test/version_tmp | |
tmp |
This file contains hidden or 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
syoboi_calendar: | |
user: user | |
pass: pass | |
irc: | |
host: hoge | |
port: 6667 | |
pass: fuga | |
nick: syoboi | |
channels: | |
- "#anime" | |
character_set: iso-2022-jp |
This file contains hidden or 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
source 'https://rubygems.org' | |
gem 'cinch' | |
gem 'syoboi_calendar' |
This file contains hidden or 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
GEM | |
remote: https://rubygems.org/ | |
specs: | |
cinch (2.0.4) | |
domain_name (0.5.11) | |
unf (>= 0.0.5, < 1.0.0) | |
mechanize (2.6.0) | |
domain_name (~> 0.5, >= 0.5.1) | |
mime-types (~> 1.17, >= 1.17.2) | |
net-http-digest_auth (~> 1.1, >= 1.1.1) | |
net-http-persistent (~> 2.5, >= 2.5.2) | |
nokogiri (~> 1.4) | |
ntlm-http (~> 0.1, >= 0.1.1) | |
webrobots (>= 0.0.9, < 0.2) | |
mime-types (1.22) | |
net-http-digest_auth (1.3) | |
net-http-persistent (2.8) | |
nokogiri (1.5.9) | |
ntlm-http (0.1.1) | |
syoboi_calendar (0.1.3) | |
mechanize (>= 2.3) | |
unf (0.1.1) | |
unf_ext | |
unf_ext (0.0.6) | |
webrobots (0.1.1) | |
PLATFORMS | |
ruby | |
DEPENDENCIES | |
cinch | |
syoboi_calendar |
This file contains hidden or 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
# encoding: utf-8 | |
require 'cinch' | |
require 'syoboi_calendar' | |
require 'yaml' | |
Config = YAML.load_file('./config.yml') | |
def irc_message(msg) | |
result = msg.encode( Config['irc']['character_set'] ) | |
result.force_encoding('binary') | |
result | |
end | |
class Yukari | |
include Cinch::Plugin | |
def initialize(*args) | |
super | |
@yeah_count = 0 | |
end | |
match /fu/i, method: :fu | |
def fu(m) | |
m.channel.msg irc_message("Happy♪ fancy♪ Babydoll〜♪"), true | |
end | |
match /yeah/i, method: :yeah | |
def yeah(m) | |
if @yeah_count == 0 | |
m.channel.msg irc_message("Love me♪ fancy♪ Babydoll〜♪"), true | |
else | |
m.channel.msg irc_message("世界一! かわいい子に! 生まれたかった〜♪"), true | |
end | |
@yeah_count = (@yeah_count - 1) * -1 | |
end | |
end | |
class Hello | |
include Cinch::Plugin | |
match /hi/, method: :hi | |
def hi(m) | |
m.channel.msg irc_message("どうも"), true | |
end | |
end | |
class Syoboi | |
include Cinch::Plugin | |
WEEK_DAYS = %w(日 月 火 水 木 金 土) | |
def initialize(*args) | |
super | |
@client = SyoboiCalendar.new( | |
user: Config['syoboi_calendar']['user'], | |
pass: Config['syoboi_calendar']['pass'], | |
) | |
end | |
match /r(?:ecent)?/, method: :recent | |
def recent(m) | |
@client.search( | |
range: [ | |
Time.now - 60 * 60 * 24, | |
Time.now + 60 * 60 * 24 | |
].map { |i| Time.at(i).strftime("%Y/%m/%d") }.join("-") | |
).find_all {|program| | |
start_time = program.start_time | |
program.title.cat == "1" && # アニメ | |
(( 22 <= start_time.hour && start_time.hour <= 23) || ( 0 <= start_time.hour && start_time.hour <= 5)) | |
}.each {|program| | |
time = program.start_time | |
month = time.month | |
day = time.day | |
hour = time.hour | |
minute = time.min | |
wday = WEEK_DAYS[time.wday] | |
if 0 <= time.hour and time.hour <= 5 | |
hour += 24 | |
day -= 1 | |
wday = WEEK_DAYS[ (time.wday - 1) % 7 ] | |
end | |
m.channel.msg irc_message("[#{ month }月#{ day }日(#{wday}) #{hour}:#{ "%02d" % minute }〜] #{program.name} (#{program.channel_name})"), true | |
} | |
end | |
match /s(?:earch)? (.*)/, method: :search | |
def search(m, query) | |
query.force_encoding(Config['irc']['character_set']) | |
results = @client.search( | |
mode: :title, | |
keyword: query.encode('utf-8'), | |
range: :all, | |
) | |
if results.size > 0 | |
results.slice(0,5).each {|title| | |
m.channel.msg irc_message("#{ title.name } 公式:#{ title.url || '-'} 放送予定:http://cal.syoboi.jp/tid/#{ title.tid }"), true | |
} | |
else | |
m.channel.msg irc_message("見つからなんだ"), true | |
end | |
end | |
end | |
bot = Cinch::Bot.new do | |
configure do |c| | |
c.server = Config['irc']['host'] | |
c.port = Config['irc']['port'] | |
c.nick = Config['irc']['nick'] | |
c.password = Config['irc']['pass'] | |
c.channels = Config['irc']['channels'] | |
c.plugins.plugins = [Syoboi, Hello, Yukari] | |
end | |
end | |
bot.start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment