From f6f5543972597fd975f0a0c665830567b1ee5282 Mon Sep 17 00:00:00 2001 From: Octol1ttle Date: Tue, 14 Feb 2023 22:32:29 +0500 Subject: [PATCH] Use modern Tuple syntax Signed-off-by: Octol1ttle --- Boyfriend.cs | 21 +++++++++------------ CommandProcessor.cs | 4 ++-- Commands/BanCommand.cs | 21 ++++++++++++--------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/Boyfriend.cs b/Boyfriend.cs index b8c406b..fb462c4 100644 --- a/Boyfriend.cs +++ b/Boyfriend.cs @@ -25,16 +25,13 @@ public static class Boyfriend { private static DateTimeOffset _nextSongAt = DateTimeOffset.MinValue; private static uint _nextSongIndex; - private static readonly Tuple[] ActivityList = { - Tuple.Create( - new Game("Masayoshi Minoshima (ft. nomico) - Bad Apple!!", ActivityType.Listening), - new TimeSpan(0, 3, 40)), - Tuple.Create(new Game("Xi - Blue Zenith", ActivityType.Listening), new TimeSpan(0, 4, 16)), - Tuple.Create( - new Game("UNDEAD CORPORATION - Everything will freeze", ActivityType.Listening), new TimeSpan(0, 3, 18)), - Tuple.Create(new Game("Splatoon 3 - Candy-Coated Rocks", ActivityType.Listening), new TimeSpan(0, 2, 39)), - Tuple.Create(new Game("RetroSpecter - Overtime", ActivityType.Listening), new TimeSpan(0, 4, 33)), - Tuple.Create(new Game("beatMARIO - Night of Knights", ActivityType.Listening), new TimeSpan(0, 4, 10)) + private static readonly (Game Song, TimeSpan Duration)[] ActivityList = { + (new Game("Masayoshi Minoshima (ft. nomico) - Bad Apple!!", ActivityType.Listening), new TimeSpan(0, 3, 40)), + (new Game("Xi - Blue Zenith", ActivityType.Listening), new TimeSpan(0, 4, 16)), + (new Game("UNDEAD CORPORATION - Everything will freeze", ActivityType.Listening), new TimeSpan(0, 3, 18)), + (new Game("Splatoon 3 - Candy-Coated Rocks", ActivityType.Listening), new TimeSpan(0, 2, 39)), + (new Game("RetroSpecter - Overtime", ActivityType.Listening), new TimeSpan(0, 4, 33)), + (new Game("beatMARIO - Night of Knights", ActivityType.Listening), new TimeSpan(0, 4, 10)) }; public static readonly DiscordSocketClient Client = new(Config); @@ -73,8 +70,8 @@ public static class Boyfriend { if (now >= _nextSongAt) { var nextSong = ActivityList[_nextSongIndex]; - await Client.SetActivityAsync(nextSong.Item1); - _nextSongAt = now.Add(nextSong.Item2); + await Client.SetActivityAsync(nextSong.Song); + _nextSongAt = now.Add(nextSong.Duration); _nextSongIndex++; if (_nextSongIndex >= ActivityList.Length) _nextSongIndex = 0; } diff --git a/CommandProcessor.cs b/CommandProcessor.cs index 428f271..3ee91b6 100644 --- a/CommandProcessor.cs +++ b/CommandProcessor.cs @@ -118,7 +118,7 @@ public sealed class CommandProcessor { return null; } - public Tuple? GetUser(string[] args, string[] cleanArgs, int index) { + public (ulong Id, SocketUser? User)? GetUser(string[] args, string[] cleanArgs, int index) { if (index >= args.Length) { Utils.SafeAppendToBuilder( _stackedReplyMessage, $"{ReplyEmojis.MissingArgument} {Messages.MissingUser}", @@ -144,7 +144,7 @@ public sealed class CommandProcessor { return null; } - return Tuple.Create(mention, Boyfriend.Client.GetUser(mention))!; + return (mention, Boyfriend.Client.GetUser(mention)); } public bool HasPermission(GuildPermission permission) { diff --git a/Commands/BanCommand.cs b/Commands/BanCommand.cs index 9c00656..f984fd4 100644 --- a/Commands/BanCommand.cs +++ b/Commands/BanCommand.cs @@ -11,33 +11,36 @@ public sealed class BanCommand : ICommand { var toBan = cmd.GetUser(args, cleanArgs, 0); if (toBan is null || !cmd.HasPermission(GuildPermission.BanMembers)) return; - var memberToBan = cmd.GetMember(toBan.Item1); + var memberToBan = cmd.GetMember(toBan.Value.Id); if (memberToBan is not null && !cmd.CanInteractWith(memberToBan, "Ban")) return; var duration = CommandProcessor.GetTimeSpan(args, 1); var reason = cmd.GetRemaining(args, duration.TotalSeconds < 1 ? 1 : 2, "BanReason"); - if (reason is not null) await BanUserAsync(cmd, toBan, duration, reason); + if (reason is not null) await BanUserAsync(cmd, toBan.Value, duration, reason); } - private static async Task BanUserAsync(CommandProcessor cmd, Tuple toBan, TimeSpan duration, - string reason) { + private static async Task BanUserAsync( + CommandProcessor cmd, (ulong Id, SocketUser? User) toBan, TimeSpan duration, + string reason) { var author = cmd.Context.User; var guild = cmd.Context.Guild; - if (toBan.Item2 is not null) - await Utils.SendDirectMessage(toBan.Item2, + if (toBan.User is not null) + await Utils.SendDirectMessage( + toBan.User, string.Format(Messages.YouWereBanned, author.Mention, guild.Name, Utils.Wrap(reason))); var guildBanMessage = $"({author}) {reason}"; - await guild.AddBanAsync(toBan.Item1, 0, guildBanMessage); + await guild.AddBanAsync(toBan.Id, 0, guildBanMessage); - var memberData = GuildData.Get(guild).MemberData[toBan.Item1]; + var memberData = GuildData.Get(guild).MemberData[toBan.Id]; memberData.BannedUntil = duration.TotalSeconds < 1 ? DateTimeOffset.MaxValue : DateTimeOffset.Now.Add(duration); memberData.Roles.Clear(); cmd.ConfigWriteScheduled = true; - var feedback = string.Format(Messages.FeedbackUserBanned, $"<@{toBan.Item1.ToString()}>", + var feedback = string.Format( + Messages.FeedbackUserBanned, $"<@{toBan.Id.ToString()}>", Utils.GetHumanizedTimeSpan(duration), Utils.Wrap(reason)); cmd.Reply(feedback, ReplyEmojis.Banned); cmd.Audit(feedback);