Archived
0
0
Fork 0

Compare commits

..

No commits in common. "0e2ffa7e9a7226292c37838fa448e0440c818681" and "b6a2c1d68f14d8220fef9b909db3237d2823c7ba" have entirely different histories.

3 changed files with 259 additions and 310 deletions

View file

@ -3,13 +3,11 @@ 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
@ -21,7 +19,6 @@ 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;
@ -51,12 +48,6 @@ namespace chord
await client.LoginAsync(TokenType.Bot, settings.Token); await client.LoginAsync(TokenType.Bot, settings.Token);
await client.StartAsync(); await client.StartAsync();
if (settings.EnableRichPresence) {
rpcClient = new DiscordRpcClient("923436807297859625");
rpcClient.Initialize();
rpcClient.SetPresence(new RichPresence());
}
Application.Init(); Application.Init();
window = new Window("chord") window = new Window("chord")
@ -71,18 +62,6 @@ 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 += () => client.Ready += () =>
{ {
guilds = new SortedDictionary<ulong, List<ulong>>(); guilds = new SortedDictionary<ulong, List<ulong>>();
@ -103,6 +82,7 @@ namespace chord
} }
} }
var menuBar = buildMenu();
var serverList = buildServerList(); var serverList = buildServerList();
var channelList = buildChannelList(serverList); var channelList = buildChannelList(serverList);
var chatBox = buildChatBox(serverList); var chatBox = buildChatBox(serverList);
@ -194,10 +174,6 @@ namespace chord
{ {
channelListTree.AddObject(category.Value); channelListTree.AddObject(category.Value);
} }
if (settings.EnableRichPresence) {
rpcClient.UpdateDetails($"Chatting in {client.GetGuild(currentSelectedGuild).Name}");
}
}; };
channelListTree.SelectionChanged += async (arg1, arg2) => channelListTree.SelectionChanged += async (arg1, arg2) =>
@ -253,38 +229,22 @@ namespace chord
foreach (var roles in client.GetGuild(currentSelectedGuild).Roles) 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 roleName = Regex.Replace(roles.Name, @"[^\u0000-\u007F]+", string.Empty);
var node = new TreeNode(roleName); var node = new TreeNode(roleName);
foreach (var users in roles.Members) foreach (var users in roles.Members)
{ {
var userName = Regex.Replace(users.Username, @"[^\u0000-\u007F]+", string.Empty); node.Children.Add(new TreeNode($"{users.Username}#{users.Discriminator} ({users.Nickname})"));
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.TryAdd(Math.Abs(roles.Position - client.GetGuild(currentSelectedGuild).Roles.Count()), node); rolesDict.Add(roles.Position, node);
}
}
} }
foreach (var role in rolesDict) foreach (var role in rolesDict)
{ {
userListTree.AddObject(role.Value); 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>()); await chatBoxList.SetSourceAsync(new List<string>());
} }
}; };
@ -350,7 +310,7 @@ namespace chord
} }
}; };
window.RemoveAll(); Application.Top.Add(window, menuBar);
window.Add(serverList, channelList, messageBox, chatBox, userList); window.Add(serverList, channelList, messageBox, chatBox, userList);
serverList.Add(serverListList); serverList.Add(serverListList);
channelList.Add(channelListTree); channelList.Add(channelListTree);
@ -380,21 +340,12 @@ namespace chord
chatBoxList.SelectedItem = currentChannelMessages.Count - 1; chatBoxList.SelectedItem = currentChannelMessages.Count - 1;
}; };
Application.MainLoop.AddTimeout(TimeSpan.FromMilliseconds(100), caller => { Application.MainLoop.AddTimeout(TimeSpan.FromMilliseconds(100), caller => true);
if (settings.EnableRichPresence)
rpcClient.Invoke();
return true;
});
Application.Top.Add(window, menuBar);
window.Add(loadingLabel);
Application.Run(); Application.Run();
Application.Shutdown(); Application.Shutdown();
} catch (System.Exception err) { } catch (System.Exception err) {
Console.WriteLine(err); Console.WriteLine(err);
Application.Shutdown();
} }
} }
@ -475,7 +426,6 @@ 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

2
TODO
View file

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

View file

@ -23,7 +23,6 @@
<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" />