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;
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace Noikoio.RegexBot.ConfigItem
|
namespace Noikoio.RegexBot.ConfigItem
|
||||||
|
@ -9,25 +8,20 @@ namespace Noikoio.RegexBot.ConfigItem
|
||||||
/// </summary>
|
/// </summary>
|
||||||
class ServerConfig
|
class ServerConfig
|
||||||
{
|
{
|
||||||
private readonly string _name;
|
private readonly ulong _id;
|
||||||
private ulong? _id;
|
|
||||||
private EntityList _moderators;
|
private EntityList _moderators;
|
||||||
private ReadOnlyDictionary<BotFeature, object> _featureData;
|
private ReadOnlyDictionary<BotFeature, object> _featureData;
|
||||||
|
|
||||||
public string Name => _name;
|
public ulong? Id => _id;
|
||||||
public ulong? Id {
|
|
||||||
get => _id; set { if (!_id.HasValue) _id = value; }
|
|
||||||
}
|
|
||||||
public EntityList Moderators => _moderators;
|
public EntityList Moderators => _moderators;
|
||||||
public ReadOnlyDictionary<BotFeature, object> FeatureConfigs => _featureData;
|
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;
|
_id = id;
|
||||||
_moderators = moderators;
|
_moderators = moderators;
|
||||||
_featureData = featureconf;
|
_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>())
|
foreach (JObject sconf in conf["servers"].Children<JObject>())
|
||||||
{
|
{
|
||||||
// Server name
|
// 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;
|
return false;
|
||||||
}
|
}
|
||||||
string snamestr = sconf["name"].Value<string>();
|
ulong sid = sconf["id"].Value<ulong>();
|
||||||
string sname;
|
string sname = sconf["name"]?.Value<string>();
|
||||||
ulong? sid;
|
|
||||||
|
|
||||||
int snseparator = snamestr.IndexOf("::");
|
var SLog = Logger.GetLogger(LogPrefix + "/" + (sname ?? sid.ToString()));
|
||||||
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);
|
|
||||||
|
|
||||||
// Load server moderator list
|
// Load server moderator list
|
||||||
EntityList mods = new EntityList(sconf["moderators"]);
|
EntityList mods = new EntityList(sconf["moderators"]);
|
||||||
|
@ -180,7 +168,7 @@ namespace Noikoio.RegexBot
|
||||||
|
|
||||||
// Switch to using new data
|
// Switch to using new data
|
||||||
List<Tuple<Regex, string[]>> rulesfinal = new List<Tuple<Regex, string[]>>();
|
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();
|
_servers = newservers.ToArray();
|
||||||
|
|
|
@ -35,7 +35,6 @@ namespace Noikoio.RegexBot.Feature.AutoRespond
|
||||||
var ch = arg.Channel as SocketGuildChannel;
|
var ch = arg.Channel as SocketGuildChannel;
|
||||||
if (ch == null) return;
|
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>;
|
var defs = GetConfig(ch.Guild.Id) as IEnumerable<ConfigItem>;
|
||||||
if (defs == null) return;
|
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.
|
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.
|
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.
|
* id *(integer)* - **Required.** A value 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.
|
* name *(string)* - The server name. Only used during configuration (re)load to make logs more readable.
|
||||||
* For example: `"285450825525927585::My Testing Server"`
|
|
||||||
* 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*.
|
* 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.
|
* [AutoMod](automod.html) *(name/value pairs)* - Auto-moderation matching and response definitions.
|
||||||
* [AutoResponses](autorespond.html) *(name/value pairs)* - Definitions for automatic responses.
|
* [AutoResponses](autorespond.html) *(name/value pairs)* - Definitions for automatic responses.
|
||||||
|
|
Loading…
Reference in a new issue