diff options
| author | Max Isom <[email protected]> | 2022-01-26 12:58:33 -0500 |
|---|---|---|
| committer | Max Isom <[email protected]> | 2022-01-26 12:58:33 -0500 |
| commit | aacb107f43db6b8c53d160b5913701959f81cf09 (patch) | |
| tree | a63d0717d03c84987b69d5af1c1f5b45ef019a4a /src/utils/loading-message.ts | |
| parent | 09665af53ee1b1903fc9ea719722aa5dfdc26325 (diff) | |
| parent | af05210be4a8857ea707866192efa79b3945b314 (diff) | |
| download | muse-aacb107f43db6b8c53d160b5913701959f81cf09.tar.xz muse-aacb107f43db6b8c53d160b5913701959f81cf09.zip | |
Merge branch 'master' into feature/slash-commands
Diffstat (limited to 'src/utils/loading-message.ts')
| -rw-r--r-- | src/utils/loading-message.ts | 81 |
1 files changed, 0 insertions, 81 deletions
diff --git a/src/utils/loading-message.ts b/src/utils/loading-message.ts deleted file mode 100644 index 53a2aed..0000000 --- a/src/utils/loading-message.ts +++ /dev/null @@ -1,81 +0,0 @@ -import {TextChannel, Message, MessageReaction} from 'discord.js'; -import delay from 'delay'; - -const INITAL_DELAY = 500; -const PERIOD = 500; - -export default class { - public isStopped = true; - private readonly channel: TextChannel; - private readonly text: string; - private msg!: Message; - - constructor(channel: TextChannel, text = 'cows! count \'em') { - this.channel = channel; - this.text = text; - } - - async start(): Promise<void> { - this.msg = await this.channel.send(this.text); - - const icons = ['🐮', '🐴', '🐄']; - - const reactions: MessageReaction[] = []; - - let i = 0; - let isRemoving = false; - - this.isStopped = false; - - (async () => { - await delay(INITAL_DELAY); - - while (!this.isStopped) { - if (reactions.length === icons.length) { - isRemoving = true; - } - - // eslint-disable-next-line no-await-in-loop - await delay(PERIOD); - - if (isRemoving) { - const reactionToRemove = reactions.shift(); - - if (reactionToRemove) { - // eslint-disable-next-line no-await-in-loop - await reactionToRemove.users.remove(this.msg.client.user!.id); - } else { - isRemoving = false; - } - } else { - if (!this.isStopped) { - // eslint-disable-next-line no-await-in-loop - reactions.push(await this.msg.react(icons[i % icons.length])); - } - - i++; - } - } - })(); - } - - async stop(str = 'u betcha'): Promise<Message> { - const wasAlreadyStopped = this.isStopped; - - this.isStopped = true; - - const editPromise = str ? this.msg.edit(str) : null; - const reactPromise = str && !wasAlreadyStopped ? (async () => { - await this.msg.fetch(); - await Promise.all(this.msg.reactions.cache.map(async react => { - if (react.me) { - await react.users.remove(this.msg.client.user!.id); - } - })); - })() : null; - - await Promise.all([editPromise, reactPromise]); - - return this.msg; - } -} |
