Compare commits
No commits in common. "0e2ffa7e9a7226292c37838fa448e0440c818681" and "b6a2c1d68f14d8220fef9b909db3237d2823c7ba" have entirely different histories.
0e2ffa7e9a
...
b6a2c1d68f
3 changed files with 259 additions and 310 deletions
62
Program.cs
62
Program.cs
|
@ -3,13 +3,11 @@ 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
|
||||
|
@ -21,7 +19,6 @@ namespace chord
|
|||
private ulong currentSelectedChannel;
|
||||
private ulong currentSelectedGuild;
|
||||
private SortedDictionary<ulong, List<ulong>> guilds;
|
||||
private DiscordRpcClient rpcClient;
|
||||
private Settings settings;
|
||||
private Window window;
|
||||
|
||||
|
@ -51,12 +48,6 @@ 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")
|
||||
|
@ -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 += () =>
|
||||
{
|
||||
guilds = new SortedDictionary<ulong, List<ulong>>();
|
||||
|
@ -103,6 +82,7 @@ namespace chord
|
|||
}
|
||||
}
|
||||
|
||||
var menuBar = buildMenu();
|
||||
var serverList = buildServerList();
|
||||
var channelList = buildChannelList(serverList);
|
||||
var chatBox = buildChatBox(serverList);
|
||||
|
@ -194,10 +174,6 @@ namespace chord
|
|||
{
|
||||
channelListTree.AddObject(category.Value);
|
||||
}
|
||||
|
||||
if (settings.EnableRichPresence) {
|
||||
rpcClient.UpdateDetails($"Chatting in {client.GetGuild(currentSelectedGuild).Name}");
|
||||
}
|
||||
};
|
||||
|
||||
channelListTree.SelectionChanged += async (arg1, arg2) =>
|
||||
|
@ -253,38 +229,22 @@ 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)
|
||||
{
|
||||
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})"));
|
||||
node.Children.Add(new TreeNode($"{users.Username}#{users.Discriminator} ({users.Nickname})"));
|
||||
}
|
||||
|
||||
rolesDict.TryAdd(Math.Abs(roles.Position - client.GetGuild(currentSelectedGuild).Roles.Count()), node);
|
||||
}
|
||||
}
|
||||
rolesDict.Add(roles.Position, node);
|
||||
}
|
||||
|
||||
foreach (var role in rolesDict)
|
||||
{
|
||||
userListTree.AddObject(role.Value);
|
||||
}
|
||||
|
||||
if (settings.EnableRichPresence) {
|
||||
rpcClient.UpdateState($"In channel {client.GetGuild(currentSelectedGuild).GetTextChannel(currentSelectedChannel).Name}");
|
||||
rpcClient.UpdateStartTime();
|
||||
}
|
||||
} catch(Exception err) {
|
||||
Console.WriteLine(err);
|
||||
} catch {
|
||||
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);
|
||||
serverList.Add(serverListList);
|
||||
channelList.Add(channelListTree);
|
||||
|
@ -380,21 +340,12 @@ namespace chord
|
|||
chatBoxList.SelectedItem = currentChannelMessages.Count - 1;
|
||||
};
|
||||
|
||||
Application.MainLoop.AddTimeout(TimeSpan.FromMilliseconds(100), caller => {
|
||||
if (settings.EnableRichPresence)
|
||||
rpcClient.Invoke();
|
||||
return true;
|
||||
});
|
||||
|
||||
Application.Top.Add(window, menuBar);
|
||||
window.Add(loadingLabel);
|
||||
Application.MainLoop.AddTimeout(TimeSpan.FromMilliseconds(100), caller => true);
|
||||
|
||||
Application.Run();
|
||||
Application.Shutdown();
|
||||
} catch (System.Exception err) {
|
||||
Console.WriteLine(err);
|
||||
|
||||
Application.Shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -475,7 +426,6 @@ namespace chord
|
|||
public class Settings
|
||||
{
|
||||
public string Token { get; set; }
|
||||
public bool EnableRichPresence { get; set; }
|
||||
}
|
||||
|
||||
public class GetMessagesResponse
|
||||
|
|
2
TODO
2
TODO
|
@ -3,6 +3,6 @@
|
|||
- Convert message attachments to links (DONE)
|
||||
- Sort Channels by catagories (DONE)
|
||||
- DMs
|
||||
- Loading Screen (DONE)
|
||||
- Loading Screen
|
||||
- Hotkeys (Partially Done. Still some weird stuff that happens that idfk why happens)
|
||||
- User roles sorting (DONE)
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
|
||||
<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" />
|
||||
|
|
Reference in a new issue