Require Guild ID in server definition
Due to how guild configuration is retrieved by features, it's easier to have the ID be defined explicitly in server configuration instead of having to look it up each time it's necessary.
This commit is contained in:
parent
4a1326711f
commit
1e2e615a23
4 changed files with 15 additions and 35 deletions
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Noikoio.RegexBot.ConfigItem
|
||||
|
@ -9,25 +8,20 @@ namespace Noikoio.RegexBot.ConfigItem
|
|||
/// </summary>
|
||||
class ServerConfig
|
||||
{
|
||||
private readonly string _name;
|
||||
private ulong? _id;
|
||||
private readonly ulong _id;
|
||||
private EntityList _moderators;
|
||||
private ReadOnlyDictionary<BotFeature, object> _featureData;
|
||||
|
||||
public string Name => _name;
|
||||
public ulong? Id {
|
||||
get => _id; set { if (!_id.HasValue) _id = value; }
|
||||
}
|
||||
public ulong? Id => _id;
|
||||
public EntityList Moderators => _moderators;
|
||||
public ReadOnlyDictionary<BotFeature, object> FeatureConfigs => _featureData;
|
||||
|
||||
public ServerConfig(string name, ulong? id, EntityList moderators, ReadOnlyDictionary<BotFeature, object> featureconf)
|
||||
public ServerConfig(ulong id, EntityList moderators, ReadOnlyDictionary<BotFeature, object> featureconf)
|
||||
{
|
||||
_name = name;
|
||||
_id = id;
|
||||
_moderators = moderators;
|
||||
_featureData = featureconf;
|
||||
Debug.Assert(_name != null && _moderators != null);
|
||||
Debug.Assert(_moderators != null && _featureData != null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -117,28 +117,16 @@ namespace Noikoio.RegexBot
|
|||
foreach (JObject sconf in conf["servers"].Children<JObject>())
|
||||
{
|
||||
// Server name
|
||||
if (sconf["name"] == null || string.IsNullOrWhiteSpace(sconf["name"].Value<string>()))
|
||||
//if (sconf["id"] == null || sconf["id"].Type != JTokenType.Integer))
|
||||
if (sconf["id"] == null)
|
||||
{
|
||||
await Log("Error: Server definition is missing a name.");
|
||||
await Log("Error: Server ID is missing within definition.");
|
||||
return false;
|
||||
}
|
||||
string snamestr = sconf["name"].Value<string>();
|
||||
string sname;
|
||||
ulong? sid;
|
||||
ulong sid = sconf["id"].Value<ulong>();
|
||||
string sname = sconf["name"]?.Value<string>();
|
||||
|
||||
int snseparator = snamestr.IndexOf("::");
|
||||
if (ulong.TryParse(snamestr.Substring(0, snseparator), out var id))
|
||||
{
|
||||
sid = id;
|
||||
sname = snamestr.Substring(snseparator + 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
sid = null;
|
||||
sname = snamestr;
|
||||
}
|
||||
|
||||
var SLog = Logger.GetLogger(LogPrefix + "/" + sname);
|
||||
var SLog = Logger.GetLogger(LogPrefix + "/" + (sname ?? sid.ToString()));
|
||||
|
||||
// Load server moderator list
|
||||
EntityList mods = new EntityList(sconf["moderators"]);
|
||||
|
@ -180,7 +168,7 @@ namespace Noikoio.RegexBot
|
|||
|
||||
// Switch to using new data
|
||||
List<Tuple<Regex, string[]>> rulesfinal = new List<Tuple<Regex, string[]>>();
|
||||
newservers.Add(new ServerConfig(sname, sid, mods, new ReadOnlyDictionary<BotFeature, object>(customConfs)));
|
||||
newservers.Add(new ServerConfig(sid, mods, new ReadOnlyDictionary<BotFeature, object>(customConfs)));
|
||||
}
|
||||
|
||||
_servers = newservers.ToArray();
|
||||
|
|
|
@ -35,7 +35,6 @@ namespace Noikoio.RegexBot.Feature.AutoRespond
|
|||
var ch = arg.Channel as SocketGuildChannel;
|
||||
if (ch == null) return;
|
||||
|
||||
// TODO either search server by name or remove server name support entirely
|
||||
var defs = GetConfig(ch.Guild.Id) as IEnumerable<ConfigItem>;
|
||||
if (defs == null) return;
|
||||
|
||||
|
|
|
@ -3,9 +3,8 @@
|
|||
Server definitions are defined within the `servers` array. Each definition represents unique configuration for a single server. Defining multiple servers allows for a single bot instance to be uniquely configured for use in several servers at once.
|
||||
|
||||
The following is a list of accepted members within a server definition.
|
||||
* name *(string)* - **Required.** A string containing the server ID, and optionally the name, of the server that this definition represents.
|
||||
* If you wish to enter both a name and ID, you must first enter the ID, followed by two colon (:) characters, followed by the name.
|
||||
* For example: `"285450825525927585::My Testing Server"`
|
||||
* id *(integer)* - **Required.** A value containing the server ID, and optionally the name, of the server that this definition represents.
|
||||
* name *(string)* - The server name. Only used during configuration (re)load to make logs more readable.
|
||||
* moderators *[(entity list)](entitylist.html)* - A list of entities to consider as moderators. Actions done by the members of those in this list are able to execute *ModTools* commands and are exempt from certain *AutoMod* rules if a particular rule has its *AllowModBypass* setting set to *false*.
|
||||
* [AutoMod](automod.html) *(name/value pairs)* - Auto-moderation matching and response definitions.
|
||||
* [AutoResponses](autorespond.html) *(name/value pairs)* - Definitions for automatic responses.
|
||||
|
|
Loading…
Reference in a new issue