diff --git a/src/Discord.Net/Events/BanEventArgs.cs b/src/Discord.Net/Events/BanEventArgs.cs new file mode 100644 index 000000000..0bddc38ea --- /dev/null +++ b/src/Discord.Net/Events/BanEventArgs.cs @@ -0,0 +1,16 @@ +using System; + +namespace Discord +{ + public class BanEventArgs : EventArgs + { + public Server Server { get; } + public ulong UserId { get; } + + public BanEventArgs(Server server, ulong userId) + { + Server = server; + UserId = userId; + } + } +} diff --git a/src/Discord.Net/Extensions.cs b/src/Discord.Net/Extensions.cs new file mode 100644 index 000000000..675efb253 --- /dev/null +++ b/src/Discord.Net/Extensions.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Concurrent; +using System.Globalization; +using System.Runtime.CompilerServices; + +namespace Discord +{ + internal static class InternalExtensions + { + internal static readonly IFormatProvider _format = CultureInfo.InvariantCulture; + + public static ulong ToId(this string value) + => ulong.Parse(value, NumberStyles.None, _format); + public static ulong? ToNullableId(this string value) + => value == null ? (ulong?)null : ulong.Parse(value, NumberStyles.None, _format); + + public static string ToIdString(this ulong value) + => value.ToString(_format); + public static string ToIdString(this ulong? value) + => value?.ToString(_format); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool HasBit(this uint value, byte bit) => ((value >> bit) & 1U) == 1; + + public static bool TryGetAdd(this ConcurrentDictionary d, + TKey key, Func factory, out TValue result) + { + while (true) + { + if (d.TryGetValue(key, out result)) + return false; + if (d.TryAdd(key, factory(key))) + return true; + } + } + } +}