Skip to content

Instantly share code, notes, and snippets.

@smottt
Created September 9, 2012 09:52
Show Gist options
  • Save smottt/3683526 to your computer and use it in GitHub Desktop.
Save smottt/3683526 to your computer and use it in GitHub Desktop.
Post msgs to Teamspeak3 instance
<?php
namespace Acme\Demo;
// some configuration
$all_channels = true;
$bot_name = 'TS3 BOT';
$msg = 'Hello World!';
$url = vsprintf('serverquery://username:password@127.0.0.1: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