diff --git a/config.example.ini b/config.example.ini index 8b403a9..ff3c145 100644 --- a/config.example.ini +++ b/config.example.ini @@ -1,8 +1,8 @@ # Required settings # ----------------- token = REPLACE_WITH_TOKEN -mainGuildId = REPLACE_WITH_MAIN_SERVER_ID -mailGuildId = REPLACE_WITH_INBOX_SERVER_ID +mainServerId = REPLACE_WITH_MAIN_SERVER_ID +inboxServerId = REPLACE_WITH_INBOX_SERVER_ID logChannelId = REPLACE_WITH_LOG_CHANNEL_ID # Add new options below this line: diff --git a/docs/configuration.md b/docs/configuration.md index fb50674..fe06522 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -22,7 +22,7 @@ vice versa. ## Adding new options To add a new option to your `config.ini`, open the file in a text editor such as notepad. -Each option is put on a new line, and follows the format `option = value`. For example, `mainGuildId = 1234`. +Each option is put on a new line, and follows the format `option = value`. For example, `mainServerId = 1234`. **You need to restart the bot for configuration changes to take effect!** @@ -65,12 +65,12 @@ greetingMessage[] = Fourth line! With an empty line in the middle. #### token The bot user's token from [Discord Developer Portal](https://discordapp.com/developers/). -#### mainGuildId +#### mainServerId **Accepts multiple values** Your server's ID. -#### mailGuildId -For a two-server setup, the inbox server's ID. -For a single-server setup, same as [mainGuildId](#mainguildid). +#### inboxServerId +For a single-server setup, same as [mainServerId](#mainServerId). +For a two-server setup, the inbox server's ID. #### logChannelId ID of a channel on the inbox server where logs are posted after a modmail thread is closed @@ -190,6 +190,12 @@ See ["Permissions" on this page](https://abal.moe/Eris/docs/reference) for suppo **Default:** `You haven't been a member of the server for long enough to contact modmail.` If `requiredTimeOnServer` is set, users that are too new will be sent this message if they try to message modmail. +#### mainGuildId +Alias for [mainServerId](#mainServerId) + +#### mailGuildId +Alias for [inboxServerId](#inboxServerId) + #### mentionRole **Default:** `here` **Accepts multiple values.** Role that is mentioned when new threads are created or the bot is mentioned. @@ -359,7 +365,7 @@ However, there are some differences between `config.ini` and `config.json`. *See [the example on the Wikipedia page for JSON](https://en.wikipedia.org/wiki/JSON#Example) for a general overview of the JSON format.* -* In `config.json`, all text values and IDs need to be wrapped in quotes, e.g. `"mainGuildId": "94882524378968064"` +* In `config.json`, all text values and IDs need to be wrapped in quotes, e.g. `"mainServerId": "94882524378968064"` * In `config.json`, all numbers (other than IDs) are written without quotes, e.g. `"port": 3000` ### Toggle options @@ -400,7 +406,7 @@ being replaced by two underscores and add `MM_` as a prefix. If adding multiple values with two pipe characters: `||`. Examples: -* `mainGuildId` -> `MM_MAIN_GUILD_ID` +* `mainServerId` -> `MM_MAIN_SERVER_ID` * `commandAliases.mv` -> `MM_COMMAND_ALIASES__MV` * From: ```ini diff --git a/docs/setup.md b/docs/setup.md index fcb6e0d..4d3a447 100644 --- a/docs/setup.md +++ b/docs/setup.md @@ -25,7 +25,7 @@ In this setup, modmail threads are opened on the main server in a special catego This is the recommended setup for small and medium sized servers. 1. **Go through the [prerequisites](#prerequisites) above first!** -2. Open `config.ini` in a text editor and fill in the required values. `mainGuildId` and `mailGuildId` should both be set to your server's id. +2. Open `config.ini` in a text editor and fill in the required values. `mainServerId` and `inboxServerId` should both be set to your server's id. 3. Invite the bot to the server 4. On a new line at the end of `config.ini`, add `categoryAutomation.newThread = CATEGORY_ID_HERE` * Replace `CATEGORY_ID_HERE` with the ID of the category where new modmail threads should go @@ -44,8 +44,8 @@ You might also want this setup for privacy concerns*. 1. **Go through the [prerequisites](#prerequisites) above first!** 2. Create an inbox server on Discord 3. Open `config.ini` in a text editor and fill in the required values - * Set `mainGuildId` to the ID of the *main* server where users will message the bot from - * Set `mailGuildId` to the ID of the *inbox* server created in step 2 + * Set `mainServerId` to the ID of the *main* server where users will message the bot from + * Set `inboxServerId` to the ID of the *inbox* server created in step 2 4. Invite the bot to both the main server and the newly-created inbox server 5. Open `config.ini` in a text editor and fill in the values 6. Make sure the bot has the `Manage Channels`, `Manage Messages`, and `Attach Files` permissions on the **inbox** server diff --git a/src/cfg.js b/src/cfg.js index 35c2371..2d91e8c 100644 --- a/src/cfg.js +++ b/src/cfg.js @@ -102,6 +102,15 @@ for (const [key, value] of Object.entries(config)) { delete config[key]; } +// mainGuildId => mainServerId +// mailGuildId => inboxServerId +if (config.mainGuildId && ! config.mainServerId) { + config.mainServerId = config.mainGuildId; +} +if (config.mailGuildId && ! config.inboxServerId) { + config.inboxServerId = config.mailGuildId; +} + if (! config.dbType) { config.dbType = "sqlite"; } @@ -117,7 +126,7 @@ if (! config.sqliteOptions) { // already have something set up in guildGreetings. This retains backwards compatibility while allowing you to override // greetings for specific servers in guildGreetings. if (config.greetingMessage || config.greetingAttachment) { - for (const guildId of config.mainGuildId) { + for (const guildId of config.mainServerId) { if (config.guildGreetings[guildId]) continue; config.guildGreetings[guildId] = { message: config.greetingMessage, diff --git a/src/data/cfg.jsdoc.js b/src/data/cfg.jsdoc.js index 8d614c7..45dc6ff 100644 --- a/src/data/cfg.jsdoc.js +++ b/src/data/cfg.jsdoc.js @@ -1,9 +1,11 @@ /** * @typedef {object} ModmailConfig * @property {string} [token] + * @property {array} [mainServerId] + * @property {string} [inboxServerId] + * @property {string} [logChannelId] * @property {array} [mainGuildId] * @property {string} [mailGuildId] - * @property {string} [logChannelId] * @property {string} [prefix="!"] * @property {string} [snippetPrefix="!!"] * @property {string} [snippetPrefixAnon="!!!"] diff --git a/src/data/cfg.schema.json b/src/data/cfg.schema.json index 519802d..64550e6 100644 --- a/src/data/cfg.schema.json +++ b/src/data/cfg.schema.json @@ -46,16 +46,25 @@ "token": { "type": "string" }, - "mainGuildId": { + "mainServerId": { "$ref": "#/definitions/stringArray" }, - "mailGuildId": { + "inboxServerId": { "type": "string" }, "logChannelId": { "type": "string" }, + "mainGuildId": { + "$comment": "Alias for mainServerId", + "$ref": "#/definitions/stringArray" + }, + "mailGuildId": { + "$comment": "Alias for inboxServerId", + "type": "string" + }, + "prefix": { "type": "string", "default": "!" @@ -323,7 +332,7 @@ "allOf": [ { "$comment": "Base required values", - "required": ["token", "mainGuildId", "mailGuildId", "logChannelId", "dbType"] + "required": ["token", "mainServerId", "inboxServerId", "logChannelId", "dbType"] }, { "$comment": "Make attachmentStorageChannelId required if attachmentStorage is set to 'discord'", diff --git a/src/main.js b/src/main.js index 7d1a9eb..8af38be 100644 --- a/src/main.js +++ b/src/main.js @@ -38,8 +38,8 @@ module.exports = { bot.once("ready", async () => { console.log("Connected! Waiting for guilds to become available..."); await Promise.all([ - ...config.mainGuildId.map(id => waitForGuild(id)), - waitForGuild(config.mailGuildId) + ...config.mainServerId.map(id => waitForGuild(id)), + waitForGuild(config.inboxServerId), ]); console.log("Initializing..."); diff --git a/src/utils.js b/src/utils.js index 8c993b2..2a8bddb 100644 --- a/src/utils.js +++ b/src/utils.js @@ -17,7 +17,7 @@ let logChannel = null; * @returns {Eris~Guild} */ function getInboxGuild() { - if (! inboxGuild) inboxGuild = bot.guilds.find(g => g.id === config.mailGuildId); + if (! inboxGuild) inboxGuild = bot.guilds.find(g => g.id === config.inboxServerId); if (! inboxGuild) throw new BotError("The bot is not on the modmail (inbox) server!"); return inboxGuild; } @@ -27,11 +27,11 @@ function getInboxGuild() { */ function getMainGuilds() { if (mainGuilds.length === 0) { - mainGuilds = bot.guilds.filter(g => config.mainGuildId.includes(g.id)); + mainGuilds = bot.guilds.filter(g => config.mainServerId.includes(g.id)); } - if (mainGuilds.length !== config.mainGuildId.length) { - if (config.mainGuildId.length === 1) { + if (mainGuilds.length !== config.mainServerId.length) { + if (config.mainServerId.length === 1) { console.warn("[WARN] The bot hasn't joined the main guild!"); } else { console.warn("[WARN] The bot hasn't joined one or more main guilds!");