From 3c4158bcf48db3ed839a5becfc99aec3a09553f1 Mon Sep 17 00:00:00 2001 From: Madpeterz <57852827+Madpeterz@users.noreply.github.com> Date: Sun, 31 Jan 2021 03:38:06 +0000 Subject: [PATCH] new config value: DiscordFull_Keep_GroupChat When set to True discord group chat messages will not be removed --- BSBshared/Json/JsonConfig.cs | 2 ++ BSBshared/Json/JsonConfigApi.cs | 4 +++ CLI/DiscordSupervisor/ChannelControl.cs | 39 ++++++++++++++++++------- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/BSBshared/Json/JsonConfig.cs b/BSBshared/Json/JsonConfig.cs index 5697944..4855607 100644 --- a/BSBshared/Json/JsonConfig.cs +++ b/BSBshared/Json/JsonConfig.cs @@ -40,6 +40,8 @@ namespace BetterSecondBotShared.Json public string DiscordFull_Token { get; set; } public ulong DiscordFull_ServerID { get; set; } + public bool DiscordFull_Keep_GroupChat { get; set; } + // HTTP interface public bool Http_Enable { get; set; } public int Http_Port { get; set; } diff --git a/BSBshared/Json/JsonConfigApi.cs b/BSBshared/Json/JsonConfigApi.cs index 4ec9cb5..fb237b3 100644 --- a/BSBshared/Json/JsonConfigApi.cs +++ b/BSBshared/Json/JsonConfigApi.cs @@ -113,6 +113,10 @@ namespace BetterSecondBotShared.Json { return "UUID of a object the bot should attempt to sit on after logging in"; } + else if (cmd == "DiscordFull_Keep_GroupChat") + { + return "When set to true discord group chat messages will not be removed"; + } return ""; } protected string GetHelp_HTTP(string cmd) diff --git a/CLI/DiscordSupervisor/ChannelControl.cs b/CLI/DiscordSupervisor/ChannelControl.cs index 7dfe1e8..a5aeed6 100644 --- a/CLI/DiscordSupervisor/ChannelControl.cs +++ b/CLI/DiscordSupervisor/ChannelControl.cs @@ -17,26 +17,42 @@ namespace BetterSecondBot.DiscordSupervisor channelname = channelname.ToLowerInvariant(); channelname = String.Concat(channelname.Where(char.IsLetterOrDigit)); - ITextChannel Channel = await FindTextChannel(channelname, catmap[catmapid], sender_id, TopicType).ConfigureAwait(true); + ITextChannel Channel = await FindTextChannel(channelname, catmap[catmapid], sender_id, TopicType, false).ConfigureAwait(true); if (Channel != null) { return await Channel.SendMessageAsync(message).ConfigureAwait(false); } } return null; + } + + protected async Task FindTextChannel(string channelname, ICategoryChannel cat, UUID sender, string TopicType, bool CleanChannel) + { + return await FindTextChannel(DiscordServer, channelname, cat, sender, TopicType, true, CleanChannel); } - protected async Task FindTextChannel(string channelname, ICategoryChannel cat, UUID sender, string TopicType) - { - return await FindTextChannel(DiscordServer, channelname, cat, sender, TopicType); - } protected async Task FindTextChannel(IGuild onserver, string channelname) { - return await FindTextChannel(onserver, channelname, null, UUID.Zero, "notUSED", false); + return await FindTextChannel(onserver, channelname, null, UUID.Zero, "notUSED"); + } + + protected async Task FindTextChannel(IGuild onserver, string channelname, ICategoryChannel cat) + { + return await FindTextChannel(onserver, channelname, cat, UUID.Zero, "notUSED", true); + } + + protected async Task FindTextChannel(IGuild onserver, string channelname, ICategoryChannel cat, UUID sender, string TopicType) + { + return await FindTextChannel(onserver, channelname, cat, sender, TopicType, true); + } + + protected async Task FindTextChannel(IGuild onserver, string channelname, ICategoryChannel cat, UUID sender, string TopicType, bool create_channel) + { + return await FindTextChannel(onserver, channelname, cat, sender, TopicType, create_channel, true); } - protected async Task FindTextChannel(IGuild onserver,string channelname, ICategoryChannel cat, UUID sender, string TopicType,bool create_channel=true) + protected async Task FindTextChannel(IGuild onserver,string channelname, ICategoryChannel cat, UUID sender, string TopicType,bool create_channel, bool CleanChannel) { await WaitForUnlock().ConfigureAwait(false); channelname = channelname.ToLowerInvariant(); @@ -74,7 +90,10 @@ namespace BetterSecondBot.DiscordSupervisor } else { - await CleanDiscordChannel(result, 24).ConfigureAwait(false); + if (CleanChannel == true) + { + await CleanDiscordChannel(result, 24).ConfigureAwait(false); + } } } DiscordLock = false; @@ -256,7 +275,7 @@ namespace BetterSecondBot.DiscordSupervisor } foreach (string A in required_channels) { - _ = await FindTextChannel(A, catmap["bot"], UUID.Zero, "bot").ConfigureAwait(false); + _ = await FindTextChannel(A, catmap["bot"], UUID.Zero, "bot", true).ConfigureAwait(false); } if (HasBot() == true) @@ -267,7 +286,7 @@ namespace BetterSecondBot.DiscordSupervisor groupname = String.Concat(groupname.Where(char.IsLetterOrDigit)); if (GroupChannels.Contains(groupname) == false) { - _ = await FindTextChannel(groupname, catmap["group"], G.ID, "Group").ConfigureAwait(false); + _ = await FindTextChannel(groupname, catmap["group"], G.ID, "Group", !myconfig.DiscordFull_Keep_GroupChat).ConfigureAwait(false); } } }