2017-04-16 14:42:59 +01:00
|
|
|
require 'teamspeak-ruby'
|
|
|
|
|
|
|
|
|
|
class Janitor
|
2017-04-17 14:50:39 +01:00
|
|
|
debug_mode = true
|
2017-04-17 15:44:24 +01:00
|
|
|
$ts = Teamspeak::Client.new('ts3.vereto.net')
|
|
|
|
|
def new
|
|
|
|
|
$ts = login()
|
|
|
|
|
end
|
2017-04-17 14:50:39 +01:00
|
|
|
|
2017-04-16 14:42:59 +01:00
|
|
|
def login()
|
2017-04-17 15:44:24 +01:00
|
|
|
|
|
|
|
|
$ts.login('serveradmin', ENV["SrvQry"].dup)
|
|
|
|
|
$ts.command('use', {sid: 1})
|
2017-04-16 14:42:59 +01:00
|
|
|
return ts
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def roll()
|
|
|
|
|
return 1 + rand(6)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def gsay(msg)
|
2017-04-17 14:50:39 +01:00
|
|
|
if debug_mode == true
|
2017-04-17 15:44:24 +01:00
|
|
|
$ts.command('sendtextmessage', {targetmode: 3, target: 1, msg: msg})
|
2017-04-17 14:50:39 +01:00
|
|
|
else
|
2017-04-17 15:44:24 +01:00
|
|
|
$ts.command('sendtextmessage', {targetmode: 1, target: 13, msg: msg})
|
2017-04-17 14:50:39 +01:00
|
|
|
end
|
|
|
|
|
|
2017-04-16 14:42:59 +01:00
|
|
|
end
|
|
|
|
|
|
2017-04-17 14:07:32 +01:00
|
|
|
def listen(global)
|
2017-04-17 14:08:44 +01:00
|
|
|
if global == true
|
2017-04-17 15:44:24 +01:00
|
|
|
return $ts.command('servernotifyregister', event: 'textserver')[0]
|
2017-04-17 14:07:32 +01:00
|
|
|
else
|
2017-04-17 14:50:39 +01:00
|
|
|
move_self('218')
|
2017-04-17 15:44:24 +01:00
|
|
|
return $ts.command('servernotifyregister', event: 'textchannel', id: '218' )[0]
|
2017-04-17 14:07:32 +01:00
|
|
|
end
|
2017-04-16 14:42:59 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def get_clients()
|
2017-04-17 15:44:24 +01:00
|
|
|
return $ts.command('clientlist')
|
2017-04-16 14:42:59 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def get_channels()
|
2017-04-17 15:44:24 +01:00
|
|
|
return $ts.command('channellist')
|
2017-04-16 14:42:59 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def find_client(name)
|
2017-04-17 15:44:24 +01:00
|
|
|
#//This doesnt seem to work very well
|
|
|
|
|
return $ts.command('clientfind', {pattern: name.to_s})
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def whoami()
|
|
|
|
|
return $ts.command('whoami')
|
2017-04-16 14:42:59 +01:00
|
|
|
end
|
|
|
|
|
|
2017-04-17 14:50:39 +01:00
|
|
|
def move_client(clid, cid)
|
2017-04-17 15:44:24 +01:00
|
|
|
return $ts.command('clientmove', clid: clid, cid: cid)
|
2017-04-17 14:50:39 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def move_self(cid)
|
2017-04-17 15:44:24 +01:00
|
|
|
return move_client(find_client('serveradmin from')[0]['clid'], cid)
|
2017-04-17 14:50:39 +01:00
|
|
|
end
|
|
|
|
|
|
2017-04-16 14:42:59 +01:00
|
|
|
|
2017-04-17 15:44:24 +01:00
|
|
|
def check_channels()
|
|
|
|
|
server_info = $ts.command('serverinfo')
|
2017-04-16 14:42:59 +01:00
|
|
|
|
|
|
|
|
t = server_info['virtualserver_uptime']
|
|
|
|
|
mm, ss = t.divmod(60) #=> [4515, 21]
|
|
|
|
|
hh, mm = mm.divmod(60) #=> [75, 15]
|
|
|
|
|
dd, hh = hh.divmod(24) #=> [3, 3]
|
|
|
|
|
|
|
|
|
|
puts "Server has been online for: %d days, %d hours, %d minutes and %d seconds" % [dd, hh, mm, ss]
|
|
|
|
|
puts "Clients Online: " + server_info['virtualserver_clientsonline'].to_s
|
|
|
|
|
|
2017-04-17 15:44:24 +01:00
|
|
|
$ts.command('channellist').each do |channel|
|
2017-04-16 14:42:59 +01:00
|
|
|
channel_quality = ts.command('channelinfo', cid: channel['cid'])['channel_codec_quality']
|
|
|
|
|
puts "(" << channel['cid'].to_s << ")" << channel['channel_name'] << "| [Codec] " << channel_quality.to_s
|
|
|
|
|
|
|
|
|
|
if channel_quality != 9
|
|
|
|
|
puts "Needs set!"
|
2017-04-17 15:44:24 +01:00
|
|
|
$ts.command('channeledit', cid: channel['cid'], channel_codec_quality: 9)
|
2017-04-16 14:42:59 +01:00
|
|
|
end
|
|
|
|
|
|
2017-04-17 15:44:24 +01:00
|
|
|
$ts.command('clientlist').each do |user|
|
2017-04-16 14:42:59 +01:00
|
|
|
if user['cid'] == channel['cid']
|
2017-04-17 15:44:24 +01:00
|
|
|
server_groups = $ts.command('servergroupsbyclientid', cldbid: user['client_database_id'])
|
2017-04-16 14:42:59 +01:00
|
|
|
puts "--------" << user['client_nickname'] << "(" << user['clid'].to_s << ")" << "[" << server_groups[0]["name"].to_s << "]"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|