aboutsummaryrefslogtreecommitdiff
path: root/src/modules/typingProxy.js
blob: 58818082024da2d889a9a6a9198a5b40fe8e8c97 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const config = require('../config');
const threads = require("../data/threads");
const Eris = require("eris");

module.exports = ({ bot }) => {
  // 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();
        if (! dmChannel) return;

        try {
          await bot.sendChannelTyping(dmChannel.id);
        } catch(e) {}
      }
    });
  }
};