Skip to content

Commit

Permalink
Development (#7)
Browse files Browse the repository at this point in the history
* * Updated pipeline functions

* * Optimized Dockerfile

* * Bugfix

* * Added several channel properties to env file

* * Added several channel properties to env file

* * Added several channel properties to env file

* * Bugfix

---------

Co-authored-by: Dominik süßenbach <dominik.suessenbach@compleet.com>
  • Loading branch information
Domenikus and Dominik süßenbach authored Sep 3, 2023
1 parent 40b651a commit 06ae1b1
Show file tree
Hide file tree
Showing 10 changed files with 252 additions and 1,590 deletions.
1,504 changes: 0 additions & 1,504 deletions .editorconfig

This file was deleted.

31 changes: 20 additions & 11 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ jobs:
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Check out the repo
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -31,28 +34,34 @@ jobs:
- name: Run Laravel Pint
run: composer sniff

- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: domenikus/channel-creator-bot

- name: Get Version
id: get_version
uses: battila7/get-version-action@v2
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push Docker image
uses: docker/build-push-action@v3
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64,linux/arm64
build-args:
version=${{steps.get_version.outputs.version}}
version=${{ env.RELEASE_VERSION }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
2 changes: 1 addition & 1 deletion .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down
20 changes: 9 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@ FROM php:8.1-cli-alpine

ARG version

RUN apk add ncurses composer
RUN mkdir -p /usr/src/channel-creator-bot

COPY . /usr/src/channel-creator-bot/

RUN php /usr/bin/composer.phar install --working-dir=/usr/src/channel-creator-bot --no-scripts
RUN chmod 755 /usr/src/channel-creator-bot/vendor/laravel-zero/framework/bin/box
RUN php /usr/src/channel-creator-bot/channel-creator-bot app:build --build-version=${version}
RUN php /usr/bin/composer.phar dump-autoload --working-dir=/usr/src/channel-creator-bot --classmap-authoritative --no-dev -vvv --optimize

RUN mkdir -p /app \
RUN apk add ncurses composer \
&& $(php -r '$extensionInstalled = array_map("strtolower", \get_loaded_extensions(false));$requiredExtensions = ["zlib", "phar", "openssl", "pcre", "tokenizer"];$extensionsToInstall = array_diff($requiredExtensions, $extensionInstalled);if ([] !== $extensionsToInstall) {echo \sprintf("docker-php-ext-install %s", implode(" ", $extensionsToInstall));}echo "echo \"No extensions\"";') \
&& php /usr/bin/composer.phar install --working-dir=/usr/src/channel-creator-bot --no-dev --no-scripts \
&& chmod 755 /usr/src/channel-creator-bot/vendor/laravel-zero/framework/bin/box \
&& php /usr/src/channel-creator-bot/channel-creator-bot app:build --build-version=${version} \
&& php /usr/bin/composer.phar dump-autoload --working-dir=/usr/src/channel-creator-bot --classmap-authoritative --no-dev -vvv --optimize \
&& mkdir -p /app \
&& mkdir -p /app/storage \
&& mkdir -p /app/views \
&& cp /usr/src/channel-creator-bot/builds/channel-creator-bot /app \
&& cp /usr/src/channel-creator-bot/entrypoint.sh /app \
&& rm -R /usr/src/channel-creator-bot
RUN chmod +x /app/entrypoint.sh
&& rm -R /usr/src/channel-creator-bot \
&& chmod +x /app/entrypoint.sh

WORKDIR /app
ENTRYPOINT ["/bin/sh", "/app/entrypoint.sh"]
44 changes: 36 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,28 +70,49 @@ TEAMSPEAK_QUERY_PASSWORD=
# Query user port, default is 10011
TEAMSPEAK_QUERY_PORT=10011
# Bot default channel, if not provided bot will stay in servers default channel
TEAMSPEAK_DEFAULT_CHANNEL=
# Parent channel where group channels created below
TEAMSPEAK_PARENT_CHANNEL=
# Client limit for created sub channel
TEAMSPEAK_CHANNEL_CLIENT_LIMIT=
# Id of channel admin groups which will be assiged to client. If not provided no channel group will be assigned to client
# (Optional) Bot default channel, if not provided bot will stay in servers default channel
TEAMSPEAK_DEFAULT_CHANNEL=
# (Optional) Set channel codec, default is opus_voice. Valid values: opus_voice, opus_music
TEAMSPEAK_CHANNEL_CODEC=
# (Optional) Set channel codec quality. Provide value between 1 and 10. If not provided server standard will be used
TEAMSPEAK_CHANNEL_CODEC_QUALITY=
# (Optional) Set channel topic of created channel. If not provided, topic will be empty
TEAMSPEAK_CHANNEL_TOPIC=
# (Optional) Set channel description of created channel. If not provided, description will be empty
TEAMSPEAK_CHANNEL_DESCRIPTION=
# (Optional) Id of channel admin groups which will be assiged to client. If not provided no channel group will be assigned to client
TEAMSPEAK_CHANNEL_ADMIN_GROUP_ID=
# Needed join power to join the created channel, if not provided no join power is needed.
# (Optional) Needed join power to join the created channel, if not provided no join power is needed.
TEAMSPEAK_NEEDED_CHANNEL_JOIN_POWER=
# Needed subscribe power to subscribe the created channel, if not provided no subscribe power is needed.
# (Optional) Needed subscribe power to subscribe the created channel, if not provided no subscribe power is needed.
TEAMSPEAK_NEEDED_CHANNEL_SUBSCRIBE_POWER=
#Specify how the application will log messages like erros. Default will be stack.
# (Optional) Needed description view power to view created channel description, if not provided no subscribe power is needed.
TEAMSPEAK_NEEDED_CHANNEL_DESCRIPTION_VIEW_POWER=
# (Optional) Needed modify power to modify created channel, if not provided no modify power is needed.
TEAMSPEAK_NEEDED_CHANNEL_MODIFY_POWER=
# (Optional) Needed talk power to speak in created channel, if not provided no talk power is needed.
TEAMSPEAK_NEEDED_CHANNEL_TALK_POWER=
# (Optional) Specify how the application will log messages like erros. Default will be stack.
LOG_CHANNEL=stack
# Default is 'info' if you want to debug the application may you want to change this to 'debug'
# (Optional) Default is 'info' if you want to debug the application may you want to change this to 'debug'
LOG_LEVEL=info
# (Optional) Default is empty. Allow customizing the list of channel names by providing additonal ones. Variable need to be json encoded string.
Expand All @@ -113,14 +134,21 @@ b_virtualserver_notify_unregister
b_channel_create_child
b_channel_create_temporary
b_channel_create_modify_with_codec_opusvoice
b_channel_create_modify_with_codec_opusmusic
i_channel_create_modify_with_codec_maxquality (10)
i_channel_create_modify_with_codec_latency_factor_min (0)
b_channel_create_with_topic
b_channel_create_with_description
b_channel_create_with_maxclients
i_channel_modify_power
b_channel_join_permanent
b_channel_join_temporary
i_channel_needed_join_power (grant)
i_channel_needed_subscribe_power (grant)
i_channel_max_depth (-1)
i_channel_needed_permission_modify_power (grant)
i_channel_needed_description_view_power (grant)
i_channel_needed_modify_power (grant)
b_virtualserver_channel_permission_list
i_group_member_add_power
i_group_member_add_power (grant)
Expand Down
66 changes: 59 additions & 7 deletions app/Providers/ClientServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,36 @@ public function provides(): array

public function register(): void
{
$channelTopic = config('teamspeak.channel_topic');
$channelDescription = config('teamspeak.channel_description');
$parentChannel = config('teamspeak.parent_channel');
$channelClientLimit = config('teamspeak.channel_client_limit');
$channelAdminGroupId = config('teamspeak.channel_admin_group_id');
$channelCodec = config('teamspeak.channel_codec');
$channelCodecQuality = config('teamspeak.channel_codec_quality');
$channelNeededJoinPower = config('teamspeak.channel_needed_join_power');
$channelNeededSubscribePower = config('teamspeak.channel_needed_subscribe_power');
$channelNeededDescriptionViewPower = config('teamspeak.channel_needed_description_view_power');
$channelNeededModifyPower = config('teamspeak.channel_needed_modify_power');
$channelNeededTalkPower = config('teamspeak.channel_needed_talk_power');
$defaultChannel = config('teamspeak.default_channel');
$channelNameLists = config('channel-names.lists');
$channelListName = config('channel-names.default');
$channelNameClientLists = config('channel-names.clients');

if (
(! is_string($channelTopic) && ! is_null($channelTopic)) ||
(! is_string($channelDescription) && ! is_null($channelDescription)) ||
(! is_numeric($parentChannel)) ||
(! is_numeric($channelClientLimit) && ! is_null($channelClientLimit)) ||
(! is_numeric($channelAdminGroupId) && ! is_null($channelAdminGroupId)) ||
(! is_string($channelCodec)) ||
(! is_numeric($channelCodecQuality) && ! is_null($channelCodecQuality)) ||
(! is_numeric($channelNeededJoinPower) && ! is_null($channelNeededJoinPower)) ||
(! is_numeric($channelNeededSubscribePower) && ! is_null($channelNeededSubscribePower)) ||
(! is_numeric($channelNeededDescriptionViewPower) && ! is_null($channelNeededDescriptionViewPower)) ||
(! is_numeric($channelNeededModifyPower) && ! is_null($channelNeededModifyPower)) ||
(! is_numeric($channelNeededTalkPower) && ! is_null($channelNeededTalkPower)) ||
(! is_numeric($defaultChannel) && ! is_null($defaultChannel)) ||
(! is_array($channelNameLists)) ||
(! is_array($channelNameClientLists)) ||
Expand All @@ -45,17 +59,55 @@ public function register(): void

$channelNames = $channelNameLists[$channelListName];

/** @var int|null $channelClientLimit */
/** @var int|null $channelAdminGroupId */
/** @var int|null $channelNeededJoinPower */
/** @var int|null $channelNeededSubscribePower */
/** @var int|null $defaultChannel */
/**
* @var int $parentChannel
* @var string|null $channelTopic
* @var string|null $channelDescription
* @var int|null $channelClientLimit
* @var int|null $channelAdminGroupId
* @var string $channelCodec
* @var int|null $channelCodecQuality
* @var int|null $channelNeededJoinPower
* @var int|null $channelNeededSubscribePower
* @var int|null $channelNeededDescriptionViewPower
* @var int|null $channelNeededModifyPower
* @var int|null $channelNeededTalkPower
* @var int|null $defaultChannel
* */
$this->app->bind(ClientServiceInterface::class, function () use (
$channelCodecQuality,
$channelCodec,
$channelTopic,
$channelDescription,
$channelNeededModifyPower,
$channelNeededDescriptionViewPower,
$channelNeededTalkPower,
$channelNameClientLists,
$defaultChannel,
$channelNeededSubscribePower,
$channelNeededJoinPower, $channelClientLimit, $channelAdminGroupId, $parentChannel, $channelNames) {
return new ClientService((int) $parentChannel, $channelNames, $defaultChannel, $channelClientLimit, $channelAdminGroupId, $channelNeededJoinPower, $channelNeededSubscribePower, $channelNameClientLists);
$channelNeededJoinPower,
$channelClientLimit,
$channelAdminGroupId,
$parentChannel,
$channelNames
) {
return new ClientService(
$parentChannel,
$channelNames,
channelCodec: $channelCodec,
defaultChannel: $defaultChannel,
channelTopic: $channelTopic,
channelDescription: $channelDescription,
channelClientLimit: $channelClientLimit,
channelCodecQuality: $channelCodecQuality,
channelAdminGroupId: $channelAdminGroupId,
channelNeededJoinPower: $channelNeededJoinPower,
channelNeededSubscribePower: $channelNeededSubscribePower,
channelNeededDescriptionViewPower: $channelNeededDescriptionViewPower,
channelNeededModifyPowerPower: $channelNeededModifyPower,
channelNeededTalkPowerPower: $channelNeededTalkPower,
channelNameClientLists: $channelNameClientLists
);
});
}
}
84 changes: 50 additions & 34 deletions app/Services/ClientService.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,23 @@

class ClientService implements ClientServiceInterface
{
protected ?int $channelAdminGroupId;

protected ?int $channelClientLimit;

protected array $channelNames;

protected ?int $defaultChannel;

protected ?int $channelNeededJoinPower;

protected ?int $channelNeededSubscribePower;

protected int $parentChannel;

protected array $channelNameClientLists;

public function __construct(int $parentChannel, array $channelNames, ?int $defaultChannel, int $channelClientLimit = null, int $channelAdminGroupId = null, int $channelNeededJoinPower = null, int $channelNeededSubscribePower = null, array $channelNameClientLists = [])
{
$this->parentChannel = $parentChannel;
$this->channelNames = $channelNames;
$this->defaultChannel = $defaultChannel;
$this->channelClientLimit = $channelClientLimit;
$this->channelAdminGroupId = $channelAdminGroupId;
$this->channelNeededJoinPower = $channelNeededJoinPower;
$this->channelNeededSubscribePower = $channelNeededSubscribePower;
$this->channelNameClientLists = $channelNameClientLists;
public function __construct(
protected int $parentChannel,
protected array $channelNames,
protected string $channelCodec,
protected ?int $defaultChannel,
protected ?string $channelTopic = null,
protected ?string $channelDescription = null,
protected ?int $channelClientLimit = null,
protected ?int $channelCodecQuality = null,
protected ?int $channelAdminGroupId = null,
protected ?int $channelNeededJoinPower = null,
protected ?int $channelNeededSubscribePower = null,
protected ?int $channelNeededDescriptionViewPower = null,
protected ?int $channelNeededModifyPowerPower = null,
protected ?int $channelNeededTalkPowerPower = null,
protected array $channelNameClientLists = []
) {
}

public function handleClientMove(int $clientId, int $targetChannelId): void
Expand All @@ -50,7 +41,14 @@ public function handleClientMove(int $clientId, int $targetChannelId): void
} else {
$channelName = $this->generateChannelName($this->channelNames);
}
$newChannelId = TeamspeakGateway::createChannel($channelName, $this->parentChannel, $this->channelClientLimit);

$newChannelId = TeamspeakGateway::createChannel(
name: $channelName,
codec: $this->channelCodec,
parent: $this->parentChannel,
maxClients: $this->channelClientLimit, neededTalkPower: $this->channelNeededTalkPowerPower,
topic: $this->channelTopic, description: $this->channelDescription,
codecQuality: $this->channelCodecQuality);

if (! $newChannelId) {
return;
Expand All @@ -64,13 +62,7 @@ public function handleClientMove(int $clientId, int $targetChannelId): void
TeamspeakGateway::assignChannelGroupToClient($client, $newChannelId, $this->channelAdminGroupId);
}

if ($this->channelNeededJoinPower) {
TeamspeakGateway::assignPermissionToChannel($newChannelId, TeamspeakGateway::CHANNEL_PERMISSION_NEEDED_JOIN_POWER, $this->channelNeededJoinPower);
}

if ($this->channelNeededSubscribePower) {
TeamspeakGateway::assignPermissionToChannel($newChannelId, TeamspeakGateway::CHANNEL_PERMISSION_NEEDED_SUBSCRIBE_POWER, $this->channelNeededSubscribePower);
}
$this->assignChannelPermissions($newChannelId);
}
}

Expand All @@ -89,4 +81,28 @@ protected function generateChannelName(array $listOfNames, string $channelName =

return $channelName;
}

protected function assignChannelPermissions(int $channelId): void
{
if ($this->channelNeededJoinPower) {
TeamspeakGateway::assignPermissionToChannel($channelId,
TeamspeakGateway::CHANNEL_PERMISSION_NEEDED_JOIN_POWER, $this->channelNeededJoinPower);
}

if ($this->channelNeededSubscribePower) {
TeamspeakGateway::assignPermissionToChannel($channelId,
TeamspeakGateway::CHANNEL_PERMISSION_NEEDED_SUBSCRIBE_POWER, $this->channelNeededSubscribePower);
}

if ($this->channelNeededDescriptionViewPower) {
TeamspeakGateway::assignPermissionToChannel($channelId,
TeamspeakGateway::CHANNEL_PERMISSION_NEEDED_DESCRIPTION_VIEW_POWER,
$this->channelNeededDescriptionViewPower);
}

if ($this->channelNeededModifyPowerPower) {
TeamspeakGateway::assignPermissionToChannel($channelId,
TeamspeakGateway::CHANNEL_PERMISSION_NEEDED_MODIFY_POWER, $this->channelNeededModifyPowerPower);
}
}
}
Loading

0 comments on commit 06ae1b1

Please sign in to comment.