Skip to content
This repository has been archived by the owner on Feb 13, 2023. It is now read-only.

Commit

Permalink
Added Switch Channel, Fixed: "|" not working, Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ZerGo0 committed Aug 29, 2020
1 parent b750471 commit 06db32f
Show file tree
Hide file tree
Showing 20 changed files with 556 additions and 256 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Allows you to interact with the TeamSpeak 3 Client via the ClientQuery (Telnet)
You need to have the [ClientQuery plugin](https://www.myteamspeak.com/addons/943dd816-7ef2-48d7-82b8-d60c3b9b10b3) installed in your TeamSpeak 3 Client in order to use this plugin.

## Changelog
[v1.6](https://github.com/ZerGo0/streamdeck-teamspeak3integration/releases/tag/v1.6):
- Fixed: "|" in `Change Nickname`, `Away Status Message` and so on not working
- Added `Channel Switch` Action which allows you to switch the channel when you press the button

[v1.5](https://github.com/ZerGo0/streamdeck-teamspeak3integration/releases/tag/v1.5):
- Fixed: Spaces in `Change Nickname`, `Away Status Message` and so on not working
- Added `Toggle INPUT (Local) Mute` Action which allows you to toggle the input mute status locally so that no one on the server can see it (Currently there is no dynamic way to update this status (couldn't find any public information about this), it will use the button state for now)
Expand All @@ -14,7 +18,7 @@ You need to have the [ClientQuery plugin](https://www.myteamspeak.com/addons/943
- All actions use 1 Telnet Client now (This should fix a lot of issues and hopefully it shouldn't use that much resources anymore when it fails to create a new Telnet connection)

[v1.3](https://github.com/ZerGo0/streamdeck-teamspeak3integration/releases/tag/v1.3):
- Added `Toggle AFK Status` Action which allows you to toggle the away status, input and output mute when you press the button
- Added `Toggle AFK Status` Action which allows you to toggle the away status, input and output mute.FixTs3SpecificChars()

[v1.2](https://github.com/ZerGo0/streamdeck-teamspeak3integration/releases/tag/v1.2):
- Added `Change Nickname` Action which allows you to change your name when you press the button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public TeamSpeak3AfkStatusAction(SDConnection connection, InitialPayload payload

public override void Dispose()
{
TeamSpeak3Telnet.Ts3Client?.Dispose();
TeamSpeak3Telnet.TS3_CLIENT?.Dispose();
Connection.StreamDeckConnection.OnSendToPlugin -= StreamDeckConnection_OnSendToPlugin;
Logger.Instance.LogMessage(TracingLevel.INFO, "Destructor called");
}
Expand All @@ -42,10 +42,10 @@ public override async void KeyPressed(KeyPayload payload)

try
{
if (TeamSpeak3Telnet.Ts3Client == null || !TeamSpeak3Telnet.Ts3Client.IsConnected)
if (TeamSpeak3Telnet.TS3_CLIENT == null || !TeamSpeak3Telnet.TS3_CLIENT.IsConnected)
{
TeamSpeak3Telnet.SetupTelnetClient(_settings.ApiKey);
if (TeamSpeak3Telnet.Ts3Client == null) return;
if (TeamSpeak3Telnet.TS3_CLIENT == null) return;
}

if (payload.IsInMultiAction)
Expand All @@ -55,8 +55,8 @@ public override async void KeyPressed(KeyPayload payload)
}
catch (Exception)
{
TeamSpeak3Telnet.Ts3Client?.Dispose();
TeamSpeak3Telnet.Ts3Client = null;
TeamSpeak3Telnet.TS3_CLIENT?.Dispose();
TeamSpeak3Telnet.TS3_CLIENT = null;
await SetAwayStatusState();
}
}
Expand All @@ -69,17 +69,17 @@ public override async void OnTick()
{
try
{
if (TeamSpeak3Telnet.Ts3Client == null || !TeamSpeak3Telnet.Ts3Client.IsConnected)
if (TeamSpeak3Telnet.TS3_CLIENT == null || !TeamSpeak3Telnet.TS3_CLIENT.IsConnected)
{
TeamSpeak3Telnet.SetupTelnetClient(_settings.ApiKey);
if (TeamSpeak3Telnet.Ts3Client == null) return;
if (TeamSpeak3Telnet.TS3_CLIENT == null) return;
}

var clientId = TeamSpeak3Telnet.GetClientId();
if (clientId == -1)
{
TeamSpeak3Telnet.Ts3Client?.Dispose();
TeamSpeak3Telnet.Ts3Client = null;
TeamSpeak3Telnet.TS3_CLIENT?.Dispose();
TeamSpeak3Telnet.TS3_CLIENT = null;
return;
}

Expand All @@ -106,8 +106,8 @@ public override async void OnTick()
}
catch (Exception)
{
TeamSpeak3Telnet.Ts3Client?.Dispose();
TeamSpeak3Telnet.Ts3Client = null;
TeamSpeak3Telnet.TS3_CLIENT?.Dispose();
TeamSpeak3Telnet.TS3_CLIENT = null;
await SetAwayStatusState();
}
}
Expand Down Expand Up @@ -170,8 +170,8 @@ private async Task ToggleAwayStatus(int desiredState = -1)
var clientId = TeamSpeak3Telnet.GetClientId();
if (clientId == -1)
{
TeamSpeak3Telnet.Ts3Client?.Dispose();
TeamSpeak3Telnet.Ts3Client = null;
TeamSpeak3Telnet.TS3_CLIENT?.Dispose();
TeamSpeak3Telnet.TS3_CLIENT = null;
return;
}

Expand Down Expand Up @@ -204,8 +204,8 @@ private async Task ToggleAwayStatus(int desiredState = -1)
}
catch (Exception)
{
TeamSpeak3Telnet.Ts3Client?.Dispose();
TeamSpeak3Telnet.Ts3Client = null;
TeamSpeak3Telnet.TS3_CLIENT?.Dispose();
TeamSpeak3Telnet.TS3_CLIENT = null;
await SetAwayStatusState();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public TeamSpeak3AwayStatusAction(SDConnection connection, InitialPayload payloa

public override void Dispose()
{
TeamSpeak3Telnet.Ts3Client?.Dispose();
TeamSpeak3Telnet.TS3_CLIENT?.Dispose();
Connection.StreamDeckConnection.OnSendToPlugin -= StreamDeckConnection_OnSendToPlugin;
Logger.Instance.LogMessage(TracingLevel.INFO, "Destructor called");
}
Expand All @@ -42,10 +42,10 @@ public override async void KeyPressed(KeyPayload payload)

try
{
if (TeamSpeak3Telnet.Ts3Client == null || !TeamSpeak3Telnet.Ts3Client.IsConnected)
if (TeamSpeak3Telnet.TS3_CLIENT == null || !TeamSpeak3Telnet.TS3_CLIENT.IsConnected)
{
TeamSpeak3Telnet.SetupTelnetClient(_settings.ApiKey);
if (TeamSpeak3Telnet.Ts3Client == null) return;
if (TeamSpeak3Telnet.TS3_CLIENT == null) return;
}

if (payload.IsInMultiAction)
Expand All @@ -55,8 +55,8 @@ public override async void KeyPressed(KeyPayload payload)
}
catch (Exception)
{
TeamSpeak3Telnet.Ts3Client?.Dispose();
TeamSpeak3Telnet.Ts3Client = null;
TeamSpeak3Telnet.TS3_CLIENT?.Dispose();
TeamSpeak3Telnet.TS3_CLIENT = null;
await SetAwayStatusState();
}
}
Expand All @@ -69,17 +69,17 @@ public override async void OnTick()
{
try
{
if (TeamSpeak3Telnet.Ts3Client == null || !TeamSpeak3Telnet.Ts3Client.IsConnected)
if (TeamSpeak3Telnet.TS3_CLIENT == null || !TeamSpeak3Telnet.TS3_CLIENT.IsConnected)
{
TeamSpeak3Telnet.SetupTelnetClient(_settings.ApiKey);
if (TeamSpeak3Telnet.Ts3Client == null) return;
if (TeamSpeak3Telnet.TS3_CLIENT == null) return;
}

var clientId = TeamSpeak3Telnet.GetClientId();
if (clientId == -1)
{
TeamSpeak3Telnet.Ts3Client?.Dispose();
TeamSpeak3Telnet.Ts3Client = null;
TeamSpeak3Telnet.TS3_CLIENT?.Dispose();
TeamSpeak3Telnet.TS3_CLIENT = null;
return;
}

Expand All @@ -106,8 +106,8 @@ public override async void OnTick()
}
catch (Exception)
{
TeamSpeak3Telnet.Ts3Client?.Dispose();
TeamSpeak3Telnet.Ts3Client = null;
TeamSpeak3Telnet.TS3_CLIENT?.Dispose();
TeamSpeak3Telnet.TS3_CLIENT = null;
await SetAwayStatusState();
}
}
Expand Down Expand Up @@ -170,8 +170,8 @@ private async Task ToggleAwayStatus(int desiredState = -1)
var clientId = TeamSpeak3Telnet.GetClientId();
if (clientId == -1)
{
TeamSpeak3Telnet.Ts3Client?.Dispose();
TeamSpeak3Telnet.Ts3Client = null;
TeamSpeak3Telnet.TS3_CLIENT?.Dispose();
TeamSpeak3Telnet.TS3_CLIENT = null;
return;
}

Expand Down Expand Up @@ -200,8 +200,8 @@ private async Task ToggleAwayStatus(int desiredState = -1)
}
catch (Exception)
{
TeamSpeak3Telnet.Ts3Client?.Dispose();
TeamSpeak3Telnet.Ts3Client = null;
TeamSpeak3Telnet.TS3_CLIENT?.Dispose();
TeamSpeak3Telnet.TS3_CLIENT = null;
await SetAwayStatusState();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public TeamSpeak3ChangeNicknameAction(SDConnection connection, InitialPayload pa

public override void Dispose()
{
TeamSpeak3Telnet.Ts3Client?.Dispose();
TeamSpeak3Telnet.TS3_CLIENT?.Dispose();
Connection.StreamDeckConnection.OnSendToPlugin -= StreamDeckConnection_OnSendToPlugin;
Logger.Instance.LogMessage(TracingLevel.INFO, "Destructor called");
}
Expand All @@ -43,13 +43,21 @@ public override async void KeyPressed(KeyPayload payload)
{
Logger.Instance.LogMessage(TracingLevel.INFO, "Key Pressed");

if (TeamSpeak3Telnet.Ts3Client == null || !TeamSpeak3Telnet.Ts3Client.IsConnected)
try
{
TeamSpeak3Telnet.SetupTelnetClient(_settings.ApiKey);
if (TeamSpeak3Telnet.Ts3Client == null) return;
}
if (TeamSpeak3Telnet.TS3_CLIENT == null || !TeamSpeak3Telnet.TS3_CLIENT.IsConnected)
{
TeamSpeak3Telnet.SetupTelnetClient(_settings.ApiKey);
if (TeamSpeak3Telnet.TS3_CLIENT == null) return;
}

ChangeNickname();
ChangeNickname();
}
catch (Exception)
{
TeamSpeak3Telnet.TS3_CLIENT?.Dispose();
TeamSpeak3Telnet.TS3_CLIENT = null;
}
}

public override void KeyReleased(KeyPayload payload)
Expand Down Expand Up @@ -117,17 +125,17 @@ private void ChangeNickname()
var clientId = TeamSpeak3Telnet.GetClientId();
if (clientId == -1)
{
TeamSpeak3Telnet.Ts3Client?.Dispose();
TeamSpeak3Telnet.Ts3Client = null;
TeamSpeak3Telnet.TS3_CLIENT?.Dispose();
TeamSpeak3Telnet.TS3_CLIENT = null;
return;
}

TeamSpeak3Telnet.ChangeNickname(_settings.NickName);
}
catch (Exception)
{
TeamSpeak3Telnet.Ts3Client?.Dispose();
TeamSpeak3Telnet.Ts3Client = null;
TeamSpeak3Telnet.TS3_CLIENT?.Dispose();
TeamSpeak3Telnet.TS3_CLIENT = null;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
using System;
using System.Threading.Tasks;

using BarRaider.SdTools;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

using streamdeck_client_csharp;
using streamdeck_client_csharp.Events;

using ZerGo0.TeamSpeak3Integration.Helpers;

using KeyPayload = BarRaider.SdTools.KeyPayload;

namespace ZerGo0.TeamSpeak3Integration.Actions
{
[PluginActionId("com.zergo0.teamspeak3integration.channelswitch")]
public class TeamSpeak3ChannelSwitchAction : PluginBase
{
public TeamSpeak3ChannelSwitchAction(SDConnection connection, InitialPayload payload) : base(connection, payload)
{
if (payload.Settings == null || payload.Settings.Count == 0)
_settings = PluginSettings.CreateDefaultSettings();
else
_settings = payload.Settings.ToObject<PluginSettings>();
connection.StreamDeckConnection.OnSendToPlugin += StreamDeckConnection_OnSendToPlugin;

SaveSettings();
}

public override void Dispose()
{
TeamSpeak3Telnet.TS3_CLIENT?.Dispose();
Connection.StreamDeckConnection.OnSendToPlugin -= StreamDeckConnection_OnSendToPlugin;
Logger.Instance.LogMessage(TracingLevel.INFO, "Destructor called");
}

public override async void KeyPressed(KeyPayload payload)
{
Logger.Instance.LogMessage(TracingLevel.INFO, "Key Pressed");

try
{
if (TeamSpeak3Telnet.TS3_CLIENT == null || !TeamSpeak3Telnet.TS3_CLIENT.IsConnected)
{
TeamSpeak3Telnet.SetupTelnetClient(_settings.ApiKey);
if (TeamSpeak3Telnet.TS3_CLIENT == null) return;
}

ChannelSwitch();
}
catch (Exception)
{
TeamSpeak3Telnet.TS3_CLIENT?.Dispose();
TeamSpeak3Telnet.TS3_CLIENT = null;
}
}

public override void KeyReleased(KeyPayload payload)
{
}

public override async void OnTick()
{
}

public override void ReceivedSettings(ReceivedSettingsPayload payload)
{
Tools.AutoPopulateSettings(_settings, payload.Settings);
SaveSettings();
}

public override void ReceivedGlobalSettings(ReceivedGlobalSettingsPayload payload)
{
}

private class PluginSettings
{
[JsonProperty(PropertyName = "apiKey")]
public string ApiKey { get; set; }

[JsonProperty(PropertyName = "channelName")]
public string ChannelName { get; set; }

public static PluginSettings CreateDefaultSettings()
{
var instance = new PluginSettings
{
ApiKey = string.Empty,
ChannelName = string.Empty
};

return instance;
}
}

#region Private Members

private readonly PluginSettings _settings;

#endregion

#region Private Methods

private Task SaveSettings()
{
return Connection.SetSettingsAsync(JObject.FromObject(_settings));
}

private void StreamDeckConnection_OnSendToPlugin(object sender,
StreamDeckEventReceivedEventArgs<SendToPluginEvent> e)
{
var payload = e.Event.Payload;
if (Connection.ContextId != e.Event.Context) return;
}

private void ChannelSwitch()
{
try
{
var clientId = TeamSpeak3Telnet.GetClientId();
if (clientId == -1)
{
TeamSpeak3Telnet.TS3_CLIENT?.Dispose();
TeamSpeak3Telnet.TS3_CLIENT = null;
return;
}

TeamSpeak3Telnet.ChannelSwitch(_settings.ChannelName, clientId);
}
catch (Exception)
{
TeamSpeak3Telnet.TS3_CLIENT?.Dispose();
TeamSpeak3Telnet.TS3_CLIENT = null;
}
}

#endregion
}
}
Loading

0 comments on commit 06db32f

Please sign in to comment.