ramirez/README.md

172 lines
13 KiB
Markdown
Raw Normal View History

2017-02-10 00:19:14 -05:00
# Modmail for Discord
A bot for [Discord](https://discordapp.com/) that allows users to DM the bot to contact the server's entire mod team.
These DMs get relayed to a modmail server where each user gets their own channel, or "thread".
Moderators and admins can then reply to these threads, and these responses are relayed back to the original user as a DM.
Inspired by Reddit's modmail system.
2019-06-09 13:42:51 -04:00
## NOTE! If you're upgrading to v2.23.0, note that Node.js 10 is now required at minimum.
2019-06-09 10:53:49 -04:00
## Table of contents
- [Setup](#setup)
2019-09-11 14:39:37 -04:00
- [Support server](#support-server)
2019-06-09 10:53:49 -04:00
- [Changelog](#changelog)
- [Commands](#commands)
- [Anywhere on the inbox server](#anywhere-on-the-inbox-server)
- [Inside a modmail thread](#inside-a-modmail-thread)
- [Configuration options](#configuration-options)
- [Plugins](#plugins)
- [Specifying plugins to load](#specifying-plugins-to-load)
- [Creating a plugin](#creating-a-plugin)
2017-02-10 00:19:14 -05:00
## Setup
2019-06-09 13:42:51 -04:00
1. Install Node.js 10 (LTS) or higher
2. Download the latest release from [the releases page](https://github.com/Dragory/modmailbot/releases)
2017-02-10 00:19:14 -05:00
3. Create a Discord server to be used as the modmail inbox
2017-06-14 03:12:19 -04:00
4. Make a copy of the file `config.example.json` in the same folder and name the copy `config.json`. Open the file and fill in the values.
- You can also find more configurable options at the end of this page!
5. Install dependencies: `npm ci`
2017-05-01 05:14:28 -04:00
6. Add bot to servers, and make sure to give it proper permissions on the mail server.
7. Run the bot: `npm start`
2017-02-10 00:19:14 -05:00
2019-09-11 14:39:37 -04:00
## Support server
If you need help with setting up the bot or would like to discuss other things related to the bot, join the support server on Discord here:
https://discord.gg/vRuhG9R
## Changelog
See [CHANGELOG.md](CHANGELOG.md)
2017-02-10 00:19:14 -05:00
## Commands
2019-06-09 10:53:49 -04:00
### Anywhere on the inbox server
`!logs <user> <page>` Lists previous modmail logs with the specified user. If there are a lot of logs, they will be paginated. In this case, you can specify the page number to view as the second argument.
`!block <user> <time>` Blocks the specified user from using modmail. If a time is specified, the block is temporary.
`!unblock <user> <time>` Unblocks the specified user from using modmail. If a time is specified, the user will be scheduled to be unblocked after that time.
`!is_blocked <user>` Checks whether the user is blocked and for how long
2019-06-09 13:35:10 -04:00
`!s <shortcut> <text>` Adds a snippet (a canned response). Supports {1}, {2}, etc. for arguments. See below for how to use it.
`!edit_snippet <shortcut> <text>` Edits an existing snippet (alias `!es`)
`!delete_snippet <shortcut>` Deletes the specified snippet (alias `!ds`)
`!snippets` Lists all available snippets
`!version` Print the version of the bot you're running
`!newthread <user>` Opens a new thread with the specified user
2017-02-10 00:19:14 -05:00
2019-06-09 10:53:49 -04:00
### Inside a modmail thread
2017-02-10 00:19:14 -05:00
`!reply <text>` Sends a reply to the user in the format "(Role) User: text" (alias `!r`)
2017-05-01 18:04:14 -04:00
`!anonreply <text>` Sends an anonymous reply to the user in the format "Role: text" (alias `!ar`)
2018-03-11 15:39:10 -04:00
`!close <time>` Closes the modmail thread. If a time is specified, the thread is scheduled to be closed later. Scheduled closing is cancelled if a message is sent to or received from the user.
`!logs <page>` Lists previous modmail logs with this user. If there are a lot of logs, they will be paginated. In this case, you can specify the page number to view as an argument.
`!block <time>` Blocks the user from using modmail. If a time is specified, the block is temporary.
`!unblock <time>` Unblocks the user from using modmail. If a time is specified, the user will be scheduled to be unblocked after that time.
`!!shortcut` Reply with a snippet. Replace `shortcut` with the snippet's actual shortcut.
2018-09-20 16:38:53 -04:00
`!!!shortcut` Reply with a snippet anonymously. Replace `shortcut` with the snippet's actual shortcut.
2018-02-24 06:15:28 -05:00
`!move <category>` If `allowMove` is enabled, moves the thread channel to the specified category
`!loglink` Shows the link to the current thread's log
`!suspend` Suspend a thread. The thread will act as closed and not receive any messages until unsuspended.
`!unsuspend` Unsuspend a thread
`!id` Prints the user's ID
2018-04-21 09:41:25 -04:00
`!alert` Pings you when the thread gets a new reply. Use `!alert cancel` to cancel.
2017-05-01 05:14:28 -04:00
To automatically reply without using !reply or !r, enable `alwaysReply` in the config. `alwaysReplyAnon` sets whether to reply anonymously. If you do not wish to reply, it will ignore any message starting in the prefix (which defaults to !), such as !note
2017-05-17 23:04:20 -04:00
## Configuration options
These go in `config.json`. See also `config.example.json`.
|Option|Default|Description|
|------|-------|-----------|
2018-09-20 16:38:53 -04:00
|**token**|None|**Required!** The bot user's token|
|**logChannelId**|None|**Required!** Channel where to post log links to closed threads and other alerts|
|**mailGuildId**|None|**Required!** The inbox server's ID|
|**mainGuildId**|None|**Required!** ID (or array of IDs) of the main server where people contact the bot from. Used for displaying users' nicknames and join dates, and catching bot pings.|
|accountAgeDeniedMessage|"Your Discord account is not old enough to contact modmail."|See `requiredAccountAge` below|
2018-09-20 16:38:53 -04:00
|allowMove|false|If enabled, allows you to move the thread to another category using `!move <category>`|
|allowUserClose|false|If set to true, users can use the close command to close threads by themselves from their DMs with the bot|
2017-05-17 23:04:20 -04:00
|alwaysReplyAnon|false|If `alwaysReply` is set to true, this option controls whether the auto-reply is anonymous|
2018-09-20 16:38:53 -04:00
|alwaysReply|false|If set to true, all messages in modmail threads will be relayed back to the user, even ones without `!r`|
|attachmentStorage|"local"|Controls where sent/received attachments are saved.<br><br>**"local"** - Files are saved locally on the machine running the bot<br>**"discord"** - Files are saved as attachments on a special channel on the inbox server. Requires `attachmentStorageChannelId` to be set.|
|attachmentStorageChannelId|null|When using "discord" attachment storage, the id of the channel on the inbox server where attachments should be saved|
|botMentionResponse|None|If set, the bot auto-responds to bot mentions with this message. Allows `{userMention}` to be added to mention the user who mentioned the bot.|
|categoryAutomation|{}|Various ways of automating thread categories on the inbox server. **Note that the options below with a dot in the name are object properties for `categoryAutomation`.**|
|categoryAutomation.newThread|None|Same as `newThreadCategoryId`. Specifies a category to open all new threads in. Also functions as a fallback for `categoryAutomation.newThreadFromGuild`.|
|categoryAutomation.newThreadFromGuild|None|Allows you to open threads in specific categories based on which guild the user is messaging the bot from. The value is an object with guild ids as the keys and category ids as the values.|
2018-09-20 16:38:53 -04:00
|closeMessage|None|The bot's message to the user when the thread is closed|
2019-06-09 12:31:16 -04:00
|commandAliases|None|Custom aliases for commands. Value is an object with the alias as the key and the real command as the value.|
2017-05-17 23:04:20 -04:00
|enableGreeting|false|Set to true to send a welcome message to new main guild members. Requires `mainGuildId` to be set.|
|greetingAttachment|None|Path to an image or other attachment to send along with the greeting|
2018-09-20 16:38:53 -04:00
|greetingMessage|None|Text content of the welcome message|
2019-06-09 08:56:04 -04:00
|guildGreetings|None|When using multiple mainGuildIds, this option allows you to configure greetings on a per-server basis. The syntax is an object with the guild ID as the key, and another object with `message` and `attachment` properties as the value (identical to greetingMessage and greetingAttachment)|
2018-09-20 16:38:53 -04:00
|ignoreAccidentalThreads|false|If set to true, the bot attempts to ignore common "accidental" messages that would start a new thread, such as "ok", "thanks", etc.|
2019-08-14 03:38:42 -04:00
|inboxServerPermission|None|Permission name, user id, or role id required to use bot commands on the inbox server. Also supports arrays. See ["Permissions" on this page](https://abal.moe/Eris/docs/reference) for supported permission names (e.g. `kickMembers`).|
|timeOnServerDeniedMessage|"You haven't been a member of the server for long enough to contact modmail."|See `requiredTimeOnServer` below|
|mentionRole|"here"|Role that is mentioned when new threads are created or the bot is mentioned. Accepted values are "here", "everyone", or a role id as a string. Set to null to disable these pings entirely. Multiple values in an array are supported.|
2018-09-20 16:38:53 -04:00
|mentionUserInThreadHeader|false|If set to true, mentions the thread's user in the thread header|
|newThreadCategoryId|None|**Deprecated** ID of the category where new modmail thread channels should be placed|
2018-09-20 16:38:53 -04:00
|pingOnBotMention|true|If enabled, the bot will mention staff (see mentionRole above) on the inbox server when the bot is mentioned on the main server.|
2019-06-09 10:53:49 -04:00
|plugins|None|Array of plugins to load on startup. See [Plugins](#plugins) section below for more information.|
2018-09-20 16:38:53 -04:00
|port|8890|Port from which to serve attachments and logs|
|prefix|"!"|Prefix for bot commands|
2018-08-07 17:59:09 -04:00
|relaySmallAttachmentsAsAttachments|false|Whether to relay small attachments from users as native attachments rather than links in modmail threads|
2018-09-20 16:38:53 -04:00
|requiredAccountAge|None|Required account age for contacting modmail (in hours). If the account is not old enough, a new thread will not be created and the bot will reply with `accountAgeDeniedMessage` (if set) instead.|
|requiredTimeOnServer|None|Required amount of time (in minutes) the user must be a member of the server before being able to contact modmail. If the user hasn't been a member of the server for the specified time, a new thread will not be created and the bot will reply with `timeOnServerDeniedMessage` (if set) instead.|
2018-09-20 16:38:53 -04:00
|responseMessage|"Thank you for your message! Our mod team will reply to you here as soon as possible."|The bot's response to DMs that start a new thread|
2019-06-09 09:04:17 -04:00
|rolesInThreadHeader|false|If enabled, the user's roles will be shown in the thread header|
2018-08-07 17:59:09 -04:00
|smallAttachmentLimit|2097152|Size limit of `relaySmallAttachmentsAsAttachments`, in bytes (default is 2MB)|
2018-09-20 16:38:53 -04:00
|snippetPrefix|"!!"|Prefix to use snippets|
|snippetPrefixAnon|"!!!"|Prefix to use snippets anonymously|
|status|"Message me for help"|The bot's "Playing" text|
2019-08-14 03:38:42 -04:00
|syncPermissionsOnMove|true|Whether to sync thread channel permissions to the category when moved with !move|
|threadTimestamps|false|Whether to show custom timestamps in threads, in addition to Discord's own timestamps. Logs always have accurate timestamps, regardless of this setting.|
2018-02-24 16:19:19 -05:00
|typingProxy|false|If enabled, any time a user is typing to modmail in their DMs, the modmail thread will show the bot as "typing"|
|typingProxyReverse|false|If enabled, any time a moderator is typing in a modmail thread, the user will see the bot "typing" in their DMs|
2019-06-09 10:31:17 -04:00
|updateNotifications|true|Whether to automatically check for bot updates and notify about them in new threads|
2018-09-20 16:38:53 -04:00
|url|None|URL to use for attachment and log links. Defaults to `IP:PORT`|
|useNicknames|false|If set to true, mod replies will use their nickname (on the inbox server) instead of their username|
2019-06-09 10:53:49 -04:00
## Plugins
The bot supports loading external plugins.
### Specifying plugins to load
Add the path to the plugin's file to the `plugins` array in the config.
The plugin will be automatically loaded on startup.
The path is relative to the bot's folder.
### Creating a plugin
Create a `.js` file that exports a function.
This function will be called when the plugin is loaded with an object that has the following properties:
* `bot` - the [Eris Client object](https://abal.moe/Eris/docs/Client)
* `knex` - the [Knex database object](https://knexjs.org/#Builder)
* `config` - the loaded config
2019-09-17 19:20:00 -04:00
* `commands` - an object with functions to add and manage commands
* `attachments` - an object with functions to save attachments and manage attachment storage types
See [src/plugins.js#L4](src/plugins.js#L4) for more details
2019-06-09 10:53:49 -04:00
#### Example plugin file
2019-09-17 19:20:00 -04:00
This example adds a command `!mycommand` that replies with `"Reply from my custom plugin!"` when the command is used inside a modmail inbox thread channel.
2019-06-09 10:53:49 -04:00
```js
module.exports = function({ bot, knex, config, commands }) {
2019-06-17 03:22:01 -04:00
commands.addInboxThreadCommand('mycommand', [], (msg, args, thread) => {
thread.replyToUser(msg.author, 'Reply from my custom plugin!');
});
2019-06-09 10:53:49 -04:00
}
```
(Note the use of [object destructuring](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#Unpacking_fields_from_objects_passed_as_function_parameter) in the function parameters)
2019-09-17 18:55:12 -04:00
#### Example of a custom attachment storage type
This example adds a custom type for the `attachmentStorage` option called `"original"` that simply returns the original attachment URL without rehosting it in any way.
```js
module.exports = function({ attachments }) {
attachments.addStorageType('original', attachment => {
return { url: attachment.url };
});
};
```
To use this custom attachment storage type, you would set the `attachmentStorage` config option to `"original"`.
2019-06-09 10:53:49 -04:00
### Work in progress
The current plugin API is fairly rudimentary and will be expanded in the future.
2019-06-17 03:22:01 -04:00
The API can change in non-major releases during this early stage. Keep an eye on [CHANGELOG.md](CHANGELOG.md) for any changes.
2019-06-09 10:53:49 -04:00
Please send any feature suggestions to the [issue tracker](https://github.com/Dragory/modmailbot/issues)!