Skip to content

Commit

Permalink
better /contributions and /missing filenames
Browse files Browse the repository at this point in the history
also faster command deployment probably
  • Loading branch information
3vorp committed Apr 6, 2024
1 parent d3026e6 commit b11b395
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
26 changes: 14 additions & 12 deletions src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,17 +282,19 @@ export class ExtendedClient<Ready extends boolean = boolean> extends Client<Read
guilds.global.push(cmd.command);
}

for (const [name, { id }] of Object.entries(allGuilds)) {
// if the client isn't in the guild, skip it
if (!this.guilds.cache.get(id)) continue;
// add guild-specific commands (e.g. /eval)
await rest
.put(Routes.applicationGuildCommands(this.user.id, id), {
body: guilds[name],
})
.then(() => console.log(`${success}Successfully added slash commands to server: ${name}`))
.catch((err) => console.error(err));
}
// faster than for..of (order doesn't matter)
await Promise.all(
Object.entries(allGuilds)
// if the client isn't in the guild, skip it
.filter(([, { id }]) => this.guilds.cache.get(id))
.map(async ([name, { id }]) => {
// add guild-specific commands (e.g. /eval)
await rest.put(Routes.applicationGuildCommands(this.user.id, id), {
body: guilds[name],
});
console.log(`${success}Successfully added slash commands to server: ${name}`);
}),
);

// we add global commands to all guilds (only if not in dev mode)
if (!this.tokens.dev) {
Expand All @@ -307,7 +309,7 @@ export class ExtendedClient<Ready extends boolean = boolean> extends Client<Read
*/
private loadEvents() {
if (this.tokens.maintenance)
return this.on("ready", async () => {
return this.on("ready", () => {
this.user.setPresence({
activities: [{ name: "under maintenance", type: ActivityType.Playing }],
status: "idle",
Expand Down
7 changes: 5 additions & 2 deletions src/commands/faithful/contributions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ export const command: SlashCommand = {
});
}

const files: AttachmentBuilder[] = [];
const embed = new EmbedBuilder();
const files: AttachmentBuilder[] = [];

// nested ternaries were getting really ugly here
let embedTitle = `${user.displayName} has ${response.results.length} `;
Expand All @@ -68,8 +68,11 @@ export const command: SlashCommand = {

if (response.count && !pack) embed.setDescription(response.count);

let fileName = `contributions-${user.username.replace(/\.|_/g, "-")}`;
if (pack) fileName += `-${pack.replace(/_/g, "-")}`;

if (response.results.length)
files.push(new AttachmentBuilder(response.file, { name: "about.txt" }));
files.push(new AttachmentBuilder(response.file, { name: `${fileName}.txt` }));

await interaction
.editReply({ embeds: [embed], files })
Expand Down
4 changes: 2 additions & 2 deletions src/commands/faithful/missing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,14 @@ export const command: SlashCommand = {
if (response.results.length)
files.push(
new AttachmentBuilder(response.diffFile, {
name: `missing-${pack}-${response.data.edition}.txt`,
name: `missing-${pack.replace(/_/g, "-")}-${response.data.edition}.txt`,
}),
);

if (response.nonvanillaFile && interaction.options.getBoolean("nonvanilla", false))
files.push(
new AttachmentBuilder(response.nonvanillaFile, {
name: `nonvanilla-${pack}-${response.data.edition}.txt`,
name: `nonvanilla-${pack.replace(/_/g, "-")}-${response.data.edition}.txt`,
}),
);

Expand Down

0 comments on commit b11b395

Please sign in to comment.