new SettingsCache()
SettingGateway's driver to make new instances of it, with the purpose to handle different databases simultaneously.
Members
-
readonly client :KomadaClient
-
The client this SettingsCache was created with.
-
readonly defaultDataSchema
-
The data schema Komada uses for guild settings.
-
guilds :SettingGateway
-
The SettingGateway instance created to handle guild settings.
Methods
-
async add(name, validateFunction, schemaopt) → {SettingGateway}
-
Add a new instance of SettingGateway, with its own validateFunction and schema.
Parameters:
Name Type Attributes Default Description name
string The name for the new instance. validateFunction
function The function that validates the input. schema
Object <optional>
{} The schema. Returns:
SettingGatewayExample
// Add a new SettingGateway instance, called 'users', which input takes users, and stores a quote which is a string between 2 and 140 characters. const validate = async function(resolver, user) { const result = await resolver.user(user); if (!result) throw "The parameter <User> expects either a User ID or a User Object."; return result; }; const schema = { quote: { type: "String", default: null, array: false, min: 2, max: 140, }, }; SettingsCache.add("users", validate, schema);
-
async validate(resolver, guild) → {Promise.<any>}
-
The validator function Komada uses for guild settings.
Parameters:
Name Type Description resolver
SettingResolver The resolver instance this SettingGateway uses to parse the data. guild
Object | string The data to validate. Returns:
Promise.<any>