Archived
0
0
Fork 0

feat: added discord rich presence

This commit is contained in:
Daryl Ronningen 2021-12-22 22:02:06 -07:00
parent fd6d1830c5
commit b9672f82d6
Signed by: Daryl Ronningen
GPG key ID: FD23F0C934A5EC6B
2 changed files with 16 additions and 1 deletions

View file

@ -3,11 +3,13 @@ using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Discord; using Discord;
using Discord.WebSocket; using Discord.WebSocket;
using DiscordRPC;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using RestSharp; using RestSharp;
using Terminal.Gui; using Terminal.Gui;
using Terminal.Gui.Trees; using Terminal.Gui.Trees;
using Attribute = Terminal.Gui.Attribute; using Attribute = Terminal.Gui.Attribute;
using Button = Terminal.Gui.Button;
using Color = Terminal.Gui.Color; using Color = Terminal.Gui.Color;
namespace chord namespace chord
@ -48,6 +50,10 @@ 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");
rpcClient.Initialize();
rpcClient.SetPresence(new RichPresence());
Application.Init(); Application.Init();
window = new Window("chord") window = new Window("chord")
@ -174,6 +180,8 @@ namespace chord
{ {
channelListTree.AddObject(category.Value); channelListTree.AddObject(category.Value);
} }
rpcClient.UpdateDetails($"Chatting in {client.GetGuild(currentSelectedGuild).Name}");
}; };
channelListTree.SelectionChanged += async (arg1, arg2) => channelListTree.SelectionChanged += async (arg1, arg2) =>
@ -244,6 +252,9 @@ namespace chord
{ {
userListTree.AddObject(role.Value); userListTree.AddObject(role.Value);
} }
rpcClient.UpdateState($"In channel {client.GetGuild(currentSelectedGuild).GetTextChannel(currentSelectedChannel).Name}");
rpcClient.UpdateStartTime();
} catch { } catch {
await chatBoxList.SetSourceAsync(new List<string>()); await chatBoxList.SetSourceAsync(new List<string>());
} }
@ -340,7 +351,10 @@ namespace chord
chatBoxList.SelectedItem = currentChannelMessages.Count - 1; chatBoxList.SelectedItem = currentChannelMessages.Count - 1;
}; };
Application.MainLoop.AddTimeout(TimeSpan.FromMilliseconds(100), caller => true); Application.MainLoop.AddTimeout(TimeSpan.FromMilliseconds(100), caller => {
rpcClient.Invoke();
return true;
});
Application.Run(); Application.Run();
Application.Shutdown(); Application.Shutdown();

View file

@ -23,6 +23,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Discord.Net.Labs" Version="3.5.0" /> <PackageReference Include="Discord.Net.Labs" Version="3.5.0" />
<PackageReference Include="DiscordRichPresence" Version="1.0.175" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.0" /> <PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" /> <PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" /> <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />