Browse Source

Add source as a button after the question is answered

pull/41/head
Abheek Dhawan 3 years ago
parent
commit
75708be6b2
Signed by: abheekd GPG Key ID: 7BE81B8C14475B67
  1. 22
      src/commands/train.ts

22
src/commands/train.ts

@ -103,8 +103,15 @@ export async function execute(interaction) {
answers[1] = answers[1].slice(0, answers[1].length - 1); // If there are multiple elements, it means there was an 'accept' and therefore a trailing ')' which should be removed answers[1] = answers[1].slice(0, answers[1].length - 1); // If there are multiple elements, it means there was an 'accept' and therefore a trailing ')' which should be removed
answers = [answers[0], ...answers[1].split(new RegExp(' OR ', 'i'))]; // Use the first element plus the last element split by 'OR' case insensitive answers = [answers[0], ...answers[1].split(new RegExp(' OR ', 'i'))]; // Use the first element plus the last element split by 'OR' case insensitive
} }
interaction.followUp({ content: decode(tossupQuestion) + `\n\n||Source: ${questionData.uri}||`, fetchMessage: true }) interaction.followUp({ content: decode(tossupQuestion), fetchMessage: true })
.then(questionMessage => { .then(questionMessage => {
const sourceButton = new MessageActionRow()
.addComponents(
new MessageButton()
.setURL(questionData.uri)
.setLabel('Source')
.setStyle('LINK'),
);
switch (tossupFormat) { switch (tossupFormat) {
case 'Short Answer': { case 'Short Answer': {
// eslint-disable-next-line no-case-declarations // eslint-disable-next-line no-case-declarations
@ -161,6 +168,7 @@ export async function execute(interaction) {
}).catch(err => log({ logger: 'train', content: `Failed to override score: ${err}`, level: 'error' })); }).catch(err => log({ logger: 'train', content: `Failed to override score: ${err}`, level: 'error' }));
}).catch(err => log({ logger: 'train', content: `Failed to send override message: ${err}`, level: 'error' })); }).catch(err => log({ logger: 'train', content: `Failed to send override message: ${err}`, level: 'error' }));
} }
interaction.editReply({ components: [sourceButton] });
}).catch(err => log({ logger: 'train', content: `${err}`, level: 'error' })); }).catch(err => log({ logger: 'train', content: `${err}`, level: 'error' }));
break; break;
} }
@ -194,11 +202,15 @@ export async function execute(interaction) {
); );
} }
else { else {
mcChoice.reply({ embeds: [ const incorrectEmbed = new MessageEmbed()
new MessageEmbed() .setAuthor({ name: interaction.user.tag, iconURL: interaction.user.displayAvatarURL() })
.setDescription(`Unfortunately, ${mcChoice.customId.toUpperCase()} was not the correct answer. The correct answer was actually \`${tossupAnswer}\`.`), .addField('Correct answer', `\`${tossupAnswer}\``)
] }); .setDescription(`It seems your answer ${mcChoice.customId.toUpperCase()} was incorrect.`)
.setColor('#ffffff')
.setTimestamp();
mcChoice.reply({ embeds: [incorrectEmbed] });
} }
interaction.editReply({ components: [sourceButton] });
}); });
break; break;
} }

Loading…
Cancel
Save