Last active
October 27, 2015 06:12
-
-
Save lancepioch/2e38429795a7fd1f2696 to your computer and use it in GitHub Desktop.
This file contains 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
<?php | |
namespace Hardwire\Console\Commands; | |
use Illuminate\Console\Command; | |
use TeamSpeak3; | |
class CopyChannelsCommand extends Command | |
{ | |
/** | |
* The name and signature of the console command. | |
* | |
* @var string | |
*/ | |
protected $signature = 'teamspeak:copy-channels'; | |
/** | |
* The console command description. | |
* | |
* @var string | |
*/ | |
protected $description = 'Copies channel structure from one teamspeak to another'; | |
/** | |
* Create a new command instance. | |
* | |
* @return void | |
*/ | |
public function __construct() | |
{ | |
parent::__construct(); | |
} | |
/** | |
* Execute the console command. | |
* | |
* @return mixed | |
*/ | |
public function handle() | |
{ | |
$teamspeakServer = TeamSpeak3::factory('serverquery://admin:abcdefg@ts.hardwiregaming.com:9100/?server_port=9258'); | |
$new = TeamSpeak3::factory('serverquery://admin:abcdefg@abc.sandwich.com:10011/?server_port=9987'); | |
$channels = $teamspeakServer->channelList(); | |
$structure = []; | |
$matching = [0 => 0]; | |
foreach ($channels as $channel) { | |
$structure[$channel->cid] = $channel->pid; | |
$pid = $matching[$channel->pid]; | |
$cid = $new->channelCreate([ | |
'channel_name' => $channel->channel_name, | |
'channel_topic' => $channel->channel_topic, | |
'channel_flag_permanent' => 1, | |
'pid' => $pid, // doesn't work for some reason | |
]); | |
if ($pid != 0) | |
$new->channelMove($cid, $matching[$channel->pid]); | |
$matching[$channel->cid] = $cid; | |
} | |
} | |
} |
This file contains 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
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/css/select2.min.css"> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/js/select2.full.min.js"></script> | |
<script> | |
function formatRepo (repo) { | |
if (repo.loading) return repo.text; | |
var markup = '<div class="clearfix">' + | |
'<div class="col-sm-1">' + | |
'<img src="' + repo.owner.avatar_url + '" style="max-width: 100%" />' + | |
'</div>' + | |
'<div clas="col-sm-10">' + | |
'<div class="clearfix">' + | |
'<div class="col-sm-6">' + repo.full_name + '</div>' + | |
'<div class="col-sm-3"><i class="fa fa-code-fork"></i> ' + repo.forks_count + '</div>' + | |
'<div class="col-sm-2"><i class="fa fa-star"></i> ' + repo.stargazers_count + '</div>' + | |
'</div>'; | |
if (repo.description) { | |
markup += '<div>' + repo.description + '</div>'; | |
} | |
markup += '</div></div>'; | |
return markup; | |
} | |
function formatRepoSelection (repo) { | |
return repo.full_name || repo.text; | |
} | |
$(function() { | |
$(".steamUsers").select2({ | |
ajax: { | |
url: "https://api.github.com/search/repositories", | |
dataType: 'json', | |
delay: 250, | |
data: function (params) { | |
return { | |
q: params.term, // search term | |
page: params.page | |
}; | |
}, | |
processResults: function (data, params) { | |
// parse the results into the format expected by Select2 | |
// since we are using custom formatting functions we do not need to | |
// alter the remote JSON data, except to indicate that infinite | |
// scrolling can be used | |
params.page = params.page || 1; | |
return { | |
results: data.items, | |
pagination: { | |
more: (params.page * 30) < data.total_count | |
} | |
}; | |
}, | |
cache: true | |
}, | |
escapeMarkup: function (markup) { | |
return markup; | |
}, | |
minimumInputLength: 1, | |
templateResult: formatRepo, | |
templateSelection: formatRepoSelection | |
}); | |
}); | |
</script> | |
<table> | |
<tr><th>Teamspeak Name</th><th>Teamspeak Id</th><th style="width: 200px;">Steam Id</th></tr> | |
@foreach ($clients as $client) | |
<tr> | |
<td>{{ $client }}</td> | |
<td>{{ $client['client_database_id'] }}</td> | |
<td><select style="width: 100%;" class="steamUsers"></select></td> | |
<!-- <td>@if (in_array($client['client_database_id'], $nonAttachedTeamspeakIds)) none @else @endif</td> --> | |
</tr> | |
@endforeach | |
</table> |
This file contains 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
<?php | |
// Controller Method | |
public function afk() | |
{ | |
$teamspeakServer = TeamSpeak3::factory(config('services.teamspeak.connect')); | |
$teamspeakServer->selfUpdate(['client_nickname' => '~Hardwire Gaming~']); | |
$this->dispatch(new TeamspeakMoveAfk($teamspeakServer, '109972')); | |
} | |
?> | |
<?php namespace Hardwire\Commands; | |
use Illuminate\Contracts\Bus\SelfHandling; | |
use TeamSpeak3_Node_Server; | |
class TeamspeakMoveAfk extends Command implements SelfHandling { | |
protected $teamspeakServer, $afkChannel, $afkTime; | |
public function __construct(TeamSpeak3_Node_Server $teamspeak, $afkChannel = null, $afkTimeSeconds = 3600) | |
{ | |
$this->teamspeakServer = $teamspeak; | |
$this->afkTime = $afkTimeSeconds; | |
$this->afkChannel = $afkChannel; | |
} | |
public function handle() | |
{ | |
$afkChannelId = $this->afkChannel; | |
$clients = $this->teamspeakServer->clientList(); | |
foreach ($clients as $client) { | |
$idleTime = $client['client_idle_time'] / 1000; // Idle Time in Seconds | |
if ($idleTime > $this->afkTime && $client['cid'] != $afkChannelId) { | |
$client->move($afkChannelId); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment