Testing using login as a global variable. this way i only need to control 1 instance of serveradmin

This commit is contained in:
promostarr 2017-04-17 15:44:24 +01:00
parent 0c1e45907b
commit 4cdee5c61f
3 changed files with 53 additions and 49 deletions

44
.idea/workspace.xml generated
View file

@ -3,7 +3,7 @@
<component name="ChangeListManager">
<list default="true" id="ecb21532-0ae7-441d-90a8-4b144fd51290" name="Default" comment="">
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/Janitor.rb" afterPath="$PROJECT_DIR$/Janitor.rb" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/core.rb" afterPath="$PROJECT_DIR$/core.rb" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/notification.rb" afterPath="$PROJECT_DIR$/notification.rb" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="TRACKING_ENABLED" value="true" />
@ -15,21 +15,21 @@
<component name="ExecutionTargetManager" SELECTED_TARGET="default_target" />
<component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file leaf-file-name="Janitor.rb" pinned="false" current-in-tab="true">
<file leaf-file-name="Janitor.rb" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/Janitor.rb">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="200">
<caret line="13" column="22" lean-forward="true" selection-start-line="13" selection-start-column="22" selection-end-line="13" selection-end-column="22" />
<state relative-caret-position="769">
<caret line="86" column="29" lean-forward="false" selection-start-line="86" selection-start-column="29" selection-end-line="86" selection-end-column="29" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="notification.rb" pinned="false" current-in-tab="false">
<file leaf-file-name="notification.rb" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/notification.rb">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="369">
<caret line="20" column="13" lean-forward="true" selection-start-line="20" selection-start-column="13" selection-end-line="20" selection-end-column="13" />
<state relative-caret-position="100">
<caret line="5" column="4" lean-forward="true" selection-start-line="5" selection-start-column="4" selection-end-line="5" selection-end-column="4" />
<folding />
</state>
</provider>
@ -53,8 +53,8 @@
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/notification.rb" />
<option value="$PROJECT_DIR$/core.rb" />
<option value="$PROJECT_DIR$/notification.rb" />
<option value="$PROJECT_DIR$/Janitor.rb" />
</list>
</option>
@ -269,12 +269,12 @@
<option name="presentableId" value="Default" />
<updated>1492353576138</updated>
<workItem from="1492353577745" duration="1817000" />
<workItem from="1492433677612" duration="5209000" />
<workItem from="1492433677612" duration="6539000" />
</task>
<servers />
</component>
<component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="7026000" />
<option name="totallyTimeSpent" value="8356000" />
</component>
<component name="ToolWindowManager">
<frame x="0" y="27" width="1920" height="1020" extended-state="6" />
@ -284,11 +284,11 @@
<window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
<window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="true" content_ui="tabs" />
<window_info id="Database" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.26859045" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.26859045" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.22530521" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.22530521" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="true" content_ui="tabs" />
<window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
@ -334,14 +334,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/notification.rb">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="369">
<caret line="20" column="13" lean-forward="true" selection-start-line="20" selection-start-column="13" selection-end-line="20" selection-end-column="13" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/core.rb">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="640">
@ -352,8 +344,16 @@
</entry>
<entry file="file://$PROJECT_DIR$/Janitor.rb">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="200">
<caret line="13" column="22" lean-forward="true" selection-start-line="13" selection-start-column="22" selection-end-line="13" selection-end-column="22" />
<state relative-caret-position="769">
<caret line="86" column="29" lean-forward="false" selection-start-line="86" selection-start-column="29" selection-end-line="86" selection-end-column="29" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/notification.rb">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="100">
<caret line="5" column="4" lean-forward="true" selection-start-line="5" selection-start-column="4" selection-end-line="5" selection-end-column="4" />
<folding />
</state>
</provider>

View file

@ -2,11 +2,15 @@ require 'teamspeak-ruby'
class Janitor
debug_mode = true
$ts = Teamspeak::Client.new('ts3.vereto.net')
def new
$ts = login()
end
def login()
ts = Teamspeak::Client.new('ts3.vereto.net')
ts.login('serveradmin', ENV["SrvQry"].dup)
ts.command('use', {sid: 1})
$ts.login('serveradmin', ENV["SrvQry"].dup)
$ts.command('use', {sid: 1})
return ts
end
@ -15,53 +19,51 @@ class Janitor
end
def gsay(msg)
ts = login()
if debug_mode == true
ts.command('sendtextmessage', {targetmode: 3, target: 1, msg: msg})
$ts.command('sendtextmessage', {targetmode: 3, target: 1, msg: msg})
else
ts.command('sendtextmessage', {targetmode: 1, target: 13, msg: msg})
$ts.command('sendtextmessage', {targetmode: 1, target: 13, msg: msg})
end
end
def listen(global)
ts = login()
if global == true
return ts.command('servernotifyregister', event: 'textserver')[0]['msg']
return $ts.command('servernotifyregister', event: 'textserver')[0]
else
move_self('218')
return ts.command('servernotifyregister', event: 'textchannel', id: '218' )[0]['msg']
return $ts.command('servernotifyregister', event: 'textchannel', id: '218' )[0]
end
end
def get_clients()
ts = login()
return ts.command('clientlist')
return $ts.command('clientlist')
end
def get_channels()
ts = login()
return ts.command('channellist')
return $ts.command('channellist')
end
def find_client(name)
ts = login()
return ts.command('clientfind', {pattern: name.to_s})
#//This doesnt seem to work very well
return $ts.command('clientfind', {pattern: name.to_s})
end
def whoami()
return $ts.command('whoami')
end
def move_client(clid, cid)
ts = login()
return ts.command('clientmove', clid: clid, cid: cid)
return $ts.command('clientmove', clid: clid, cid: cid)
end
def move_self(cid)
return move_client(find_client('serveradmin from'), cid)
return move_client(find_client('serveradmin from')[0]['clid'], cid)
end
def check_channels()
ts = login()
server_info = ts.command('serverinfo')
def check_channels()
server_info = $ts.command('serverinfo')
t = server_info['virtualserver_uptime']
mm, ss = t.divmod(60) #=> [4515, 21]
@ -71,18 +73,18 @@ class Janitor
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
ts.command('channellist').each do |channel|
$ts.command('channellist').each do |channel|
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!"
ts.command('channeledit', cid: channel['cid'], channel_codec_quality: 9)
$ts.command('channeledit', cid: channel['cid'], channel_codec_quality: 9)
end
ts.command('clientlist').each do |user|
$ts.command('clientlist').each do |user|
if user['cid'] == channel['cid']
server_groups = ts.command('servergroupsbyclientid', cldbid: user['client_database_id'])
server_groups = $ts.command('servergroupsbyclientid', cldbid: user['client_database_id'])
puts "--------" << user['client_nickname'] << "(" << user['clid'].to_s << ")" << "[" << server_groups[0]["name"].to_s << "]"
end
end

View file

@ -6,8 +6,10 @@
jan = Janitor.new
while (i > 0)
begin
cmd = jan.listen(false)
puts cmd
return_report = jan.listen(false)
invokerid = return_report['invokerid']
cmd = return_report['msg']
puts cmd + " - " + invokerid.to_s
if cmd == '!help'
msg = "I am Janitor, you can tell me to do things."
jan.gsay(msg)