diff --git a/docs/configuration.md b/docs/configuration.md index cbb107f..b32912e 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -170,15 +170,7 @@ greetingMessage[] = Remember to read the rules. ``` #### guildGreetings -**Default:** *None* -When running the bot on multiple main servers, this allows you to set different greetings for each server. Example: -```ini -guildGreetings.94882524378968064.message = Welcome to server ID 94882524378968064! -guildGreetings.94882524378968064.attachment = greeting.png - -guildGreetings.541484311354933258.message[] = Welcome to server ID 541484311354933258! -guildGreetings.541484311354933258.message[] = Second line of the greeting. -``` +Alias for [`serverGreetings`](#serverGreetings) #### ignoreAccidentalThreads **Default:** `off` @@ -261,6 +253,17 @@ The bot's response to the user when they message the bot and open a new modmail **Default:** `off` If enabled, the user's roles will be shown in the modmail thread header +#### serverGreetings +**Default:** *None* +When running the bot on multiple main servers, this allows you to set different greetings for each server. Example: +```ini +serverGreetings.94882524378968064.message = Welcome to server ID 94882524378968064! +serverGreetings.94882524378968064.attachment = greeting.png + +serverGreetings.541484311354933258.message[] = Welcome to server ID 541484311354933258! +serverGreetings.541484311354933258.message[] = Second line of the greeting. +``` + #### smallAttachmentLimit **Default:** `2097152` Size limit of `relaySmallAttachmentsAsAttachments` in bytes (default is 2MB) diff --git a/src/cfg.js b/src/cfg.js index abff870..1d7c304 100644 --- a/src/cfg.js +++ b/src/cfg.js @@ -126,14 +126,19 @@ if (config.categoryAutomation && config.categoryAutomation.newThreadFromGuild && config.categoryAutomation.newThreadFromServer = config.categoryAutomation.newThreadFromGuild; } -// Move greetingMessage/greetingAttachment to the guildGreetings object internally +// guildGreetings => serverGreetings +if (config.guildGreetings && ! config.serverGreetings) { + config.serverGreetings = config.guildGreetings; +} + +// Move greetingMessage/greetingAttachment to the serverGreetings object internally // Or, in other words, if greetingMessage and/or greetingAttachment is set, it is applied for all servers that don't -// already have something set up in guildGreetings. This retains backwards compatibility while allowing you to override -// greetings for specific servers in guildGreetings. +// already have something set up in serverGreetings. This retains backwards compatibility while allowing you to override +// greetings for specific servers in serverGreetings. if (config.greetingMessage || config.greetingAttachment) { for (const guildId of config.mainServerId) { - if (config.guildGreetings[guildId]) continue; - config.guildGreetings[guildId] = { + if (config.serverGreetings[guildId]) continue; + config.serverGreetings[guildId] = { message: config.greetingMessage, attachment: config.greetingAttachment }; diff --git a/src/data/cfg.jsdoc.js b/src/data/cfg.jsdoc.js index 2d1a6b2..1e1658e 100644 --- a/src/data/cfg.jsdoc.js +++ b/src/data/cfg.jsdoc.js @@ -34,7 +34,8 @@ * @property {boolean} [enableGreeting=false] * @property {string} [greetingMessage] * @property {string} [greetingAttachment] - * @property {*} [guildGreetings={}] + * @property {*} [serverGreetings={}] + * @property {*} [guildGreetings] * @property {number} [requiredAccountAge] Required account age to message Modmail, in hours * @property {string} [accountAgeDeniedMessage="Your Discord account is not old enough to contact modmail."] * @property {number} [requiredTimeOnServer] Required time on server to message Modmail, in minutes diff --git a/src/data/cfg.schema.json b/src/data/cfg.schema.json index 6e0b676..5b1469b 100644 --- a/src/data/cfg.schema.json +++ b/src/data/cfg.schema.json @@ -175,14 +175,26 @@ "greetingAttachment": { "type": "string" }, - "guildGreetings": { + "serverGreetings": { "patternProperties": { "^\\d+$": { - "$ref": "#/definitions/multilineString" + "type": "object", + "properties": { + "message": { + "$ref": "#/definitions/multilineString" + }, + "attachment": { + "type": "string" + } + } } }, "default": {} }, + "guildGreetings": { + "$comment": "Alias for serverGreetings", + "$ref": "#/properties/serverGreetings" + }, "requiredAccountAge": { "description": "Required account age to message Modmail, in hours", diff --git a/src/modules/greeting.js b/src/modules/greeting.js index 37a2620..81d7d50 100644 --- a/src/modules/greeting.js +++ b/src/modules/greeting.js @@ -7,8 +7,8 @@ module.exports = ({ bot }) => { if (! config.enableGreeting) return; bot.on("guildMemberAdd", (guild, member) => { - const guildGreeting = config.guildGreetings[guild.id]; - if (! guildGreeting || (! guildGreeting.message && ! guildGreeting.attachment)) return; + const serverGreeting = config.serverGreetings[guild.id]; + if (! serverGreeting || (! serverGreeting.message && ! serverGreeting.attachment)) return; function sendGreeting(message, file) { bot.getDMChannel(member.id).then(channel => { @@ -22,11 +22,11 @@ module.exports = ({ bot }) => { }); } - const greetingMessage = utils.readMultilineConfigValue(guildGreeting.message); + const greetingMessage = utils.readMultilineConfigValue(serverGreeting.message); - if (guildGreeting.attachment) { - const filename = path.basename(guildGreeting.attachment); - fs.readFile(guildGreeting.attachment, (err, data) => { + if (serverGreeting.attachment) { + const filename = path.basename(serverGreeting.attachment); + fs.readFile(serverGreeting.attachment, (err, data) => { const file = {file: data, name: filename}; sendGreeting(greetingMessage, file); });