From 4f9b342fa8640524a71774c6dc550f80f6064986 Mon Sep 17 00:00:00 2001 From: Daryl Ronningen Date: Wed, 22 Dec 2021 22:42:42 -0700 Subject: [PATCH] feat: made discord rich presence toggleable --- Program.cs | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/Program.cs b/Program.cs index d5d369c..76c86b6 100644 --- a/Program.cs +++ b/Program.cs @@ -21,6 +21,7 @@ namespace chord private ulong currentSelectedChannel; private ulong currentSelectedGuild; private SortedDictionary> guilds; + private DiscordRpcClient rpcClient; private Settings settings; private Window window; @@ -50,9 +51,11 @@ namespace chord await client.LoginAsync(TokenType.Bot, settings.Token); await client.StartAsync(); - var rpcClient = new DiscordRpcClient("923436807297859625"); - rpcClient.Initialize(); - rpcClient.SetPresence(new RichPresence()); + if (settings.EnableRichPresence) { + rpcClient = new DiscordRpcClient("923436807297859625"); + rpcClient.Initialize(); + rpcClient.SetPresence(new RichPresence()); + } Application.Init(); @@ -181,7 +184,9 @@ namespace chord channelListTree.AddObject(category.Value); } - rpcClient.UpdateDetails($"Chatting in {client.GetGuild(currentSelectedGuild).Name}"); + if (settings.EnableRichPresence) { + rpcClient.UpdateDetails($"Chatting in {client.GetGuild(currentSelectedGuild).Name}"); + } }; channelListTree.SelectionChanged += async (arg1, arg2) => @@ -253,8 +258,10 @@ namespace chord userListTree.AddObject(role.Value); } - rpcClient.UpdateState($"In channel {client.GetGuild(currentSelectedGuild).GetTextChannel(currentSelectedChannel).Name}"); - rpcClient.UpdateStartTime(); + if (settings.EnableRichPresence) { + rpcClient.UpdateState($"In channel {client.GetGuild(currentSelectedGuild).GetTextChannel(currentSelectedChannel).Name}"); + rpcClient.UpdateStartTime(); + } } catch { await chatBoxList.SetSourceAsync(new List()); } @@ -352,7 +359,8 @@ namespace chord }; Application.MainLoop.AddTimeout(TimeSpan.FromMilliseconds(100), caller => { - rpcClient.Invoke(); + if (settings.EnableRichPresence) + rpcClient.Invoke(); return true; }); @@ -440,6 +448,7 @@ namespace chord public class Settings { public string Token { get; set; } + public bool EnableRichPresence { get; set; } } public class GetMessagesResponse