From 8d44536ea084fad0ab6e03b766e66e0c92447882 Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Wed, 1 Jul 2020 14:06:46 -0400 Subject: [PATCH] Add voice chat commands --- GamecraftRPC/CallbackUtility.cs | 1 + GamecraftRPC/Plugin.cs | 28 ++++++++++++++++++++++++++++ GamecraftRPC/PresenceUtility.cs | 2 ++ 3 files changed, 31 insertions(+) diff --git a/GamecraftRPC/CallbackUtility.cs b/GamecraftRPC/CallbackUtility.cs index 3648c10..30ffcea 100644 --- a/GamecraftRPC/CallbackUtility.cs +++ b/GamecraftRPC/CallbackUtility.cs @@ -74,6 +74,7 @@ namespace GamecraftRPC } PresenceUtility.IsActivityHost = false; PresenceUtility.IsServerActive = false; + PresenceUtility.IsVoiceConnected = false; Plugin.SetDiscordActivity(PresenceUtility.Activity, debug: "MenuEnter-API-callback"); } diff --git a/GamecraftRPC/Plugin.cs b/GamecraftRPC/Plugin.cs index 59bdefd..bf3df70 100644 --- a/GamecraftRPC/Plugin.cs +++ b/GamecraftRPC/Plugin.cs @@ -145,6 +145,34 @@ namespace GamecraftRPC }) .Build(); + + CommandBuilder.Builder() + .Name("DiscordVoice") + .Description("Connect to Discord Voice Lobby") + .Action(() => + { + if (DiscordRPC != null) + { + GamecraftModdingAPI.Utility.Logging.CommandLogError("Discord GameSDK is unavailable. Please make sure Discord is open when launching Gamecraft."); + return; + } + if (PresenceUtility.Lobby.HasValue) + { + //LobbyManager lm = DiscordRPC.GetLobbyManager(); + if (PresenceUtility.IsVoiceConnected) + { + lm.DisconnectLobby(PresenceUtility.Lobby.Value.Id, (result) => { GamecraftModdingAPI.Utility.Logging.CommandLog($"Disconnected voice (Result: {result})"); }); + PresenceUtility.IsVoiceConnected = false; + } + else + { + lm.ConnectVoice(PresenceUtility.Lobby.Value.Id, (result) => { GamecraftModdingAPI.Utility.Logging.CommandLog($"Connected voice (Result: {result})"); }); + PresenceUtility.IsVoiceConnected = true; + } + + } + }) + .Build(); #if !RELEASE bool alreadyWarned = false; Client.EnterMenu += (_, args) => diff --git a/GamecraftRPC/PresenceUtility.cs b/GamecraftRPC/PresenceUtility.cs index 96b413d..226576b 100644 --- a/GamecraftRPC/PresenceUtility.cs +++ b/GamecraftRPC/PresenceUtility.cs @@ -28,5 +28,7 @@ namespace GamecraftRPC public static bool IsServerActive = false; public static bool IsConnecting = false; + + public static bool IsVoiceConnected = false; } }