From 5be86f13f447e6f00ff128a55ea8bbf4fec7aff3 Mon Sep 17 00:00:00 2001 From: Daryl Ronningen Date: Thu, 16 Dec 2021 15:58:32 -0700 Subject: [PATCH] feat: sorted channels by category --- Program.cs | 40 ++++++++++++++++++++++++++++++++++------ TODO | 2 +- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/Program.cs b/Program.cs index eb407ee..d645881 100644 --- a/Program.cs +++ b/Program.cs @@ -5,6 +5,7 @@ using Discord.WebSocket; using Microsoft.Extensions.Configuration; using RestSharp; using Terminal.Gui; +using Terminal.Gui.Trees; using Attribute = Terminal.Gui.Attribute; using Color = Terminal.Gui.Color; @@ -98,7 +99,7 @@ namespace chord serverListList.SetSource(guildNames); - var channelListList = new ListView + var channelListTree = new TreeView { X = 0, Y = 0, @@ -143,12 +144,39 @@ namespace chord var channelNames = guilds.GetValueOrDefault(currentSelectedGuild)! .Select(channel => client.GetGuild(currentSelectedGuild).GetTextChannel(channel).Name).ToList(); - channelListList.SetSource(channelNames); + var categoryDict = new SortedDictionary(); + + foreach (var categories in client.GetGuild(currentSelectedGuild).CategoryChannels) + { + var node = new TreeNode(categories.Name); + + foreach(var channel in categories.Channels) + { + if (channel.GetType().Name == "SocketTextChannel") + { + var channelNode = new TreeNode(channel.Name); + channelNode.Tag = new { Id = channel.Id }; + + node.Children.Add(channelNode); + } + } + + categoryDict.Add(categories.Id, node); + } + + foreach (var category in categoryDict) + { + channelListTree.AddObject(category.Value); + } }; - channelListList.OpenSelectedItem += async args => + channelListTree.SelectionChanged += async (arg1, arg2) => { - currentSelectedChannel = guilds.GetValueOrDefault(currentSelectedGuild)!.ToList()[args.Item]; + try { + currentSelectedChannel = (ulong)arg2.NewValue.Tag.GetType().GetProperty("Id").GetValue(arg2.NewValue.Tag); + } catch { + return; + } var restSharpClient = new RestClient("https://discord.com/api/v9"); var restSharpReq = new RestRequest($"channels/{currentSelectedChannel}/messages"); @@ -233,7 +261,7 @@ namespace chord serverListList.SetFocus(); break; case Key.CtrlMask | Key.C: - channelListList.SetFocus(); + channelListTree.SetFocus(); break; case Key.CtrlMask | Key.AltMask | Key.C: chatBoxList.SetFocus(); @@ -257,7 +285,7 @@ namespace chord Application.Top.Add(window, menuBar); window.Add(serverList, channelList, messageBox, chatBox, userList); serverList.Add(serverListList); - channelList.Add(channelListList); + channelList.Add(channelListTree); chatBox.Add(chatBoxList); messageBox.Add(messageBoxText, messageBoxSend); userList.Add(userListList); diff --git a/TODO b/TODO index bc1d363..5fadd6e 100644 --- a/TODO +++ b/TODO @@ -1,7 +1,7 @@ - Figure out how to bypass discord intents for user list (Currently just using Discord.NET cache) - Message Conversion - Convert message attachments to links (DONE) - - Sort Channels by catagories + - Sort Channels by catagories (DONE) - DMs - Loading Screen - Hotkeys (Partially Done. Still some weird stuff that happens that idfk why happens)