Skip to content

Instantly share code, notes, and snippets.

@sorah sorah/gist:719566
Created Nov 29, 2010

Embed
What would you like to do?
#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"
end
def on_ping(m)
post PONG, BOTNICK
end
def 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)
case m[1]
when /^tce$/i
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$/i
srv("CTF for All People",m,"113.151.8.227:27960")
when /^CTF-PB$/i
srv("CTF for All People 2 [sv_fps 40, PB]",m,"113.151.8.227:27962")
when /^non(pb)?$/i
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]*$/i
srv("AsunoSekaiwoMegassamoriageru [DEVELOP]TCE_Custom 0.49b! fixed",m,"113.151.8.227:27961")
when /^active$/i
active if /^active.new$/i =~ m[1]
@active.each do |i|
post NOTICE, m[0],i
sleep 0.5
end
end
case m[1].dup.force_encoding("iso-2022-jp")
when "びゃっこ鯖".encode("iso-2022-jp")
srv("びゃっこ鯖",m,"59.143.50.237:27960")
when "まっち2".encode("iso-2022-jp")
srv("まっち2",m,"58.190.88.141:27960")
when "やばし鯖".encode("iso-2022-jp")
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
You can’t perform that action at this time.