Skip to content

Commit

Permalink
Merge pull request #173 from iminlikewithyou/fix-name-restrictions
Browse files Browse the repository at this point in the history
fix /badge name
  • Loading branch information
iminlikewithyou authored Jul 28, 2024
2 parents 4263e2f + 5f5bba2 commit 02dacc7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lame-bot/commands/badge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ChatInputCommandInteraction, CommandInteraction, GuildMemberRoleManager
import sharp from 'sharp';
import { replyToInteraction } from '../../src/command-handler';
import { getProfile, setBoosterRole } from '../../src/database/db';
import { assignRole, createBoosterRole, setRoleIcon } from '../../src/sleuth';
import { assignRole, createBoosterRole, renameRole, setRoleIcon } from '../../src/sleuth';
import { getCleanRoleName } from '../../src/utils';

export const data = new SlashCommandBuilder()
Expand Down Expand Up @@ -82,19 +82,19 @@ export async function execute(interaction: ChatInputCommandInteraction, _preferB
const newName = getCleanRoleName(name);
if (!newName) {
await replyToInteraction(interaction, "Error", "\nPlease provide a valid name for your badge.", false);
return
return;
}

try {
// check if other roles have this name (not including any booster roles)
let existingRole = roles.cache.find((role) => {
return role.name.toLowerCase() == newName.toLowerCase() && role.position <= lowerPosition && role.position >= higherPosition;
return role.name.toLowerCase() == newName.toLowerCase() && (role.position <= lowerPosition || role.position >= higherPosition);
});
if (existingRole) {
await replyToInteraction(interaction, "Error", `\nA role with the name \`${newName}\` already exists.`, false);
await replyToInteraction(interaction, "Error", `\nA role with that name already exists.`, false);
return;
}
await userBoosterRole.setName(newName);
await renameRole(userBoosterRole.id, newName);
} catch (e) {
console.error(e);
await replyToInteraction(interaction, "Error", `\nFailed to name your role!`, false);
Expand Down
4 changes: 4 additions & 0 deletions src/sleuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ export async function assignRole(userID: string, roleID: string): Promise<void>
await member.roles.add(roleID);
}

export async function renameRole(roleID: string, newName: string) {
await sleuthClient.guilds.cache.get(process.env.GUILD_ID).roles.cache.get(roleID).setName(newName);
}

/**
* Set the icon of a role using Sleuth.
*
Expand Down

0 comments on commit 02dacc7

Please sign in to comment.