Skip to content

Instantly share code, notes, and snippets.

@sorah
Created December 16, 2010 05:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sorah/743090 to your computer and use it in GitHub Desktop.
Save sorah/743090 to your computer and use it in GitHub Desktop.
#encoding: utf-8
require 'nokogiri'
require 'net/irc'
BOTNICK = "Glass_bot"
class TCEBot < Net::IRC::Client
def initialize(*args)
super
@active = []
Thread.start do
loop do
active
sleep 300
end
end
end
def on_rpl_welcome(m)
# post JOIN, "#bot_test" #テスト用チャンネル
post JOIN, "#pasratce"
post JOIN, "#NonPB_OBJ"
post JOIN, "#stepup"
post JOIN, "#pasrasan"
end
def on_ping(m)
post PONG, BOTNICK
end
def active
puts "active"
@active_hash = []
Nokogiri(`qstat -xml -u -q3m,84 etmaster.idsoftware.com:27950`).search("server").each do |data|
if data[:type] == "Q3S" && data.at("gametype").inner_text == "tcetest" && data.at("numplayers").inner_text.to_i > 0
@active_hash << {
:name => data.at("name").inner_text,
:addr => data.at("hostname").inner_text,
:map => data.at("map").inner_text,
:users => data.at("numplayers").inner_text.to_i,
:max => data.at("maxplayers").inner_text.to_i
}
end
end
@active = @active_hash.sort{|b,a| a[:users] <=> b[:users]}.map do |server|
"#{server[:name]} /connect #{server[:addr]} @ #{server[:map]} (#{server[:users]}/#{server[:max]}人)".encode!("iso-2022-jp")
end
end
def srv(name,m,ip)
data = Nokogiri(`qstat -xml -P -q3s #{ip}`)
if data.at("server")[:status] == "UP"
post NOTICE, m[0],"#{data.at("name").inner_text} /connect #{ip} @#{data.at("map").inner_text} (#{data.at("numplayers").inner_text}/#{data.at("maxplayers").inner_text}人)".encode!("iso-2022-jp")
else
post NOTICE, m[0],"鯖落ち: #{name} ( #{ip} )".encode!("iso-2022-jp")
end
end
def on_privmsg(m)
m[1].encode!("utf-8")
case m[1]
when /^tce$/ui
srv("CTF for All People",m,"113.151.8.227:27960")
srv("CTF for All People 2 [sv_fps 40, PB]",m,"113.151.8.227:27962")
if m[0] != "#NonPB_OBJ"
srv("NonPB[official]OBJ",m,"202.231.146.178:27961")
srv("NonPB[official]BC",m,"202.231.146.178:27962")
end
srv("AsunoSekaiwoMegassamoriageru [DEVELOP]TCE_Custom 0.49b! fixed",m,"113.151.8.227:27961")
when /^CTF$/ui
srv("CTF for All People",m,"113.151.8.227:27960")
when /^CTF-PB$/ui
srv("CTF for All People 2 [sv_fps 40, PB]",m,"113.151.8.227:27962")
when /^non(pb)?$/ui
print "\n"
p m[0]
if m[0] != "#NonPB_OBJ"
srv("NonPB[official]OBJ",m,"202.231.146.178:27961")
srv("NonPB[official]BC",m,"202.231.146.178:27962")
end
when /^asuno[a-z]*$/ui
srv("AsunoSekaiwoMegassamoriageru [DEVELOP]TCE_Custom 0.49b! fixed",m,"113.151.8.227:27961")
when /^active$/ui
@active.each do |i|
post NOTICE, m[0],i
sleep 0.5
end
when /^active\.new$/ui
post NOTICE, m[0],"しばらくお待ちください".encode!("iso-2022-jp")
active
@active.each do |i|
post NOTICE, m[0],i
sleep 0.5
end
when /^びゃっこ鯖$/ui
srv("びゃっこ鯖",m,"59.143.50.237:27960")
when /^まっち2$/ui
srv("まっち2",m,"58.190.88.141:27960")
when /^やばし鯖$/ui
srv("やばし鯖 5on5",m,"yabasi.mydns.jp:27961") if m[0] != "#NonPB_OBJ"
end
post NOTICE, m[0],"http://sheen.esel-project.net/add/".encode!("iso-2022-jp") if /^sheen$/i =~ m[1]
post NOTICE, m[0],"http://tce.privs.net/add/".encode!("iso-2022-jp") if /^privs$/i =~ m[1]
end
end
TCEBot.new("irc.friend-chat.jp", "6667", { :nick => BOTNICK,:user => BOTNICK,:real => BOTNICK}).start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment