Created
September 9, 2012 09:52
-
-
Save smottt/3683526 to your computer and use it in GitHub Desktop.
Post msgs to Teamspeak3 instance
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 Acme\Demo; | |
// some configuration | |
$all_channels = true; | |
$bot_name = 'TS3 BOT'; | |
$msg = 'Hello World!'; | |
$url = vsprintf('serverquery://username:[email protected]:10011/?server_port=9987&nickname=%s', array( | |
urlencode($bot_name) | |
)); | |
// connect to the ts3 instance | |
$ts3 = \TeamSpeak3::factory($url); | |
// do we post our message to every channel | |
if ($all_channels) { | |
$active_channels = new \SplObjectStorage(); | |
// get clients on the server | |
// so we know to which channels we need to post the msg | |
foreach ($ts3->clientList() as $client) { | |
$channel = $ts3->channelGetById($client['cid']); | |
// 1 client is our client, so we ignore it | |
if ($client['client_nickname'] !== $bot_name && !$active_channels->contains($channel)) { | |
$active_channels->attach($channel); | |
} | |
} | |
// post to every active channel | |
foreach ($active_channels as $channel) { | |
$channel->message($msg); | |
} | |
} else { | |
// post to global server chat | |
$ts3->message($msg); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment