From d0f79724865fce2b13cd7dee45b9e790c8e302c0 Mon Sep 17 00:00:00 2001 From: Michael Kenzel Date: Fri, 19 Jul 2024 05:38:35 +0200 Subject: [PATCH] Add Herald support --- src/components/username-manager.ts | 27 ++++++++++++++++++++++++++- src/wheatley.ts | 1 + 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/components/username-manager.ts b/src/components/username-manager.ts index cd455bc4..057721f2 100644 --- a/src/components/username-manager.ts +++ b/src/components/username-manager.ts @@ -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; @@ -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 @@ -96,7 +121,7 @@ export default class UsernameManager extends BotComponent { ); await member.setNickname(new_name); } else { - return; + await this.check_herald(member); } } diff --git a/src/wheatley.ts b/src/wheatley.ts index 5ee9a073..6f173915 100644 --- a/src/wheatley.ts +++ b/src/wheatley.ts @@ -196,6 +196,7 @@ const roles_map = { official_bot: "331886851784704001", jedi_council: "1138950835208990750", announcements: "1231635207132807290", + herald: "1095555811536797787", }; const skill_roles_map = {