diff --git a/Module/ModTools/Commands/BanKick.cs b/Module/ModTools/Commands/BanKick.cs index 872b57b..24d85b0 100644 --- a/Module/ModTools/Commands/BanKick.cs +++ b/Module/ModTools/Commands/BanKick.cs @@ -20,9 +20,6 @@ namespace Noikoio.RegexBot.Module.ModTools.Commands private readonly string _notifyMsg; const string DefaultMsg = "You have been {0} from $s for the following reason:\n$r"; - const string DefaultMsgBanAppend = "\n\nIf the moderators have allowed it, you may petition your ban by" + - " submitting **one** message to the moderation team. To do so, reply to this message with" + - " `!petition [Your message here]`."; // Configuration: // "forcereason" - boolean; Force a reason to be given. Defaults to false. @@ -46,7 +43,6 @@ namespace Noikoio.RegexBot.Module.ModTools.Commands { // Message not specified - use default _notifyMsg = string.Format(DefaultMsg, mode == CommandMode.Ban ? "banned" : "kicked"); - if (_mode == CommandMode.Ban) _notifyMsg += DefaultMsgBanAppend; } else { @@ -131,9 +127,6 @@ namespace Noikoio.RegexBot.Module.ModTools.Commands } else notifyfail = true; - // Give target user ability to petition - if (_mode == CommandMode.Ban) Mt.AddPetition(g.Id, targetuid); - // Do the action try { diff --git a/Module/ModTools/ConfigItem.cs b/Module/ModTools/ConfigItem.cs index a135a3f..5a29ac6 100644 --- a/Module/ModTools/ConfigItem.cs +++ b/Module/ModTools/ConfigItem.cs @@ -11,10 +11,8 @@ namespace Noikoio.RegexBot.Module.ModTools /// class ConfigItem { - private EntityName? _petitionReportCh; private readonly ReadOnlyDictionary _cmdInstances; - - public EntityName? PetitionReportingChannel => _petitionReportCh; + public ReadOnlyDictionary Commands => _cmdInstances; public ConfigItem(ModTools instance, JToken inconf) @@ -24,19 +22,7 @@ namespace Noikoio.RegexBot.Module.ModTools throw new RuleImportException("Configuration for this section is invalid."); } var config = (JObject)inconf; - - // Ban petition reporting channel - var petitionstr = config["PetitionRelay"]?.Value(); - if (string.IsNullOrEmpty(petitionstr)) _petitionReportCh = null; - else if (petitionstr.Length > 1 && petitionstr[0] != '#') - { - // Not a channel. - throw new RuleImportException("PetitionRelay value must be set to a channel."); - } - else - { - _petitionReportCh = new EntityName(petitionstr.Substring(1), EntityType.Channel); - } + // Command instances var commands = new Dictionary(StringComparer.OrdinalIgnoreCase); @@ -62,14 +48,5 @@ namespace Noikoio.RegexBot.Module.ModTools } _cmdInstances = new ReadOnlyDictionary(commands); } - - public void UpdatePetitionChannel(ulong id) - { - if (!PetitionReportingChannel.HasValue) return; - if (PetitionReportingChannel.Value.Id.HasValue) return; // nothing to update - - // For lack of a better option - create a new EntityName with ID already provided - _petitionReportCh = new EntityName($"{id}::{PetitionReportingChannel.Value.Name}", EntityType.Channel); - } } } diff --git a/Module/ModTools/ModTools.cs b/Module/ModTools/ModTools.cs index 2d75022..231de46 100644 --- a/Module/ModTools/ModTools.cs +++ b/Module/ModTools/ModTools.cs @@ -3,7 +3,6 @@ using Discord.WebSocket; using Newtonsoft.Json.Linq; using Noikoio.RegexBot.ConfigItem; using System; -using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -27,8 +26,7 @@ namespace Noikoio.RegexBot.Module.ModTools // Always ignore bots if (arg.Author.IsBot) return; - if (arg.Channel is IDMChannel) await PetitionRelayCheck(arg); - else if (arg.Channel is IGuildChannel) await CommandCheckInvoke(arg); + if (arg.Channel is IGuildChannel) await CommandCheckInvoke(arg); } [ConfigSection("ModTools")] @@ -40,8 +38,6 @@ namespace Noikoio.RegexBot.Module.ModTools // Log results if (conf.Commands.Count > 0) await Log(conf.Commands.Count + " command definition(s) loaded."); - if (conf.PetitionReportingChannel.HasValue) - await Log("Ban petitioning has been enabled."); return conf; } @@ -83,133 +79,5 @@ namespace Noikoio.RegexBot.Module.ModTools } } } - - #region Ban petitions - /// - /// List of available appeals. Key is user (for quick lookup). Value is guild (for quick config resolution). - /// TODO expiration? - /// - private Dictionary _openPetitions = new Dictionary(); - public void AddPetition(ulong guild, ulong user) - { - // Do nothing if disabled - if (!GetConfig(guild).PetitionReportingChannel.HasValue) return; - lock (_openPetitions) _openPetitions[user] = guild; - } - private async Task PetitionRelayCheck(SocketMessage msg) - { - const string PetitionAccepted = "Your petition has been forwarded to the moderators for review."; - const string PetitionDenied = "You may not submit a ban petition."; - - // It's possible the sender may still block messages sent to them, - // hence the empty catch blocks you'll see up ahead. - - if (!msg.Content.StartsWith("!petition ", StringComparison.InvariantCultureIgnoreCase)) return; - - // Input validation - string ptext = msg.Content.Substring(10); - if (string.IsNullOrWhiteSpace(ptext)) - { - // Just ignore. - return; - } - if (ptext.Length > 1000) - { - // Enforce petition length limit. - try { await msg.Author.SendMessageAsync("Your petition message is too long. Try again with a shorter message."); } - catch (Discord.Net.HttpException) { } - return; - } - - ulong targetGuild = 0; - lock (_openPetitions) - { - if (_openPetitions.TryGetValue(msg.Author.Id, out targetGuild)) - { - _openPetitions.Remove(msg.Author.Id); - } - } - - if (targetGuild == 0) - { - // Not in the list. Nothing to do. - try { await msg.Author.SendMessageAsync(PetitionDenied); } - catch (Discord.Net.HttpException) { } - return; - } - var gObj = Client.GetGuild(targetGuild); - if (gObj == null) - { - // Guild is missing. No longer in guild? - try { await msg.Author.SendMessageAsync(PetitionDenied); } - catch (Discord.Net.HttpException) { } - return; - } - - // Get petition reporting target - var pcv = GetConfig(targetGuild).PetitionReportingChannel; - if (!pcv.HasValue) return; // No target. This should be logically impossible, but... just in case. - var rch = pcv.Value; - ISocketMessageChannel rchObj; - if (!rch.Id.HasValue) - { - rchObj = gObj.TextChannels - .Where(c => c.Name.Equals(rch.Name, StringComparison.InvariantCultureIgnoreCase)) - .FirstOrDefault(); - // Update value if found - if (rchObj != null) - { - GetConfig(targetGuild).UpdatePetitionChannel(rchObj.Id); - } - } - else - { - rchObj = gObj.GetChannel(rch.Id.Value) as ISocketMessageChannel; - } - - if (rchObj == null) - { - // Channel not found. - await Log("Petition reporting channel could not be resolved."); - try { await msg.Author.SendMessageAsync(PetitionDenied); } - catch (Discord.Net.HttpException) { } - return; - } - - // Ready to relay - try - { - await rchObj.SendMessageAsync("", embed: new EmbedBuilder() - { - Color = new Color(0x00FFD9), - - Author = new EmbedAuthorBuilder() - { - Name = $"{msg.Author.ToString()} - Ban petition:", - IconUrl = msg.Author.GetAvatarUrl() - }, - Description = ptext, - Timestamp = msg.Timestamp, - - Footer = new EmbedFooterBuilder() - { - Text = "User ID: " + msg.Author.Id - } - }); - } - catch (Discord.Net.HttpException ex) - { - await Log("Failed to relay petition message by " + msg.Author.ToString()); - await Log(ex.Message); - // For the user's point of view, fail silently. - try { await msg.Author.SendMessageAsync(PetitionDenied); } - catch (Discord.Net.HttpException) { } - } - - // Success. Notify user. - try { await msg.Author.SendMessageAsync(PetitionAccepted); } - catch (Discord.Net.HttpException) { } - } - #endregion } } diff --git a/RegexBot.csproj b/RegexBot.csproj index 342bb6c..c4e8f15 100644 --- a/RegexBot.csproj +++ b/RegexBot.csproj @@ -4,7 +4,7 @@ Exe netcoreapp2.0 Noikoio.RegexBot - 2.4.0.0 + 2.4.1.0 Highly configurable Discord moderation bot Noikoio