From 108578656b3972ede3117c13f9849358dd6cad5a Mon Sep 17 00:00:00 2001 From: Madpeterz <57852827+Madpeterz@users.noreply.github.com> Date: Sun, 31 Jan 2021 02:45:30 +0000 Subject: [PATCH] discord-v status fixs --- CLI/DiscordSupervisor/ChannelControl.cs | 99 +++++++++++++------------ CLI/DiscordSupervisor/Discord-super.cs | 10 ++- CLI/DiscordSupervisor/DiscordBot.cs | 6 +- CLI/DiscordSupervisor/Inbound.cs | 1 + CLI/DiscordSupervisor/Values.cs | 1 + 5 files changed, 64 insertions(+), 53 deletions(-) diff --git a/CLI/DiscordSupervisor/ChannelControl.cs b/CLI/DiscordSupervisor/ChannelControl.cs index 9ef3c63..7dfe1e8 100644 --- a/CLI/DiscordSupervisor/ChannelControl.cs +++ b/CLI/DiscordSupervisor/ChannelControl.cs @@ -210,62 +210,65 @@ namespace BetterSecondBot.DiscordSupervisor protected async Task DiscordRebuildChannels() { - List required_cats = new List() { "bot", "group", "im" }; - IReadOnlyCollection found_cats = await DiscordServer.GetCategoriesAsync(CacheMode.AllowDownload); - foreach (ICategoryChannel fcat in found_cats) - { - if (catmap.ContainsKey(fcat.Name) == false) + if (DiscordServer != null) + { + List required_cats = new List() { "bot", "group", "im" }; + IReadOnlyCollection found_cats = await DiscordServer.GetCategoriesAsync(CacheMode.AllowDownload); + foreach (ICategoryChannel fcat in found_cats) { - if (required_cats.Contains(fcat.Name) == true) + if (catmap.ContainsKey(fcat.Name) == false) + { + if (required_cats.Contains(fcat.Name) == true) + { + required_cats.Remove(fcat.Name); + catmap.Add(fcat.Name, fcat); + } + } + else { required_cats.Remove(fcat.Name); - catmap.Add(fcat.Name, fcat); - } - } - else + } + } + foreach (string A in required_cats) { - required_cats.Remove(fcat.Name); - } - } - foreach (string A in required_cats) - { - ICategoryChannel newcat = await DiscordServer.CreateCategoryAsync(A).ConfigureAwait(true); - catmap.Add(A, newcat); - } - List required_channels = new List() { "status", "interface","localchat" }; - IReadOnlyCollection found_chans = await DiscordServer.GetTextChannelsAsync(CacheMode.AllowDownload); - List GroupChannels = new List(); - foreach (ITextChannel chan in found_chans) - { - if (chan.CategoryId == catmap["bot"].Id) - { - required_channels.Remove(chan.Name); - } - else - { - if (GroupChannels.Contains(chan.Name) == false) + ICategoryChannel newcat = await DiscordServer.CreateCategoryAsync(A).ConfigureAwait(true); + catmap.Add(A, newcat); + } + List required_channels = new List() { "status", "interface", "localchat" }; + IReadOnlyCollection found_chans = await DiscordServer.GetTextChannelsAsync(CacheMode.AllowDownload); + List GroupChannels = new List(); + foreach (ITextChannel chan in found_chans) + { + if (chan.CategoryId == catmap["bot"].Id) { - if (chan.CategoryId == catmap["group"].Id) + required_channels.Remove(chan.Name); + } + else + { + if (GroupChannels.Contains(chan.Name) == false) { - GroupChannels.Add(chan.Name); - } - } - } - } - foreach (string A in required_channels) - { - _ = await FindTextChannel(A, catmap["bot"], UUID.Zero, "bot").ConfigureAwait(false); - } - - if (HasBot() == true) - { - foreach (Group G in controler.Bot.MyGroups.Values) + if (chan.CategoryId == catmap["group"].Id) + { + GroupChannels.Add(chan.Name); + } + } + } + } + foreach (string A in required_channels) { - string groupname = G.Name.ToLowerInvariant(); - groupname = String.Concat(groupname.Where(char.IsLetterOrDigit)); - if (GroupChannels.Contains(groupname) == false) + _ = await FindTextChannel(A, catmap["bot"], UUID.Zero, "bot").ConfigureAwait(false); + } + + if (HasBot() == true) + { + foreach (Group G in controler.Bot.MyGroups.Values) { - _ = await FindTextChannel(groupname, catmap["group"], G.ID, "Group").ConfigureAwait(false); + string groupname = G.Name.ToLowerInvariant(); + groupname = String.Concat(groupname.Where(char.IsLetterOrDigit)); + if (GroupChannels.Contains(groupname) == false) + { + _ = await FindTextChannel(groupname, catmap["group"], G.ID, "Group").ConfigureAwait(false); + } } } } diff --git a/CLI/DiscordSupervisor/Discord-super.cs b/CLI/DiscordSupervisor/Discord-super.cs index f5a40dd..2f8e5eb 100644 --- a/CLI/DiscordSupervisor/Discord-super.cs +++ b/CLI/DiscordSupervisor/Discord-super.cs @@ -57,7 +57,6 @@ namespace BetterSecondBot.DiscordSupervisor if (myconfig.DiscordFull_Enable == true) { _ = StartDiscordClientService(); - login_bot(false); keep_alive(); } else @@ -68,9 +67,12 @@ namespace BetterSecondBot.DiscordSupervisor protected override void login_bot(bool self_keep_alive) { - controler = new CliExitOnLogout(myconfig, running_as_docker, self_keep_alive); - controler.Bot.setDiscordClient(DiscordClient); - attach_events(); + if (controler != null) + { + controler = new CliExitOnLogout(myconfig, running_as_docker, self_keep_alive); + controler.Bot.setDiscordClient(DiscordClient); + attach_events(); + } } } diff --git a/CLI/DiscordSupervisor/DiscordBot.cs b/CLI/DiscordSupervisor/DiscordBot.cs index bf17776..21537e1 100644 --- a/CLI/DiscordSupervisor/DiscordBot.cs +++ b/CLI/DiscordSupervisor/DiscordBot.cs @@ -27,7 +27,11 @@ namespace BetterSecondBot.DiscordSupervisor await DiscordClient.SetGameAsync("Not connected", null, ActivityType.CustomStatus); DiscordServer = DiscordClient.GetGuild(myconfig.DiscordFull_ServerID); if (DiscordServer != null) - { + { + if (myconfig.DiscordFull_Enable == true) + { + login_bot(false); + } DiscordUnixTimeOnine = helpers.UnixTimeNow(); DiscordClientConnected = true; await DiscordRebuildChannels(); diff --git a/CLI/DiscordSupervisor/Inbound.cs b/CLI/DiscordSupervisor/Inbound.cs index d145dfb..a9cd264 100644 --- a/CLI/DiscordSupervisor/Inbound.cs +++ b/CLI/DiscordSupervisor/Inbound.cs @@ -39,6 +39,7 @@ namespace BetterSecondBot.DiscordSupervisor return await MarkMessage(message, "❌"); } controler.Bot.KillMePlease(); + controler = null; return await MarkMessage(message, "✅").ConfigureAwait(false); } else if(message.Content == "exit") diff --git a/CLI/DiscordSupervisor/Values.cs b/CLI/DiscordSupervisor/Values.cs index ce98fba..5df36f5 100644 --- a/CLI/DiscordSupervisor/Values.cs +++ b/CLI/DiscordSupervisor/Values.cs @@ -15,6 +15,7 @@ namespace BetterSecondBot.DiscordSupervisor protected bool discord_group_relay; protected DiscordSocketClient DiscordClient; protected bool DiscordClientConnected; + protected IGuild DiscordServer; protected string LastSendDiscordStatus = ""; protected long DiscordUnixTimeOnine;