Fully implemented ban petitions
This commit is contained in:
parent
1e681478f5
commit
1656e4fa64
2 changed files with 57 additions and 29 deletions
|
@ -22,6 +22,7 @@ namespace Noikoio.RegexBot.Module.ModTools
|
||||||
private readonly string _label;
|
private readonly string _label;
|
||||||
private readonly string _command;
|
private readonly string _command;
|
||||||
|
|
||||||
|
protected ModTools Mt => _modtools;
|
||||||
public string Label => _label;
|
public string Label => _label;
|
||||||
public string Command => _command;
|
public string Command => _command;
|
||||||
|
|
||||||
|
|
|
@ -37,18 +37,33 @@ namespace Noikoio.RegexBot.Module.ModTools
|
||||||
{
|
{
|
||||||
throw new RuleImportException("Configuration for this section is invalid.");
|
throw new RuleImportException("Configuration for this section is invalid.");
|
||||||
}
|
}
|
||||||
|
var config = (JObject)configSection;
|
||||||
|
|
||||||
// BIG TO DO LIST:
|
// Ban petition reporting channel
|
||||||
/*
|
EntityName? petitionrpt;
|
||||||
* 1. Have commands go into their own space within modtools. Candidate name: "banappeal"
|
var petitionstr = config["PetitionRelay"]?.Value<string>();
|
||||||
* 2. Add a property for where to put the petition channel
|
if (string.IsNullOrEmpty(petitionstr)) petitionrpt = null;
|
||||||
* 3. Within ban cmd load, have it check for the existence of a petition channel... if possible?
|
else if (petitionstr.Length > 1 && petitionstr[0] != '#')
|
||||||
* I guess otherwise silently discard, if the info isn't readily available. I don't know.
|
{
|
||||||
*/
|
// Not a channel.
|
||||||
|
throw new RuleImportException("PetitionRelay value must be set to a channel.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
petitionrpt = new EntityName(petitionstr.Substring(1), EntityType.Channel);
|
||||||
|
}
|
||||||
|
|
||||||
|
// And then the commands
|
||||||
var commands = new Dictionary<string, CommandBase>(StringComparer.OrdinalIgnoreCase);
|
var commands = new Dictionary<string, CommandBase>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
var commandconf = config["Commands"];
|
||||||
|
if (commandconf != null)
|
||||||
|
{
|
||||||
|
if (commandconf.Type != JTokenType.Object)
|
||||||
|
{
|
||||||
|
throw new RuleImportException("CommandDefs is not properly defined.");
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var def in configSection.Children<JProperty>())
|
foreach (var def in commandconf.Children<JProperty>())
|
||||||
{
|
{
|
||||||
string label = def.Name;
|
string label = def.Name;
|
||||||
var cmd = CommandBase.CreateInstance(this, def);
|
var cmd = CommandBase.CreateInstance(this, def);
|
||||||
|
@ -60,7 +75,10 @@ namespace Noikoio.RegexBot.Module.ModTools
|
||||||
commands.Add(cmd.Command, cmd);
|
commands.Add(cmd.Command, cmd);
|
||||||
}
|
}
|
||||||
await Log($"Loaded {commands.Count} command definition(s).");
|
await Log($"Loaded {commands.Count} command definition(s).");
|
||||||
return new ReadOnlyDictionary<string, CommandBase>(commands);
|
}
|
||||||
|
|
||||||
|
return new Tuple<ReadOnlyDictionary<string, CommandBase>, EntityName?>(
|
||||||
|
new ReadOnlyDictionary<string, CommandBase>(commands), petitionrpt);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -70,10 +88,10 @@ namespace Noikoio.RegexBot.Module.ModTools
|
||||||
* Item 2: Ban petition channel (EntityName)
|
* Item 2: Ban petition channel (EntityName)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private new Tuple<Dictionary<string, CommandBase>, EntityName> GetConfig(ulong guildId)
|
private new Tuple<ReadOnlyDictionary<string, CommandBase>, EntityName?> GetConfig(ulong guildId)
|
||||||
=> (Tuple<Dictionary<string, CommandBase>, EntityName>)base.GetConfig(guildId);
|
=> (Tuple<ReadOnlyDictionary<string, CommandBase>, EntityName?>)base.GetConfig(guildId);
|
||||||
private Dictionary<string, CommandBase> GetCommandConfig(ulong guild) => GetConfig(guild).Item1;
|
private ReadOnlyDictionary<string, CommandBase> GetCommandConfig(ulong guild) => GetConfig(guild).Item1;
|
||||||
private EntityName GetPetitionConfig(ulong guild) => GetConfig(guild).Item2;
|
private EntityName? GetPetitionConfig(ulong guild) => GetConfig(guild).Item2;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public new Task Log(string text) => base.Log(text);
|
public new Task Log(string text) => base.Log(text);
|
||||||
|
@ -116,9 +134,11 @@ namespace Noikoio.RegexBot.Module.ModTools
|
||||||
/// List of available appeals. Key is user (for quick lookup). Value is guild (for quick config resolution).
|
/// List of available appeals. Key is user (for quick lookup). Value is guild (for quick config resolution).
|
||||||
/// TODO expiration?
|
/// TODO expiration?
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private Dictionary<ulong, ulong> _openPetitions; // Key: user, Value: guild
|
private Dictionary<ulong, ulong> _openPetitions = new Dictionary<ulong, ulong>();
|
||||||
public void AddPetition(ulong guild, ulong user)
|
public void AddPetition(ulong guild, ulong user)
|
||||||
{
|
{
|
||||||
|
// Do nothing if disabled
|
||||||
|
if (GetPetitionConfig(guild) == null) return;
|
||||||
lock (_openPetitions) _openPetitions[user] = guild;
|
lock (_openPetitions) _openPetitions[user] = guild;
|
||||||
}
|
}
|
||||||
private async Task PetitionRelayCheck(SocketMessage msg)
|
private async Task PetitionRelayCheck(SocketMessage msg)
|
||||||
|
@ -163,7 +183,9 @@ namespace Noikoio.RegexBot.Module.ModTools
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get petition reporting target if not already known
|
// Get petition reporting target if not already known
|
||||||
var rch = GetPetitionConfig(targetGuild);
|
var pcv = GetPetitionConfig(targetGuild);
|
||||||
|
if (!pcv.HasValue) return; // No target. How'd we get here, anyway?
|
||||||
|
var rch = pcv.Value;
|
||||||
ISocketMessageChannel rchObj;
|
ISocketMessageChannel rchObj;
|
||||||
if (!rch.Id.HasValue)
|
if (!rch.Id.HasValue)
|
||||||
{
|
{
|
||||||
|
@ -197,7 +219,12 @@ namespace Noikoio.RegexBot.Module.ModTools
|
||||||
IconUrl = msg.Author.GetAvatarUrl()
|
IconUrl = msg.Author.GetAvatarUrl()
|
||||||
},
|
},
|
||||||
Description = ptext,
|
Description = ptext,
|
||||||
Timestamp = msg.Timestamp
|
Timestamp = msg.Timestamp,
|
||||||
|
|
||||||
|
Footer = new EmbedFooterBuilder()
|
||||||
|
{
|
||||||
|
Text = "User ID: " + msg.Author.Id
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (Discord.Net.HttpException ex)
|
catch (Discord.Net.HttpException ex)
|
||||||
|
|
Loading…
Reference in a new issue