Browse Source

Defer all replies before responding to prevent timeouts

pull/28/head
Abheek Dhawan 3 years ago
parent
commit
583eb6f86f
Signed by: abheekd GPG Key ID: 7BE81B8C14475B67
  1. 8
      commands/about.js
  2. 4
      commands/help.js
  3. 10
      commands/rounds.js
  4. 6
      commands/top.js
  5. 6
      commands/train.js
  6. 1
      events/interactionCreate.js

8
commands/about.js

@ -28,6 +28,8 @@ module.exports = {
return subcommand;
}),
async execute(interaction) {
await interaction.deferReply();
const client = interaction.client;
const action = interaction.options.getSubcommand();
if (action === 'contributors') {
@ -37,7 +39,7 @@ module.exports = {
.setTimestamp()
.setColor('#ffffff');
interaction.reply({ embeds: [contributorEmbed] });
interaction.followUp({ embeds: [contributorEmbed] });
}
else if (action === 'changelog') {
const gitRepoLocation = __dirname;
@ -58,7 +60,7 @@ module.exports = {
changelogEmbed.addField(commit.abbrevHash, `> \`Hash:\`${commit.hash}\n> \`Subject:\`${commit.subject}\n> \`Author:\`${commit.authorName}\n> \`Date:\`${commit.authorDateRel}\n> \`Link\`: [GitHub](https://github.com/ADawesomeguy/AwesomeSciBo/commit/${commit.hash})\n`);
});
interaction.reply({ embeds: [changelogEmbed] });
interaction.followUp({ embeds: [changelogEmbed] });
}
else if (action === 'bot') {
await client.guilds.fetch();
@ -70,7 +72,7 @@ module.exports = {
.addField('Training Users', `${trainingDocuments}`, true)
.setTimestamp();
interaction.reply({ embeds: [aboutBotEmbed] });
interaction.followUp({ embeds: [aboutBotEmbed] });
}
},
};

4
commands/help.js

@ -6,9 +6,11 @@ module.exports = {
.setName('help')
.setDescription('Replies with a help message explaining what the bot can do'),
async execute(interaction) {
await interaction.deferReply();
const helpEmbed = new MessageEmbed()
.setDescription('AwesomeSciBo has migrated to using slash commands! You can take a look at the different commands by typing `/` and clicking on the AwesomeSciBo icon.')
.setColor('#ffffff');
interaction.reply({ embeds: [helpEmbed] });
interaction.followUp({ embeds: [helpEmbed] });
},
};

10
commands/rounds.js

@ -29,6 +29,8 @@ module.exports = {
return subcommand;
}),
async execute(interaction) {
await interaction.deferReply();
const action = interaction.options.getSubcommand();
if (action === 'generate') {
let i;
@ -70,7 +72,7 @@ module.exports = {
log({ logger: 'rounds', content: `Saving round to DB failed: ${err}`, level: 'error' });
return;
}
interaction.reply(`Here's your round: https://api.adawesome.tech/round/${round._id.toString()}`, { ephemeral: true });
interaction.followUp(`Here's your round: https://api.adawesome.tech/round/${round._id.toString()}`, { ephemeral: true });
});
});
}
@ -78,7 +80,7 @@ module.exports = {
let roundsList = await generatedRound.find({ requestedBy: interaction.user.id }).sort({ timestamp: -1 });
let finalMessage = '';
if (!roundsList) {
interaction.reply('You haven\'t requested any roundsList!');
interaction.followUp('You haven\'t requested any roundsList!');
return;
}
@ -96,7 +98,7 @@ module.exports = {
.setDescription(finalMessage)
.setTimestamp();
interaction.reply({
interaction.followUp({
embeds: [roundsListEmbed],
ephemeral: true,
});
@ -105,7 +107,7 @@ module.exports = {
const totalCount = await generatedRound.countDocuments({});
const userCount = await generatedRound.countDocuments({ requestedBy: interaction.user.id });
interaction.reply(`Total Hits: ${totalCount}\nYour Hits: ${userCount}`);
interaction.followUp(`Total Hits: ${totalCount}\nYour Hits: ${userCount}`);
}
},
};

6
commands/top.js

@ -9,6 +9,8 @@ module.exports = {
.setName('top')
.setDescription('Lists top ten scores across servers (server specific leaderboard WIP)'),
async execute(interaction) {
await interaction.deferReply();
let messageContent = '';
userScore
.find({})
@ -20,7 +22,7 @@ module.exports = {
}
if (obj.length < 10) {
// Need at least 10 scores for top 10
return interaction.reply(
return interaction.followUp(
`There are only ${obj.length} users, we need at least 10!`,
);
}
@ -32,7 +34,7 @@ module.exports = {
.setDescription(messageContent)
.setColor('#ffffff');
interaction.reply({ embeds: [leaderboardEmbed] });
interaction.followUp({ embeds: [leaderboardEmbed] });
});
},
};

6
commands/train.js

@ -29,6 +29,8 @@ module.exports = {
return option;
}),
async execute(interaction) {
await interaction.deferReply();
const subject = interaction.options.get('subject') ? interaction.options.get('subject').value : null;
const authorId = interaction.user.id;
let score;
@ -81,7 +83,7 @@ module.exports = {
categoryArray = ['ENERGY'];
break;
default:
interaction.reply(
interaction.followUp(
new MessageEmbed()
.setDescription('<:red_x:816791117671825409> Not a valid subject!')
.setColor('#ffffff'),
@ -96,7 +98,7 @@ module.exports = {
const tossupQuestion = data.tossup_question;
const tossupAnswer = data.tossup_answer;
const messageFilter = message => message.author.id === interaction.author.id;
interaction.reply({ content: decode(tossupQuestion) + `\n\n||Source: ${data.uri}||` })
interaction.followUp({ content: decode(tossupQuestion) + `\n\n||Source: ${data.uri}||` })
.then(() => {
interaction.channel.awaitMessages({
messageFilter,

1
events/interactionCreate.js

@ -8,7 +8,6 @@ module.exports = {
if (!interaction.isCommand()) return;
const command = client.commands.get(interaction.commandName);
if (!command) return;
try {

Loading…
Cancel
Save