From f41b1fb93c1dc732dddff82bd25dcd0ad8ce9b35 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Mon, 11 Jul 2022 00:06:19 +0200 Subject: [PATCH] Base for 4.3 work. Split Nadeko.Common into a separate project --- NadekoBot.sln | 9 ++ .../Common => Nadeko.Common}/AsyncLazy.cs | 5 +- .../Collections/ConcurrentHashSet.cs | 9 +- .../Collections/IndexedCollection.cs | 11 ++- .../Extensions}/ArrayExtensions.cs | 12 ++- .../Extensions}/EnumerableExtensions.cs | 4 +- .../Extensions/HttpClientExtensions.cs | 35 ++++++++ .../Extensions}/PipeExtensions.cs | 3 +- src/Nadeko.Common/GlobalUsings.cs | 1 + .../Helpers}/LogSetup.cs | 4 +- .../Helpers}/StandardConversions.cs | 3 +- .../Common => Nadeko.Common}/Kwum.cs | 7 +- src/Nadeko.Common/Nadeko.Common.csproj | 15 ++++ .../Common => Nadeko.Common}/QueueRunner.cs | 3 +- .../Common => Nadeko.Common}/ShmartNumber.cs | 15 ++-- src/NadekoBot.Tests/IndexedCollectionTests.cs | 2 +- src/NadekoBot.Tests/NadekoBot.Tests.csproj | 1 + src/NadekoBot/Bot.cs | 1 + src/NadekoBot/Common/OldImageUrls.cs | 47 ---------- src/NadekoBot/Common/PlatformHelper.cs | 25 ------ src/NadekoBot/Common/Replacements/Replacer.cs | 1 + .../Common/TypeReaders/KwumTypeReader.cs | 2 + .../TypeReaders/ShmartNumberTypeReader.cs | 1 + src/NadekoBot/Db/Models/GuildConfig.cs | 1 - src/NadekoBot/Db/Models/Permission.cs | 5 -- src/NadekoBot/Db/Models/Poll.cs | 2 - src/NadekoBot/GlobalUsings.cs | 3 +- .../Administration/AdministrationService.cs | 1 + .../AutoAssignRoleCommands.cs | 1 + .../AutoAssignRoleService.cs | 1 + .../Administration/ImageOnlyChannelService.cs | 1 + .../Administration/Mute/MuteService.cs | 1 + .../DiscordPermOverrideCommands.cs | 1 + .../DiscordPermOverrideService.cs | 1 + .../Administration/Prune/PruneService.cs | 2 + .../Administration/Self/SelfService.cs | 1 + .../ServerLog/ServerLogCommandService.cs | 1 + .../Timezone/GuildTimezoneService.cs | 1 + .../Administration/VcRole/VcRoleService.cs | 1 + .../Modules/CustomReactions/ExportedExpr.cs | 1 + .../CustomReactions/NadekoExpressions.cs | 2 + .../NadekoExpressionsService.cs | 1 + .../Gambling/AnimalRacing/AnimalRace.cs | 1 + .../AnimalRacing/AnimalRacingCommands.cs | 1 + .../Modules/Gambling/Bank/BankCommands.cs | 3 +- .../Gambling/BlackJack/BlackJackCommands.cs | 1 + .../Gambling/Events/GameStatusEvent.cs | 1 + .../Gambling/FlipCoin/FlipCoinCommands.cs | 1 + src/NadekoBot/Modules/Gambling/Gambling.cs | 1 + .../PlantPick/PlantAndPickCommands.cs | 1 + .../Gambling/Raffle/CurrencyRaffleCommands.cs | 1 + .../Modules/Gambling/Shop/ShopCommands.cs | 2 +- .../Modules/Gambling/Shop/ShopService.cs | 2 +- .../Modules/Gambling/Slot/SlotCommands.cs | 1 + .../Gambling/Waifus/WaifuClaimCommands.cs | 1 + .../Modules/Gambling/~Shared/Decks/Deck.cs | 2 + src/NadekoBot/Modules/Games/GamesService.cs | 1 + src/NadekoBot/Modules/Games/GirlRating.cs | 1 + .../Modules/Games/Hangman/HangmanCommands.cs | 1 + .../Modules/Games/Polls/PollService.cs | 1 - .../Games/Trivia/DefaultQuestionPool.cs | 33 +++++++ .../Modules/Games/Trivia/IQuestionPool.cs | 6 ++ .../Games/Trivia/PokemonQuestionPool.cs | 32 +++++++ .../Modules/Games/Trivia/TriviaGame.cs | 2 +- src/NadekoBot/Modules/Help/Help.cs | 1 + src/NadekoBot/Modules/Help/HelpService.cs | 1 + src/NadekoBot/Modules/Medusae/Medusa.cs | 3 +- src/NadekoBot/Modules/Music/Music.cs | 1 + .../Modules/Music/Services/MusicService.cs | 1 + .../Modules/Music/_Common/Impl/MusicPlayer.cs | 1 + .../_Common/Resolvers/LocalTrackResolver.cs | 1 + .../_Common/Resolvers/SoundcloudResolver.cs | 1 + src/NadekoBot/Modules/Nsfw/Nsfw.cs | 1 + .../Modules/Nsfw/SearchImageCacher.cs | 1 + .../Modules/Nsfw/SearchImagesService.cs | 1 + src/NadekoBot/Modules/Nsfw/UrlReply.cs | 3 +- .../Downloaders/DapiImageDownloader.cs | 1 + .../Downloaders/DerpibooruImageDownloader.cs | 1 + .../Downloaders/E621ImageDownloader.cs | 1 + .../Downloaders/SankakuImageDownloader.cs | 1 + .../Blacklist/BlacklistCommands.cs | 1 + .../Permissions/PermissionsCollection.cs | 3 - .../Searches/Anime/AnimeSearchCommands.cs | 1 + .../Crypto/DefaultStockDataService.cs | 1 + .../Modules/Searches/Feeds/FeedsService.cs | 1 + src/NadekoBot/Modules/Searches/OsuCommands.cs | 1 + .../Modules/Searches/Search/SearchCommands.cs | 1 + src/NadekoBot/Modules/Searches/Searches.cs | 1 + .../Modules/Searches/SearchesService.cs | 1 + .../StreamNotificationService.cs | 1 + .../StreamNotifications/NotifChecker.cs | 3 +- .../Providers/TwitchHelixProvider.cs | 1 + .../Modules/Utility/Info/InfoCommands.cs | 1 + .../Modules/Utility/Quote/QuoteCommands.cs | 1 + .../Modules/Utility/Remind/RemindService.cs | 1 + .../Utility/Repeater/RepeaterService.cs | 1 + .../Utility/StreamRole/StreamRoleService.cs | 1 + src/NadekoBot/Modules/Utility/Utility.cs | 1 + src/NadekoBot/Modules/Xp/Club/ClubService.cs | 1 + src/NadekoBot/Modules/Xp/Xp.cs | 1 + src/NadekoBot/Modules/Xp/XpService.cs | 1 + src/NadekoBot/NadekoBot.csproj | 4 + src/NadekoBot/Program.cs | 2 + src/NadekoBot/Services/CommandHandler.cs | 1 + .../Services/Impl/RemoteGrpcCoordinator.cs | 1 + .../Impl/StartingGuildsListService.cs | 5 +- src/NadekoBot/Services/Impl/YtdlOperation.cs | 1 + .../strings/impl/RedisBotStringsProvider.cs | 1 + src/NadekoBot/_Extensions/Extensions.cs | 32 +------ .../_Extensions/IMessageChannelExtensions.cs | 2 + .../_Extensions/ProcessExtensions.cs | 87 ------------------- .../SocketMessageComponentExtensions.cs | 4 +- src/NadekoBot/_Extensions/StringExtensions.cs | 1 + 113 files changed, 271 insertions(+), 255 deletions(-) rename src/{NadekoBot/Common => Nadeko.Common}/AsyncLazy.cs (78%) rename src/{NadekoBot/Common => Nadeko.Common}/Collections/ConcurrentHashSet.cs (94%) rename src/{NadekoBot/Common => Nadeko.Common}/Collections/IndexedCollection.cs (95%) rename src/{NadekoBot/_Extensions => Nadeko.Common/Extensions}/ArrayExtensions.cs (76%) rename src/{NadekoBot/_Extensions => Nadeko.Common/Extensions}/EnumerableExtensions.cs (97%) create mode 100644 src/Nadeko.Common/Extensions/HttpClientExtensions.cs rename src/{NadekoBot/_Extensions => Nadeko.Common/Extensions}/PipeExtensions.cs (95%) create mode 100644 src/Nadeko.Common/GlobalUsings.cs rename src/{NadekoBot/Services => Nadeko.Common/Helpers}/LogSetup.cs (96%) rename src/{NadekoBot/Services => Nadeko.Common/Helpers}/StandardConversions.cs (73%) rename src/{NadekoBot/Common => Nadeko.Common}/Kwum.cs (95%) create mode 100644 src/Nadeko.Common/Nadeko.Common.csproj rename src/{NadekoBot/Common => Nadeko.Common}/QueueRunner.cs (97%) rename src/{NadekoBot/Common => Nadeko.Common}/ShmartNumber.cs (69%) delete mode 100644 src/NadekoBot/Common/OldImageUrls.cs delete mode 100644 src/NadekoBot/Common/PlatformHelper.cs create mode 100644 src/NadekoBot/Modules/Games/Trivia/DefaultQuestionPool.cs create mode 100644 src/NadekoBot/Modules/Games/Trivia/IQuestionPool.cs create mode 100644 src/NadekoBot/Modules/Games/Trivia/PokemonQuestionPool.cs delete mode 100644 src/NadekoBot/_Extensions/ProcessExtensions.cs diff --git a/NadekoBot.sln b/NadekoBot.sln index 15d30e71c..ba47a3446 100644 --- a/NadekoBot.sln +++ b/NadekoBot.sln @@ -30,6 +30,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NadekoBot.VotesApi", "src\N EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nadeko.Medusa", "src\Nadeko.Medusa\Nadeko.Medusa.csproj", "{E685977E-31A4-46F4-A5D7-4E3E39E82E43}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nadeko.Common", "src\Nadeko.Common\Nadeko.Common.csproj", "{A6022F5F-A764-4D3F-847B-36F0391FF659}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -79,6 +81,12 @@ Global {E685977E-31A4-46F4-A5D7-4E3E39E82E43}.GlobalNadeko|Any CPU.Build.0 = Debug|Any CPU {E685977E-31A4-46F4-A5D7-4E3E39E82E43}.Release|Any CPU.ActiveCfg = Release|Any CPU {E685977E-31A4-46F4-A5D7-4E3E39E82E43}.Release|Any CPU.Build.0 = Release|Any CPU + {A6022F5F-A764-4D3F-847B-36F0391FF659}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A6022F5F-A764-4D3F-847B-36F0391FF659}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A6022F5F-A764-4D3F-847B-36F0391FF659}.GlobalNadeko|Any CPU.ActiveCfg = Debug|Any CPU + {A6022F5F-A764-4D3F-847B-36F0391FF659}.GlobalNadeko|Any CPU.Build.0 = Debug|Any CPU + {A6022F5F-A764-4D3F-847B-36F0391FF659}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A6022F5F-A764-4D3F-847B-36F0391FF659}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -92,6 +100,7 @@ Global {3BC3BDF8-1A0B-45EB-AB2B-C0891D4D37B8} = {04929013-5BAB-42B0-B9B2-8F2BB8F16AF2} {3BC82CFE-BEE7-451F-986B-17EDD1570C4F} = {04929013-5BAB-42B0-B9B2-8F2BB8F16AF2} {E685977E-31A4-46F4-A5D7-4E3E39E82E43} = {04929013-5BAB-42B0-B9B2-8F2BB8F16AF2} + {A6022F5F-A764-4D3F-847B-36F0391FF659} = {04929013-5BAB-42B0-B9B2-8F2BB8F16AF2} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {5F3F555C-855F-4BE8-B526-D062D3E8ACA4} diff --git a/src/NadekoBot/Common/AsyncLazy.cs b/src/Nadeko.Common/AsyncLazy.cs similarity index 78% rename from src/NadekoBot/Common/AsyncLazy.cs rename to src/Nadeko.Common/AsyncLazy.cs index 54adcf9a2..f6f2a3491 100644 --- a/src/NadekoBot/Common/AsyncLazy.cs +++ b/src/Nadeko.Common/AsyncLazy.cs @@ -1,7 +1,6 @@ -#nullable disable -using System.Runtime.CompilerServices; +using System.Runtime.CompilerServices; -namespace NadekoBot.Common; +namespace Nadeko.Common; public class AsyncLazy : Lazy> { diff --git a/src/NadekoBot/Common/Collections/ConcurrentHashSet.cs b/src/Nadeko.Common/Collections/ConcurrentHashSet.cs similarity index 94% rename from src/NadekoBot/Common/Collections/ConcurrentHashSet.cs rename to src/Nadeko.Common/Collections/ConcurrentHashSet.cs index 324a6b26d..581df4b6c 100644 --- a/src/NadekoBot/Common/Collections/ConcurrentHashSet.cs +++ b/src/Nadeko.Common/Collections/ConcurrentHashSet.cs @@ -1,14 +1,9 @@ -#nullable enable -#pragma warning disable -// License MIT -// Source: https://github.com/i3arnon/ConcurrentHashSet - -using System.Diagnostics; +using System.Diagnostics; namespace System.Collections.Generic; [DebuggerDisplay("{_backingStore.Count}")] -public sealed class ConcurrentHashSet : IReadOnlyCollection, ICollection +public sealed class ConcurrentHashSet : IReadOnlyCollection, ICollection where T : notnull { private readonly ConcurrentDictionary _backingStore; diff --git a/src/NadekoBot/Common/Collections/IndexedCollection.cs b/src/Nadeko.Common/Collections/IndexedCollection.cs similarity index 95% rename from src/NadekoBot/Common/Collections/IndexedCollection.cs rename to src/Nadeko.Common/Collections/IndexedCollection.cs index 746ceb687..e7331630f 100644 --- a/src/NadekoBot/Common/Collections/IndexedCollection.cs +++ b/src/Nadeko.Common/Collections/IndexedCollection.cs @@ -1,8 +1,11 @@ -#nullable disable -using NadekoBot.Services.Database.Models; -using System.Collections; +using System.Collections; -namespace NadekoBot.Common.Collections; +namespace Nadeko.Common; + +public interface IIndexed +{ + int Index { get; set; } +} public class IndexedCollection : IList where T : class, IIndexed diff --git a/src/NadekoBot/_Extensions/ArrayExtensions.cs b/src/Nadeko.Common/Extensions/ArrayExtensions.cs similarity index 76% rename from src/NadekoBot/_Extensions/ArrayExtensions.cs rename to src/Nadeko.Common/Extensions/ArrayExtensions.cs index 7300c45d3..5d25ed9cf 100644 --- a/src/NadekoBot/_Extensions/ArrayExtensions.cs +++ b/src/Nadeko.Common/Extensions/ArrayExtensions.cs @@ -1,6 +1,4 @@ -using System.Buffers; - -namespace NadekoBot.Extensions; +namespace Nadeko.Common; // made for expressions because they almost never get added // and they get looped through constantly @@ -32,6 +30,14 @@ public static class ArrayExtensions public static TOut[] Map(this TIn[] arr, Func f) => Array.ConvertAll(arr, x => f(x)); + /// + /// Creates a new array by applying the specified function to every element in the input array + /// + /// Array to modify + /// Function to apply + /// Orignal type of the elements in the array + /// Output type of the elements of the array + /// New array with updated elements public static TOut[] Map(this IReadOnlyCollection col, Func f) { var toReturn = new TOut[col.Count]; diff --git a/src/NadekoBot/_Extensions/EnumerableExtensions.cs b/src/Nadeko.Common/Extensions/EnumerableExtensions.cs similarity index 97% rename from src/NadekoBot/_Extensions/EnumerableExtensions.cs rename to src/Nadeko.Common/Extensions/EnumerableExtensions.cs index edcfab4ba..e3591d291 100644 --- a/src/NadekoBot/_Extensions/EnumerableExtensions.cs +++ b/src/Nadeko.Common/Extensions/EnumerableExtensions.cs @@ -1,8 +1,6 @@ -using NadekoBot.Common.Collections; -using NadekoBot.Services.Database.Models; using System.Security.Cryptography; -namespace NadekoBot.Extensions; +namespace Nadeko.Common; public static class EnumerableExtensions { diff --git a/src/Nadeko.Common/Extensions/HttpClientExtensions.cs b/src/Nadeko.Common/Extensions/HttpClientExtensions.cs new file mode 100644 index 000000000..a267d8f90 --- /dev/null +++ b/src/Nadeko.Common/Extensions/HttpClientExtensions.cs @@ -0,0 +1,35 @@ +using System.Net.Http.Headers; + +namespace Nadeko.Common; + +public static class HttpClientExtensions +{ + public static HttpClient AddFakeHeaders(this HttpClient http) + { + AddFakeHeaders(http.DefaultRequestHeaders); + return http; + } + + public static void AddFakeHeaders(this HttpHeaders dict) + { + dict.Clear(); + dict.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); + dict.Add("User-Agent", + "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.202 Safari/535.1"); + } + + public static bool IsImage(this HttpResponseMessage msg) + => IsImage(msg, out _); + + public static bool IsImage(this HttpResponseMessage msg, out string? mimeType) + { + mimeType = msg.Content.Headers.ContentType?.MediaType; + if (mimeType is "image/png" or "image/jpeg" or "image/gif") + return true; + + return false; + } + + public static long GetContentLength(this HttpResponseMessage msg) + => msg.Content.Headers.ContentLength ?? long.MaxValue; +} \ No newline at end of file diff --git a/src/NadekoBot/_Extensions/PipeExtensions.cs b/src/Nadeko.Common/Extensions/PipeExtensions.cs similarity index 95% rename from src/NadekoBot/_Extensions/PipeExtensions.cs rename to src/Nadeko.Common/Extensions/PipeExtensions.cs index 4eb761a0c..f45147c50 100644 --- a/src/NadekoBot/_Extensions/PipeExtensions.cs +++ b/src/Nadeko.Common/Extensions/PipeExtensions.cs @@ -1,5 +1,4 @@ -namespace NadekoBot.Extensions; - +namespace Nadeko.Common; public delegate TOut PipeFunc(in TIn a); public delegate TOut PipeFunc(in TIn1 a, in TIn2 b); diff --git a/src/Nadeko.Common/GlobalUsings.cs b/src/Nadeko.Common/GlobalUsings.cs new file mode 100644 index 000000000..55fdcac5b --- /dev/null +++ b/src/Nadeko.Common/GlobalUsings.cs @@ -0,0 +1 @@ +global using NonBlocking; \ No newline at end of file diff --git a/src/NadekoBot/Services/LogSetup.cs b/src/Nadeko.Common/Helpers/LogSetup.cs similarity index 96% rename from src/NadekoBot/Services/LogSetup.cs rename to src/Nadeko.Common/Helpers/LogSetup.cs index 5ebcd009a..ad8836f44 100644 --- a/src/NadekoBot/Services/LogSetup.cs +++ b/src/Nadeko.Common/Helpers/LogSetup.cs @@ -1,9 +1,9 @@ -#nullable disable using Serilog.Events; using Serilog.Sinks.SystemConsole.Themes; using System.Text; +using Serilog; -namespace NadekoBot.Services; +namespace Nadeko.Common; public static class LogSetup { diff --git a/src/NadekoBot/Services/StandardConversions.cs b/src/Nadeko.Common/Helpers/StandardConversions.cs similarity index 73% rename from src/NadekoBot/Services/StandardConversions.cs rename to src/Nadeko.Common/Helpers/StandardConversions.cs index 2518fb0dd..038db0e10 100644 --- a/src/NadekoBot/Services/StandardConversions.cs +++ b/src/Nadeko.Common/Helpers/StandardConversions.cs @@ -1,5 +1,4 @@ -#nullable disable -namespace NadekoBot.Services; +namespace Nadeko.Common; public static class StandardConversions { diff --git a/src/NadekoBot/Common/Kwum.cs b/src/Nadeko.Common/Kwum.cs similarity index 95% rename from src/NadekoBot/Common/Kwum.cs rename to src/Nadeko.Common/Kwum.cs index 347792c50..18646854b 100644 --- a/src/NadekoBot/Common/Kwum.cs +++ b/src/Nadeko.Common/Kwum.cs @@ -1,7 +1,6 @@ -#nullable disable -using System.Runtime.CompilerServices; +using System.Runtime.CompilerServices; -namespace NadekoBot.Common; +namespace Nadeko.Common; // needs proper invalid input check (character array input out of range) // needs negative number support @@ -90,7 +89,7 @@ public readonly struct kwum : IEquatable return new(chars); } - public override bool Equals(object obj) + public override bool Equals(object? obj) => obj is kwum kw && kw == this; public bool Equals(kwum other) diff --git a/src/Nadeko.Common/Nadeko.Common.csproj b/src/Nadeko.Common/Nadeko.Common.csproj new file mode 100644 index 000000000..e531b15bf --- /dev/null +++ b/src/Nadeko.Common/Nadeko.Common.csproj @@ -0,0 +1,15 @@ + + + + net6.0 + enable + enable + + + + + + + + + diff --git a/src/NadekoBot/Common/QueueRunner.cs b/src/Nadeko.Common/QueueRunner.cs similarity index 97% rename from src/NadekoBot/Common/QueueRunner.cs rename to src/Nadeko.Common/QueueRunner.cs index 2b141bae8..95e1e2667 100644 --- a/src/NadekoBot/Common/QueueRunner.cs +++ b/src/Nadeko.Common/QueueRunner.cs @@ -1,6 +1,7 @@ using System.Threading.Channels; +using Serilog; -namespace NadekoBot.Common; +namespace Nadeko.Common; public sealed class QueueRunner { diff --git a/src/NadekoBot/Common/ShmartNumber.cs b/src/Nadeko.Common/ShmartNumber.cs similarity index 69% rename from src/NadekoBot/Common/ShmartNumber.cs rename to src/Nadeko.Common/ShmartNumber.cs index 5ffd67572..42723df98 100644 --- a/src/NadekoBot/Common/ShmartNumber.cs +++ b/src/Nadeko.Common/ShmartNumber.cs @@ -1,14 +1,11 @@ -#nullable disable -using System; +namespace Nadeko.Common; -namespace NadekoBot.Common; - -public struct ShmartNumber : IEquatable +public readonly struct ShmartNumber : IEquatable { public long Value { get; } - public string Input { get; } + public string? Input { get; } - public ShmartNumber(long val, string input = null) + public ShmartNumber(long val, string? input = null) { Value = val; Input = input; @@ -26,14 +23,14 @@ public struct ShmartNumber : IEquatable public override string ToString() => Value.ToString(); - public override bool Equals(object obj) + public override bool Equals(object? obj) => obj is ShmartNumber sn && Equals(sn); public bool Equals(ShmartNumber other) => other.Value == Value; public override int GetHashCode() - => Value.GetHashCode() ^ Input.GetHashCode(StringComparison.InvariantCulture); + => Value.GetHashCode(); public static bool operator ==(ShmartNumber left, ShmartNumber right) => left.Equals(right); diff --git a/src/NadekoBot.Tests/IndexedCollectionTests.cs b/src/NadekoBot.Tests/IndexedCollectionTests.cs index 02949852b..faa4cc5f1 100644 --- a/src/NadekoBot.Tests/IndexedCollectionTests.cs +++ b/src/NadekoBot.Tests/IndexedCollectionTests.cs @@ -1,4 +1,4 @@ -using NadekoBot.Common.Collections; +using Nadeko.Common; using NadekoBot.Services.Database.Models; using NUnit.Framework; using System; diff --git a/src/NadekoBot.Tests/NadekoBot.Tests.csproj b/src/NadekoBot.Tests/NadekoBot.Tests.csproj index accef680b..64ca56022 100644 --- a/src/NadekoBot.Tests/NadekoBot.Tests.csproj +++ b/src/NadekoBot.Tests/NadekoBot.Tests.csproj @@ -14,6 +14,7 @@ + diff --git a/src/NadekoBot/Bot.cs b/src/NadekoBot/Bot.cs index 5a723b516..3327becc9 100644 --- a/src/NadekoBot/Bot.cs +++ b/src/NadekoBot/Bot.cs @@ -10,6 +10,7 @@ using System.Collections.Immutable; using System.Diagnostics; using System.Net; using System.Reflection; +using Nadeko.Common; using RunMode = Discord.Commands.RunMode; namespace NadekoBot; diff --git a/src/NadekoBot/Common/OldImageUrls.cs b/src/NadekoBot/Common/OldImageUrls.cs deleted file mode 100644 index dfae53834..000000000 --- a/src/NadekoBot/Common/OldImageUrls.cs +++ /dev/null @@ -1,47 +0,0 @@ -#nullable disable -namespace NadekoBot.Common; - -public class OldImageUrls -{ - public int Version { get; set; } = 2; - - public CoinData Coins { get; set; } - public Uri[] Currency { get; set; } - public Uri[] Dice { get; set; } - public RategirlData Rategirl { get; set; } - public XpData Xp { get; set; } - - //new - public RipData Rip { get; set; } - public SlotData Slots { get; set; } - - public class RipData - { - public Uri Bg { get; set; } - public Uri Overlay { get; set; } - } - - public class SlotData - { - public Uri[] Emojis { get; set; } - public Uri[] Numbers { get; set; } - public Uri Bg { get; set; } - } - - public class CoinData - { - public Uri[] Heads { get; set; } - public Uri[] Tails { get; set; } - } - - public class RategirlData - { - public Uri Matrix { get; set; } - public Uri Dot { get; set; } - } - - public class XpData - { - public Uri Bg { get; set; } - } -} \ No newline at end of file diff --git a/src/NadekoBot/Common/PlatformHelper.cs b/src/NadekoBot/Common/PlatformHelper.cs deleted file mode 100644 index 19592e5d2..000000000 --- a/src/NadekoBot/Common/PlatformHelper.cs +++ /dev/null @@ -1,25 +0,0 @@ -#nullable disable -namespace NadekoBot.Common; - -public static class PlatformHelper -{ - private const int PROCESSOR_COUNT_REFRESH_INTERVAL_MS = 30000; - - private static volatile int processorCount; - private static volatile int lastProcessorCountRefreshTicks; - - public static int ProcessorCount - { - get - { - var now = Environment.TickCount; - if (processorCount == 0 || now - lastProcessorCountRefreshTicks >= PROCESSOR_COUNT_REFRESH_INTERVAL_MS) - { - processorCount = Environment.ProcessorCount; - lastProcessorCountRefreshTicks = now; - } - - return processorCount; - } - } -} \ No newline at end of file diff --git a/src/NadekoBot/Common/Replacements/Replacer.cs b/src/NadekoBot/Common/Replacements/Replacer.cs index 8c0c84d9f..2d049a95e 100644 --- a/src/NadekoBot/Common/Replacements/Replacer.cs +++ b/src/NadekoBot/Common/Replacements/Replacer.cs @@ -1,5 +1,6 @@ #nullable disable using System.Text.RegularExpressions; +using Nadeko.Common; namespace NadekoBot.Common; diff --git a/src/NadekoBot/Common/TypeReaders/KwumTypeReader.cs b/src/NadekoBot/Common/TypeReaders/KwumTypeReader.cs index 166477621..3d0d288ef 100644 --- a/src/NadekoBot/Common/TypeReaders/KwumTypeReader.cs +++ b/src/NadekoBot/Common/TypeReaders/KwumTypeReader.cs @@ -1,4 +1,6 @@ #nullable disable +using Nadeko.Common; + namespace NadekoBot.Common.TypeReaders; public sealed class KwumTypeReader : NadekoTypeReader diff --git a/src/NadekoBot/Common/TypeReaders/ShmartNumberTypeReader.cs b/src/NadekoBot/Common/TypeReaders/ShmartNumberTypeReader.cs index 7b04e06a9..494ce8007 100644 --- a/src/NadekoBot/Common/TypeReaders/ShmartNumberTypeReader.cs +++ b/src/NadekoBot/Common/TypeReaders/ShmartNumberTypeReader.cs @@ -3,6 +3,7 @@ using NadekoBot.Db; using NadekoBot.Modules.Gambling.Services; using NCalc; using System.Text.RegularExpressions; +using Nadeko.Common; namespace NadekoBot.Common.TypeReaders; diff --git a/src/NadekoBot/Db/Models/GuildConfig.cs b/src/NadekoBot/Db/Models/GuildConfig.cs index 38211e565..48eefe149 100644 --- a/src/NadekoBot/Db/Models/GuildConfig.cs +++ b/src/NadekoBot/Db/Models/GuildConfig.cs @@ -1,5 +1,4 @@ #nullable disable -using NadekoBot.Common.Collections; using NadekoBot.Db.Models; namespace NadekoBot.Services.Database.Models; diff --git a/src/NadekoBot/Db/Models/Permission.cs b/src/NadekoBot/Db/Models/Permission.cs index 5ad1b021e..05fa4b727 100644 --- a/src/NadekoBot/Db/Models/Permission.cs +++ b/src/NadekoBot/Db/Models/Permission.cs @@ -4,11 +4,6 @@ using System.Diagnostics; namespace NadekoBot.Services.Database.Models; -public interface IIndexed -{ - int Index { get; set; } -} - [DebuggerDisplay("{PrimaryTarget}{SecondaryTarget} {SecondaryTargetName} {State} {PrimaryTargetId}")] public class Permissionv2 : DbEntity, IIndexed { diff --git a/src/NadekoBot/Db/Models/Poll.cs b/src/NadekoBot/Db/Models/Poll.cs index 271777a38..6649217f6 100644 --- a/src/NadekoBot/Db/Models/Poll.cs +++ b/src/NadekoBot/Db/Models/Poll.cs @@ -1,6 +1,4 @@ #nullable disable -using NadekoBot.Common.Collections; - namespace NadekoBot.Services.Database.Models; public class Poll : DbEntity diff --git a/src/NadekoBot/GlobalUsings.cs b/src/NadekoBot/GlobalUsings.cs index 4f8beedac..f36328bd4 100644 --- a/src/NadekoBot/GlobalUsings.cs +++ b/src/NadekoBot/GlobalUsings.cs @@ -8,7 +8,8 @@ global using Humanizer; // nadekobot global using NadekoBot; global using NadekoBot.Services; -global using NadekoBot.Common; +global using Nadeko.Common; // new project +global using NadekoBot.Common; // old + nadekobot specific things global using NadekoBot.Common.Attributes; global using NadekoBot.Extensions; global using Nadeko.Snake; diff --git a/src/NadekoBot/Modules/Administration/AdministrationService.cs b/src/NadekoBot/Modules/Administration/AdministrationService.cs index 3a5f7613d..371bd0b07 100644 --- a/src/NadekoBot/Modules/Administration/AdministrationService.cs +++ b/src/NadekoBot/Modules/Administration/AdministrationService.cs @@ -1,5 +1,6 @@ #nullable disable using Microsoft.EntityFrameworkCore; +using Nadeko.Common; using NadekoBot.Db; using NadekoBot.Services.Database.Models; diff --git a/src/NadekoBot/Modules/Administration/AutoAssignableRoles/AutoAssignRoleCommands.cs b/src/NadekoBot/Modules/Administration/AutoAssignableRoles/AutoAssignRoleCommands.cs index 6e8d19539..a86a2f034 100644 --- a/src/NadekoBot/Modules/Administration/AutoAssignableRoles/AutoAssignRoleCommands.cs +++ b/src/NadekoBot/Modules/Administration/AutoAssignableRoles/AutoAssignRoleCommands.cs @@ -1,4 +1,5 @@ #nullable disable +using Nadeko.Common; using NadekoBot.Modules.Administration.Services; namespace NadekoBot.Modules.Administration; diff --git a/src/NadekoBot/Modules/Administration/AutoAssignableRoles/AutoAssignRoleService.cs b/src/NadekoBot/Modules/Administration/AutoAssignableRoles/AutoAssignRoleService.cs index d0d20def8..2a6f2dd6e 100644 --- a/src/NadekoBot/Modules/Administration/AutoAssignableRoles/AutoAssignRoleService.cs +++ b/src/NadekoBot/Modules/Administration/AutoAssignableRoles/AutoAssignRoleService.cs @@ -5,6 +5,7 @@ using NadekoBot.Db; using NadekoBot.Services.Database.Models; using System.Net; using System.Threading.Channels; +using Nadeko.Common; namespace NadekoBot.Modules.Administration.Services; diff --git a/src/NadekoBot/Modules/Administration/ImageOnlyChannelService.cs b/src/NadekoBot/Modules/Administration/ImageOnlyChannelService.cs index 0860fa618..b823007ff 100644 --- a/src/NadekoBot/Modules/Administration/ImageOnlyChannelService.cs +++ b/src/NadekoBot/Modules/Administration/ImageOnlyChannelService.cs @@ -4,6 +4,7 @@ using Microsoft.Extensions.Caching.Memory; using NadekoBot.Common.ModuleBehaviors; using System.Net; using System.Threading.Channels; +using Nadeko.Common; namespace NadekoBot.Modules.Administration.Services; diff --git a/src/NadekoBot/Modules/Administration/Mute/MuteService.cs b/src/NadekoBot/Modules/Administration/Mute/MuteService.cs index c066f7c71..070ba48c0 100644 --- a/src/NadekoBot/Modules/Administration/Mute/MuteService.cs +++ b/src/NadekoBot/Modules/Administration/Mute/MuteService.cs @@ -1,5 +1,6 @@ #nullable disable using Microsoft.EntityFrameworkCore; +using Nadeko.Common; using NadekoBot.Db; using NadekoBot.Services.Database.Models; diff --git a/src/NadekoBot/Modules/Administration/PermOverrides/DiscordPermOverrideCommands.cs b/src/NadekoBot/Modules/Administration/PermOverrides/DiscordPermOverrideCommands.cs index 92848b839..2f94218f2 100644 --- a/src/NadekoBot/Modules/Administration/PermOverrides/DiscordPermOverrideCommands.cs +++ b/src/NadekoBot/Modules/Administration/PermOverrides/DiscordPermOverrideCommands.cs @@ -1,4 +1,5 @@ #nullable disable +using Nadeko.Common; using NadekoBot.Common.TypeReaders; using NadekoBot.Modules.Administration.Services; diff --git a/src/NadekoBot/Modules/Administration/PermOverrides/DiscordPermOverrideService.cs b/src/NadekoBot/Modules/Administration/PermOverrides/DiscordPermOverrideService.cs index 847982377..b81ba5d65 100644 --- a/src/NadekoBot/Modules/Administration/PermOverrides/DiscordPermOverrideService.cs +++ b/src/NadekoBot/Modules/Administration/PermOverrides/DiscordPermOverrideService.cs @@ -1,5 +1,6 @@ #nullable disable using Microsoft.EntityFrameworkCore; +using Nadeko.Common; using NadekoBot.Common.ModuleBehaviors; using NadekoBot.Services.Database.Models; diff --git a/src/NadekoBot/Modules/Administration/Prune/PruneService.cs b/src/NadekoBot/Modules/Administration/Prune/PruneService.cs index 1a0851006..3f9aafd12 100644 --- a/src/NadekoBot/Modules/Administration/Prune/PruneService.cs +++ b/src/NadekoBot/Modules/Administration/Prune/PruneService.cs @@ -1,4 +1,6 @@ #nullable disable +using Nadeko.Common; + namespace NadekoBot.Modules.Administration.Services; public class PruneService : INService diff --git a/src/NadekoBot/Modules/Administration/Self/SelfService.cs b/src/NadekoBot/Modules/Administration/Self/SelfService.cs index a714ef552..a17a6cb92 100644 --- a/src/NadekoBot/Modules/Administration/Self/SelfService.cs +++ b/src/NadekoBot/Modules/Administration/Self/SelfService.cs @@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore; using NadekoBot.Common.ModuleBehaviors; using NadekoBot.Services.Database.Models; using System.Collections.Immutable; +using Nadeko.Common; namespace NadekoBot.Modules.Administration.Services; diff --git a/src/NadekoBot/Modules/Administration/ServerLog/ServerLogCommandService.cs b/src/NadekoBot/Modules/Administration/ServerLog/ServerLogCommandService.cs index 89e15a901..7ac5e9e3c 100644 --- a/src/NadekoBot/Modules/Administration/ServerLog/ServerLogCommandService.cs +++ b/src/NadekoBot/Modules/Administration/ServerLog/ServerLogCommandService.cs @@ -1,5 +1,6 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Caching.Memory; +using Nadeko.Common; using NadekoBot.Common.ModuleBehaviors; using NadekoBot.Db; using NadekoBot.Modules.Administration.Services; diff --git a/src/NadekoBot/Modules/Administration/Timezone/GuildTimezoneService.cs b/src/NadekoBot/Modules/Administration/Timezone/GuildTimezoneService.cs index 92934cb47..a4bf5b1d9 100644 --- a/src/NadekoBot/Modules/Administration/Timezone/GuildTimezoneService.cs +++ b/src/NadekoBot/Modules/Administration/Timezone/GuildTimezoneService.cs @@ -1,4 +1,5 @@ #nullable disable +using Nadeko.Common; using NadekoBot.Db; using NadekoBot.Services.Database.Models; diff --git a/src/NadekoBot/Modules/Administration/VcRole/VcRoleService.cs b/src/NadekoBot/Modules/Administration/VcRole/VcRoleService.cs index e4513f50a..eedf04a4e 100644 --- a/src/NadekoBot/Modules/Administration/VcRole/VcRoleService.cs +++ b/src/NadekoBot/Modules/Administration/VcRole/VcRoleService.cs @@ -1,5 +1,6 @@ #nullable disable using Microsoft.EntityFrameworkCore; +using Nadeko.Common; using NadekoBot.Db; using NadekoBot.Services.Database.Models; diff --git a/src/NadekoBot/Modules/CustomReactions/ExportedExpr.cs b/src/NadekoBot/Modules/CustomReactions/ExportedExpr.cs index b1b1383f8..c91e7939d 100644 --- a/src/NadekoBot/Modules/CustomReactions/ExportedExpr.cs +++ b/src/NadekoBot/Modules/CustomReactions/ExportedExpr.cs @@ -1,4 +1,5 @@ #nullable disable +using Nadeko.Common; using NadekoBot.Services.Database.Models; namespace NadekoBot.Modules.NadekoExpressions; diff --git a/src/NadekoBot/Modules/CustomReactions/NadekoExpressions.cs b/src/NadekoBot/Modules/CustomReactions/NadekoExpressions.cs index 7fdabb927..e93c7862d 100644 --- a/src/NadekoBot/Modules/CustomReactions/NadekoExpressions.cs +++ b/src/NadekoBot/Modules/CustomReactions/NadekoExpressions.cs @@ -1,5 +1,7 @@ #nullable disable +using Nadeko.Common; + namespace NadekoBot.Modules.NadekoExpressions; [Name("Expressions")] diff --git a/src/NadekoBot/Modules/CustomReactions/NadekoExpressionsService.cs b/src/NadekoBot/Modules/CustomReactions/NadekoExpressionsService.cs index 9dab77b5a..51fed4648 100644 --- a/src/NadekoBot/Modules/CustomReactions/NadekoExpressionsService.cs +++ b/src/NadekoBot/Modules/CustomReactions/NadekoExpressionsService.cs @@ -7,6 +7,7 @@ using NadekoBot.Modules.Permissions.Common; using NadekoBot.Modules.Permissions.Services; using NadekoBot.Services.Database.Models; using System.Runtime.CompilerServices; +using Nadeko.Common; using YamlDotNet.Serialization; using YamlDotNet.Serialization.NamingConventions; diff --git a/src/NadekoBot/Modules/Gambling/AnimalRacing/AnimalRace.cs b/src/NadekoBot/Modules/Gambling/AnimalRacing/AnimalRace.cs index b56e13109..b05dcc830 100644 --- a/src/NadekoBot/Modules/Gambling/AnimalRacing/AnimalRace.cs +++ b/src/NadekoBot/Modules/Gambling/AnimalRacing/AnimalRace.cs @@ -1,4 +1,5 @@ #nullable disable +using Nadeko.Common; using NadekoBot.Modules.Gambling.Common.AnimalRacing.Exceptions; using NadekoBot.Modules.Games.Common; diff --git a/src/NadekoBot/Modules/Gambling/AnimalRacing/AnimalRacingCommands.cs b/src/NadekoBot/Modules/Gambling/AnimalRacing/AnimalRacingCommands.cs index dc11b272f..0e9a6d13d 100644 --- a/src/NadekoBot/Modules/Gambling/AnimalRacing/AnimalRacingCommands.cs +++ b/src/NadekoBot/Modules/Gambling/AnimalRacing/AnimalRacingCommands.cs @@ -1,4 +1,5 @@ #nullable disable +using Nadeko.Common; using NadekoBot.Modules.Gambling.Common; using NadekoBot.Modules.Gambling.Common.AnimalRacing; using NadekoBot.Modules.Gambling.Common.AnimalRacing.Exceptions; diff --git a/src/NadekoBot/Modules/Gambling/Bank/BankCommands.cs b/src/NadekoBot/Modules/Gambling/Bank/BankCommands.cs index 7061da101..4fda56563 100644 --- a/src/NadekoBot/Modules/Gambling/Bank/BankCommands.cs +++ b/src/NadekoBot/Modules/Gambling/Bank/BankCommands.cs @@ -1,4 +1,5 @@ -using NadekoBot.Modules.Gambling.Bank; +using Nadeko.Common; +using NadekoBot.Modules.Gambling.Bank; using NadekoBot.Modules.Gambling.Common; using NadekoBot.Modules.Gambling.Services; diff --git a/src/NadekoBot/Modules/Gambling/BlackJack/BlackJackCommands.cs b/src/NadekoBot/Modules/Gambling/BlackJack/BlackJackCommands.cs index 4ceeab4e6..539cecfa8 100644 --- a/src/NadekoBot/Modules/Gambling/BlackJack/BlackJackCommands.cs +++ b/src/NadekoBot/Modules/Gambling/BlackJack/BlackJackCommands.cs @@ -1,4 +1,5 @@ #nullable disable +using Nadeko.Common; using NadekoBot.Modules.Gambling.Common; using NadekoBot.Modules.Gambling.Common.Blackjack; using NadekoBot.Modules.Gambling.Services; diff --git a/src/NadekoBot/Modules/Gambling/Events/GameStatusEvent.cs b/src/NadekoBot/Modules/Gambling/Events/GameStatusEvent.cs index 9e9142a2b..a673e794a 100644 --- a/src/NadekoBot/Modules/Gambling/Events/GameStatusEvent.cs +++ b/src/NadekoBot/Modules/Gambling/Events/GameStatusEvent.cs @@ -1,6 +1,7 @@ #nullable disable using NadekoBot.Services.Database.Models; using System.Collections.Concurrent; +using Nadeko.Common; namespace NadekoBot.Modules.Gambling.Common.Events; diff --git a/src/NadekoBot/Modules/Gambling/FlipCoin/FlipCoinCommands.cs b/src/NadekoBot/Modules/Gambling/FlipCoin/FlipCoinCommands.cs index 7059ae46c..1a33d8c0d 100644 --- a/src/NadekoBot/Modules/Gambling/FlipCoin/FlipCoinCommands.cs +++ b/src/NadekoBot/Modules/Gambling/FlipCoin/FlipCoinCommands.cs @@ -1,4 +1,5 @@ #nullable disable +using Nadeko.Common; using NadekoBot.Modules.Gambling.Common; using NadekoBot.Modules.Gambling.Services; using SixLabors.ImageSharp; diff --git a/src/NadekoBot/Modules/Gambling/Gambling.cs b/src/NadekoBot/Modules/Gambling/Gambling.cs index c42263f7f..6f5dfe48e 100644 --- a/src/NadekoBot/Modules/Gambling/Gambling.cs +++ b/src/NadekoBot/Modules/Gambling/Gambling.cs @@ -13,6 +13,7 @@ using NadekoBot.Services.Database.Models; using System.Collections.Immutable; using System.Globalization; using System.Text; +using Nadeko.Common; namespace NadekoBot.Modules.Gambling; diff --git a/src/NadekoBot/Modules/Gambling/PlantPick/PlantAndPickCommands.cs b/src/NadekoBot/Modules/Gambling/PlantPick/PlantAndPickCommands.cs index f22ecd176..19d8bedb2 100644 --- a/src/NadekoBot/Modules/Gambling/PlantPick/PlantAndPickCommands.cs +++ b/src/NadekoBot/Modules/Gambling/PlantPick/PlantAndPickCommands.cs @@ -1,4 +1,5 @@ #nullable disable +using Nadeko.Common; using NadekoBot.Modules.Gambling.Common; using NadekoBot.Modules.Gambling.Services; diff --git a/src/NadekoBot/Modules/Gambling/Raffle/CurrencyRaffleCommands.cs b/src/NadekoBot/Modules/Gambling/Raffle/CurrencyRaffleCommands.cs index d4d04331f..5c9fbc9b0 100644 --- a/src/NadekoBot/Modules/Gambling/Raffle/CurrencyRaffleCommands.cs +++ b/src/NadekoBot/Modules/Gambling/Raffle/CurrencyRaffleCommands.cs @@ -1,4 +1,5 @@ #nullable disable +using Nadeko.Common; using NadekoBot.Modules.Gambling.Common; using NadekoBot.Modules.Gambling.Services; diff --git a/src/NadekoBot/Modules/Gambling/Shop/ShopCommands.cs b/src/NadekoBot/Modules/Gambling/Shop/ShopCommands.cs index 673326b44..d753542be 100644 --- a/src/NadekoBot/Modules/Gambling/Shop/ShopCommands.cs +++ b/src/NadekoBot/Modules/Gambling/Shop/ShopCommands.cs @@ -1,6 +1,6 @@ #nullable disable using Microsoft.EntityFrameworkCore; -using NadekoBot.Common.Collections; +using Nadeko.Common; using NadekoBot.Db; using NadekoBot.Modules.Gambling.Common; using NadekoBot.Modules.Gambling.Services; diff --git a/src/NadekoBot/Modules/Gambling/Shop/ShopService.cs b/src/NadekoBot/Modules/Gambling/Shop/ShopService.cs index d9dc9d171..107f19ccd 100644 --- a/src/NadekoBot/Modules/Gambling/Shop/ShopService.cs +++ b/src/NadekoBot/Modules/Gambling/Shop/ShopService.cs @@ -1,6 +1,6 @@ #nullable disable using Microsoft.EntityFrameworkCore; -using NadekoBot.Common.Collections; +using Nadeko.Common; using NadekoBot.Db; using NadekoBot.Services.Database; using NadekoBot.Services.Database.Models; diff --git a/src/NadekoBot/Modules/Gambling/Slot/SlotCommands.cs b/src/NadekoBot/Modules/Gambling/Slot/SlotCommands.cs index d8898d565..2cc43ee6c 100644 --- a/src/NadekoBot/Modules/Gambling/Slot/SlotCommands.cs +++ b/src/NadekoBot/Modules/Gambling/Slot/SlotCommands.cs @@ -8,6 +8,7 @@ using SixLabors.ImageSharp.Drawing.Processing; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using System.Text; +using Nadeko.Common; using Color = SixLabors.ImageSharp.Color; using Image = SixLabors.ImageSharp.Image; diff --git a/src/NadekoBot/Modules/Gambling/Waifus/WaifuClaimCommands.cs b/src/NadekoBot/Modules/Gambling/Waifus/WaifuClaimCommands.cs index bdee7d11a..7157aa4a1 100644 --- a/src/NadekoBot/Modules/Gambling/Waifus/WaifuClaimCommands.cs +++ b/src/NadekoBot/Modules/Gambling/Waifus/WaifuClaimCommands.cs @@ -1,4 +1,5 @@ #nullable disable +using Nadeko.Common; using NadekoBot.Modules.Gambling.Common; using NadekoBot.Modules.Gambling.Common.Waifu; using NadekoBot.Modules.Gambling.Services; diff --git a/src/NadekoBot/Modules/Gambling/~Shared/Decks/Deck.cs b/src/NadekoBot/Modules/Gambling/~Shared/Decks/Deck.cs index aa6c2a2e2..1ecbead19 100644 --- a/src/NadekoBot/Modules/Gambling/~Shared/Decks/Deck.cs +++ b/src/NadekoBot/Modules/Gambling/~Shared/Decks/Deck.cs @@ -1,4 +1,6 @@ #nullable disable +using Nadeko.Common; + namespace NadekoBot.Modules.Gambling.Common; public class Deck diff --git a/src/NadekoBot/Modules/Games/GamesService.cs b/src/NadekoBot/Modules/Games/GamesService.cs index b970e6d0a..1159a253e 100644 --- a/src/NadekoBot/Modules/Games/GamesService.cs +++ b/src/NadekoBot/Modules/Games/GamesService.cs @@ -1,5 +1,6 @@ #nullable disable using Microsoft.Extensions.Caching.Memory; +using Nadeko.Common; using NadekoBot.Common.ModuleBehaviors; using NadekoBot.Modules.Games.Common; using NadekoBot.Modules.Games.Common.Acrophobia; diff --git a/src/NadekoBot/Modules/Games/GirlRating.cs b/src/NadekoBot/Modules/Games/GirlRating.cs index 3c7738b30..731195ebd 100644 --- a/src/NadekoBot/Modules/Games/GirlRating.cs +++ b/src/NadekoBot/Modules/Games/GirlRating.cs @@ -1,4 +1,5 @@ #nullable disable +using Nadeko.Common; using SixLabors.ImageSharp; using SixLabors.ImageSharp.Processing; using Image = SixLabors.ImageSharp.Image; diff --git a/src/NadekoBot/Modules/Games/Hangman/HangmanCommands.cs b/src/NadekoBot/Modules/Games/Hangman/HangmanCommands.cs index 5dfdd0504..24d70a568 100644 --- a/src/NadekoBot/Modules/Games/Hangman/HangmanCommands.cs +++ b/src/NadekoBot/Modules/Games/Hangman/HangmanCommands.cs @@ -1,3 +1,4 @@ +using Nadeko.Common; using NadekoBot.Modules.Games.Hangman; namespace NadekoBot.Modules.Games; diff --git a/src/NadekoBot/Modules/Games/Polls/PollService.cs b/src/NadekoBot/Modules/Games/Polls/PollService.cs index e4a850c7f..1563710fc 100644 --- a/src/NadekoBot/Modules/Games/Polls/PollService.cs +++ b/src/NadekoBot/Modules/Games/Polls/PollService.cs @@ -1,5 +1,4 @@ #nullable disable -using NadekoBot.Common.Collections; using NadekoBot.Common.ModuleBehaviors; using NadekoBot.Db; using NadekoBot.Modules.Games.Common; diff --git a/src/NadekoBot/Modules/Games/Trivia/DefaultQuestionPool.cs b/src/NadekoBot/Modules/Games/Trivia/DefaultQuestionPool.cs new file mode 100644 index 000000000..945d832f1 --- /dev/null +++ b/src/NadekoBot/Modules/Games/Trivia/DefaultQuestionPool.cs @@ -0,0 +1,33 @@ +namespace NadekoBot.Modules.Games.Common.Trivia; + +public sealed class DefaultQuestionPool : IQuestionPool +{ + private readonly ILocalDataCache _cache; + private readonly NadekoRandom _rng; + + public DefaultQuestionPool(ILocalDataCache cache) + { + _cache = cache; + _rng = new NadekoRandom(); + } + public async Task GetRandomQuestionAsync(ISet exclude) + { + TriviaQuestion randomQuestion; + var pool = await _cache.GetTriviaQuestionsAsync(); + + if(pool is null) + return default; + + while (exclude.Contains(randomQuestion = new(pool[_rng.Next(0, pool.Length)]))) + { + // if too many questions are excluded, clear the exclusion list and start over + if (exclude.Count > pool.Length / 10 * 9) + { + exclude.Clear(); + break; + } + } + + return randomQuestion; + } +} \ No newline at end of file diff --git a/src/NadekoBot/Modules/Games/Trivia/IQuestionPool.cs b/src/NadekoBot/Modules/Games/Trivia/IQuestionPool.cs new file mode 100644 index 000000000..dcffa1df8 --- /dev/null +++ b/src/NadekoBot/Modules/Games/Trivia/IQuestionPool.cs @@ -0,0 +1,6 @@ +namespace NadekoBot.Modules.Games.Common.Trivia; + +public interface IQuestionPool +{ + Task GetRandomQuestionAsync(ISet exclude); +} \ No newline at end of file diff --git a/src/NadekoBot/Modules/Games/Trivia/PokemonQuestionPool.cs b/src/NadekoBot/Modules/Games/Trivia/PokemonQuestionPool.cs new file mode 100644 index 000000000..3fb843c16 --- /dev/null +++ b/src/NadekoBot/Modules/Games/Trivia/PokemonQuestionPool.cs @@ -0,0 +1,32 @@ +namespace NadekoBot.Modules.Games.Common.Trivia; + +public sealed class PokemonQuestionPool : IQuestionPool +{ + public int QuestionsCount => 721; // xd + private readonly NadekoRandom _rng; + private readonly ILocalDataCache _cache; + + public PokemonQuestionPool(ILocalDataCache cache) + { + _cache = cache; + _rng = new NadekoRandom(); + } + + public async Task GetRandomQuestionAsync(ISet exclude) + { + var pokes = await _cache.GetPokemonMapAsync(); + + if (pokes is null or { Count: 0 }) + return default; + + var num = _rng.Next(1, QuestionsCount + 1); + return new(new() + { + Question = "Who's That Pokémon?", + Answer = pokes[num].ToTitleCase(), + Category = "Pokemon", + ImageUrl = $@"https://nadeko.bot/images/pokemon/shadows/{num}.png", + AnswerImageUrl = $@"https://nadeko.bot/images/pokemon/real/{num}.png" + }); + } +} \ No newline at end of file diff --git a/src/NadekoBot/Modules/Games/Trivia/TriviaGame.cs b/src/NadekoBot/Modules/Games/Trivia/TriviaGame.cs index 0f07d2d9a..ddfd7c754 100644 --- a/src/NadekoBot/Modules/Games/Trivia/TriviaGame.cs +++ b/src/NadekoBot/Modules/Games/Trivia/TriviaGame.cs @@ -234,9 +234,9 @@ public class TriviaGame if (!guess) return; + triviaCancelSource.Cancel(); - if (_options.WinRequirement != 0 && Users[guildUser] == _options.WinRequirement) { ShouldStopGame = true; diff --git a/src/NadekoBot/Modules/Help/Help.cs b/src/NadekoBot/Modules/Help/Help.cs index 23b08cdaf..dce48814c 100644 --- a/src/NadekoBot/Modules/Help/Help.cs +++ b/src/NadekoBot/Modules/Help/Help.cs @@ -7,6 +7,7 @@ using NadekoBot.Modules.Permissions.Services; using Newtonsoft.Json; using System.Text; using System.Text.Json; +using Nadeko.Common; using JsonSerializer = System.Text.Json.JsonSerializer; namespace NadekoBot.Modules.Help; diff --git a/src/NadekoBot/Modules/Help/HelpService.cs b/src/NadekoBot/Modules/Help/HelpService.cs index 1739c5eac..bec3d1642 100644 --- a/src/NadekoBot/Modules/Help/HelpService.cs +++ b/src/NadekoBot/Modules/Help/HelpService.cs @@ -1,5 +1,6 @@ #nullable disable using CommandLine; +using Nadeko.Common; using Nadeko.Medusa; using NadekoBot.Common.ModuleBehaviors; using NadekoBot.Modules.Administration.Services; diff --git a/src/NadekoBot/Modules/Medusae/Medusa.cs b/src/NadekoBot/Modules/Medusae/Medusa.cs index ec58afb92..86b097e99 100644 --- a/src/NadekoBot/Modules/Medusae/Medusa.cs +++ b/src/NadekoBot/Modules/Medusae/Medusa.cs @@ -1,4 +1,5 @@ -using Nadeko.Medusa; +using Nadeko.Common; +using Nadeko.Medusa; namespace NadekoBot.Modules; diff --git a/src/NadekoBot/Modules/Music/Music.cs b/src/NadekoBot/Modules/Music/Music.cs index ad703723c..7412a553a 100644 --- a/src/NadekoBot/Modules/Music/Music.cs +++ b/src/NadekoBot/Modules/Music/Music.cs @@ -1,4 +1,5 @@ #nullable disable +using Nadeko.Common; using NadekoBot.Modules.Music.Services; using NadekoBot.Services.Database.Models; diff --git a/src/NadekoBot/Modules/Music/Services/MusicService.cs b/src/NadekoBot/Modules/Music/Services/MusicService.cs index cb49cf0c5..b20506ef7 100644 --- a/src/NadekoBot/Modules/Music/Services/MusicService.cs +++ b/src/NadekoBot/Modules/Music/Services/MusicService.cs @@ -1,6 +1,7 @@ using NadekoBot.Db; using NadekoBot.Services.Database.Models; using System.Diagnostics.CodeAnalysis; +using Nadeko.Common; namespace NadekoBot.Modules.Music.Services; diff --git a/src/NadekoBot/Modules/Music/_Common/Impl/MusicPlayer.cs b/src/NadekoBot/Modules/Music/_Common/Impl/MusicPlayer.cs index 963c90270..21b8d5980 100644 --- a/src/NadekoBot/Modules/Music/_Common/Impl/MusicPlayer.cs +++ b/src/NadekoBot/Modules/Music/_Common/Impl/MusicPlayer.cs @@ -4,6 +4,7 @@ using System.ComponentModel; using System.Diagnostics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using Nadeko.Common; namespace NadekoBot.Modules.Music; diff --git a/src/NadekoBot/Modules/Music/_Common/Resolvers/LocalTrackResolver.cs b/src/NadekoBot/Modules/Music/_Common/Resolvers/LocalTrackResolver.cs index c5a07039e..128bafdac 100644 --- a/src/NadekoBot/Modules/Music/_Common/Resolvers/LocalTrackResolver.cs +++ b/src/NadekoBot/Modules/Music/_Common/Resolvers/LocalTrackResolver.cs @@ -1,6 +1,7 @@ using System.ComponentModel; using System.Diagnostics; using System.Text; +using Nadeko.Common; namespace NadekoBot.Modules.Music.Resolvers; diff --git a/src/NadekoBot/Modules/Music/_Common/Resolvers/SoundcloudResolver.cs b/src/NadekoBot/Modules/Music/_Common/Resolvers/SoundcloudResolver.cs index d4c0defd2..09d95e819 100644 --- a/src/NadekoBot/Modules/Music/_Common/Resolvers/SoundcloudResolver.cs +++ b/src/NadekoBot/Modules/Music/_Common/Resolvers/SoundcloudResolver.cs @@ -1,6 +1,7 @@ using Newtonsoft.Json.Linq; using System.Runtime.CompilerServices; using System.Text.RegularExpressions; +using Nadeko.Common; namespace NadekoBot.Modules.Music.Resolvers; diff --git a/src/NadekoBot/Modules/Nsfw/Nsfw.cs b/src/NadekoBot/Modules/Nsfw/Nsfw.cs index 05d18f075..513357807 100644 --- a/src/NadekoBot/Modules/Nsfw/Nsfw.cs +++ b/src/NadekoBot/Modules/Nsfw/Nsfw.cs @@ -1,4 +1,5 @@ #nullable disable +using Nadeko.Common; using NadekoBot.Modules.Searches.Common; using Newtonsoft.Json.Linq; diff --git a/src/NadekoBot/Modules/Nsfw/SearchImageCacher.cs b/src/NadekoBot/Modules/Nsfw/SearchImageCacher.cs index f576b591d..fb60382f4 100644 --- a/src/NadekoBot/Modules/Nsfw/SearchImageCacher.cs +++ b/src/NadekoBot/Modules/Nsfw/SearchImageCacher.cs @@ -1,5 +1,6 @@ #nullable disable using Microsoft.Extensions.Caching.Memory; +using Nadeko.Common; namespace NadekoBot.Modules.Nsfw.Common; diff --git a/src/NadekoBot/Modules/Nsfw/SearchImagesService.cs b/src/NadekoBot/Modules/Nsfw/SearchImagesService.cs index 8e15dd0d2..76639250a 100644 --- a/src/NadekoBot/Modules/Nsfw/SearchImagesService.cs +++ b/src/NadekoBot/Modules/Nsfw/SearchImagesService.cs @@ -1,5 +1,6 @@ #nullable disable warnings using LinqToDB; +using Nadeko.Common; using NadekoBot.Modules.Nsfw.Common; using NadekoBot.Modules.Searches.Common; using Newtonsoft.Json.Linq; diff --git a/src/NadekoBot/Modules/Nsfw/UrlReply.cs b/src/NadekoBot/Modules/Nsfw/UrlReply.cs index 85bde32d7..c442bea94 100644 --- a/src/NadekoBot/Modules/Nsfw/UrlReply.cs +++ b/src/NadekoBot/Modules/Nsfw/UrlReply.cs @@ -1,4 +1,5 @@ -namespace NadekoBot.Modules.Nsfw; +#nullable disable warnings +namespace NadekoBot.Modules.Nsfw; public record UrlReply { diff --git a/src/NadekoBot/Modules/Nsfw/_Common/Downloaders/DapiImageDownloader.cs b/src/NadekoBot/Modules/Nsfw/_Common/Downloaders/DapiImageDownloader.cs index d7b6e058d..2b08414a9 100644 --- a/src/NadekoBot/Modules/Nsfw/_Common/Downloaders/DapiImageDownloader.cs +++ b/src/NadekoBot/Modules/Nsfw/_Common/Downloaders/DapiImageDownloader.cs @@ -1,5 +1,6 @@ #nullable disable using System.Net.Http.Json; +using Nadeko.Common; namespace NadekoBot.Modules.Nsfw.Common; diff --git a/src/NadekoBot/Modules/Nsfw/_Common/Downloaders/DerpibooruImageDownloader.cs b/src/NadekoBot/Modules/Nsfw/_Common/Downloaders/DerpibooruImageDownloader.cs index b6b49714a..7ef7eaccf 100644 --- a/src/NadekoBot/Modules/Nsfw/_Common/Downloaders/DerpibooruImageDownloader.cs +++ b/src/NadekoBot/Modules/Nsfw/_Common/Downloaders/DerpibooruImageDownloader.cs @@ -1,5 +1,6 @@ #nullable disable using System.Net.Http.Json; +using Nadeko.Common; namespace NadekoBot.Modules.Nsfw.Common; diff --git a/src/NadekoBot/Modules/Nsfw/_Common/Downloaders/E621ImageDownloader.cs b/src/NadekoBot/Modules/Nsfw/_Common/Downloaders/E621ImageDownloader.cs index cfc3253cb..18b792e4f 100644 --- a/src/NadekoBot/Modules/Nsfw/_Common/Downloaders/E621ImageDownloader.cs +++ b/src/NadekoBot/Modules/Nsfw/_Common/Downloaders/E621ImageDownloader.cs @@ -1,5 +1,6 @@ #nullable disable using System.Net.Http.Json; +using Nadeko.Common; namespace NadekoBot.Modules.Nsfw.Common; diff --git a/src/NadekoBot/Modules/Nsfw/_Common/Downloaders/SankakuImageDownloader.cs b/src/NadekoBot/Modules/Nsfw/_Common/Downloaders/SankakuImageDownloader.cs index 6cd20f7f4..cba25f452 100644 --- a/src/NadekoBot/Modules/Nsfw/_Common/Downloaders/SankakuImageDownloader.cs +++ b/src/NadekoBot/Modules/Nsfw/_Common/Downloaders/SankakuImageDownloader.cs @@ -1,5 +1,6 @@ #nullable disable using System.Text.Json; +using Nadeko.Common; namespace NadekoBot.Modules.Nsfw.Common; diff --git a/src/NadekoBot/Modules/Permissions/Blacklist/BlacklistCommands.cs b/src/NadekoBot/Modules/Permissions/Blacklist/BlacklistCommands.cs index e60559d59..f6578bcb1 100644 --- a/src/NadekoBot/Modules/Permissions/Blacklist/BlacklistCommands.cs +++ b/src/NadekoBot/Modules/Permissions/Blacklist/BlacklistCommands.cs @@ -1,4 +1,5 @@ #nullable disable +using Nadeko.Common; using NadekoBot.Modules.Permissions.Services; using NadekoBot.Services.Database.Models; diff --git a/src/NadekoBot/Modules/Permissions/PermissionsCollection.cs b/src/NadekoBot/Modules/Permissions/PermissionsCollection.cs index d80b590a2..62cccf81e 100644 --- a/src/NadekoBot/Modules/Permissions/PermissionsCollection.cs +++ b/src/NadekoBot/Modules/Permissions/PermissionsCollection.cs @@ -1,7 +1,4 @@ #nullable disable -using NadekoBot.Common.Collections; -using NadekoBot.Services.Database.Models; - namespace NadekoBot.Modules.Permissions.Common; public class PermissionsCollection : IndexedCollection diff --git a/src/NadekoBot/Modules/Searches/Anime/AnimeSearchCommands.cs b/src/NadekoBot/Modules/Searches/Anime/AnimeSearchCommands.cs index 62e754041..ec8ccf39a 100644 --- a/src/NadekoBot/Modules/Searches/Anime/AnimeSearchCommands.cs +++ b/src/NadekoBot/Modules/Searches/Anime/AnimeSearchCommands.cs @@ -1,6 +1,7 @@ #nullable disable using AngleSharp; using AngleSharp.Html.Dom; +using Nadeko.Common; using NadekoBot.Modules.Searches.Services; namespace NadekoBot.Modules.Searches; diff --git a/src/NadekoBot/Modules/Searches/Crypto/DefaultStockDataService.cs b/src/NadekoBot/Modules/Searches/Crypto/DefaultStockDataService.cs index dee5c27b8..1203550ab 100644 --- a/src/NadekoBot/Modules/Searches/Crypto/DefaultStockDataService.cs +++ b/src/NadekoBot/Modules/Searches/Crypto/DefaultStockDataService.cs @@ -4,6 +4,7 @@ using Google.Protobuf.WellKnownTypes; using System.Globalization; using System.Net.Http.Json; using System.Text.Json; +using Nadeko.Common; namespace NadekoBot.Modules.Searches; diff --git a/src/NadekoBot/Modules/Searches/Feeds/FeedsService.cs b/src/NadekoBot/Modules/Searches/Feeds/FeedsService.cs index 38f51eb5a..f6f855ee0 100644 --- a/src/NadekoBot/Modules/Searches/Feeds/FeedsService.cs +++ b/src/NadekoBot/Modules/Searches/Feeds/FeedsService.cs @@ -4,6 +4,7 @@ using CodeHollow.FeedReader.Feeds; using LinqToDB; using LinqToDB.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; +using Nadeko.Common; using NadekoBot.Db; using NadekoBot.Services.Database.Models; diff --git a/src/NadekoBot/Modules/Searches/OsuCommands.cs b/src/NadekoBot/Modules/Searches/OsuCommands.cs index ed302dbdc..cbca61bce 100644 --- a/src/NadekoBot/Modules/Searches/OsuCommands.cs +++ b/src/NadekoBot/Modules/Searches/OsuCommands.cs @@ -1,4 +1,5 @@ #nullable disable +using Nadeko.Common; using NadekoBot.Modules.Searches.Common; using Newtonsoft.Json; diff --git a/src/NadekoBot/Modules/Searches/Search/SearchCommands.cs b/src/NadekoBot/Modules/Searches/Search/SearchCommands.cs index 68fd9231d..04f069473 100644 --- a/src/NadekoBot/Modules/Searches/Search/SearchCommands.cs +++ b/src/NadekoBot/Modules/Searches/Search/SearchCommands.cs @@ -2,6 +2,7 @@ using StackExchange.Redis; using System.Net.Http.Json; using System.Text.Json.Serialization; +using Nadeko.Common; namespace NadekoBot.Modules.Searches; diff --git a/src/NadekoBot/Modules/Searches/Searches.cs b/src/NadekoBot/Modules/Searches/Searches.cs index 0bc986486..aed060d80 100644 --- a/src/NadekoBot/Modules/Searches/Searches.cs +++ b/src/NadekoBot/Modules/Searches/Searches.cs @@ -11,6 +11,7 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using System.Diagnostics.CodeAnalysis; using System.Net; +using Nadeko.Common; using Color = SixLabors.ImageSharp.Color; namespace NadekoBot.Modules.Searches; diff --git a/src/NadekoBot/Modules/Searches/SearchesService.cs b/src/NadekoBot/Modules/Searches/SearchesService.cs index b1604b32b..e088c489f 100644 --- a/src/NadekoBot/Modules/Searches/SearchesService.cs +++ b/src/NadekoBot/Modules/Searches/SearchesService.cs @@ -1,5 +1,6 @@ #nullable disable using Html2Markdown; +using Nadeko.Common; using NadekoBot.Modules.Searches.Common; using Newtonsoft.Json; using Newtonsoft.Json.Linq; diff --git a/src/NadekoBot/Modules/Searches/StreamNotification/StreamNotificationService.cs b/src/NadekoBot/Modules/Searches/StreamNotification/StreamNotificationService.cs index a4f15e1ba..fccff7d4b 100644 --- a/src/NadekoBot/Modules/Searches/StreamNotification/StreamNotificationService.cs +++ b/src/NadekoBot/Modules/Searches/StreamNotification/StreamNotificationService.cs @@ -2,6 +2,7 @@ using LinqToDB; using LinqToDB.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; +using Nadeko.Common; using NadekoBot.Common.ModuleBehaviors; using NadekoBot.Db; using NadekoBot.Db.Models; diff --git a/src/NadekoBot/Modules/Searches/_Common/StreamNotifications/NotifChecker.cs b/src/NadekoBot/Modules/Searches/_Common/StreamNotifications/NotifChecker.cs index be18267b4..c3c30953f 100644 --- a/src/NadekoBot/Modules/Searches/_Common/StreamNotifications/NotifChecker.cs +++ b/src/NadekoBot/Modules/Searches/_Common/StreamNotifications/NotifChecker.cs @@ -1,4 +1,5 @@ -using NadekoBot.Db.Models; +using Nadeko.Common; +using NadekoBot.Db.Models; using NadekoBot.Modules.Searches.Common.StreamNotifications.Providers; namespace NadekoBot.Modules.Searches.Common.StreamNotifications; diff --git a/src/NadekoBot/Modules/Searches/_Common/StreamNotifications/Providers/TwitchHelixProvider.cs b/src/NadekoBot/Modules/Searches/_Common/StreamNotifications/Providers/TwitchHelixProvider.cs index c758cb0c1..0840b8e7a 100644 --- a/src/NadekoBot/Modules/Searches/_Common/StreamNotifications/Providers/TwitchHelixProvider.cs +++ b/src/NadekoBot/Modules/Searches/_Common/StreamNotifications/Providers/TwitchHelixProvider.cs @@ -1,5 +1,6 @@ using NadekoBot.Db.Models; using System.Text.RegularExpressions; +using Nadeko.Common; using TwitchLib.Api; using JsonSerializer = System.Text.Json.JsonSerializer; diff --git a/src/NadekoBot/Modules/Utility/Info/InfoCommands.cs b/src/NadekoBot/Modules/Utility/Info/InfoCommands.cs index e1af89181..fc916d517 100644 --- a/src/NadekoBot/Modules/Utility/Info/InfoCommands.cs +++ b/src/NadekoBot/Modules/Utility/Info/InfoCommands.cs @@ -1,6 +1,7 @@ #nullable disable using NadekoBot.Modules.Utility.Patronage; using System.Text; +using Nadeko.Common; namespace NadekoBot.Modules.Utility; diff --git a/src/NadekoBot/Modules/Utility/Quote/QuoteCommands.cs b/src/NadekoBot/Modules/Utility/Quote/QuoteCommands.cs index d5c066094..7f5ac0816 100644 --- a/src/NadekoBot/Modules/Utility/Quote/QuoteCommands.cs +++ b/src/NadekoBot/Modules/Utility/Quote/QuoteCommands.cs @@ -1,4 +1,5 @@ #nullable disable warnings +using Nadeko.Common; using NadekoBot.Common.Yml; using NadekoBot.Db; using NadekoBot.Services.Database.Models; diff --git a/src/NadekoBot/Modules/Utility/Remind/RemindService.cs b/src/NadekoBot/Modules/Utility/Remind/RemindService.cs index 0d3d9dcd0..9031fd5c4 100644 --- a/src/NadekoBot/Modules/Utility/Remind/RemindService.cs +++ b/src/NadekoBot/Modules/Utility/Remind/RemindService.cs @@ -4,6 +4,7 @@ using LinqToDB.EntityFrameworkCore; using NadekoBot.Common.ModuleBehaviors; using NadekoBot.Services.Database.Models; using System.Text.RegularExpressions; +using Nadeko.Common; namespace NadekoBot.Modules.Utility.Services; diff --git a/src/NadekoBot/Modules/Utility/Repeater/RepeaterService.cs b/src/NadekoBot/Modules/Utility/Repeater/RepeaterService.cs index 81b7feff1..a87ff5f0d 100644 --- a/src/NadekoBot/Modules/Utility/Repeater/RepeaterService.cs +++ b/src/NadekoBot/Modules/Utility/Repeater/RepeaterService.cs @@ -1,6 +1,7 @@ using LinqToDB; using LinqToDB.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; +using Nadeko.Common; using NadekoBot.Common.ModuleBehaviors; using NadekoBot.Services.Database.Models; diff --git a/src/NadekoBot/Modules/Utility/StreamRole/StreamRoleService.cs b/src/NadekoBot/Modules/Utility/StreamRole/StreamRoleService.cs index 71172e02d..d8595d7cf 100644 --- a/src/NadekoBot/Modules/Utility/StreamRole/StreamRoleService.cs +++ b/src/NadekoBot/Modules/Utility/StreamRole/StreamRoleService.cs @@ -6,6 +6,7 @@ using NadekoBot.Modules.Utility.Common.Exceptions; using NadekoBot.Services.Database.Models; using System.Diagnostics; using System.Net; +using Nadeko.Common; namespace NadekoBot.Modules.Utility.Services; diff --git a/src/NadekoBot/Modules/Utility/Utility.cs b/src/NadekoBot/Modules/Utility/Utility.cs index 2782b9d74..73182f7f9 100644 --- a/src/NadekoBot/Modules/Utility/Utility.cs +++ b/src/NadekoBot/Modules/Utility/Utility.cs @@ -7,6 +7,7 @@ using System.Diagnostics; using System.Text; using System.Text.Json; using System.Text.Json.Serialization; +using Nadeko.Common; using SystemTextJsonSamples; namespace NadekoBot.Modules.Utility; diff --git a/src/NadekoBot/Modules/Xp/Club/ClubService.cs b/src/NadekoBot/Modules/Xp/Club/ClubService.cs index fcedc6567..fbc118ad3 100644 --- a/src/NadekoBot/Modules/Xp/Club/ClubService.cs +++ b/src/NadekoBot/Modules/Xp/Club/ClubService.cs @@ -2,6 +2,7 @@ using LinqToDB; using LinqToDB.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; +using Nadeko.Common; using NadekoBot.Db; using NadekoBot.Db.Models; diff --git a/src/NadekoBot/Modules/Xp/Xp.cs b/src/NadekoBot/Modules/Xp/Xp.cs index 74a87a58d..13ee90a2d 100644 --- a/src/NadekoBot/Modules/Xp/Xp.cs +++ b/src/NadekoBot/Modules/Xp/Xp.cs @@ -3,6 +3,7 @@ using NadekoBot.Modules.Gambling.Services; using NadekoBot.Modules.Xp.Services; using NadekoBot.Services.Database.Models; using System.Diagnostics; +using Nadeko.Common; namespace NadekoBot.Modules.Xp; diff --git a/src/NadekoBot/Modules/Xp/XpService.cs b/src/NadekoBot/Modules/Xp/XpService.cs index b55606355..38235af48 100644 --- a/src/NadekoBot/Modules/Xp/XpService.cs +++ b/src/NadekoBot/Modules/Xp/XpService.cs @@ -14,6 +14,7 @@ using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using System.Threading.Channels; +using Nadeko.Common; using Color = SixLabors.ImageSharp.Color; using Image = SixLabors.ImageSharp.Image; diff --git a/src/NadekoBot/NadekoBot.csproj b/src/NadekoBot/NadekoBot.csproj index 17f44c02d..27e263644 100644 --- a/src/NadekoBot/NadekoBot.csproj +++ b/src/NadekoBot/NadekoBot.csproj @@ -101,6 +101,7 @@ + @@ -122,6 +123,9 @@ Always + + + 4.0.0 diff --git a/src/NadekoBot/Program.cs b/src/NadekoBot/Program.cs index dc89a4a8f..ec82365ef 100644 --- a/src/NadekoBot/Program.cs +++ b/src/NadekoBot/Program.cs @@ -1,3 +1,5 @@ +using Nadeko.Common; + var pid = Environment.ProcessId; var shardId = 0; diff --git a/src/NadekoBot/Services/CommandHandler.cs b/src/NadekoBot/Services/CommandHandler.cs index 215c2fba5..1bb4d30ab 100644 --- a/src/NadekoBot/Services/CommandHandler.cs +++ b/src/NadekoBot/Services/CommandHandler.cs @@ -3,6 +3,7 @@ using NadekoBot.Common.Configs; using NadekoBot.Common.ModuleBehaviors; using NadekoBot.Db; using System.Collections.Immutable; +using Nadeko.Common; using ExecuteResult = Discord.Commands.ExecuteResult; using PreconditionResult = Discord.Commands.PreconditionResult; diff --git a/src/NadekoBot/Services/Impl/RemoteGrpcCoordinator.cs b/src/NadekoBot/Services/Impl/RemoteGrpcCoordinator.cs index 6bfab0c80..e445fe5a4 100644 --- a/src/NadekoBot/Services/Impl/RemoteGrpcCoordinator.cs +++ b/src/NadekoBot/Services/Impl/RemoteGrpcCoordinator.cs @@ -1,6 +1,7 @@ #nullable disable using Grpc.Core; using Grpc.Net.Client; +using Nadeko.Common; using NadekoBot.Common.ModuleBehaviors; using NadekoBot.Coordinator; diff --git a/src/NadekoBot/Services/Impl/StartingGuildsListService.cs b/src/NadekoBot/Services/Impl/StartingGuildsListService.cs index bcb5b3ee2..3d51d239b 100644 --- a/src/NadekoBot/Services/Impl/StartingGuildsListService.cs +++ b/src/NadekoBot/Services/Impl/StartingGuildsListService.cs @@ -1,15 +1,14 @@ #nullable disable using System.Collections; -using System.Collections.Immutable; namespace NadekoBot.Services; public class StartingGuildsService : IEnumerable, INService { - private readonly ImmutableList _guilds; + private readonly IReadOnlyList _guilds; public StartingGuildsService(DiscordSocketClient client) - => _guilds = client.Guilds.Select(x => x.Id).ToImmutableList(); + => _guilds = client.Guilds.Select(x => x.Id).ToList(); public IEnumerator GetEnumerator() => _guilds.GetEnumerator(); diff --git a/src/NadekoBot/Services/Impl/YtdlOperation.cs b/src/NadekoBot/Services/Impl/YtdlOperation.cs index 84a424c78..96ea60d9c 100644 --- a/src/NadekoBot/Services/Impl/YtdlOperation.cs +++ b/src/NadekoBot/Services/Impl/YtdlOperation.cs @@ -2,6 +2,7 @@ using System.ComponentModel; using System.Diagnostics; using System.Text; +using Nadeko.Common; namespace NadekoBot.Services; diff --git a/src/NadekoBot/Services/strings/impl/RedisBotStringsProvider.cs b/src/NadekoBot/Services/strings/impl/RedisBotStringsProvider.cs index 70f766392..4087182d6 100644 --- a/src/NadekoBot/Services/strings/impl/RedisBotStringsProvider.cs +++ b/src/NadekoBot/Services/strings/impl/RedisBotStringsProvider.cs @@ -1,6 +1,7 @@ #nullable disable using StackExchange.Redis; using System.Web; +using Nadeko.Common; namespace NadekoBot.Services; diff --git a/src/NadekoBot/_Extensions/Extensions.cs b/src/NadekoBot/_Extensions/Extensions.cs index 607bcdbba..aad7045d1 100644 --- a/src/NadekoBot/_Extensions/Extensions.cs +++ b/src/NadekoBot/_Extensions/Extensions.cs @@ -5,6 +5,7 @@ using System.Globalization; using System.Net.Http.Headers; using System.Text.Json; using System.Text.RegularExpressions; +using Nadeko.Common; namespace NadekoBot.Extensions; @@ -145,20 +146,6 @@ public static class Extensions public static IEmbedBuilder WithErrorColor(this IEmbedBuilder eb) => eb.WithColor(EmbedColor.Error); - public static HttpClient AddFakeHeaders(this HttpClient http) - { - AddFakeHeaders(http.DefaultRequestHeaders); - return http; - } - - public static void AddFakeHeaders(this HttpHeaders dict) - { - dict.Clear(); - dict.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); - dict.Add("User-Agent", - "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.202 Safari/535.1"); - } - public static IMessage DeleteAfter(this IUserMessage msg, int seconds, ILogCommandService? logService = null) { Task.Run(async () => @@ -203,23 +190,6 @@ public static class Extensions public static IEnumerable GetRoles(this IGuildUser user) => user.RoleIds.Select(r => user.Guild.GetRole(r)).Where(r => r is not null); - public static bool IsImage(this HttpResponseMessage msg) - => IsImage(msg, out _); - - public static bool IsImage(this HttpResponseMessage msg, out string? mimeType) - { - mimeType = msg.Content.Headers.ContentType?.MediaType; - if (mimeType is "image/png" or "image/jpeg" or "image/gif") - return true; - - return false; - } - - public static long GetContentLength(this HttpResponseMessage msg) - => msg.Content.Headers.ContentLength is long length - ? length - : long.MaxValue; - public static void Lap(this Stopwatch sw, string checkpoint) { Log.Information("Checkpoint {CheckPoint}: {Time}ms", checkpoint, sw.Elapsed.TotalMilliseconds); diff --git a/src/NadekoBot/_Extensions/IMessageChannelExtensions.cs b/src/NadekoBot/_Extensions/IMessageChannelExtensions.cs index 5d8cd12ae..4f78073d2 100644 --- a/src/NadekoBot/_Extensions/IMessageChannelExtensions.cs +++ b/src/NadekoBot/_Extensions/IMessageChannelExtensions.cs @@ -1,3 +1,5 @@ +using Nadeko.Common; + namespace NadekoBot.Extensions; public static class MessageChannelExtensions diff --git a/src/NadekoBot/_Extensions/ProcessExtensions.cs b/src/NadekoBot/_Extensions/ProcessExtensions.cs deleted file mode 100644 index f160608a8..000000000 --- a/src/NadekoBot/_Extensions/ProcessExtensions.cs +++ /dev/null @@ -1,87 +0,0 @@ -// // Copyright (c) .NET Foundation. All rights reserved. -// // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -// // https://github.com/aspnet/Common/blob/dev/shared/Microsoft.Extensions.Process.Sources/ProcessHelper.cs -// -// using System.Diagnostics; -// using System.Runtime.InteropServices; -// -// namespace NadekoBot.Extensions; -// -// public static class ProcessExtensions -// { -// private static readonly bool _isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); -// private static readonly TimeSpan _defaultTimeout = TimeSpan.FromSeconds(10); -// -// public static void KillTree(this Process process) -// => process.KillTree(_defaultTimeout); -// -// public static void KillTree(this Process process, TimeSpan timeout) -// { -// if (_isWindows) -// RunProcessAndWaitForExit("taskkill", $"/T /F /PID {process.Id}", timeout, out _); -// else -// { -// var children = new HashSet(); -// GetAllChildIdsUnix(process.Id, children, timeout); -// foreach (var childId in children) -// KillProcessUnix(childId, timeout); -// -// KillProcessUnix(process.Id, timeout); -// } -// } -// -// private static void GetAllChildIdsUnix(int parentId, ISet children, TimeSpan timeout) -// { -// var exitCode = RunProcessAndWaitForExit("pgrep", $"-P {parentId}", timeout, out var stdout); -// -// if (exitCode == 0 && !string.IsNullOrEmpty(stdout)) -// { -// using var reader = new StringReader(stdout); -// while (true) -// { -// var text = reader.ReadLine(); -// if (text is null) -// return; -// -// if (int.TryParse(text, out var id)) -// { -// children.Add(id); -// // Recursively get the children -// GetAllChildIdsUnix(id, children, timeout); -// } -// } -// } -// } -// -// private static void KillProcessUnix(int processId, TimeSpan timeout) -// => RunProcessAndWaitForExit("kill", $"-TERM {processId}", timeout, out _); -// -// private static int RunProcessAndWaitForExit( -// string fileName, -// string arguments, -// TimeSpan timeout, -// out string? stdout) -// { -// stdout = null; -// -// var startInfo = new ProcessStartInfo -// { -// FileName = fileName, -// Arguments = arguments, -// RedirectStandardOutput = true, -// UseShellExecute = false -// }; -// -// using var process = Process.Start(startInfo); -// -// if (process is null) -// return -1; -// -// if (process.WaitForExit((int)timeout.TotalMilliseconds)) -// stdout = process.StandardOutput.ReadToEnd(); -// else -// process.Kill(); -// -// return process.ExitCode; -// } -// } \ No newline at end of file diff --git a/src/NadekoBot/_Extensions/SocketMessageComponentExtensions.cs b/src/NadekoBot/_Extensions/SocketMessageComponentExtensions.cs index b00be6472..28166782d 100644 --- a/src/NadekoBot/_Extensions/SocketMessageComponentExtensions.cs +++ b/src/NadekoBot/_Extensions/SocketMessageComponentExtensions.cs @@ -1,4 +1,6 @@ -namespace NadekoBot.Extensions; +using Nadeko.Common; + +namespace NadekoBot.Extensions; public static class SocketMessageComponentExtensions { diff --git a/src/NadekoBot/_Extensions/StringExtensions.cs b/src/NadekoBot/_Extensions/StringExtensions.cs index c59ebb1a0..e98f68b60 100644 --- a/src/NadekoBot/_Extensions/StringExtensions.cs +++ b/src/NadekoBot/_Extensions/StringExtensions.cs @@ -2,6 +2,7 @@ using NadekoBot.Common.Yml; using Newtonsoft.Json; using System.Text; using System.Text.RegularExpressions; +using Nadeko.Common; namespace NadekoBot.Extensions;