diff options
| author | Sin-MacBook <[email protected]> | 2020-08-10 23:44:20 +0200 |
|---|---|---|
| committer | Sin-MacBook <[email protected]> | 2020-08-10 23:44:20 +0200 |
| commit | 2a53887abba882bf7b63aeda8dfa55fdb3ab8792 (patch) | |
| tree | ad7a95eb41faa6ff13c3142285cdc0eb3ca92183 /src/modules/newthread.js | |
| download | modmail-2a53887abba882bf7b63aeda8dfa55fdb3ab8792.tar.xz modmail-2a53887abba882bf7b63aeda8dfa55fdb3ab8792.zip | |
clean this up when home
Diffstat (limited to 'src/modules/newthread.js')
| -rw-r--r-- | src/modules/newthread.js | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/modules/newthread.js b/src/modules/newthread.js new file mode 100644 index 0000000..aca6f54 --- /dev/null +++ b/src/modules/newthread.js @@ -0,0 +1,23 @@ +const utils = require("../utils"); +const threads = require("../data/threads"); + +module.exports = ({ bot, knex, config, commands }) => { + commands.addInboxServerCommand('newthread', '<userId:userId>', async (msg, args, thread) => { + const user = bot.users.get(args.userId); + if (! user) { + utils.postSystemMessageWithFallback(msg.channel, thread, 'User not found!'); + return; + } + + const existingThread = await threads.findOpenThreadByUserId(user.id); + if (existingThread) { + utils.postSystemMessageWithFallback(msg.channel, thread, `Cannot create a new thread; there is another open thread with this user: <#${existingThread.channel_id}>`); + return; + } + + const createdThread = await threads.createNewThreadForUser(user, true, true); + createdThread.postSystemMessage(`Thread was opened by ${msg.author.username}#${msg.author.discriminator}`); + + msg.channel.createMessage(`Thread opened: <#${createdThread.channel_id}>`); + }); +}; |