diff --git a/src/Services/GuildUpdateService.cs b/src/Services/GuildUpdateService.cs index 64277ea..3a5b846 100644 --- a/src/Services/GuildUpdateService.cs +++ b/src/Services/GuildUpdateService.cs @@ -20,7 +20,7 @@ namespace Boyfriend.Services; /// /// Handles executing guild updates (also called "ticks") once per second. /// -public class GuildUpdateService : BackgroundService { +public partial class GuildUpdateService : BackgroundService { private static readonly (string Name, TimeSpan Duration)[] SongList = { ("UNDEAD CORPORATION - The Empress", new TimeSpan(0, 4, 34)), ("UNDEAD CORPORATION - Everything will freeze", new TimeSpan(0, 3, 17)), @@ -125,7 +125,7 @@ public class GuildUpdateService : BackgroundService { var guildUser = await _guildApi.GetGuildMemberAsync(guildId, user.ID, ct); - var pattern = new Regex(@"^[~`!?@#№$%^&*:;.,()<>{}\[\]\-_=+/\\|']*(.*)"); + var pattern = IllegalCharsRegex(); var match = pattern.Match(guildUser.Entity.Nickname.ToString()); await _guildApi.ModifyGuildMemberAsync(guildId, user.ID, match.Groups[1].ToString(), ct: ct); await TickMemberAsync(guildId, user, memberData, defaultRole, ct); @@ -138,6 +138,9 @@ public class GuildUpdateService : BackgroundService { await TickScheduledEventsAsync(guildId, data, eventsResult.Entity, ct); } + [GeneratedRegex("^[~`!?@#№$%^&*:;.,()<>{}\\[\\]\\-_=+/\\\\|']*(.*)")] + private static partial Regex IllegalCharsRegex(); + private async Task TickScheduledEventsAsync( Snowflake guildId, GuildData data, IEnumerable events, CancellationToken ct) { foreach (var scheduledEvent in events) {