Merge branch 'judge2020-master'

master
Dragory 2018-02-24 23:16:37 +02:00
commit f6ac84cb1a
4 changed files with 40 additions and 1 deletions

View File

@ -62,6 +62,8 @@ These go in `config.json`. See also `config.example.json`.
|alwaysReplyAnon|false|If `alwaysReply` is set to true, this option controls whether the auto-reply is anonymous| |alwaysReplyAnon|false|If `alwaysReply` is set to true, this option controls whether the auto-reply is anonymous|
|useNicknames|false|If set to true, mod replies will use their nickname (on the inbox server) instead of their username| |useNicknames|false|If set to true, mod replies will use their nickname (on the inbox server) instead of their username|
|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.| |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.|
|typingProxy|false|If set to true, the bot will start typing in the corresponding modmail channel when the user starts typing in DM.
|typingProxyReverse|false|If set to true, the bot will start typing in the user's DM when someone starts typing in the corresponding thread.
|enableGreeting|false|Set to true to send a welcome message to new main guild members. Requires `mainGuildId` to be set.| |enableGreeting|false|Set to true to send a welcome message to new main guild members. Requires `mainGuildId` to be set.|
|greetingMessage|None|Text content of the welcome message| |greetingMessage|None|Text content of the welcome message|
|greetingAttachment|None|Path to an image or other attachment to send along with the greeting| |greetingAttachment|None|Path to an image or other attachment to send along with the greeting|

View File

@ -29,6 +29,8 @@ const defaultConfig = {
"ignoreAccidentalThreads": false, "ignoreAccidentalThreads": false,
"threadTimestamps": false, "threadTimestamps": false,
"allowMove": false, "allowMove": false,
"typingProxy": false,
"typingProxyReverse": false,
"enableGreeting": false, "enableGreeting": false,
"greetingMessage": null, "greetingMessage": null,

View File

@ -138,6 +138,13 @@ class Thread {
}); });
} }
/**
* @returns {Promise<PrivateChannel>}
*/
getDMChannel() {
return bot.getDMChannel(this.user_id);
}
/** /**
* @param {String} text * @param {String} text
* @param {Eris~MessageFile|Eris~MessageFile[]} file * @param {Eris~MessageFile|Eris~MessageFile[]} file
@ -146,7 +153,7 @@ class Thread {
*/ */
async postToUser(text, file = null) { async postToUser(text, file = null) {
// Try to open a DM channel with the user // Try to open a DM channel with the user
const dmChannel = await bot.getDMChannel(this.user_id); const dmChannel = await this.getDMChannel();
if (! dmChannel) { if (! dmChannel) {
throw new Error('Could not open DMs with the user. They may have blocked the bot or set their privacy settings higher.'); throw new Error('Could not open DMs with the user. They may have blocked the bot or set their privacy settings higher.');
} }

View File

@ -146,6 +146,34 @@ bot.on('messageCreate', async msg => {
}); });
}); });
// Typing proxy: forwarding typing events between the DM and the modmail thread
if(config.typingProxy || config.typingProxyReverse) {
bot.on("typingStart", async (channel, user) => {
// config.typingProxy: forward user typing in a DM to the modmail thread
if (config.typingProxy && (channel instanceof Eris.PrivateChannel)) {
const thread = await threads.findOpenThreadByUserId(user.id);
if (! thread) return;
try {
await bot.sendChannelTyping(thread.channel_id);
} catch (e) {}
}
// config.typingProxyReverse: forward moderator typing in a thread to the DM
else if (config.typingProxyReverse && (channel instanceof Eris.GuildChannel) && ! user.bot) {
const thread = await threads.findByChannelId(channel.id);
if (! thread) return;
const dmChannel = await thread.getDMChannel(thread.user_id);
if (! dmChannel) return;
try {
await bot.sendChannelTyping(dmChannel.id);
} catch(e) {}
}
});
}
// Mods can reply to modmail threads using !r or !reply // Mods can reply to modmail threads using !r or !reply
// These messages get relayed back to the DM thread between the bot and the user // These messages get relayed back to the DM thread between the bot and the user
addInboxServerCommand('reply', async (msg, args, thread) => { addInboxServerCommand('reply', async (msg, args, thread) => {