Archived
0
0
Fork 0

feat: made discord rich presence toggleable

This commit is contained in:
Daryl Ronningen 2021-12-22 22:42:42 -07:00
parent b9672f82d6
commit 4f9b342fa8
Signed by: Daryl Ronningen
GPG key ID: FD23F0C934A5EC6B

View file

@ -21,6 +21,7 @@ namespace chord
private ulong currentSelectedChannel; private ulong currentSelectedChannel;
private ulong currentSelectedGuild; private ulong currentSelectedGuild;
private SortedDictionary<ulong, List<ulong>> guilds; private SortedDictionary<ulong, List<ulong>> guilds;
private DiscordRpcClient rpcClient;
private Settings settings; private Settings settings;
private Window window; private Window window;
@ -50,9 +51,11 @@ namespace chord
await client.LoginAsync(TokenType.Bot, settings.Token); await client.LoginAsync(TokenType.Bot, settings.Token);
await client.StartAsync(); await client.StartAsync();
var rpcClient = new DiscordRpcClient("923436807297859625"); if (settings.EnableRichPresence) {
rpcClient = new DiscordRpcClient("923436807297859625");
rpcClient.Initialize(); rpcClient.Initialize();
rpcClient.SetPresence(new RichPresence()); rpcClient.SetPresence(new RichPresence());
}
Application.Init(); Application.Init();
@ -181,7 +184,9 @@ namespace chord
channelListTree.AddObject(category.Value); channelListTree.AddObject(category.Value);
} }
if (settings.EnableRichPresence) {
rpcClient.UpdateDetails($"Chatting in {client.GetGuild(currentSelectedGuild).Name}"); rpcClient.UpdateDetails($"Chatting in {client.GetGuild(currentSelectedGuild).Name}");
}
}; };
channelListTree.SelectionChanged += async (arg1, arg2) => channelListTree.SelectionChanged += async (arg1, arg2) =>
@ -253,8 +258,10 @@ namespace chord
userListTree.AddObject(role.Value); userListTree.AddObject(role.Value);
} }
if (settings.EnableRichPresence) {
rpcClient.UpdateState($"In channel {client.GetGuild(currentSelectedGuild).GetTextChannel(currentSelectedChannel).Name}"); rpcClient.UpdateState($"In channel {client.GetGuild(currentSelectedGuild).GetTextChannel(currentSelectedChannel).Name}");
rpcClient.UpdateStartTime(); rpcClient.UpdateStartTime();
}
} catch { } catch {
await chatBoxList.SetSourceAsync(new List<string>()); await chatBoxList.SetSourceAsync(new List<string>());
} }
@ -352,6 +359,7 @@ namespace chord
}; };
Application.MainLoop.AddTimeout(TimeSpan.FromMilliseconds(100), caller => { Application.MainLoop.AddTimeout(TimeSpan.FromMilliseconds(100), caller => {
if (settings.EnableRichPresence)
rpcClient.Invoke(); rpcClient.Invoke();
return true; return true;
}); });
@ -440,6 +448,7 @@ namespace chord
public class Settings public class Settings
{ {
public string Token { get; set; } public string Token { get; set; }
public bool EnableRichPresence { get; set; }
} }
public class GetMessagesResponse public class GetMessagesResponse