aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bot.ts2
-rw-r--r--src/events/handle-typing-start.ts21
2 files changed, 23 insertions, 0 deletions
diff --git a/src/bot.ts b/src/bot.ts
index 296c06b..d6874b7 100644
--- a/src/bot.ts
+++ b/src/bot.ts
@@ -7,6 +7,7 @@ import Command from './commands';
import debug from './utils/debug';
import NaturalLanguage from './services/natural-language-commands';
import handleGuildCreate from './events/guild-create';
+import handleTypingStart from './events/handle-typing-start';
import handleVoiceStateUpdate from './events/voice-state-update';
import errorMsg from './utils/error-msg';
import {isUserInVoice} from './utils/channels';
@@ -104,6 +105,7 @@ export default class {
// Register event handlers
this.client.on('guildCreate', handleGuildCreate);
+ this.client.on('typingStart', handleTypingStart);
this.client.on('voiceStateUpdate', handleVoiceStateUpdate);
return this.client.login(this.token);
diff --git a/src/events/handle-typing-start.ts b/src/events/handle-typing-start.ts
new file mode 100644
index 0000000..603d2bd
--- /dev/null
+++ b/src/events/handle-typing-start.ts
@@ -0,0 +1,21 @@
+import {Channel, TextChannel, PartialDMChannel, User, PartialUser} from 'discord.js';
+
+const WAIT_TIME_SECONDS = 12;
+
+export default (channel: Channel | PartialDMChannel, user: User | PartialUser): void => {
+ if (channel.type !== 'text') {
+ return;
+ }
+
+ const textChannel = channel as TextChannel;
+
+ setTimeout(async () => {
+ if (user.typingIn(channel)) {
+ const msg = await textChannel.send(`take your time why don'tcha <@${user.id}>`);
+
+ setTimeout(async () => {
+ await msg.delete();
+ }, 2000);
+ }
+ }, WAIT_TIME_SECONDS * 1000); // Discord sends typing updates every 10s
+};