Archived
0
0
Fork 0

Compare commits

...

10 commits

3 changed files with 312 additions and 261 deletions

View file

@ -3,11 +3,13 @@ using System.Text;
using System.Text.RegularExpressions;
using Discord;
using Discord.WebSocket;
using DiscordRPC;
using Microsoft.Extensions.Configuration;
using RestSharp;
using Terminal.Gui;
using Terminal.Gui.Trees;
using Attribute = Terminal.Gui.Attribute;
using Button = Terminal.Gui.Button;
using Color = Terminal.Gui.Color;
namespace chord
@ -19,6 +21,7 @@ namespace chord
private ulong currentSelectedChannel;
private ulong currentSelectedGuild;
private SortedDictionary<ulong, List<ulong>> guilds;
private DiscordRpcClient rpcClient;
private Settings settings;
private Window window;
@ -48,6 +51,12 @@ namespace chord
await client.LoginAsync(TokenType.Bot, settings.Token);
await client.StartAsync();
if (settings.EnableRichPresence) {
rpcClient = new DiscordRpcClient("923436807297859625");
rpcClient.Initialize();
rpcClient.SetPresence(new RichPresence());
}
Application.Init();
window = new Window("chord")
@ -62,6 +71,18 @@ namespace chord
}
};
var menuBar = buildMenu();
var loadingLabel = new Label("Loading...")
{
X = 0,
Y = 0,
Width = Dim.Fill(),
Height = Dim.Fill(),
TextAlignment = TextAlignment.Centered,
VerticalTextAlignment = VerticalTextAlignment.Middle,
};
client.Ready += () =>
{
guilds = new SortedDictionary<ulong, List<ulong>>();
@ -82,7 +103,6 @@ namespace chord
}
}
var menuBar = buildMenu();
var serverList = buildServerList();
var channelList = buildChannelList(serverList);
var chatBox = buildChatBox(serverList);
@ -174,6 +194,10 @@ namespace chord
{
channelListTree.AddObject(category.Value);
}
if (settings.EnableRichPresence) {
rpcClient.UpdateDetails($"Chatting in {client.GetGuild(currentSelectedGuild).Name}");
}
};
channelListTree.SelectionChanged += async (arg1, arg2) =>
@ -229,22 +253,38 @@ namespace chord
foreach (var roles in client.GetGuild(currentSelectedGuild).Roles)
{
if (roles.IsHoisted) {
if (roles.Members.Count() != 0) {
var roleName = Regex.Replace(roles.Name, @"[^\u0000-\u007F]+", string.Empty);
var node = new TreeNode(roleName);
foreach (var users in roles.Members)
{
node.Children.Add(new TreeNode($"{users.Username}#{users.Discriminator} ({users.Nickname})"));
var userName = Regex.Replace(users.Username, @"[^\u0000-\u007F]+", string.Empty);
string userNick = string.Empty;
if (users.Nickname != null)
userNick = Regex.Replace(users.Nickname, @"[^\u0000-\u007F]+", string.Empty);
node.Children.Add(new TreeNode($"{userName}#{users.Discriminator} ({userNick})"));
}
rolesDict.Add(roles.Position, node);
rolesDict.TryAdd(Math.Abs(roles.Position - client.GetGuild(currentSelectedGuild).Roles.Count()), node);
}
}
}
foreach (var role in rolesDict)
{
userListTree.AddObject(role.Value);
}
} catch {
if (settings.EnableRichPresence) {
rpcClient.UpdateState($"In channel {client.GetGuild(currentSelectedGuild).GetTextChannel(currentSelectedChannel).Name}");
rpcClient.UpdateStartTime();
}
} catch(Exception err) {
Console.WriteLine(err);
await chatBoxList.SetSourceAsync(new List<string>());
}
};
@ -310,7 +350,7 @@ namespace chord
}
};
Application.Top.Add(window, menuBar);
window.RemoveAll();
window.Add(serverList, channelList, messageBox, chatBox, userList);
serverList.Add(serverListList);
channelList.Add(channelListTree);
@ -340,12 +380,21 @@ namespace chord
chatBoxList.SelectedItem = currentChannelMessages.Count - 1;
};
Application.MainLoop.AddTimeout(TimeSpan.FromMilliseconds(100), caller => true);
Application.MainLoop.AddTimeout(TimeSpan.FromMilliseconds(100), caller => {
if (settings.EnableRichPresence)
rpcClient.Invoke();
return true;
});
Application.Top.Add(window, menuBar);
window.Add(loadingLabel);
Application.Run();
Application.Shutdown();
} catch (System.Exception err) {
Console.WriteLine(err);
Application.Shutdown();
}
}
@ -426,6 +475,7 @@ namespace chord
public class Settings
{
public string Token { get; set; }
public bool EnableRichPresence { get; set; }
}
public class GetMessagesResponse

2
TODO
View file

@ -3,6 +3,6 @@
- Convert message attachments to links (DONE)
- Sort Channels by catagories (DONE)
- DMs
- Loading Screen
- Loading Screen (DONE)
- Hotkeys (Partially Done. Still some weird stuff that happens that idfk why happens)
- User roles sorting (DONE)

View file

@ -23,6 +23,7 @@
<ItemGroup>
<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.Binder" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />