From 2a53887abba882bf7b63aeda8dfa55fdb3ab8792 Mon Sep 17 00:00:00 2001 From: Sin-MacBook Date: Mon, 10 Aug 2020 23:44:20 +0200 Subject: clean this up when home --- .DS_Store | Bin 0 -> 6148 bytes .editorconfig | 13 + .eslintrc | 24 + .gitattributes | 2 + .gitignore | 7 + .npmrc | 1 + .nvmrc | 1 + CHANGELOG.md | 284 ++ LICENSE.md | 21 + README.md | 20 + attachments/.gitignore | 2 + db/.gitignore.example | 3 + db/data.sqlite | Bin 0 -> 86016 bytes db/migrations/20171223203915_create_tables.js | 45 + .../20180224235946_add_close_at_to_threads.js | 15 + .../20180421161550_add_alert_id_to_threads.js | 11 + ...0920224224_remove_is_anonymous_from_snippets.js | 11 + ...204728_add_scheduled_close_silent_to_threads.js | 11 + ...90306211534_add_scheduled_suspend_to_threads.js | 15 + .../20190609161116_create_updates_table.js | 14 + ...190609193213_add_expires_at_to_blocked_users.js | 11 + docs/commands.md | 31 + docs/configuration.md | 342 ++ docs/faq.md | 21 + docs/plugins.md | 47 + docs/setup.md | 50 + docs/starting-the-bot.md | 16 + knexfile.js | 2 + logs/.gitignore | 2 + modmailbot-pm2.json | 8 + package-lock.json | 4180 ++++++++++++++++++++ package.json | 37 + src/bot.js | 9 + src/commands.js | 130 + src/config.js | 289 ++ src/data/Snippet.js | 15 + src/data/Thread.js | 468 +++ src/data/ThreadMessage.js | 20 + src/data/attachments.js | 202 + src/data/blocked.js | 94 + src/data/constants.js | 55 + src/data/snippets.js | 58 + src/data/threads.js | 381 ++ src/data/updates.js | 115 + src/index.js | 93 + src/knex.js | 2 + src/legacy/jsonDb.js | 71 + src/legacy/legacyMigrator.js | 222 ++ src/main.js | 281 ++ src/modules/alert.js | 11 + src/modules/block.js | 99 + src/modules/close.js | 153 + src/modules/greeting.js | 37 + src/modules/id.js | 5 + src/modules/logs.js | 69 + src/modules/move.js | 82 + src/modules/newthread.js | 23 + src/modules/reply.js | 32 + src/modules/snippets.js | 138 + src/modules/suspend.js | 77 + src/modules/typingProxy.js | 33 + src/modules/version.js | 53 + src/modules/webserver.js | 92 + src/plugins.js | 26 + src/queue.js | 40 + src/utils.js | 357 ++ start.bat | 17 + 67 files changed, 9096 insertions(+) create mode 100644 .DS_Store create mode 100644 .editorconfig create mode 100644 .eslintrc create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 .npmrc create mode 100644 .nvmrc create mode 100644 CHANGELOG.md create mode 100644 LICENSE.md create mode 100644 README.md create mode 100644 attachments/.gitignore create mode 100644 db/.gitignore.example create mode 100644 db/data.sqlite create mode 100644 db/migrations/20171223203915_create_tables.js create mode 100644 db/migrations/20180224235946_add_close_at_to_threads.js create mode 100644 db/migrations/20180421161550_add_alert_id_to_threads.js create mode 100644 db/migrations/20180920224224_remove_is_anonymous_from_snippets.js create mode 100644 db/migrations/20190306204728_add_scheduled_close_silent_to_threads.js create mode 100644 db/migrations/20190306211534_add_scheduled_suspend_to_threads.js create mode 100644 db/migrations/20190609161116_create_updates_table.js create mode 100644 db/migrations/20190609193213_add_expires_at_to_blocked_users.js create mode 100644 docs/commands.md create mode 100644 docs/configuration.md create mode 100644 docs/faq.md create mode 100644 docs/plugins.md create mode 100644 docs/setup.md create mode 100644 docs/starting-the-bot.md create mode 100644 knexfile.js create mode 100644 logs/.gitignore create mode 100644 modmailbot-pm2.json create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 src/bot.js create mode 100644 src/commands.js create mode 100644 src/config.js create mode 100644 src/data/Snippet.js create mode 100644 src/data/Thread.js create mode 100644 src/data/ThreadMessage.js create mode 100644 src/data/attachments.js create mode 100644 src/data/blocked.js create mode 100644 src/data/constants.js create mode 100644 src/data/snippets.js create mode 100644 src/data/threads.js create mode 100644 src/data/updates.js create mode 100644 src/index.js create mode 100644 src/knex.js create mode 100644 src/legacy/jsonDb.js create mode 100644 src/legacy/legacyMigrator.js create mode 100644 src/main.js create mode 100644 src/modules/alert.js create mode 100644 src/modules/block.js create mode 100644 src/modules/close.js create mode 100644 src/modules/greeting.js create mode 100644 src/modules/id.js create mode 100644 src/modules/logs.js create mode 100644 src/modules/move.js create mode 100644 src/modules/newthread.js create mode 100644 src/modules/reply.js create mode 100644 src/modules/snippets.js create mode 100644 src/modules/suspend.js create mode 100644 src/modules/typingProxy.js create mode 100644 src/modules/version.js create mode 100644 src/modules/webserver.js create mode 100644 src/plugins.js create mode 100644 src/queue.js create mode 100644 src/utils.js create mode 100644 start.bat diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..f0c1918 Binary files /dev/null and b/.DS_Store differ diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..5d12634 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +# editorconfig.org +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..d33e1cf --- /dev/null +++ b/.eslintrc @@ -0,0 +1,24 @@ +{ + "root": true, + + "parserOptions": { + "ecmaVersion": 10, + "sourceType": "module" + }, + + "env": { + "node": true + }, + + "rules": { + "space-infix-ops": "error", + "space-unary-ops": ["error", { + "words": true, + "nonwords": false, + "overrides": { + "!": true, + "!!": true + } + }] + } +} diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6757ecf --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +/.vscode +/.idea +/node_modules +/config.* +!/config.example.ini +/welcome.png +/update.sh diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..2ae2317 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +loglevel=silent diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..f599e28 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +10 diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..f4f990b --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,284 @@ +# Changelog + +## v2.30.1 +* Fix crash with `responseMessage` and `closeMessage` introduced in v2.30.0 + ([#369](https://github.com/Dragory/modmailbot/pull/369)) + +## v2.30.0 +* The following config options now also support multi-line values: + * `responseMessage` + * `closeMessage` + * `botMentionResponse` + * `greetingMessage` + * `accountAgeDeniedMessage` + * `timeOnServerDeniedMessage` +* When the bot is mentioned on the main server, the log message about this now + also includes a link to the message ([#319](https://github.com/Dragory/modmailbot/pull/319)) +* Fix error when supplying all config values from env variables without a config file +* Fix crash in update checker if the repository value in package.json is set to + a GitHub repository without releases (this only applies to forks) + +## v2.29.1 +* Fix boolean values in `config.ini` not being handled properly + +## v2.29.0 +* **Default configuration format is now .ini** + * Existing `config.json` files will continue to work and will not be deprecated + * This makes the default configuration format for the bot much more approachable than JSON +* Config values can now also be loaded from environment variables + (see [Configuration](docs/configuration.md#environment-variables) for more details) +* New rewritten instructions for setting up and using the bot +* New easy-to-use `start.bat` file for Windows +* Update several package dependencies +* Fixed incompatibility with Node.js 10 versions prior to 10.9.0 + +## v2.28.0 +* Fix error when saving attachments locally with `attachmentStorage` set to `"local"` (default) when the bot's folder is + on a different storage device than the system's temp folder +* Add `attachments` object to the plugin API + * This allows plugins to add new storage types via `attachments.addStorageType()` + * See the [Plugins section in the README](README.md#plugins) for more details + +## v2.27.0 +* The `syncPermissionsOnMove` option now defaults to `true`, which should be more intuitive +* **Plugins:** Plugin functions are no longer called with 4 arguments. Instead, the function is called with 1 argument, +which is an object that contains the previous 4 values as properties: `bot`, `knex`, `config`, `commands`. +This will make it easier to scale the plugin system in the future with new features. +You can see an [updated example in the README](https://github.com/Dragory/modmailbot/blob/master/README.md#example-plugin-file). + +## v2.26.0 +* The bot now waits for the main server(s) and inbox server to become available before initializing. +This is a potential fix to [#335](https://github.com/Dragory/modmailbot/issues/335). +This should have little to no effect on smaller servers. +* The bot status ("Playing") is now reapplied hourly since the status can sometimes disappear + +## v2.25.0 +* Fix regression introduced in v2.24.0 where line breaks would get turned to spaces in replies and snippets ([#304](https://github.com/Dragory/modmailbot/issues/304)) +* Replace the internal command handler with a new one. This should be fairly thoroughly tested, but please report any issues you encounter! +* Plugins are now called with a fourth parameter that allows you to easily add specific types of commands + * Due to the command handler change, any calls to `bot.registerCommand` should be replaced with the new system + +## v2.24.0 +* Switch to the new stable version of Eris (0.10.0) instead of the dev version + +## v2.23.2 +* Update Node.js version check at startup to require Node.js 10 + +## v2.23.1 +* Updated required Node.js version in .nvmrc and README (v10 is now the minimum) + +## v2.23.0 +* Add update notifications. The bot will check for new versions every 12 hours and notify moderators at the top of new +modmail threads when there are new versions available. Can be disabled by setting the `updateNotifications` option to `false`. +New available versions are also shown in `!version`. + * If you have forked the repository and want to check for updates in your own repository instead, + change the `repository` value in `package.json` +* Add basic support for plugins. See the **Plugins** section in README for more information. +* Add support for snippet arguments. To use these, put {1}, {2}, etc. in the snippet text and they will be replaced by the given arguments when using the snippet. +* Add support for multiple `mentionRole` config option values in an array +* Add `commandAliases` config option to set custom command aliases +* Add support for timed blocks. Simply specify the duration as the last argument in `!block` or `!unblock`. +* Add pagination to `!logs` + +## v2.22.0 +* Add `guildGreetings` option to allow configuring greeting messages on a per-server basis +* Add `rolesInThreadHeader` option to show the user's roles in the modmail thread's header + +## v2.21.3 +* Fix crash caused by Nitro Boosting notifications + +## v2.21.2 +* Update Eris to fix crashes with news channels and nitro boosting + +## v2.21.1 +* "Account age" and "time on server" requirements are now ignored when using `!newthread` + +## v2.21.0 +* Add `requiredTimeOnServer` and `timeOnServerDeniedMessage` config options to restrict modmail from users who have just joined the server. Thanks [@reboxer](https://github.com/reboxer) ([#270](https://github.com/Dragory/modmailbot/pull/270))! + +## v2.20.0 +* Add `categoryAutomation` option to automate thread categories. Currently supported sub-options: + * `newThread` - same as `newThreadCategoryId`, the default category for new threads + * `newThreadFromGuild` - default category on a per-guild basis, value is an object with guild IDs as keys and category IDs as values +* Threads should now include member information (nickname, joined at, etc.) more reliably +* Thread header now also includes the member's current voice channel, if any + +## v2.19.0 +* Add `attachmentStorage` option to control where attachments are saved. Currently supported: + * `"local"` (default) - Same as before: attachments are saved locally on the machine running the bot and served through the bot's web server + * `"discord"` - Attachments are saved on a special Discord channel specified by the `attachmentStorageChannelId` option +* Add `syncPermissionsOnMove` option. When enabled, thread channel permissions are synced with the category when the thread is moved with `!move`. +* Add support for scheduling `!suspend`. Works the same way as with `!close`, just specify the time after the command. Can be cancelled with `!suspend cancel`. +* Scheduled `!close` can now be silent - just add `silent` as an argument to the command before or after the schedule time +* The schedule time format for `!close` is now stricter and times with whitespace (e.g. `2 h 30 m`) no longer work. Use e.g. `2h30m` instead. +* `!loglink` can now be used in suspended threads +* User can now be mentioned in `botMentionResponse` by adding `{userMention}` to the response text. Thanks @reboxer (#225)! +* Fixed a small mistake in README, thanks @GabrielLewis2 (#226)! + +## v2.18.0 +* Add `silent` option to `!close` (e.g. `!close silent`) to close threads without sending the specified `closeMessage` +* Update some package versions (may help with sqlite3 install issues) + +## v2.17.0 +* Add `mentionUserInThreadHeader` option. When set to `true`, mentions the thread's user in the thread header. Fixes #152. +* Add `botMentionResponse` option. If set, the bot auto-responds to bot mentions with this message. Fixes #143. +* Fix member info sometimes missing in thread header. Thanks @Akhawais (#136)! +* Add support for role and user IDs in inboxServerPermission instead of just permission names +* Allow specifying multiple values (an array) for inboxServerPermission. Members will be considered "staff" if they pass any of the values. +* Update Eris to 0.9.0, Knex to 0.15.2 +* Add support for sending anonymous snippets. By default, you can do this by using `!!!` instead of `!!`. Fixes #82. +* Add `snippetPrefixAnon` option +* Add `allowUserClose` option. When set to `true`, users can use the close command to close threads by themselves. +* Fix `allowMove` missing from README. Thanks @AndreasGassmann (#126)! + +## v2.16.0 +* Add support for a .js config file (export config with `module.exports`) + +## v2.15.2 +* Update several other packages as well + +## v2.15.1 +* Update `node-sqlite3` dependency to hopefully fix installation issues on some setups + +## v2.15.0 +* Add `smallAttachmentLimit` config option to control the max size of attachments forwarded by `relaySmallAttachmentsAsAttachments` +* Fix crash when `closeMessage` failed to send +* Handle webserver errors gracefully + +## v2.14.1 +* Don't alert for main server pings if the pinger is a bot + +## v2.14.0 +* Changed `requiredAccountAge` to be in hours instead of days + +## v2.13.0 +* Added `requiredAccountAge` and `accountAgeDeniedMessage` options for restricting how new accounts can message modmail + +## v2.12.0 +* Added `closeMessage` option. This option can be used to send a message to the user when their modmail thread is closed. +* Documented `pingOnBotMention` option + +## v2.11.1 +* Fixed greetings not being sent since multi-server support was added in 2.9.0 + +## v2.11.0 +* Config files are now parsed using [JSON5](https://json5.org/), allowing you to use comments, trailing commas, and other neat things in your config.json +* When using multiple main guilds, the originating guild name is now always included at the top of the thread (if possible). +Previously, if the user that messaged modmail was on only one of the guilds, the guild name would not be shown at the top. +* Fixed crash when a user edited a message in their DMs with modmail without an open thread +* Small fixes to category name matching when using `!move` +* Fixed crash when the bot was unable to send an auto-response to a user +* Added option `pingOnBotMention` (defaults to `true`) that allows you to control whether staff are pinged when the bot is mentioned +* Long messages are now chunked so they don't fail to send due to added length from e.g. user name + +## v2.10.1 +* Changed timed close default unit from seconds to minutes. +This means that doing e.g. `!close 30` now closes the thread in 30 *minutes*, not seconds. + +## v2.10.0 +* Added `!alert` +Using `!alert` in a modmail thread will ping you the next time the thread gets a new reply. +Use `!alert cancel` to cancel. + +## v2.9.1 +* If using multiple main guilds, the originating server is now specified in bot mention notifications + +## v2.9.0 +* Added multi-server support. +Multi-server support allows you to set an array of ids in mainGuildId. +Nickname and join date will be displayed for each main guild the user is in. +* Information posted at the top of modmail threads now also includes time since the user joined the guild(s) +* Added `!id` +`!id` posts the user ID of the current thread. Useful on mobile when you need to get the user ID. +* Added `!newthread` +`!newthread ` opens a new thread with the specified user +* Fixed a crash when the bot was unable to send a greeting message due to the user's privacy options + +## v2.8.0 +* Added a `!version` command for checking the version of the bot you're running + +## v2.7.0 +* Split more code from main.js to individual module files + +## v2.6.0 +* Warn the user if new dependencies haven't been installed +* `!close` now supports `d` for days in the delay +* `!close` is now stricter about the time format + +## v2.5.0 +* Commands used in inbox threads are now saved in logs again +* Moved more of the code to individual plugin files + +## v2.4.1-v2.4.4 +* Fix errors on first run after upgrading to v2.2.0 +* Various other fixes + +## v2.4.0 +* Add thread suspending. A modmail thread can now be suspended with `!suspend`. Suspended threads will function as closed until unsuspended with `!unsuspend`. + +## v2.3.2 +* Auto-close threads if their modmail channel is deleted + +## v2.3.1 +* Fixed incorrect default value for `mentionRole` (was `null`, should've been `"here"`) + +## v2.3.0 +* Added `mentionRole` configuration option ([#59](https://github.com/Dragory/modmailbot/pull/59)). This option can be used to set the role that is pinged when new threads are created or the bot is mentioned. See README for more details. + +## v2.2.0 +* Added the ability to schedule a thread to close by specifying a time after `!close`, e.g. `!close 1h`. The scheduling is cancelled if a new message is sent to or received from the user. + +## v2.1.0 +* Added typing proxy ([#48](https://github.com/Dragory/modmailbot/pull/48)): + * If the `typingProxy` config option is enabled, any time a user is typing to modmail in their DMs, the modmail thread will show the bot as "typing" + * If the `typingProxyReverse` config option is enabled, any time a moderator is typing in a modmail thread, the user will see the bot "typing" in their DMs + +## v2.0.1 +* The link to the current thread's log is no longer posted to the top of the thread. Use `!loglink` instead. + +## v2.0.0 +* Rewrote large parts of the code to be more modular and maintainable. There may be some new bugs because of this - please report them through GitHub issues if you encounter any! +* Threads, logs, and snippets are now stored in an SQLite database. The bot will migrate old data on the first run. +* Small attachments (<2MB) from users can now be relayed as Discord attachments in the modmail thread with the `relaySmallAttachmentsAsAttachments` config option. Logs will have the link as usual. +* Fixed system messages like pins in DMs being relayed to the thread +* Fixed channels sometimes being created without a category even when `newThreadCategoryId` was set +* Removed timestamps from threads by default. Logs will still have accurate timestamps. Can be re-enabled with the `threadTimestamps` config option. +* Added `!move` command to move threads between categories. Can be enabled with the `allowMove` config option, disabled by default. + +## Sep 22, 2017 +* Added `newThreadCategoryId` option. This option can be set to a category ID to place all new threads in that category. + +## Sep 20, 2017 +* Fixed crash when the bot was unable to find or create a modmail thread +* Reduced error log spam in case of network errors from Eris +* Fixed unintended error when a message was ignored due to an "accidental thread" word + +## Sep 19, 2017 +* Added `logChannelId` option +* Some code clean-up. Please open an issue if you encounter any bugs! +* The bot now throws an error for unknown options in `config.json` (assuming they're typos) and tells you if you haven't configured the token or mail guild id. + +## Aug 3, 2017 +* Fixed user nicknames not showing in new threads +* The "manageRoles" permission is no longer required to use commands on the inbox server. +This can be configured with the `inboxServerPermission` config option. + +## July 24, 2017 +* Commands are now case-insensitive (so !close, !Close, and !CLOSE all work) +* The before/after prefixes in edit notifications are now the same length, making it easier to spot the edited part +* Non-ASCII names should now result in better channel names (not just "unknown") + +## May 18, 2017 +* Identical edits are now ignored +* New thread notification (with @ here ping) is now posted in the thread instead of the inbox server default channel +* Thread close notifications no longer ping the user who closed the thread +* Received attachments are now only linked once the bot has saved them (should fix embeds) +* Replies now use your nickname, if any +* Several messages are now ignored for thread creation ("ok", "thanks", and similar) +* Logs from !logs are now sorted in descending order (newest first) + +## Feb 15, 2017 +More info is now available at the beginning of modmail threads. + +## Feb 10, 2017 +Major rewrite. Includes anonymous replies (!ar), stability improvements, and server greeting feature. diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..f682d0f --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 Miikka Virtanen + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..4863c7f --- /dev/null +++ b/README.md @@ -0,0 +1,20 @@ +# Modmail for Discord +Modmail Bot is a bot for [Discord](https://discordapp.com/) that allows users to DM the bot to contact the server's moderators/staff +without messaging them individually or pinging them publically on the server. +These DMs get relayed to modmail *threads*, channels where staff members can reply to and talk with the user. +To the user, the entire process happens in DMs with the bot. + +Inspired by Reddit's modmail system. + +## Getting started +* **[🛠️ Setting up the bot](docs/setup.md)** +* [📝 Configuration](docs/configuration.md) +* [🤖 Commands](docs/commands.md) +* [🧩 Plugins](docs/plugins.md) +* [🙋 Frequently Asked Questions](docs/faq.md) +* [Release notes](CHANGELOG.md) + +## Support server +If you need help with setting up the bot or would like to discuss other things related to it, join the support server on Discord here: + +👉 **[Join support server](https://discord.gg/vRuhG9R)** diff --git a/attachments/.gitignore b/attachments/.gitignore new file mode 100644 index 0000000..120f485 --- /dev/null +++ b/attachments/.gitignore @@ -0,0 +1,2 @@ +* +!/.gitignore diff --git a/db/.gitignore.example b/db/.gitignore.example new file mode 100644 index 0000000..08f41a1 --- /dev/null +++ b/db/.gitignore.example @@ -0,0 +1,3 @@ +/* +!/.gitignore +!/migrations/ diff --git a/db/data.sqlite b/db/data.sqlite new file mode 100644 index 0000000..967e6c5 Binary files /dev/null and b/db/data.sqlite differ diff --git a/db/migrations/20171223203915_create_tables.js b/db/migrations/20171223203915_create_tables.js new file mode 100644 index 0000000..b5880a3 --- /dev/null +++ b/db/migrations/20171223203915_create_tables.js @@ -0,0 +1,45 @@ +exports.up = async function(knex, Promise) { + await knex.schema.createTableIfNotExists('threads', table => { + table.string('id', 36).notNullable().primary(); + table.integer('status').unsigned().notNullable().index(); + table.integer('is_legacy').unsigned().notNullable(); + table.string('user_id', 20).notNullable().index(); + table.string('user_name', 128).notNullable(); + table.string('channel_id', 20).nullable().unique(); + table.dateTime('created_at').notNullable().index(); + }); + + await knex.schema.createTableIfNotExists('thread_messages', table => { + table.increments('id'); + table.string('thread_id', 36).notNullable().index().references('id').inTable('threads').onDelete('CASCADE'); + table.integer('message_type').unsigned().notNullable(); + table.string('user_id', 20).nullable(); + table.string('user_name', 128).notNullable(); + table.mediumtext('body').notNullable(); + table.integer('is_anonymous').unsigned().notNullable(); + table.string('dm_message_id', 20).nullable().unique(); + table.dateTime('created_at').notNullable().index(); + }); + + await knex.schema.createTableIfNotExists('blocked_users', table => { + table.string('user_id', 20).primary().notNullable(); + table.string('user_name', 128).notNullable(); + table.string('blocked_by', 20).nullable(); + table.dateTime('blocked_at').notNullable(); + }); + + await knex.schema.createTableIfNotExists('snippets', table => { + table.string('trigger', 32).primary().notNullable(); + table.text('body').notNullable(); + table.integer('is_anonymous').unsigned().notNullable(); + table.string('created_by', 20).nullable(); + table.dateTime('created_at').notNullable(); + }); +}; + +exports.down = async function(knex, Promise) { + await knex.schema.dropTableIfExists('thread_messages'); + await knex.schema.dropTableIfExists('threads'); + await knex.schema.dropTableIfExists('blocked_users'); + await knex.schema.dropTableIfExists('snippets'); +}; diff --git a/db/migrations/20180224235946_add_close_at_to_threads.js b/db/migrations/20180224235946_add_close_at_to_threads.js new file mode 100644 index 0000000..dbbb04d --- /dev/null +++ b/db/migrations/20180224235946_add_close_at_to_threads.js @@ -0,0 +1,15 @@ +exports.up = async function (knex, Promise) { + await knex.schema.table('threads', table => { + table.dateTime('scheduled_close_at').index().nullable().defaultTo(null).after('channel_id'); + table.string('scheduled_close_id', 20).nullable().defaultTo(null).after('channel_id'); + table.string('scheduled_close_name', 128).nullable().defaultTo(null).after('channel_id'); + }); +}; + +exports.down = async function(knex, Promise) { + await knex.schema.table('threads', table => { + table.dropColumn('scheduled_close_at'); + table.dropColumn('scheduled_close_id'); + table.dropColumn('scheduled_close_name'); + }); +}; diff --git a/db/migrations/20180421161550_add_alert_id_to_threads.js b/db/migrations/20180421161550_add_alert_id_to_threads.js new file mode 100644 index 0000000..5defc38 --- /dev/null +++ b/db/migrations/20180421161550_add_alert_id_to_threads.js @@ -0,0 +1,11 @@ +exports.up = async function (knex, Promise) { + await knex.schema.table('threads', table => { + table.string('alert_id', 20).nullable().defaultTo(null).after('scheduled_close_name'); + }); +}; + +exports.down = async function(knex, Promise) { + await knex.schema.table('threads', table => { + table.dropColumn('alert_id'); + }); +}; diff --git a/db/migrations/20180920224224_remove_is_anonymous_from_snippets.js b/db/migrations/20180920224224_remove_is_anonymous_from_snippets.js new file mode 100644 index 0000000..ac33267 --- /dev/null +++ b/db/migrations/20180920224224_remove_is_anonymous_from_snippets.js @@ -0,0 +1,11 @@ +exports.up = async function (knex, Promise) { + await knex.schema.table('snippets', table => { + table.dropColumn('is_anonymous'); + }); +}; + +exports.down = async function(knex, Promise) { + await knex.schema.table('snippets', table => { + table.integer('is_anonymous').unsigned().notNullable(); + }); +}; diff --git a/db/migrations/20190306204728_add_scheduled_close_silent_to_threads.js b/db/migrations/20190306204728_add_scheduled_close_silent_to_threads.js new file mode 100644 index 0000000..e61490d --- /dev/null +++ b/db/migrations/20190306204728_add_scheduled_close_silent_to_threads.js @@ -0,0 +1,11 @@ +exports.up = async function(knex, Promise) { + await knex.schema.table('threads', table => { + table.integer('scheduled_close_silent').nullable().after('scheduled_close_name'); + }); +}; + +exports.down = async function(knex, Promise) { + await knex.schema.table('threads', table => { + table.dropColumn('scheduled_close_silent'); + }); +}; diff --git a/db/migrations/20190306211534_add_scheduled_suspend_to_threads.js b/db/migrations/20190306211534_add_scheduled_suspend_to_threads.js new file mode 100644 index 0000000..a22b5f3 --- /dev/null +++ b/db/migrations/20190306211534_add_scheduled_suspend_to_threads.js @@ -0,0 +1,15 @@ +exports.up = async function(knex, Promise) { + await knex.schema.table('threads', table => { + table.dateTime('scheduled_suspend_at').index().nullable().defaultTo(null).after('channel_id'); + table.string('scheduled_suspend_id', 20).nullable().defaultTo(null).after('channel_id'); + table.string('scheduled_suspend_name', 128).nullable().defaultTo(null).after('channel_id'); + }); +}; + +exports.down = async function(knex, Promise) { + await knex.schema.table('threads', table => { + table.dropColumn('scheduled_suspend_at'); + table.dropColumn('scheduled_suspend_id'); + table.dropColumn('scheduled_suspend_name'); + }); +}; diff --git a/db/migrations/20190609161116_create_updates_table.js b/db/migrations/20190609161116_create_updates_table.js new file mode 100644 index 0000000..c90e9bd --- /dev/null +++ b/db/migrations/20190609161116_create_updates_table.js @@ -0,0 +1,14 @@ +exports.up = async function(knex, Promise) { + if (! await knex.schema.hasTable('updates')) { + await knex.schema.createTable('updates', table => { + table.string('available_version', 16).nullable(); + table.dateTime('last_checked').nullable(); + }); + } +}; + +exports.down = async function(knex, Promise) { + if (await knex.schema.hasTable('updates')) { + await knex.schema.dropTable('updates'); + } +}; diff --git a/db/migrations/20190609193213_add_expires_at_to_blocked_users.js b/db/migrations/20190609193213_add_expires_at_to_blocked_users.js new file mode 100644 index 0000000..ea456a6 --- /dev/null +++ b/db/migrations/20190609193213_add_expires_at_to_blocked_users.js @@ -0,0 +1,11 @@ +exports.up = async function(knex, Promise) { + await knex.schema.table('blocked_users', table => { + table.dateTime('expires_at').nullable(); + }); +}; + +exports.down = async function(knex, Promise) { + await knex.schema.table('blocked_users', table => { + table.dropColumn('expires_at'); + }); +}; diff --git a/docs/commands.md b/docs/commands.md new file mode 100644 index 0000000..397cf16 --- /dev/null +++ b/docs/commands.md @@ -0,0 +1,31 @@ +# 🤖 Commands + +## Anywhere on the inbox server +`!logs ` 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