diff --git a/src/EllieBot/_common/Abstractions/Cache/BotCacheExtensions.cs b/src/EllieBot/_common/Abstractions/Cache/BotCacheExtensions.cs index 39d5e82..2c6ea67 100644 --- a/src/EllieBot/_common/Abstractions/Cache/BotCacheExtensions.cs +++ b/src/EllieBot/_common/Abstractions/Cache/BotCacheExtensions.cs @@ -1,4 +1,4 @@ -using OneOf; +using OneOf; using OneOf.Types; namespace Ellie.Common; @@ -13,7 +13,7 @@ public static class BotCacheExtensions return default; } - + private static TypedKey GetImgKey(Uri uri) => new($"image:{uri}"); diff --git a/src/EllieBot/_common/Abstractions/Cache/IBotCache.cs b/src/EllieBot/_common/Abstractions/Cache/IBotCache.cs index 5622c5f..15f9e3f 100644 --- a/src/EllieBot/_common/Abstractions/Cache/IBotCache.cs +++ b/src/EllieBot/_common/Abstractions/Cache/IBotCache.cs @@ -15,7 +15,7 @@ public interface IBotCache /// Type of the value /// Returns whether add was sucessful. Always true unless ovewrite = false ValueTask AddAsync(TypedKey key, T value, TimeSpan? expiry = null, bool overwrite = true); - + /// /// Get an element from the cache /// @@ -23,7 +23,7 @@ public interface IBotCache /// Type of the value /// Either a value or ValueTask> GetAsync(TypedKey key); - + /// /// Remove a key from the cache /// diff --git a/src/EllieBot/_common/Abstractions/Cache/MemoryBotCache.cs b/src/EllieBot/_common/Abstractions/Cache/MemoryBotCache.cs index caac44f..2368ac2 100644 --- a/src/EllieBot/_common/Abstractions/Cache/MemoryBotCache.cs +++ b/src/EllieBot/_common/Abstractions/Cache/MemoryBotCache.cs @@ -26,12 +26,12 @@ public sealed class MemoryBotCache : IBotCache item.AbsoluteExpirationRelativeToNow = expiry; return new(true); } - + lock (_cacheLock) { if (_cache.TryGetValue(key.Key, out var old) && old is not null) return new(false); - + using var item = _cache.CreateEntry(key.Key); item.Value = value; item.AbsoluteExpirationRelativeToNow = expiry; @@ -63,7 +63,7 @@ public sealed class MemoryBotCache : IBotCache { lock (_cacheLock) { - var toReturn = _cache.TryGetValue(key.Key, out var old) && old is not null; + var toReturn = _cache.TryGetValue(key.Key, out var old ) && old is not null; _cache.Remove(key.Key); return new(toReturn); } diff --git a/src/EllieBot/_common/Abstractions/Collections/ConcurrentHashSet.cs b/src/EllieBot/_common/Abstractions/Collections/ConcurrentHashSet.cs index 19986be..7d5bbc1 100644 --- a/src/EllieBot/_common/Abstractions/Collections/ConcurrentHashSet.cs +++ b/src/EllieBot/_common/Abstractions/Collections/ConcurrentHashSet.cs @@ -1,4 +1,4 @@ -using System.Diagnostics; +using System.Diagnostics; namespace System.Collections.Generic; @@ -6,7 +6,7 @@ namespace System.Collections.Generic; public sealed class ConcurrentHashSet : IReadOnlyCollection, ICollection where T : notnull { private readonly ConcurrentDictionary _backingStore; - + public ConcurrentHashSet() => _backingStore = new(); @@ -46,12 +46,8 @@ public sealed class ConcurrentHashSet : IReadOnlyCollection, ICollection= array.Length) - throw new ArgumentOutOfRangeException(nameof(arrayIndex)); + ArgumentOutOfRangeException.ThrowIfNegative(arrayIndex); + ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(arrayIndex, array.Length); CopyToInternal(array, arrayIndex); } @@ -63,7 +59,7 @@ public sealed class ConcurrentHashSet : IReadOnlyCollection, ICollection= len) throw new IndexOutOfRangeException(nameof(arrayIndex)); - + array[arrayIndex++] = k; } } diff --git a/src/EllieBot/_common/Abstractions/Collections/IndexedCollections.cs b/src/EllieBot/_common/Abstractions/Collections/IndexedCollection.cs similarity index 98% rename from src/EllieBot/_common/Abstractions/Collections/IndexedCollections.cs rename to src/EllieBot/_common/Abstractions/Collections/IndexedCollection.cs index fe8e2c1..dce86a0 100644 --- a/src/EllieBot/_common/Abstractions/Collections/IndexedCollections.cs +++ b/src/EllieBot/_common/Abstractions/Collections/IndexedCollection.cs @@ -1,4 +1,4 @@ -using System.Collections; +using System.Collections; namespace Ellie.Common; diff --git a/src/EllieBot/_common/Abstractions/EllieRandom.cs b/src/EllieBot/_common/Abstractions/EllieRandom.cs index 0ece259..df2d073 100644 --- a/src/EllieBot/_common/Abstractions/EllieRandom.cs +++ b/src/EllieBot/_common/Abstractions/EllieRandom.cs @@ -16,7 +16,7 @@ public sealed class EllieRandom : Random _rng.GetBytes(bytes); return Math.Abs(BitConverter.ToInt32(bytes, 0)); } - + /// /// Generates a random integer between 0 (inclusive) and /// a specified exclusive upper bound using a cryptographically strong random number generator. diff --git a/src/EllieBot/_common/Abstractions/Extensions/ArrayExtensions.cs b/src/EllieBot/_common/Abstractions/Extensions/ArrayExtensions.cs index dbe2d93..f3e8ae3 100644 --- a/src/EllieBot/_common/Abstractions/Extensions/ArrayExtensions.cs +++ b/src/EllieBot/_common/Abstractions/Extensions/ArrayExtensions.cs @@ -1,4 +1,4 @@ -using System.Security.Cryptography; +using System.Security.Cryptography; namespace Ellie.Common; @@ -43,7 +43,7 @@ public static class ArrayExtensions public static TOut[] Map(this IReadOnlyCollection col, Func f) { var toReturn = new TOut[col.Count]; - + var i = 0; foreach (var item in col) toReturn[i++] = f(item); diff --git a/src/EllieBot/_common/Abstractions/Extensions/EnumerableExtensions.cs b/src/EllieBot/_common/Abstractions/Extensions/EnumerableExtensions.cs index 4e4c786..3cedd0e 100644 --- a/src/EllieBot/_common/Abstractions/Extensions/EnumerableExtensions.cs +++ b/src/EllieBot/_common/Abstractions/Extensions/EnumerableExtensions.cs @@ -1,4 +1,4 @@ -using System.Security.Cryptography; +using System.Security.Cryptography; namespace Ellie.Common; @@ -37,7 +37,7 @@ public static class EnumerableExtensions /// public static string Join(this IEnumerable data, string separator, Func? func = null) => string.Join(separator, data.Select(func ?? (x => x?.ToString() ?? string.Empty))); - + /// /// Randomize element order by performing the Fisher-Yates shuffle /// diff --git a/src/EllieBot/_common/Abstractions/Extensions/Extensions.cs b/src/EllieBot/_common/Abstractions/Extensions/Extensions.cs index 487afe7..8abf5d6 100644 --- a/src/EllieBot/_common/Abstractions/Extensions/Extensions.cs +++ b/src/EllieBot/_common/Abstractions/Extensions/Extensions.cs @@ -1,4 +1,4 @@ -namespace Ellie.Common; +namespace Ellie.Common; public static class Extensions { diff --git a/src/EllieBot/_common/Abstractions/Extensions/PipeExtensions.cs b/src/EllieBot/_common/Abstractions/Extensions/PipeExtensions.cs index 215a829..65b5bb2 100644 --- a/src/EllieBot/_common/Abstractions/Extensions/PipeExtensions.cs +++ b/src/EllieBot/_common/Abstractions/Extensions/PipeExtensions.cs @@ -7,16 +7,16 @@ public static class PipeExtensions { public static TOut Pipe(this TIn a, Func fn) => fn(a); - + public static TOut Pipe(this TIn a, PipeFunc fn) => fn(a); - + public static TOut Pipe(this (TIn1, TIn2) a, PipeFunc fn) => fn(a.Item1, a.Item2); public static (TIn, TExtra) With(this TIn a, TExtra b) => (a, b); - + public static async Task Pipe(this Task a, Func fn) => fn(await a); } \ No newline at end of file diff --git a/src/EllieBot/_common/Abstractions/Extensions/StringExtensions.cs b/src/EllieBot/_common/Abstractions/Extensions/StringExtensions.cs index 95baadb..f2fd050 100644 --- a/src/EllieBot/_common/Abstractions/Extensions/StringExtensions.cs +++ b/src/EllieBot/_common/Abstractions/Extensions/StringExtensions.cs @@ -1,4 +1,4 @@ -using EllieBot.Common.Yml; +using EllieBot.Common.Yml; using System.Text; using System.Text.RegularExpressions; @@ -82,14 +82,14 @@ public static class StringExtensions // Step 3 for (var i = 1; i <= n; i++) //Step 4 - for (var j = 1; j <= m; j++) - { - // Step 5 - var cost = t[j - 1] == s[i - 1] ? 0 : 1; + for (var j = 1; j <= m; j++) + { + // Step 5 + var cost = t[j - 1] == s[i - 1] ? 0 : 1; - // Step 6 - d[i, j] = Math.Min(Math.Min(d[i - 1, j] + 1, d[i, j - 1] + 1), d[i - 1, j - 1] + cost); - } + // Step 6 + d[i, j] = Math.Min(Math.Min(d[i - 1, j] + 1, d[i, j - 1] + 1), d[i - 1, j - 1] + cost); + } // Step 7 return d[n, m]; diff --git a/src/EllieBot/_common/Abstractions/Helpers/StandardConversions.cs b/src/EllieBot/_common/Abstractions/Helpers/StandardConversions.cs index 143c149..d277b7e 100644 --- a/src/EllieBot/_common/Abstractions/Helpers/StandardConversions.cs +++ b/src/EllieBot/_common/Abstractions/Helpers/StandardConversions.cs @@ -1,4 +1,4 @@ -namespace Ellie.Common; +namespace Ellie.Common; public static class StandardConversions { diff --git a/src/EllieBot/_common/Abstractions/PubSub/EventPubSub.cs b/src/EllieBot/_common/Abstractions/PubSub/EventPubSub.cs index a3d753a..87ce07f 100644 --- a/src/EllieBot/_common/Abstractions/PubSub/EventPubSub.cs +++ b/src/EllieBot/_common/Abstractions/PubSub/EventPubSub.cs @@ -50,9 +50,9 @@ public class EventPubSub : IPubSub { // get subscriptions for this action if (_actions.TryGetValue(key.Key, out var actions)) - // get subscriptions which have the same action hash code - // note: having this as a list allows for multiple subscriptions of - // the same insance's/static method + // get subscriptions which have the same action hash code + // note: having this as a list allows for multiple subscriptions of + // the same insance's/static method { if (actions.TryGetValue(action, out var sameActions)) { diff --git a/src/EllieBot/_common/Abstractions/PubSub/IPubSub.cs b/src/EllieBot/_common/Abstractions/PubSub/IPubSub.cs index ea84b6b..7c092cb 100644 --- a/src/EllieBot/_common/Abstractions/PubSub/IPubSub.cs +++ b/src/EllieBot/_common/Abstractions/PubSub/IPubSub.cs @@ -1,4 +1,4 @@ -namespace Ellie.Common; +namespace Ellie.Common; public interface IPubSub { diff --git a/src/EllieBot/_common/Abstractions/PubSub/ISeria.cs b/src/EllieBot/_common/Abstractions/PubSub/ISeria.cs index 76094f4..57217c2 100644 --- a/src/EllieBot/_common/Abstractions/PubSub/ISeria.cs +++ b/src/EllieBot/_common/Abstractions/PubSub/ISeria.cs @@ -1,4 +1,4 @@ -namespace Ellie.Common; +namespace Ellie.Common; public interface ISeria { diff --git a/src/EllieBot/_common/Abstractions/QueueRunner.cs b/src/EllieBot/_common/Abstractions/QueueRunner.cs index 6e582cc..7bba829 100644 --- a/src/EllieBot/_common/Abstractions/QueueRunner.cs +++ b/src/EllieBot/_common/Abstractions/QueueRunner.cs @@ -37,7 +37,7 @@ public sealed class QueueRunner while (true) { var func = await _channel.Reader.ReadAsync(cancel); - + try { await func(); @@ -55,7 +55,7 @@ public sealed class QueueRunner } } } - + public ValueTask EnqueueAsync(Func action) => _channel.Writer.WriteAsync(action); } \ No newline at end of file diff --git a/src/EllieBot/_common/Abstractions/TypedKey.cs b/src/EllieBot/_common/Abstractions/TypedKey.cs index ea3103c..0ca2554 100644 --- a/src/EllieBot/_common/Abstractions/TypedKey.cs +++ b/src/EllieBot/_common/Abstractions/TypedKey.cs @@ -1,4 +1,4 @@ -namespace Ellie.Common; +namespace Ellie.Common; public readonly struct TypedKey { diff --git a/src/EllieBot/_common/Abstractions/creds/IBotCredentials.cs b/src/EllieBot/_common/Abstractions/creds/IBotCredentials.cs index 87db412..faeae4f 100644 --- a/src/EllieBot/_common/Abstractions/creds/IBotCredentials.cs +++ b/src/EllieBot/_common/Abstractions/creds/IBotCredentials.cs @@ -1,11 +1,12 @@ -#nullable disable +#nullable disable namespace EllieBot; public interface IBotCredentials { string Token { get; } - string GoogleApiKey { get; } + string EllieAiToken { get; } ICollection OwnerIds { get; set; } + string GoogleApiKey { get; } bool UsePrivilegedIntents { get; } string RapidApiKey { get; } diff --git a/src/EllieBot/_common/Abstractions/strings/CommandStrings.cs b/src/EllieBot/_common/Abstractions/strings/CommandStrings.cs index 6f72ab0..77f16be 100644 --- a/src/EllieBot/_common/Abstractions/strings/CommandStrings.cs +++ b/src/EllieBot/_common/Abstractions/strings/CommandStrings.cs @@ -20,7 +20,7 @@ public sealed record class CommandStrings [YamlMember(Alias = "ex")] public string[] Examples { get; set; } - + [YamlMember(Alias = "params")] public Dictionary[] Params { get; set; } } @@ -29,7 +29,7 @@ public sealed record class CommandStringParam { // [YamlMember(Alias = "type", ScalarStyle = ScalarStyle.DoubleQuoted)] // public string Type { get; set; } - + [YamlMember(Alias = "desc", ScalarStyle = ScalarStyle.DoubleQuoted)] public string Desc { get; set; } } \ No newline at end of file diff --git a/src/EllieBot/_common/Abstractions/strings/IBotStrings.cs b/src/EllieBot/_common/Abstractions/strings/IBotStrings.cs index 2ded833..5c43755 100644 --- a/src/EllieBot/_common/Abstractions/strings/IBotStrings.cs +++ b/src/EllieBot/_common/Abstractions/strings/IBotStrings.cs @@ -1,4 +1,4 @@ -#nullable disable +#nullable disable using System.Globalization; namespace EllieBot.Common; diff --git a/src/EllieBot/_common/Abstractions/strings/IBotStringsExtensions.cs b/src/EllieBot/_common/Abstractions/strings/IBotStringsExtensions.cs index 17f9377..a635b4b 100644 --- a/src/EllieBot/_common/Abstractions/strings/IBotStringsExtensions.cs +++ b/src/EllieBot/_common/Abstractions/strings/IBotStringsExtensions.cs @@ -8,7 +8,7 @@ public static class BotStringsExtensions // this one is for pipe fun, see PipeExtensions.cs public static string GetText(this IBotStrings strings, in LocStr str, in ulong guildId) => strings.GetText(str.Key, guildId, str.Params); - + public static string GetText(this IBotStrings strings, in LocStr str, ulong? guildId = null) => strings.GetText(str.Key, guildId, str.Params); diff --git a/src/EllieBot/_common/Abstractions/strings/IBotStringsProvider.cs b/src/EllieBot/_common/Abstractions/strings/IBotStringsProvider.cs index 87cab9f..ef98051 100644 --- a/src/EllieBot/_common/Abstractions/strings/IBotStringsProvider.cs +++ b/src/EllieBot/_common/Abstractions/strings/IBotStringsProvider.cs @@ -1,4 +1,4 @@ -#nullable disable +#nullable disable namespace EllieBot.Services; /// diff --git a/src/EllieBot/_common/Abstractions/strings/IStringsSource.cs b/src/EllieBot/_common/Abstractions/strings/IStringsSource.cs index a2715f0..08ad986 100644 --- a/src/EllieBot/_common/Abstractions/strings/IStringsSource.cs +++ b/src/EllieBot/_common/Abstractions/strings/IStringsSource.cs @@ -1,5 +1,4 @@ #nullable disable - namespace EllieBot.Services; ///