From 7703506aae30e56ca668d078f72cc5e8abe843d8 Mon Sep 17 00:00:00 2001 From: Max Isom Date: Fri, 27 Mar 2020 17:14:08 -0500 Subject: [PATCH] Bump dependencies and add typing event handler --- package.json | 4 ++-- src/bot.ts | 2 ++ src/events/handle-typing-start.ts | 21 +++++++++++++++++++++ tsconfig.json | 2 +- yarn.lock | 16 ++++++++-------- 5 files changed, 34 insertions(+), 11 deletions(-) create mode 100644 src/events/handle-typing-start.ts diff --git a/package.json b/package.json index e29e5e2..8b827cc 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "@types/debug": "^4.1.5", "@types/fluent-ffmpeg": "^2.1.14", "@types/fs-capacitor": "^2.0.0", - "@types/node": "^13.9.1", + "@types/node": "^13.9.5", "@types/node-emoji": "^1.8.1", "@types/spotify-web-api-node": "^4.0.1", "@types/validator": "^12.0.1", @@ -71,7 +71,7 @@ "array-shuffle": "^1.0.1", "debug": "^4.1.1", "delay": "^4.3.0", - "discord.js": "^12.0.2", + "discord.js": "^12.1.1", "dotenv": "^8.2.0", "fluent-ffmpeg": "^2.1.2", "fs-capacitor": "^6.1.0", 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 +}; diff --git a/tsconfig.json b/tsconfig.json index ece24c7..219c7c7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "lib": ["ES2017"], + "lib": ["ES2018"], "target": "es6", "module": "commonjs", "declaration": true, diff --git a/yarn.lock b/yarn.lock index 00609cd..f66a9f2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -121,10 +121,10 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-13.9.0.tgz#5b6ee7a77faacddd7de719017d0bc12f52f81589" integrity sha512-0ARSQootUG1RljH2HncpsY2TJBfGQIKOOi7kxzUY6z54ePu/ZD+wJA8zI2Q6v8rol2qpG/rvqsReco8zNMPvhQ== -"@types/node@^13.9.1": - version "13.9.1" - resolved "https://registry.yarnpkg.com/@types/node/-/node-13.9.1.tgz#96f606f8cd67fb018847d9b61e93997dabdefc72" - integrity sha512-E6M6N0blf/jiZx8Q3nb0vNaswQeEyn0XlupO+xN6DtJ6r6IT4nXrTry7zhIfYvFCl3/8Cu6WIysmUBKiqV0bqQ== +"@types/node@^13.9.5": + version "13.9.5" + resolved "https://registry.yarnpkg.com/@types/node/-/node-13.9.5.tgz#59738bf30b31aea1faa2df7f4a5f55613750cf00" + integrity sha512-hkzMMD3xu6BrJpGVLeQ3htQQNAcOrJjX7WFmtK8zWQpz2UJf13LCFF2ALA7c9OVdvc2vQJeDdjfR35M0sBCxvw== "@types/parse-json@^4.0.0": version "4.0.0" @@ -760,10 +760,10 @@ diff@^4.0.1: resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d" integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A== -discord.js@^12.0.2: - version "12.0.2" - resolved "https://registry.yarnpkg.com/discord.js/-/discord.js-12.0.2.tgz#c4d68f1363d7fc05ed71a42dba6b930966ed8602" - integrity sha512-iZiEA4Y61gqq/EjFfLXnkRK9pLapnax/vTVDUhs/mAhyqozAy0GOlk/MZI9rSa1iIoKTWRq6P9CRKhLNT2wUnA== +discord.js@^12.1.1: + version "12.1.1" + resolved "https://registry.yarnpkg.com/discord.js/-/discord.js-12.1.1.tgz#440043ab5a09d66311e8b975acd31bea4f8ed227" + integrity sha512-Y6+QfAUZkb9cy27cfNqUigAgYVSKTw9jPF3mN4UDMih3Em3VQ0WjGBdX1UbE8CwFkLOu5XWQSNPdsoStTR8c2Q== dependencies: "@discordjs/collection" "^0.1.5" abort-controller "^3.0.0"