mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2024-10-02 20:13:13 +00:00
Base for 4.3 work. Split Nadeko.Common into a separate project
This commit is contained in:
parent
1396d9d55a
commit
f41b1fb93c
113 changed files with 271 additions and 255 deletions
|
@ -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}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#nullable disable
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace NadekoBot.Common;
|
||||
namespace Nadeko.Common;
|
||||
|
||||
public class AsyncLazy<T> : Lazy<Task<T>>
|
||||
{
|
|
@ -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<T> : IReadOnlyCollection<T>, ICollection<T>
|
||||
public sealed class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ICollection<T> where T : notnull
|
||||
{
|
||||
private readonly ConcurrentDictionary<T, bool> _backingStore;
|
||||
|
|
@ -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<T> : IList<T>
|
||||
where T : class, IIndexed
|
|
@ -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<TIn, TOut>(this TIn[] arr, Func<TIn, TOut> f)
|
||||
=> Array.ConvertAll(arr, x => f(x));
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new array by applying the specified function to every element in the input array
|
||||
/// </summary>
|
||||
/// <param name="col">Array to modify</param>
|
||||
/// <param name="f">Function to apply</param>
|
||||
/// <typeparam name="TIn">Orignal type of the elements in the array</typeparam>
|
||||
/// <typeparam name="TOut">Output type of the elements of the array</typeparam>
|
||||
/// <returns>New array with updated elements</returns>
|
||||
public static TOut[] Map<TIn, TOut>(this IReadOnlyCollection<TIn> col, Func<TIn, TOut> f)
|
||||
{
|
||||
var toReturn = new TOut[col.Count];
|
|
@ -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
|
||||
{
|
35
src/Nadeko.Common/Extensions/HttpClientExtensions.cs
Normal file
35
src/Nadeko.Common/Extensions/HttpClientExtensions.cs
Normal file
|
@ -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;
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
namespace NadekoBot.Extensions;
|
||||
|
||||
namespace Nadeko.Common;
|
||||
|
||||
public delegate TOut PipeFunc<TIn, out TOut>(in TIn a);
|
||||
public delegate TOut PipeFunc<TIn1, TIn2, out TOut>(in TIn1 a, in TIn2 b);
|
1
src/Nadeko.Common/GlobalUsings.cs
Normal file
1
src/Nadeko.Common/GlobalUsings.cs
Normal file
|
@ -0,0 +1 @@
|
|||
global using NonBlocking;
|
|
@ -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
|
||||
{
|
|
@ -1,5 +1,4 @@
|
|||
#nullable disable
|
||||
namespace NadekoBot.Services;
|
||||
namespace Nadeko.Common;
|
||||
|
||||
public static class StandardConversions
|
||||
{
|
|
@ -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<kwum>
|
|||
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)
|
15
src/Nadeko.Common/Nadeko.Common.csproj
Normal file
15
src/Nadeko.Common/Nadeko.Common.csproj
Normal file
|
@ -0,0 +1,15 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NonBlocking" Version="2.0.0" />
|
||||
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.1" />
|
||||
<PackageReference Include="Serilog.Sinks.Seq" Version="5.1.1" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -1,6 +1,7 @@
|
|||
using System.Threading.Channels;
|
||||
using Serilog;
|
||||
|
||||
namespace NadekoBot.Common;
|
||||
namespace Nadeko.Common;
|
||||
|
||||
public sealed class QueueRunner
|
||||
{
|
|
@ -1,14 +1,11 @@
|
|||
#nullable disable
|
||||
using System;
|
||||
namespace Nadeko.Common;
|
||||
|
||||
namespace NadekoBot.Common;
|
||||
|
||||
public struct ShmartNumber : IEquatable<ShmartNumber>
|
||||
public readonly struct ShmartNumber : IEquatable<ShmartNumber>
|
||||
{
|
||||
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<ShmartNumber>
|
|||
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);
|
|
@ -1,4 +1,4 @@
|
|||
using NadekoBot.Common.Collections;
|
||||
using Nadeko.Common;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Nadeko.Common\Nadeko.Common.csproj" />
|
||||
<ProjectReference Include="..\NadekoBot\NadekoBot.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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; }
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
#nullable disable
|
||||
using System.Text.RegularExpressions;
|
||||
using Nadeko.Common;
|
||||
|
||||
namespace NadekoBot.Common;
|
||||
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
#nullable disable
|
||||
using Nadeko.Common;
|
||||
|
||||
namespace NadekoBot.Common.TypeReaders;
|
||||
|
||||
public sealed class KwumTypeReader : NadekoTypeReader<kwum>
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#nullable disable
|
||||
using NadekoBot.Common.Collections;
|
||||
using NadekoBot.Db.Models;
|
||||
|
||||
namespace NadekoBot.Services.Database.Models;
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
#nullable disable
|
||||
using NadekoBot.Common.Collections;
|
||||
|
||||
namespace NadekoBot.Services.Database.Models;
|
||||
|
||||
public class Poll : DbEntity
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#nullable disable
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Nadeko.Common;
|
||||
using NadekoBot.Db;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#nullable disable
|
||||
using Nadeko.Common;
|
||||
using NadekoBot.Modules.Administration.Services;
|
||||
|
||||
namespace NadekoBot.Modules.Administration;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#nullable disable
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Nadeko.Common;
|
||||
using NadekoBot.Db;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#nullable disable
|
||||
using Nadeko.Common;
|
||||
using NadekoBot.Common.TypeReaders;
|
||||
using NadekoBot.Modules.Administration.Services;
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#nullable disable
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Nadeko.Common;
|
||||
using NadekoBot.Common.ModuleBehaviors;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
#nullable disable
|
||||
using Nadeko.Common;
|
||||
|
||||
namespace NadekoBot.Modules.Administration.Services;
|
||||
|
||||
public class PruneService : INService
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#nullable disable
|
||||
using Nadeko.Common;
|
||||
using NadekoBot.Db;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#nullable disable
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Nadeko.Common;
|
||||
using NadekoBot.Db;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#nullable disable
|
||||
using Nadeko.Common;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
|
||||
namespace NadekoBot.Modules.NadekoExpressions;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#nullable disable
|
||||
|
||||
using Nadeko.Common;
|
||||
|
||||
namespace NadekoBot.Modules.NadekoExpressions;
|
||||
|
||||
[Name("Expressions")]
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#nullable disable
|
||||
using Nadeko.Common;
|
||||
using NadekoBot.Modules.Gambling.Common.AnimalRacing.Exceptions;
|
||||
using NadekoBot.Modules.Games.Common;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#nullable disable
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using System.Collections.Concurrent;
|
||||
using Nadeko.Common;
|
||||
|
||||
namespace NadekoBot.Modules.Gambling.Common.Events;
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#nullable disable
|
||||
using Nadeko.Common;
|
||||
using NadekoBot.Modules.Gambling.Common;
|
||||
using NadekoBot.Modules.Gambling.Services;
|
||||
using SixLabors.ImageSharp;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#nullable disable
|
||||
using Nadeko.Common;
|
||||
using NadekoBot.Modules.Gambling.Common;
|
||||
using NadekoBot.Modules.Gambling.Services;
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#nullable disable
|
||||
using Nadeko.Common;
|
||||
using NadekoBot.Modules.Gambling.Common;
|
||||
using NadekoBot.Modules.Gambling.Services;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
#nullable disable
|
||||
using Nadeko.Common;
|
||||
|
||||
namespace NadekoBot.Modules.Gambling.Common;
|
||||
|
||||
public class Deck
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#nullable disable
|
||||
using Nadeko.Common;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
using Image = SixLabors.ImageSharp.Image;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
using Nadeko.Common;
|
||||
using NadekoBot.Modules.Games.Hangman;
|
||||
|
||||
namespace NadekoBot.Modules.Games;
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#nullable disable
|
||||
using NadekoBot.Common.Collections;
|
||||
using NadekoBot.Common.ModuleBehaviors;
|
||||
using NadekoBot.Db;
|
||||
using NadekoBot.Modules.Games.Common;
|
||||
|
|
33
src/NadekoBot/Modules/Games/Trivia/DefaultQuestionPool.cs
Normal file
33
src/NadekoBot/Modules/Games/Trivia/DefaultQuestionPool.cs
Normal file
|
@ -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<TriviaQuestion?> GetRandomQuestionAsync(ISet<TriviaQuestion> 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;
|
||||
}
|
||||
}
|
6
src/NadekoBot/Modules/Games/Trivia/IQuestionPool.cs
Normal file
6
src/NadekoBot/Modules/Games/Trivia/IQuestionPool.cs
Normal file
|
@ -0,0 +1,6 @@
|
|||
namespace NadekoBot.Modules.Games.Common.Trivia;
|
||||
|
||||
public interface IQuestionPool
|
||||
{
|
||||
Task<TriviaQuestion?> GetRandomQuestionAsync(ISet<TriviaQuestion> exclude);
|
||||
}
|
32
src/NadekoBot/Modules/Games/Trivia/PokemonQuestionPool.cs
Normal file
32
src/NadekoBot/Modules/Games/Trivia/PokemonQuestionPool.cs
Normal file
|
@ -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<TriviaQuestion?> GetRandomQuestionAsync(ISet<TriviaQuestion> 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"
|
||||
});
|
||||
}
|
||||
}
|
|
@ -234,8 +234,8 @@ public class TriviaGame
|
|||
|
||||
if (!guess)
|
||||
return;
|
||||
triviaCancelSource.Cancel();
|
||||
|
||||
triviaCancelSource.Cancel();
|
||||
|
||||
if (_options.WinRequirement != 0 && Users[guildUser] == _options.WinRequirement)
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#nullable disable
|
||||
using CommandLine;
|
||||
using Nadeko.Common;
|
||||
using Nadeko.Medusa;
|
||||
using NadekoBot.Common.ModuleBehaviors;
|
||||
using NadekoBot.Modules.Administration.Services;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using Nadeko.Medusa;
|
||||
using Nadeko.Common;
|
||||
using Nadeko.Medusa;
|
||||
|
||||
namespace NadekoBot.Modules;
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#nullable disable
|
||||
using Nadeko.Common;
|
||||
using NadekoBot.Modules.Music.Services;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using NadekoBot.Db;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Nadeko.Common;
|
||||
|
||||
namespace NadekoBot.Modules.Music.Services;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using Nadeko.Common;
|
||||
|
||||
namespace NadekoBot.Modules.Music.Resolvers;
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using Newtonsoft.Json.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text.RegularExpressions;
|
||||
using Nadeko.Common;
|
||||
|
||||
namespace NadekoBot.Modules.Music.Resolvers;
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#nullable disable
|
||||
using Nadeko.Common;
|
||||
using NadekoBot.Modules.Searches.Common;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#nullable disable
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Nadeko.Common;
|
||||
|
||||
namespace NadekoBot.Modules.Nsfw.Common;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
namespace NadekoBot.Modules.Nsfw;
|
||||
#nullable disable warnings
|
||||
namespace NadekoBot.Modules.Nsfw;
|
||||
|
||||
public record UrlReply
|
||||
{
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#nullable disable
|
||||
using System.Net.Http.Json;
|
||||
using Nadeko.Common;
|
||||
|
||||
namespace NadekoBot.Modules.Nsfw.Common;
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#nullable disable
|
||||
using System.Net.Http.Json;
|
||||
using Nadeko.Common;
|
||||
|
||||
namespace NadekoBot.Modules.Nsfw.Common;
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#nullable disable
|
||||
using System.Net.Http.Json;
|
||||
using Nadeko.Common;
|
||||
|
||||
namespace NadekoBot.Modules.Nsfw.Common;
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#nullable disable
|
||||
using System.Text.Json;
|
||||
using Nadeko.Common;
|
||||
|
||||
namespace NadekoBot.Modules.Nsfw.Common;
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#nullable disable
|
||||
using Nadeko.Common;
|
||||
using NadekoBot.Modules.Permissions.Services;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
#nullable disable
|
||||
using NadekoBot.Common.Collections;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
|
||||
namespace NadekoBot.Modules.Permissions.Common;
|
||||
|
||||
public class PermissionsCollection<T> : IndexedCollection<T>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#nullable disable
|
||||
using AngleSharp;
|
||||
using AngleSharp.Html.Dom;
|
||||
using Nadeko.Common;
|
||||
using NadekoBot.Modules.Searches.Services;
|
||||
|
||||
namespace NadekoBot.Modules.Searches;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#nullable disable
|
||||
using Nadeko.Common;
|
||||
using NadekoBot.Modules.Searches.Common;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
using StackExchange.Redis;
|
||||
using System.Net.Http.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Nadeko.Common;
|
||||
|
||||
namespace NadekoBot.Modules.Searches;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#nullable disable
|
||||
using Html2Markdown;
|
||||
using Nadeko.Common;
|
||||
using NadekoBot.Modules.Searches.Common;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using NadekoBot.Db.Models;
|
||||
using System.Text.RegularExpressions;
|
||||
using Nadeko.Common;
|
||||
using TwitchLib.Api;
|
||||
using JsonSerializer = System.Text.Json.JsonSerializer;
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#nullable disable
|
||||
using NadekoBot.Modules.Utility.Patronage;
|
||||
using System.Text;
|
||||
using Nadeko.Common;
|
||||
|
||||
namespace NadekoBot.Modules.Utility;
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#nullable disable warnings
|
||||
using Nadeko.Common;
|
||||
using NadekoBot.Common.Yml;
|
||||
using NadekoBot.Db;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using LinqToDB;
|
||||
using LinqToDB.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Nadeko.Common;
|
||||
using NadekoBot.Common.ModuleBehaviors;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
using LinqToDB;
|
||||
using LinqToDB.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Nadeko.Common;
|
||||
using NadekoBot.Db;
|
||||
using NadekoBot.Db.Models;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue