How to sort Channels between two Spacer alphabetically ?

walross99

Some random Guy
Joined
Jul 29, 2016
Messages
42
Reaction score
14
Points
40
Hey there,

I'm looking for a php-script to sort all channels between 2 spacers alphabetically

Name of the script: Channel-Sorter
Functions of the script: Sorting Channels alphabetically
Why do you want it: Because users can create their own channels on our server, which should get sorted.
Screenshots: /
Original source (if any): /
Other notes: It should only sort the channels between the spacer & not touch the subchannels of each channel inbetween. So, if a channel was called a and has a subchannel called c, and there is another channel called b, c should remain subchannel of a.

If you need any additional information, because you didn't understand the stuff i wrote right there, feel free to ask.
 

FarisDev

L oryh brx
Contributor
Joined
Jun 9, 2016
Messages
277
Reaction score
111
Points
107
Could you please do some screenshots about the script?.
 

MrWolf

Retired Staff
Contributor
Joined
Dec 27, 2016
Messages
475
Reaction score
263
Points
112
Could you please do some screenshots about the script?.
He just wants to have space for public rooms within two spacers, and that his channels are sorted all the time alphabeticly, he needs bot and script for that that will check every 1 second or x seconds depending on his needs.But its not simple to make.
 

FarisDev

L oryh brx
Contributor
Joined
Jun 9, 2016
Messages
277
Reaction score
111
Points
107
I'm not good at english, Screenshot is better.
 

MrWolf

Retired Staff
Contributor
Joined
Dec 27, 2016
Messages
475
Reaction score
263
Points
112
I'm not good at english, Screenshot is better.
Like this>
LEGEND:
k is channel


-----------SPACERX---------------
k ananas
k ailovegirls
k bitchesniga
k colocation
k zkzkktkakt
----------SPACERY-------------------


And he wants script to automaticly acomplish them to be sorted by letters

I can't go more simple on English.
 

Najsr

Moderator
TeamSpeak Developer
Joined
Apr 23, 2016
Messages
483
Reaction score
249
Points
167
Those channels you want to sort are they sub-channels of that spacer(s)?
 

walross99

Some random Guy
Joined
Jul 29, 2016
Messages
42
Reaction score
14
Points
40
Yeah, they are, but they (the subchannels of the spacers) also have subchannels, which shoudnt get sorted.
 

Najsr

Moderator
TeamSpeak Developer
Joined
Apr 23, 2016
Messages
483
Reaction score
249
Points
167
PHP:
<?php

require_once("libraries/TeamSpeak3/TeamSpeak3.php");
$ts3_VirtualServer = TeamSpeak3::factory("serverquery://serveradmin:[email protected]:10011/?server_port=9987");
$ts3_VirtualServer->selfUpdate(['client_nickname'=>"Room sorter"]);
$channelList = $ts3_VirtualServer->channelList();
$spacers = [];
foreach ($channelList as $channel) {
    if ($channel->isSpacer() && preg_match('/^\[cspacer[A-Z]]\sSector\s[A-Z]/usX', (string)$channel['channel_name'])) {
        $spacers[] = $channel;
    }
}
$channels = [];
foreach ($spacers as $spacer) {
    $clist = $spacer->subChannelList();
    $tmp_channel = $ts3_VirtualServer->channelCreate(['channel_name' => 'TMP_SORT' . rand(0, 1500), 'channel_flag_permanent' => true]);
    foreach ($clist as $channel) {
            $channels[(string)$channel['channel_name']] = $channel;
            $channel->move($tmp_channel);
    }
    ksort($channels);
    $order = 0;
    foreach ($channels as $channel) {
        try {
            $ts3_VirtualServer->channelMove($channel['cid'], $spacer['cid'], $order);
            $order = $channel['cid'];
        } catch (Exception $ex) {
            echo $ex->getMessage() . PHP_EOL;
        }
    }
        $ts3_VirtualServer->channelDelete($tmp_channel, true);
        $channels = [];
        $order = 0;
}
This is my code :D Regex is used to find spacers. Then it creates and moves all channels to a temporary channel and then it will start moving them by alphabetical order. (Couldn't make it without tmp moving yet)
 

walross99

Some random Guy
Joined
Jul 29, 2016
Messages
42
Reaction score
14
Points
40
Thats exactly what I was looking for, thanks a lot <3
 
Top