From fc00558dce58250433bda92bea02d49bfcce392a Mon Sep 17 00:00:00 2001 From: Octol1ttle Date: Thu, 8 Dec 2022 13:51:49 +0500 Subject: [PATCH] Update to .NET 7 --- Boyfriend/Boyfriend.cs | 8 ++++---- Boyfriend/Boyfriend.csproj | 16 ++++++++++------ Boyfriend/EventHandler.cs | 5 +++-- Boyfriend/Utils.cs | 9 ++++++--- global.json | 6 +++--- 5 files changed, 26 insertions(+), 18 deletions(-) diff --git a/Boyfriend/Boyfriend.cs b/Boyfriend/Boyfriend.cs index f7d00d4..aee4b8f 100644 --- a/Boyfriend/Boyfriend.cs +++ b/Boyfriend/Boyfriend.cs @@ -21,7 +21,8 @@ public static class Boyfriend { }; private static readonly List> ActivityList = new() { - Tuple.Create(new Game("UNDEAD CORPORATION - Everything will freeze", ActivityType.Listening), new TimeSpan(0, 3, 18)), + Tuple.Create(new Game("UNDEAD CORPORATION - Everything will freeze", ActivityType.Listening), + new TimeSpan(0, 3, 18)), Tuple.Create(new Game("Xi - Blue Zenith", ActivityType.Listening), new TimeSpan(0, 4, 16)), Tuple.Create(new Game("Kurokotei - Scattered Faith", ActivityType.Listening), new TimeSpan(0, 8, 21)), Tuple.Create(new Game("Splatoon 3 - Candy-Coated Rocks", ActivityType.Listening), new TimeSpan(0, 2, 39)), @@ -67,13 +68,11 @@ public static class Boyfriend { EventHandler.InitEvents(); - while (true) { + while (ActivityList.Count > 0) foreach (var activity in ActivityList) { await Client.SetActivityAsync(activity.Item1); await Task.Delay(activity.Item2); } - } - // ReSharper disable once FunctionNeverReturns } public static Task Log(LogMessage msg) { @@ -153,3 +152,4 @@ public static class Boyfriend { return removedRoles; } } + diff --git a/Boyfriend/Boyfriend.csproj b/Boyfriend/Boyfriend.csproj index e58826a..97db937 100644 --- a/Boyfriend/Boyfriend.csproj +++ b/Boyfriend/Boyfriend.csproj @@ -2,12 +2,12 @@ Exe - net6.0 + net7.0 enable enable default Boyfriend - l1ttle + Octol1ttle, mctaylors https://github.com/l1ttleO/Boyfriend-CSharp https://github.com/l1ttleO/Boyfriend-CSharp git @@ -17,16 +17,20 @@ - + true x64 none + + x64 + + - - - + + + diff --git a/Boyfriend/EventHandler.cs b/Boyfriend/EventHandler.cs index a7805b6..488daa3 100644 --- a/Boyfriend/EventHandler.cs +++ b/Boyfriend/EventHandler.cs @@ -62,7 +62,7 @@ public static class EventHandler { Utils.Wrap(msg.CleanContent)), guild.Id, mention); } - private static Task MessageReceivedEvent(SocketMessage messageParam) { + private static Task MessageReceivedEvent(IDeletable messageParam) { if (messageParam is not SocketUserMessage message) return Task.CompletedTask; _ = message.CleanContent.ToLower() switch { @@ -76,7 +76,7 @@ public static class EventHandler { return Task.CompletedTask; } - private static async Task MessageUpdatedEvent(Cacheable messageCached, SocketMessage messageSocket, + private static async Task MessageUpdatedEvent(Cacheable messageCached, IMessage messageSocket, ISocketMessageChannel channel) { var msg = messageCached.Value; if (channel is not SocketGuildChannel gChannel || msg is null or ISystemMessage || @@ -176,3 +176,4 @@ public static class EventHandler { Utils.GetHumanizedTimeOffset(DateTimeOffset.Now.Subtract(scheduledEvent.StartTime)))); } } + diff --git a/Boyfriend/Utils.cs b/Boyfriend/Utils.cs index 6fe8452..e9e34f0 100644 --- a/Boyfriend/Utils.cs +++ b/Boyfriend/Utils.cs @@ -11,7 +11,7 @@ using Humanizer.Localisation; namespace Boyfriend; -public static class Utils { +public static partial class Utils { private static readonly Dictionary ReflectionMessageCache = new(); public static readonly Dictionary CultureInfoCache = new() { @@ -48,7 +48,7 @@ public static class Utils { } public static ulong ParseMention(string mention) { - return ulong.TryParse(Regex.Replace(mention, "[^0-9]", ""), out var id) ? id : 0; + return ulong.TryParse(NumbersOnlyRegex().Replace(mention, ""), out var id) ? id : 0; } public static async Task SendDirectMessage(SocketUser user, string toSend) { @@ -70,7 +70,7 @@ public static class Utils { } public static void RemoveMuteRoleFromCache(ulong id) { - if (MuteRoleCache.ContainsKey(id)) MuteRoleCache.Remove(id); + MuteRoleCache.Remove(id); } public static async Task SilentSendAsync(SocketTextChannel? channel, string text, bool allowRoles = false) { @@ -189,4 +189,7 @@ public static class Utils { public static SocketTextChannel? GetEventNotificationChannel(SocketGuild guild) { return guild.GetTextChannel(ParseMention(Boyfriend.GetGuildConfig(guild.Id)["EventNotificationChannel"])); } + + [GeneratedRegex("[^0-9]")] + private static partial Regex NumbersOnlyRegex(); } diff --git a/global.json b/global.json index 4c1d7e5..36e1a9e 100644 --- a/global.json +++ b/global.json @@ -1,7 +1,7 @@ { "sdk": { - "version": "6.0.0", - "rollForward": "latestFeature", + "version": "7.0.0", + "rollForward": "latestMajor", "allowPrerelease": false } -} +} \ No newline at end of file