This resolves #477tags/1.0-rc
| @@ -12,6 +12,8 @@ namespace Discord | |||||
| public static DateTimeOffset FromSnowflake(ulong value) | public static DateTimeOffset FromSnowflake(ulong value) | ||||
| => FromUnixMilliseconds((long)((value >> 22) + 1420070400000UL)); | => FromUnixMilliseconds((long)((value >> 22) + 1420070400000UL)); | ||||
| public static ulong ToSnowflake(DateTimeOffset value) | |||||
| => (ulong)(ToUnixMilliseconds(value) - 1420070400000L) << 22; | |||||
| public static DateTimeOffset FromTicks(long ticks) | public static DateTimeOffset FromTicks(long ticks) | ||||
| => new DateTimeOffset(ticks, TimeSpan.Zero); | => new DateTimeOffset(ticks, TimeSpan.Zero); | ||||
| @@ -181,5 +181,13 @@ namespace Discord | |||||
| if (msg == null) return new ArgumentException($"Value must be less than {value}", name); | if (msg == null) return new ArgumentException($"Value must be less than {value}", name); | ||||
| else return new ArgumentException(msg, name); | else return new ArgumentException(msg, name); | ||||
| } | } | ||||
| // Bulk Delete | |||||
| public static void NoMessageOlderThanTwoWeeks(ulong[] collection, string name) | |||||
| { | |||||
| var minimum = DateTimeUtils.ToSnowflake(DateTimeOffset.Now.Subtract(TimeSpan.FromDays(14))); | |||||
| for (var i = 0; i < collection.Length; i++) | |||||
| if (collection[i] <= minimum) throw new ArgumentOutOfRangeException(name, "Messages must be younger than two weeks to delete."); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -484,6 +484,7 @@ namespace Discord.API | |||||
| Preconditions.NotNull(args, nameof(args)); | Preconditions.NotNull(args, nameof(args)); | ||||
| Preconditions.NotNull(args.MessageIds, nameof(args.MessageIds)); | Preconditions.NotNull(args.MessageIds, nameof(args.MessageIds)); | ||||
| Preconditions.AtMost(args.MessageIds.Length, 100, nameof(args.MessageIds.Length)); | Preconditions.AtMost(args.MessageIds.Length, 100, nameof(args.MessageIds.Length)); | ||||
| Preconditions.NoMessageOlderThanTwoWeeks(args.MessageIds, nameof(args.MessageIds)); | |||||
| options = RequestOptions.CreateOrClone(options); | options = RequestOptions.CreateOrClone(options); | ||||
| switch (args.MessageIds.Length) | switch (args.MessageIds.Length) | ||||