diff --git a/Boyfriend.cs b/Boyfriend.cs index 3403ddf..aaad927 100644 --- a/Boyfriend.cs +++ b/Boyfriend.cs @@ -61,7 +61,7 @@ public static class Boyfriend { private static async void TickAllGuildsAsync(object? sender, ElapsedEventArgs e) { if (GuildTickTasks.Count is not 0) return; - var now = DateTimeOffset.Now; + var now = DateTimeOffset.UtcNow; foreach (var guild in Client.Guilds) GuildTickTasks.Add(TickGuildAsync(guild, now)); if (now >= _nextSongAt) { diff --git a/Commands/BanCommand.cs b/Commands/BanCommand.cs index f984fd4..f12dbc7 100644 --- a/Commands/BanCommand.cs +++ b/Commands/BanCommand.cs @@ -34,7 +34,7 @@ public sealed class BanCommand : ICommand { var memberData = GuildData.Get(guild).MemberData[toBan.Id]; memberData.BannedUntil - = duration.TotalSeconds < 1 ? DateTimeOffset.MaxValue : DateTimeOffset.Now.Add(duration); + = duration.TotalSeconds < 1 ? DateTimeOffset.MaxValue : DateTimeOffset.UtcNow.Add(duration); memberData.Roles.Clear(); cmd.ConfigWriteScheduled = true; diff --git a/Commands/MuteCommand.cs b/Commands/MuteCommand.cs index 82a0e7e..241c0e2 100644 --- a/Commands/MuteCommand.cs +++ b/Commands/MuteCommand.cs @@ -19,7 +19,7 @@ public sealed class MuteCommand : ICommand { if ((role is not null && toMute.Roles.Contains(role)) || (toMute.TimedOutUntil is not null && toMute.TimedOutUntil.Value - > DateTimeOffset.Now)) { + > DateTimeOffset.UtcNow)) { cmd.Reply(Messages.MemberAlreadyMuted, ReplyEmojis.Error); return; } @@ -37,7 +37,7 @@ public sealed class MuteCommand : ICommand { var memberData = data.MemberData[toMute.Id]; if (role is not null) { - memberData.MutedUntil = DateTimeOffset.Now.Add(duration); + memberData.MutedUntil = DateTimeOffset.UtcNow.Add(duration); if (data.Preferences["RemoveRolesOnMute"] is "true") { memberData.Roles = toMute.RoleIds.ToList(); memberData.Roles.Remove(cmd.Context.Guild.Id); diff --git a/Commands/PingCommand.cs b/Commands/PingCommand.cs index 67e0861..1678046 100644 --- a/Commands/PingCommand.cs +++ b/Commands/PingCommand.cs @@ -7,7 +7,8 @@ public sealed class PingCommand : ICommand { var builder = Boyfriend.StringBuilder; builder.Append(Utils.GetBeep()) - .Append(Math.Round(Math.Abs(DateTimeOffset.Now.Subtract(cmd.Context.Message.Timestamp).TotalMilliseconds))) + .Append( + Math.Round(Math.Abs(DateTimeOffset.UtcNow.Subtract(cmd.Context.Message.Timestamp).TotalMilliseconds))) .Append(Messages.Milliseconds); cmd.Reply(builder.ToString(), ReplyEmojis.Ping); diff --git a/Commands/RemindCommand.cs b/Commands/RemindCommand.cs index 5a116fc..1d58763 100644 --- a/Commands/RemindCommand.cs +++ b/Commands/RemindCommand.cs @@ -15,7 +15,7 @@ public sealed class RemindCommand : ICommand { var reminderText = cmd.GetRemaining(cleanArgs, 1, "ReminderText"); if (reminderText is not null) { - var reminderOffset = DateTimeOffset.Now.Add(remindIn); + var reminderOffset = DateTimeOffset.UtcNow.Add(remindIn); GuildData.Get(cmd.Context.Guild).MemberData[cmd.Context.User.Id].Reminders.Add( new Reminder { RemindAt = reminderOffset, diff --git a/Data/GuildData.cs b/Data/GuildData.cs index 08f9574..8403e2c 100644 --- a/Data/GuildData.cs +++ b/Data/GuildData.cs @@ -79,7 +79,7 @@ public record GuildData { foreach (var member in guild.Users) { if (MemberData.TryGetValue(member.Id, out var memberData)) { if (!memberData.IsInGuild - && DateTimeOffset.Now.ToUnixTimeSeconds() + && DateTimeOffset.UtcNow.ToUnixTimeSeconds() - Math.Max( memberData.LeftAt.Last().ToUnixTimeSeconds(), memberData.BannedUntil?.ToUnixTimeSeconds() ?? 0) diff --git a/EventHandler.cs b/EventHandler.cs index 4866f97..3eb42dc 100644 --- a/EventHandler.cs +++ b/EventHandler.cs @@ -70,7 +70,7 @@ public static class EventHandler { await Task.Delay(500); var auditLogEntry = (await guild.GetAuditLogsAsync(1).FlattenAsync()).First(); - if (auditLogEntry.CreatedAt >= DateTimeOffset.Now.Subtract(TimeSpan.FromSeconds(1)) + if (auditLogEntry.CreatedAt >= DateTimeOffset.UtcNow.Subtract(TimeSpan.FromSeconds(1)) && auditLogEntry.Data is MessageDeleteAuditLogData data && msg.Author.Id == data.Target.Id) mention = auditLogEntry.User.Mention; @@ -89,9 +89,10 @@ public static class EventHandler { "whoami" => message.ReplyAsync("`nobody`"), "сука !!" => message.ReplyAsync("`root`"), "воооо" => message.ReplyAsync("`removing /...`"), - "пон" => message.ReplyAsync("https://cdn.discordapp.com/attachments/837385840946053181/1087236080950055023/vUORS10xPaY-1.jpg"), - "++++" => message.ReplyAsync("#"), - _ => new CommandProcessor(message).HandleCommandAsync() + "пон" => message.ReplyAsync( + "https://cdn.discordapp.com/attachments/837385840946053181/1087236080950055023/vUORS10xPaY-1.jpg"), + "++++" => message.ReplyAsync("#"), + _ => new CommandProcessor(message).HandleCommandAsync() }; return Task.CompletedTask; } @@ -141,7 +142,7 @@ public static class EventHandler { memberData.JoinedAt.Add(user.JoinedAt!.Value); } - if (DateTimeOffset.Now < memberData.MutedUntil) { + if (DateTimeOffset.UtcNow < memberData.MutedUntil) { await user.AddRoleAsync(data.MuteRole); if (config["RemoveRolesOnMute"] is "false" && config["ReturnRolesOnRejoin"] is "true") await user.AddRolesAsync(memberData.Roles); @@ -151,7 +152,7 @@ public static class EventHandler { private static Task UserLeftEvent(SocketGuild guild, SocketUser user) { var data = GuildData.Get(guild).MemberData[user.Id]; data.IsInGuild = false; - data.LeftAt.Add(DateTimeOffset.Now); + data.LeftAt.Add(DateTimeOffset.UtcNow); return Task.CompletedTask; } @@ -226,6 +227,6 @@ public static class EventHandler { await channel.SendMessageAsync( string.Format( Messages.EventCompleted, Utils.Wrap(scheduledEvent.Name), - Utils.GetHumanizedTimeSpan(DateTimeOffset.Now.Subtract(scheduledEvent.StartTime)))); + Utils.GetHumanizedTimeSpan(DateTimeOffset.UtcNow.Subtract(scheduledEvent.StartTime)))); } } diff --git a/Utils.cs b/Utils.cs index 1417370..27c6ecb 100644 --- a/Utils.cs +++ b/Utils.cs @@ -58,8 +58,10 @@ public static partial class Utils { await channel.SendMessageAsync(text, false, null, null, allowRoles ? AllowRoles : AllowedMentions.None); } catch (Exception e) { - await Boyfriend.Log(new LogMessage(LogSeverity.Error, nameof(Utils), - "Exception while silently sending message", e)); + await Boyfriend.Log( + new LogMessage( + LogSeverity.Error, nameof(Utils), + "Exception while silently sending message", e)); } } @@ -126,8 +128,10 @@ public static partial class Utils { } public static SocketTextChannel? GetEventNotificationChannel(SocketGuild guild) { - return guild.GetTextChannel(ParseMention(GuildData.Get(guild) - .Preferences["EventNotificationChannel"])); + return guild.GetTextChannel( + ParseMention( + GuildData.Get(guild) + .Preferences["EventNotificationChannel"])); } public static bool UserExists(ulong id) { @@ -138,8 +142,9 @@ public static partial class Utils { return GuildData.GuildDataDictionary.Values.Any(gData => gData.MemberData.Values.Any(mData => mData.Id == id)); } - public static async Task UnmuteMemberAsync(GuildData data, string modDiscrim, SocketGuildUser toUnmute, - string reason) { + public static async Task UnmuteMemberAsync( + GuildData data, string modDiscrim, SocketGuildUser toUnmute, + string reason) { var requestOptions = GetRequestOptions($"({modDiscrim}) {reason}"); var role = data.MuteRole; @@ -150,7 +155,7 @@ public static partial class Utils { await toUnmute.RemoveRoleAsync(role, requestOptions); data.MemberData[toUnmute.Id].MutedUntil = null; } else { - if (toUnmute.TimedOutUntil is null || toUnmute.TimedOutUntil.Value < DateTimeOffset.Now) return false; + if (toUnmute.TimedOutUntil is null || toUnmute.TimedOutUntil.Value < DateTimeOffset.UtcNow) return false; await toUnmute.RemoveTimeOutAsync(requestOptions); }