aboutsummaryrefslogtreecommitdiff
path: root/src/events
diff options
context:
space:
mode:
authorMax Isom <[email protected]>2020-10-24 14:27:02 -0400
committerMax Isom <[email protected]>2020-10-24 14:27:02 -0400
commitf941dbbdddd765e44eb0aa789fda88631e943a65 (patch)
tree75b5df304e370d88436d756984ad6c2d3ea92671 /src/events
parent30c80683638c76607e5eaf3d2dfb1be0c8534d82 (diff)
downloadmuse-f941dbbdddd765e44eb0aa789fda88631e943a65.tar.xz
muse-f941dbbdddd765e44eb0aa789fda88631e943a65.zip
Fix setup wizard when there's >20 channels
Diffstat (limited to 'src/events')
-rw-r--r--src/events/guild-create.ts42
1 files changed, 27 insertions, 15 deletions
diff --git a/src/events/guild-create.ts b/src/events/guild-create.ts
index e842b13..4bf6af2 100644
--- a/src/events/guild-create.ts
+++ b/src/events/guild-create.ts
@@ -1,6 +1,8 @@
-import {Guild, MessageReaction, TextChannel, User, Message} from 'discord.js';
+import {Guild, TextChannel, Message} from 'discord.js';
import emoji from 'node-emoji';
+import pEvent from 'p-event';
import {Settings} from '../models';
+import {chunk} from '../utils/arrays';
const DEFAULT_PREFIX = '!';
@@ -13,6 +15,9 @@ export default async (guild: Guild): Promise<void> => {
firstStep += 'I just need to ask a few questions before you start listening to music.\n\n';
firstStep += 'First, what channel should I listen to for music commands?\n\n';
+ const firstStepMsg = await owner.send(firstStep);
+
+ // Show emoji selector
interface EmojiChannel {
name: string;
id: string;
@@ -31,23 +36,30 @@ export default async (guild: Guild): Promise<void> => {
}
}
- for (const channel of emojiChannels) {
- firstStep += `${channel.emoji}: #${channel.name}\n`;
- }
+ const sentMessageIds: string[] = [];
+
+ chunk(emojiChannels, 10).map(async chunk => {
+ let str = '';
+ for (const channel of chunk) {
+ str += `${channel.emoji}: #${channel.name}\n`;
+ }
- firstStep += '\n';
+ const msg = await owner.send(str);
- // Send message
- const msg = await owner.send(firstStep);
+ sentMessageIds.push(msg.id);
- // Add reactions
- for await (const channel of emojiChannels) {
- await msg.react(channel.emoji);
- }
+ await Promise.all(chunk.map(async channel => msg.react(channel.emoji)));
+ });
- const reactions = await msg.awaitReactions((reaction: MessageReaction, user: User) => user.id !== msg.author.id && emojiChannels.map(e => e.emoji).includes(reaction.emoji.name), {max: 1});
+ // Wait for response from user
- const choice = reactions.first() as MessageReaction;
+ const [choice] = await pEvent(guild.client, 'messageReactionAdd', {
+ multiArgs: true,
+ filter: options => {
+ const [reaction, user] = options;
+ return sentMessageIds.includes(reaction.message.id) && user.id === owner.id;
+ }
+ });
const chosenChannel = emojiChannels.find(e => e.emoji === choice.emoji.name) as EmojiChannel;
@@ -57,7 +69,7 @@ export default async (guild: Guild): Promise<void> => {
await owner.send(secondStep);
- const prefixResponses = await msg.channel.awaitMessages((r: Message) => r.content.length === 1, {max: 1});
+ const prefixResponses = await firstStepMsg.channel.awaitMessages((r: Message) => r.content.length === 1, {max: 1});
const prefixCharacter = prefixResponses.first()!.content;
@@ -69,5 +81,5 @@ export default async (guild: Guild): Promise<void> => {
await boundChannel.send(`hey <@${owner.id}> try \`${prefixCharacter}play https://www.youtube.com/watch?v=dQw4w9WgXcQ\``);
- await msg.channel.send(`Sounds good. Check out **#${chosenChannel.name}** to get started.`);
+ await firstStepMsg.channel.send(`Sounds good. Check out **#${chosenChannel.name}** to get started.`);
};