diff --git a/Program.cs b/Program.cs index 9638302..d0edfa7 100644 --- a/Program.cs +++ b/Program.cs @@ -1,5 +1,6 @@ using System.Diagnostics; using System.Text; +using System.Text.RegularExpressions; using Discord; using Discord.WebSocket; using Microsoft.Extensions.Configuration; @@ -28,6 +29,7 @@ namespace chord private async void Start() { + try { #if DEBUG var config = new ConfigurationBuilder() .AddJsonFile("config.json") @@ -139,6 +141,8 @@ namespace chord serverListList.OpenSelectedItem += args => { + channelListTree.ClearObjects(); + currentSelectedGuild = guilds.Keys.ToList()[args.Item]; var channelNames = guilds.GetValueOrDefault(currentSelectedGuild)! @@ -148,13 +152,15 @@ namespace chord foreach (var categories in client.GetGuild(currentSelectedGuild).CategoryChannels) { - var node = new TreeNode(categories.Name); + var categoryName = Regex.Replace(categories.Name, @"[^\u0000-\u007F]+", string.Empty); + var node = new TreeNode(categoryName); foreach(var channel in categories.Channels) { if (channel.GetType().Name == "SocketTextChannel") { - var channelNode = new TreeNode(channel.Name); + var channelName = Regex.Replace(categories.Name, @"[^\u0000-\u007F]+", string.Empty); + var channelNode = new TreeNode(channelName); channelNode.Tag = new { Id = channel.Id }; node.Children.Add(channelNode); @@ -172,6 +178,8 @@ namespace chord channelListTree.SelectionChanged += async (arg1, arg2) => { + userListTree.ClearObjects(); + try { currentSelectedChannel = (ulong)arg2.NewValue.Tag.GetType().GetProperty("Id").GetValue(arg2.NewValue.Tag); } catch { @@ -220,7 +228,8 @@ namespace chord foreach (var roles in client.GetGuild(currentSelectedGuild).Roles) { - var node = new TreeNode(roles.Name); + var roleName = Regex.Replace(roles.Name, @"[^\u0000-\u007F]+", string.Empty); + var node = new TreeNode(roleName); foreach (var users in roles.Members) { @@ -331,6 +340,9 @@ namespace chord Application.Run(); Application.Shutdown(); + } catch (System.Exception err) { + Console.WriteLine(err); + } } private Window buildChatBox(Window serverList)