Browse Source

Combine about command into single paginated message

development
Abheek Dhawan 3 years ago
parent
commit
552b86d7b0
Signed by: abheekd GPG Key ID: 7BE81B8C14475B67
  1. 99
      src/commands/about.ts

99
src/commands/about.ts

@ -5,83 +5,54 @@ import gitlog from 'gitlog';
import userScore from '../models/userScore'; import userScore from '../models/userScore';
import { paginateInteraction } from '../helpers/util/pagination';
export const data = new SlashCommandBuilder() export const data = new SlashCommandBuilder()
.setName('about') .setName('about')
.setDescription('Commands regarding the creation/development of the bot') .setDescription('Commands regarding the creation/development of the bot');
.addSubcommand(subcommand => {
subcommand
.setName('contributors')
.setDescription('Lists contributors to the AwesomeSciBo bot');
return subcommand;
})
.addSubcommand(subcommand => {
subcommand
.setName('changelog')
.setDescription('Lists the 5 most recent changes in a "git log" type format');
return subcommand;
})
.addSubcommand(subcommand => {
subcommand
.setName('bot')
.setDescription('Lists information about AwesomeSciBo');
return subcommand;
});
export async function execute(interaction : CommandInteraction) { export async function execute(interaction : CommandInteraction) {
await interaction.deferReply(); await interaction.deferReply();
const client = interaction.client; const client = interaction.client;
const embeds : MessageEmbed[] = [];
switch (interaction.options.getSubcommand()) { const contributorEmbed = new MessageEmbed().setTitle('Contributors')
case 'contributors': { .addField('Creator', '<@745063586422063214> [ADawesomeguy#3602]', true)
const contributorEmbed = new MessageEmbed().setTitle('Contributors') .addField('Contributors', '<@650525101048987649> [tEjAs#8127]\n<@426864344463048705> [tetrident#9396]', true) // Add more contributors here, first one is Abheek, second one is Tejas
.addField('Creator', '<@745063586422063214> [ADawesomeguy#3602]', true) .setTimestamp()
.addField('Contributors', '<@650525101048987649> [tEjAs#8127]\n<@426864344463048705> [tetrident#9396]', true) // Add more contributors here, first one is Abheek, second one is Tejas .setColor('#ffffff');
.setTimestamp() embeds.push(contributorEmbed);
.setColor('#ffffff');
interaction.followUp({ embeds: [contributorEmbed] });
break;
}
case 'changelog': { const gitRepoLocation = __dirname;
const gitRepoLocation = __dirname;
const commits = gitlog({ const commits = gitlog({
repo: gitRepoLocation, repo: gitRepoLocation,
number: 5, number: 5,
fields: ['hash', 'abbrevHash', 'subject', 'authorName', 'authorDateRel'], fields: ['hash', 'abbrevHash', 'subject', 'authorName', 'authorDateRel'],
}); });
const changelogEmbed = new MessageEmbed()
.setAuthor({ name: interaction.user.tag, iconURL: interaction.user.displayAvatarURL() })
.setTitle('Changelog')
.setColor('#ffffff')
.setTimestamp();
commits.forEach(commit => {
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.followUp({ embeds: [changelogEmbed] }); const changelogEmbed = new MessageEmbed()
.setAuthor({ name: interaction.user.tag, iconURL: interaction.user.displayAvatarURL() })
.setTitle('Changelog')
.setColor('#ffffff')
.setTimestamp();
break; commits.forEach(commit => {
} 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`);
});
embeds.push(changelogEmbed);
case 'bot': { await client.guilds.fetch();
await client.guilds.fetch(); const trainingDocuments = await userScore.countDocuments({});
const trainingDocuments = await userScore.countDocuments({}); const aboutBotEmbed = new MessageEmbed()
const aboutBotEmbed = new MessageEmbed() .setAuthor({ name: interaction.user.tag, iconURL: interaction.user.displayAvatarURL() })
.setAuthor({ name: interaction.user.tag, iconURL: interaction.user.displayAvatarURL() }) .setTitle('About AwesomeSciBo')
.setTitle('About AwesomeSciBo') .addField('Servers', `${client.guilds.cache.size}`, true)
.addField('Servers', `${client.guilds.cache.size}`, true) .addField('Training Users', `${trainingDocuments}`, true)
.addField('Training Users', `${trainingDocuments}`, true) .setTimestamp();
.setTimestamp();
interaction.followUp({ embeds: [aboutBotEmbed] }); embeds.push(aboutBotEmbed);
break; paginateInteraction(interaction, embeds);
}
}
} }

Loading…
Cancel
Save