Skip to content

Commit

Permalink
Add Herald support
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-kenzel committed Jul 19, 2024
1 parent 6c10710 commit d0f7972
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/components/username-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ function is_valid_name(name: string) {
return is_all_ascii(name) || is_valid_codepoint(name[0]) || has_three_continuous_valid_asciis(name);
}

function is_herald(name: string) {
return /\S, herald of /i.test(name);
}

export default class UsernameManager extends BotComponent {
interval: NodeJS.Timeout | null = null;

Expand Down Expand Up @@ -73,6 +77,27 @@ export default class UsernameManager extends BotComponent {
}
}

has_herald(member: Discord.GuildMember) {
return member.roles.cache.filter(role => role.id == this.wheatley.roles.herald.id).size > 0;
}
async check_herald(member: Discord.GuildMember) {
if (
member.id == "152543367937392640" || // rald
member.id == "125750748272132096" || // dragon
is_herald(member.displayName.trim())
) {
if (!this.has_herald(member)) {
M.info("a new herald was born:", member.displayName);
await member.roles.add(this.wheatley.roles.herald);
}
} else {
if (this.has_herald(member)) {
M.info("an illegitimate herald was found:", member.displayName);
await member.roles.remove(this.wheatley.roles.herald);
}
}
}

async check_member(member: Discord.GuildMember) {
//M.debug(
// member.displayName, // server nickname, user display name
Expand All @@ -96,7 +121,7 @@ export default class UsernameManager extends BotComponent {
);
await member.setNickname(new_name);
} else {
return;
await this.check_herald(member);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/wheatley.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ const roles_map = {
official_bot: "331886851784704001",
jedi_council: "1138950835208990750",
announcements: "1231635207132807290",
herald: "1095555811536797787",
};

const skill_roles_map = {
Expand Down

0 comments on commit d0f7972

Please sign in to comment.