Global usings and file scoped namespaces

This commit is contained in:
Kwoth
2021-12-19 05:14:11 +01:00
parent bc31dae965
commit ee33313519
548 changed files with 47528 additions and 49115 deletions

View File

@@ -3,6 +3,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<LangVersion>10.0</LangVersion> <LangVersion>10.0</LangVersion>
<EnablePreviewFeatures>True</EnablePreviewFeatures>
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
</PropertyGroup> </PropertyGroup>

View File

@@ -6,11 +6,8 @@ using NadekoBot.Common;
using NadekoBot.Services; using NadekoBot.Services;
using NadekoBot.Services.Database.Models; using NadekoBot.Services.Database.Models;
using NadekoBot.Extensions; using NadekoBot.Extensions;
using System;
using System.Collections.Generic;
using System.Collections.Immutable; using System.Collections.Immutable;
using System.Diagnostics; using System.Diagnostics;
using System.Linq;
using System.Net.Http; using System.Net.Http;
using System.Reflection; using System.Reflection;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -19,13 +16,11 @@ using NadekoBot.Common.ModuleBehaviors;
using NadekoBot.Common.Configs; using NadekoBot.Common.Configs;
using NadekoBot.Db; using NadekoBot.Db;
using NadekoBot.Modules.Administration.Services; using NadekoBot.Modules.Administration.Services;
using NadekoBot.Modules.Searches;
using Serilog;
namespace NadekoBot namespace NadekoBot;
public sealed class Bot
{ {
public sealed class Bot
{
private readonly IBotCredentials _creds; private readonly IBotCredentials _creds;
private readonly CommandService _commandService; private readonly CommandService _commandService;
private readonly DbService _db; private readonly DbService _db;
@@ -361,5 +356,4 @@ namespace NadekoBot
await RunAsync().ConfigureAwait(false); await RunAsync().ConfigureAwait(false);
await Task.Delay(-1).ConfigureAwait(false); await Task.Delay(-1).ConfigureAwait(false);
} }
}
} }

View File

@@ -1,11 +1,10 @@
using System; using System.Runtime.CompilerServices;
using System.Runtime.CompilerServices;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace NadekoBot.Common namespace NadekoBot.Common;
public class AsyncLazy<T> : Lazy<Task<T>>
{ {
public class AsyncLazy<T> : Lazy<Task<T>>
{
public AsyncLazy(Func<T> valueFactory) : public AsyncLazy(Func<T> valueFactory) :
base(() => Task.Run(valueFactory)) base(() => Task.Run(valueFactory))
{ } { }
@@ -15,6 +14,4 @@ namespace NadekoBot.Common
{ } { }
public TaskAwaiter<T> GetAwaiter() { return Value.GetAwaiter(); } public TaskAwaiter<T> GetAwaiter() { return Value.GetAwaiter(); }
}
} }

View File

@@ -1,18 +1,13 @@
using System; using System.Runtime.CompilerServices;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using Discord.Commands; using Discord.Commands;
using NadekoBot.Services;
namespace NadekoBot.Common.Attributes namespace NadekoBot.Common.Attributes;
[AttributeUsage(AttributeTargets.Method)]
public sealed class AliasesAttribute : AliasAttribute
{ {
[AttributeUsage(AttributeTargets.Method)]
public sealed class AliasesAttribute : AliasAttribute
{
public AliasesAttribute([CallerMemberName] string memberName = "") public AliasesAttribute([CallerMemberName] string memberName = "")
: base(CommandNameLoadHelper.GetAliasesFor(memberName)) : base(CommandNameLoadHelper.GetAliasesFor(memberName))
{ {
} }
}
} }

View File

@@ -1,9 +1,9 @@
using Discord.Commands; using Discord.Commands;
namespace Discord namespace Discord;
public class BotPermAttribute : RequireBotPermissionAttribute
{ {
public class BotPermAttribute : RequireBotPermissionAttribute
{
public BotPermAttribute(GuildPerm permission) : base((GuildPermission)permission) public BotPermAttribute(GuildPerm permission) : base((GuildPermission)permission)
{ {
} }
@@ -11,5 +11,4 @@ namespace Discord
public BotPermAttribute(ChannelPerm permission) : base((ChannelPermission)permission) public BotPermAttribute(ChannelPerm permission) : base((ChannelPermission)permission)
{ {
} }
}
} }

View File

@@ -1,12 +1,9 @@
using System; using System.IO;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace NadekoBot.Common.Attributes namespace NadekoBot.Common.Attributes;
public static class CommandNameLoadHelper
{ {
public static class CommandNameLoadHelper
{
private static YamlDotNet.Serialization.IDeserializer _deserializer private static YamlDotNet.Serialization.IDeserializer _deserializer
= new YamlDotNet.Serialization.Deserializer(); = new YamlDotNet.Serialization.Deserializer();
@@ -32,5 +29,4 @@ namespace NadekoBot.Common.Attributes
: methodName; : methodName;
return toReturn; return toReturn;
} }
}
} }

View File

@@ -1,16 +1,12 @@
using System; using Discord.Commands;
using System.Runtime.CompilerServices;
using Discord.Commands;
using NadekoBot.Services;
namespace NadekoBot.Common.Attributes namespace NadekoBot.Common.Attributes;
[AttributeUsage(AttributeTargets.Method)]
public sealed class DescriptionAttribute : SummaryAttribute
{ {
[AttributeUsage(AttributeTargets.Method)]
public sealed class DescriptionAttribute : SummaryAttribute
{
// Localization.LoadCommand(memberName.ToLowerInvariant()).Desc // Localization.LoadCommand(memberName.ToLowerInvariant()).Desc
public DescriptionAttribute(string text = "") : base(text) public DescriptionAttribute(string text = "") : base(text)
{ {
} }
}
} }

View File

@@ -1,9 +1,8 @@
namespace Discord.Commands namespace Discord.Commands;
public class LeftoverAttribute : RemainderAttribute
{ {
public class LeftoverAttribute : RemainderAttribute
{
public LeftoverAttribute() public LeftoverAttribute()
{ {
} }
}
} }

View File

@@ -1,13 +1,11 @@
using System; using System.Runtime.CompilerServices;
using System.Runtime.CompilerServices;
using Discord.Commands; using Discord.Commands;
using NadekoBot.Services;
namespace NadekoBot.Common.Attributes namespace NadekoBot.Common.Attributes;
[AttributeUsage(AttributeTargets.Method)]
public sealed class NadekoCommandAttribute : CommandAttribute
{ {
[AttributeUsage(AttributeTargets.Method)]
public sealed class NadekoCommandAttribute : CommandAttribute
{
public NadekoCommandAttribute([CallerMemberName] string memberName="") public NadekoCommandAttribute([CallerMemberName] string memberName="")
: base(CommandNameLoadHelper.GetCommandNameFor(memberName)) : base(CommandNameLoadHelper.GetCommandNameFor(memberName))
{ {
@@ -15,5 +13,4 @@ namespace NadekoBot.Common.Attributes
} }
public string MethodName { get; } public string MethodName { get; }
}
} }

View File

@@ -1,14 +1,11 @@
using System; using Discord.Commands;
using Discord.Commands;
namespace NadekoBot.Common.Attributes namespace NadekoBot.Common.Attributes;
[AttributeUsage(AttributeTargets.Class)]
sealed class NadekoModuleAttribute : GroupAttribute
{ {
[AttributeUsage(AttributeTargets.Class)]
sealed class NadekoModuleAttribute : GroupAttribute
{
public NadekoModuleAttribute(string moduleName) : base(moduleName) public NadekoModuleAttribute(string moduleName) : base(moduleName)
{ {
} }
}
} }

View File

@@ -1,15 +1,12 @@
using System; namespace NadekoBot.Common.Attributes;
namespace NadekoBot.Common.Attributes [AttributeUsage(AttributeTargets.Method)]
public sealed class NadekoOptionsAttribute : Attribute
{ {
[AttributeUsage(AttributeTargets.Method)]
public sealed class NadekoOptionsAttribute : Attribute
{
public Type OptionType { get; set; } public Type OptionType { get; set; }
public NadekoOptionsAttribute(Type t) public NadekoOptionsAttribute(Type t)
{ {
this.OptionType = t; this.OptionType = t;
} }
}
} }

View File

@@ -1,20 +1,18 @@
using System; using System.Threading.Tasks;
using System.Threading.Tasks;
using Discord.Commands; using Discord.Commands;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using NadekoBot.Extensions; using NadekoBot.Extensions;
using NadekoBot.Services; using NadekoBot.Services;
namespace NadekoBot.Common.Attributes namespace NadekoBot.Common.Attributes;
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)]
public sealed class OwnerOnlyAttribute : PreconditionAttribute
{ {
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)]
public sealed class OwnerOnlyAttribute : PreconditionAttribute
{
public override Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo executingCommand, IServiceProvider services) public override Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo executingCommand, IServiceProvider services)
{ {
var creds = services.GetRequiredService<IBotCredsProvider>().GetCreds(); var creds = services.GetRequiredService<IBotCredsProvider>().GetCreds();
return Task.FromResult((creds.IsOwner(context.User) || context.Client.CurrentUser.Id == context.User.Id ? PreconditionResult.FromSuccess() : PreconditionResult.FromError("Not owner"))); return Task.FromResult((creds.IsOwner(context.User) || context.Client.CurrentUser.Id == context.User.Id ? PreconditionResult.FromSuccess() : PreconditionResult.FromError("Not owner")));
} }
}
} }

View File

@@ -1,14 +1,13 @@
using Discord.Commands; using Discord.Commands;
using NadekoBot.Services; using NadekoBot.Services;
using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
namespace NadekoBot.Common.Attributes namespace NadekoBot.Common.Attributes;
[AttributeUsage(AttributeTargets.Method)]
public sealed class RatelimitAttribute : PreconditionAttribute
{ {
[AttributeUsage(AttributeTargets.Method)]
public sealed class RatelimitAttribute : PreconditionAttribute
{
public int Seconds { get; } public int Seconds { get; }
public RatelimitAttribute(int seconds) public RatelimitAttribute(int seconds)
@@ -34,5 +33,4 @@ namespace NadekoBot.Common.Attributes
return Task.FromResult(PreconditionResult.FromError(msgContent)); return Task.FromResult(PreconditionResult.FromError(msgContent));
} }
}
} }

View File

@@ -1,14 +1,10 @@
using System; using Discord.Commands;
using System.Runtime.CompilerServices;
using Discord.Commands;
using NadekoBot.Services;
using Newtonsoft.Json;
namespace NadekoBot.Common.Attributes namespace NadekoBot.Common.Attributes;
[AttributeUsage(AttributeTargets.Method)]
public sealed class UsageAttribute : RemarksAttribute
{ {
[AttributeUsage(AttributeTargets.Method)]
public sealed class UsageAttribute : RemarksAttribute
{
// public static string GetUsage(string memberName) // public static string GetUsage(string memberName)
// { // {
// var usage = Localization.LoadCommand(memberName.ToLowerInvariant()).Usage; // var usage = Localization.LoadCommand(memberName.ToLowerInvariant()).Usage;
@@ -17,5 +13,4 @@ namespace NadekoBot.Common.Attributes
public UsageAttribute(string text = "") : base(text) public UsageAttribute(string text = "") : base(text)
{ {
} }
}
} }

View File

@@ -1,14 +1,13 @@
using System; using System.Threading.Tasks;
using System.Threading.Tasks;
using Discord.Commands; using Discord.Commands;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using NadekoBot.Modules.Administration.Services; using NadekoBot.Modules.Administration.Services;
namespace Discord namespace Discord;
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class UserPermAttribute : PreconditionAttribute
{ {
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class UserPermAttribute : PreconditionAttribute
{
public RequireUserPermissionAttribute UserPermissionAttribute { get; } public RequireUserPermissionAttribute UserPermissionAttribute { get; }
public UserPermAttribute(GuildPerm permission) public UserPermAttribute(GuildPerm permission)
@@ -29,5 +28,4 @@ namespace Discord
return UserPermissionAttribute.CheckPermissionsAsync(context, command, services); return UserPermissionAttribute.CheckPermissionsAsync(context, command, services);
} }
}
} }

View File

@@ -1,9 +1,9 @@
using Newtonsoft.Json; using Newtonsoft.Json;
namespace NadekoBot.Common namespace NadekoBot.Common;
public class CmdStrings
{ {
public class CmdStrings
{
public string[] Usages { get; } public string[] Usages { get; }
public string Description { get; } public string Description { get; }
@@ -16,5 +16,4 @@ namespace NadekoBot.Common
Usages = usages; Usages = usages;
Description = description; Description = description;
} }
}
} }

View File

@@ -1,26 +1,23 @@
// License MIT // License MIT
// Source: https://github.com/i3arnon/ConcurrentHashSet // Source: https://github.com/i3arnon/ConcurrentHashSet
using System;
using System.Collections; using System.Collections;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq;
using System.Threading; using System.Threading;
namespace NadekoBot.Common.Collections namespace NadekoBot.Common.Collections;
/// <summary>
/// Represents a thread-safe hash-based unique collection.
/// </summary>
/// <typeparam name="T">The type of the items in the collection.</typeparam>
/// <remarks>
/// All public members of <see cref="ConcurrentHashSet{T}"/> are thread-safe and may be used
/// concurrently from multiple threads.
/// </remarks>
[DebuggerDisplay("Count = {Count}")]
public sealed class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ICollection<T>
{ {
/// <summary>
/// Represents a thread-safe hash-based unique collection.
/// </summary>
/// <typeparam name="T">The type of the items in the collection.</typeparam>
/// <remarks>
/// All public members of <see cref="ConcurrentHashSet{T}"/> are thread-safe and may be used
/// concurrently from multiple threads.
/// </remarks>
[DebuggerDisplay("Count = {Count}")]
public sealed class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ICollection<T>
{
private const int DefaultCapacity = 31; private const int DefaultCapacity = 31;
private const int MaxLockNumber = 1024; private const int MaxLockNumber = 1024;
@@ -768,5 +765,4 @@ namespace NadekoBot.Common.Collections
Next = next; Next = next;
} }
} }
}
} }

View File

@@ -1,25 +1,23 @@
using System; using System.Collections;
using System.Collections;
using System.Collections.Generic;
namespace NadekoBot.Common.Collections namespace NadekoBot.Common.Collections;
public static class DisposableReadOnlyListExtensions
{ {
public static class DisposableReadOnlyListExtensions
{
public static IDisposableReadOnlyList<T> AsDisposable<T>(this IReadOnlyList<T> arr) where T : IDisposable public static IDisposableReadOnlyList<T> AsDisposable<T>(this IReadOnlyList<T> arr) where T : IDisposable
=> new DisposableReadOnlyList<T>(arr); => new DisposableReadOnlyList<T>(arr);
public static IDisposableReadOnlyList<KeyValuePair<TKey, TValue>> AsDisposable<TKey, TValue>(this IReadOnlyList<KeyValuePair<TKey, TValue>> arr) where TValue : IDisposable public static IDisposableReadOnlyList<KeyValuePair<TKey, TValue>> AsDisposable<TKey, TValue>(this IReadOnlyList<KeyValuePair<TKey, TValue>> arr) where TValue : IDisposable
=> new DisposableReadOnlyList<TKey, TValue>(arr); => new DisposableReadOnlyList<TKey, TValue>(arr);
} }
public interface IDisposableReadOnlyList<T> : IReadOnlyList<T>, IDisposable public interface IDisposableReadOnlyList<T> : IReadOnlyList<T>, IDisposable
{ {
} }
public sealed class DisposableReadOnlyList<T> : IDisposableReadOnlyList<T> public sealed class DisposableReadOnlyList<T> : IDisposableReadOnlyList<T>
where T : IDisposable where T : IDisposable
{ {
private readonly IReadOnlyList<T> _arr; private readonly IReadOnlyList<T> _arr;
public int Count => _arr.Count; public int Count => _arr.Count;
@@ -44,11 +42,11 @@ namespace NadekoBot.Common.Collections
item.Dispose(); item.Dispose();
} }
} }
} }
public sealed class DisposableReadOnlyList<T, U> : IDisposableReadOnlyList<KeyValuePair<T, U>> public sealed class DisposableReadOnlyList<T, U> : IDisposableReadOnlyList<KeyValuePair<T, U>>
where U : IDisposable where U : IDisposable
{ {
private readonly IReadOnlyList<KeyValuePair<T, U>> _arr; private readonly IReadOnlyList<KeyValuePair<T, U>> _arr;
public int Count => _arr.Count; public int Count => _arr.Count;
@@ -73,5 +71,4 @@ namespace NadekoBot.Common.Collections
item.Value.Dispose(); item.Value.Dispose();
} }
} }
}
} }

View File

@@ -1,12 +1,10 @@
using System.Collections; using System.Collections;
using System.Collections.Generic;
using System.Linq;
using NadekoBot.Services.Database.Models; using NadekoBot.Services.Database.Models;
namespace NadekoBot.Common.Collections namespace NadekoBot.Common.Collections;
public class IndexedCollection<T> : IList<T> where T : class, IIndexed
{ {
public class IndexedCollection<T> : IList<T> where T : class, IIndexed
{
public List<T> Source { get; } public List<T> Source { get; }
private readonly object _locker = new object(); private readonly object _locker = new object();
@@ -137,5 +135,4 @@ namespace NadekoBot.Common.Collections
} }
} }
} }
}
} }

View File

@@ -1,9 +1,8 @@
namespace NadekoBot.Common namespace NadekoBot.Common;
public class CommandData
{ {
public class CommandData
{
public string Cmd { get; set; } public string Cmd { get; set; }
public string Desc { get; set; } public string Desc { get; set; }
public string[] Usage { get; set; } public string[] Usage { get; set; }
}
} }

View File

@@ -1,16 +1,15 @@
using System.Collections.Generic; using System.Globalization;
using System.Globalization;
using Cloneable; using Cloneable;
using NadekoBot.Common.Yml; using NadekoBot.Common.Yml;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using YamlDotNet.Core; using YamlDotNet.Core;
using YamlDotNet.Serialization; using YamlDotNet.Serialization;
namespace NadekoBot.Common.Configs namespace NadekoBot.Common.Configs;
[Cloneable]
public sealed partial class BotConfig : ICloneable<BotConfig>
{ {
[Cloneable]
public sealed partial class BotConfig : ICloneable<BotConfig>
{
[Comment(@"DO NOT CHANGE")] [Comment(@"DO NOT CHANGE")]
public int Version { get; set; } = 2; public int Version { get; set; } = 2;
@@ -140,11 +139,11 @@ See RotatingStatuses submodule in Administration.")]
"can you do" "can you do"
}; };
} }
} }
[Cloneable] [Cloneable]
public sealed partial class BlockedConfig public sealed partial class BlockedConfig
{ {
public HashSet<string> Commands { get; set; } public HashSet<string> Commands { get; set; }
public HashSet<string> Modules { get; set; } public HashSet<string> Modules { get; set; }
@@ -153,11 +152,11 @@ See RotatingStatuses submodule in Administration.")]
Modules = new HashSet<string>(); Modules = new HashSet<string>();
Commands = new HashSet<string>(); Commands = new HashSet<string>();
} }
} }
[Cloneable] [Cloneable]
public partial class ColorConfig public partial class ColorConfig
{ {
[Comment(@"Color used for embed responses when command successfully executes")] [Comment(@"Color used for embed responses when command successfully executes")]
public Rgba32 Ok { get; set; } public Rgba32 Ok { get; set; }
@@ -173,12 +172,11 @@ See RotatingStatuses submodule in Administration.")]
Error = Rgba32.ParseHex("ee281f"); Error = Rgba32.ParseHex("ee281f");
Pending = Rgba32.ParseHex("faa61a"); Pending = Rgba32.ParseHex("faa61a");
} }
} }
public enum ConsoleOutputType public enum ConsoleOutputType
{ {
Normal = 0, Normal = 0,
Simple = 1, Simple = 1,
None = 2, None = 2,
}
} }

View File

@@ -1,10 +1,10 @@
namespace NadekoBot.Common.Configs namespace NadekoBot.Common.Configs;
/// <summary>
/// Base interface for available config serializers
/// </summary>
public interface IConfigSeria
{ {
/// <summary>
/// Base interface for available config serializers
/// </summary>
public interface IConfigSeria
{
/// <summary> /// <summary>
/// Serialize the object to string /// Serialize the object to string
/// </summary> /// </summary>
@@ -14,5 +14,4 @@
/// Deserialize string data into an object of the specified type /// Deserialize string data into an object of the specified type
/// </summary> /// </summary>
public T Deserialize<T>(string data); public T Deserialize<T>(string data);
}
} }

View File

@@ -1,11 +1,9 @@
using System.Collections.Generic; using NadekoBot.Common.Yml;
using NadekoBot.Common.Yml;
using YamlDotNet.Serialization;
namespace NadekoBot.Common namespace NadekoBot.Common;
public sealed class Creds : IBotCredentials
{ {
public sealed class Creds : IBotCredentials
{
public Creds() public Creds()
{ {
Version = 1; Version = 1;
@@ -215,5 +213,4 @@ This should be equivalent to the DiscordsKey in your NadekoBot.Votes api appsett
public string Args { get; set; } public string Args { get; set; }
} }
} }
}
} }

View File

@@ -1,14 +1,13 @@
using NadekoBot.Services; using NadekoBot.Services;
using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord; using Discord;
namespace NadekoBot.Common namespace NadekoBot.Common;
public class DownloadTracker : INService
{ {
public class DownloadTracker : INService
{
private ConcurrentDictionary<ulong, DateTime> LastDownloads { get; } = new ConcurrentDictionary<ulong, DateTime>(); private ConcurrentDictionary<ulong, DateTime> LastDownloads { get; } = new ConcurrentDictionary<ulong, DateTime>();
private SemaphoreSlim downloadUsersSemaphore = new SemaphoreSlim(1, 1); private SemaphoreSlim downloadUsersSemaphore = new SemaphoreSlim(1, 1);
@@ -39,5 +38,4 @@ namespace NadekoBot.Common
downloadUsersSemaphore.Release(); downloadUsersSemaphore.Release();
} }
} }
}
} }

View File

@@ -1,11 +1,9 @@
using Discord; using Discord;
using NadekoBot.Common;
namespace NadekoBot.Extensions namespace NadekoBot.Extensions;
public static class BotCredentialsExtensions
{ {
public static class BotCredentialsExtensions
{
public static bool IsOwner(this IBotCredentials creds, IUser user) public static bool IsOwner(this IBotCredentials creds, IUser user)
=> creds.OwnerIds.Contains(user.Id); => creds.OwnerIds.Contains(user.Id);
}
} }

View File

@@ -1,19 +1,16 @@
using System; using System.Reflection;
using System.Linq;
using System.Reflection;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using NadekoBot.Common; using NadekoBot.Common;
using NadekoBot.Modules.Music; using NadekoBot.Modules.Music;
using NadekoBot.Services; using NadekoBot.Services;
using NadekoBot.Modules.Administration.Services;
using NadekoBot.Modules.Music.Resolvers; using NadekoBot.Modules.Music.Resolvers;
using NadekoBot.Modules.Music.Services; using NadekoBot.Modules.Music.Services;
using StackExchange.Redis; using StackExchange.Redis;
namespace NadekoBot.Extensions namespace NadekoBot.Extensions;
public static class ServiceCollectionExtensions
{ {
public static class ServiceCollectionExtensions
{
public static IServiceCollection AddBotStringsServices(this IServiceCollection services, int totalShards) public static IServiceCollection AddBotStringsServices(this IServiceCollection services, int totalShards)
=> totalShards <= 1 => totalShards <= 1
? services ? services
@@ -77,5 +74,4 @@ namespace NadekoBot.Extensions
services.AddSingleton(ConnectionMultiplexer.Connect(conf)); services.AddSingleton(ConnectionMultiplexer.Connect(conf));
return services; return services;
} }
}
} }

View File

@@ -1,15 +1,11 @@
using System; namespace Discord;
// just a copy paste from discord.net in order to rename it, for compatibility iwth v3 which is gonna use custom lib
namespace Discord // Summary:
// Defines the available permissions for a channel.
[Flags]
public enum GuildPerm : ulong
{ {
// just a copy paste from discord.net in order to rename it, for compatibility iwth v3 which is gonna use custom lib
// Summary:
// Defines the available permissions for a channel.
[Flags]
public enum GuildPerm : ulong
{
// //
// Summary: // Summary:
// Allows creation of instant invites. // Allows creation of instant invites.
@@ -155,14 +151,14 @@ namespace Discord
// This permission requires the owner account to use two-factor authentication when // This permission requires the owner account to use two-factor authentication when
// used on a guild that has server-wide 2FA enabled. // used on a guild that has server-wide 2FA enabled.
ManageEmojis = 1073741824 ManageEmojis = 1073741824
} }
// //
// Summary: // Summary:
// Defines the available permissions for a channel. // Defines the available permissions for a channel.
[Flags] [Flags]
public enum ChannelPerm : ulong public enum ChannelPerm : ulong
{ {
// //
// Summary: // Summary:
// Allows creation of instant invites. // Allows creation of instant invites.
@@ -251,5 +247,4 @@ namespace Discord
// Summary: // Summary:
// Allows management and editing of webhooks. // Allows management and editing of webhooks.
ManageWebhooks = 536870912 ManageWebhooks = 536870912
}
} }

View File

@@ -1,9 +1,7 @@
using System; namespace NadekoBot.Common;
namespace NadekoBot.Common public static class Helpers
{ {
public static class Helpers
{
public static void ReadErrorAndExit(int exitCode) public static void ReadErrorAndExit(int exitCode)
{ {
if (!Console.IsInputRedirected) if (!Console.IsInputRedirected)
@@ -11,5 +9,4 @@ namespace NadekoBot.Common
Environment.Exit(exitCode); Environment.Exit(exitCode);
} }
}
} }

View File

@@ -1,13 +1,9 @@
using System.Collections.Generic; using NadekoBot.Common;
using Discord;
using System.Collections.Immutable;
using System.Linq;
using NadekoBot.Common;
namespace NadekoBot namespace NadekoBot;
public interface IBotCredentials
{ {
public interface IBotCredentials
{
string Token { get; } string Token { get; }
string GoogleApiKey { get; } string GoogleApiKey { get; }
ICollection<ulong> OwnerIds { get; } ICollection<ulong> OwnerIds { get; }
@@ -26,11 +22,10 @@ namespace NadekoBot
string TimezoneDbApiKey { get; } string TimezoneDbApiKey { get; }
string CoinmarketcapApiKey { get; } string CoinmarketcapApiKey { get; }
string CoordinatorUrl { get; set; } string CoordinatorUrl { get; set; }
} }
public class RestartConfig public class RestartConfig
{ {
public string Cmd { get; set; } public string Cmd { get; set; }
public string Args { get; set; } public string Args { get; set; }
}
} }

View File

@@ -1,7 +1,6 @@
namespace NadekoBot.Common namespace NadekoBot.Common;
public interface ICloneable<T> where T : new()
{ {
public interface ICloneable<T> where T : new()
{
public T Clone(); public T Clone();
}
} }

View File

@@ -1,9 +1,9 @@
using Discord; using Discord;
namespace NadekoBot namespace NadekoBot;
public interface IEmbedBuilder
{ {
public interface IEmbedBuilder
{
IEmbedBuilder WithDescription(string desc); IEmbedBuilder WithDescription(string desc);
IEmbedBuilder WithTitle(string title); IEmbedBuilder WithTitle(string title);
IEmbedBuilder AddField(string title, object value, bool isInline = false); IEmbedBuilder AddField(string title, object value, bool isInline = false);
@@ -14,12 +14,11 @@ namespace NadekoBot
IEmbedBuilder WithUrl(string url); IEmbedBuilder WithUrl(string url);
IEmbedBuilder WithImageUrl(string url); IEmbedBuilder WithImageUrl(string url);
IEmbedBuilder WithThumbnailUrl(string url); IEmbedBuilder WithThumbnailUrl(string url);
} }
public enum EmbedColor public enum EmbedColor
{ {
Ok, Ok,
Pending, Pending,
Error, Error,
}
} }

View File

@@ -1,7 +1,6 @@
namespace NadekoBot.Common namespace NadekoBot.Common;
public interface INadekoCommandOptions
{ {
public interface INadekoCommandOptions
{
void NormalizeOptions(); void NormalizeOptions();
}
} }

View File

@@ -1,10 +1,6 @@
using System; namespace NadekoBot.Common;
using System.Collections.Generic;
namespace NadekoBot.Common public interface IPlaceholderProvider
{ {
public interface IPlaceholderProvider
{
public IEnumerable<(string Name, Func<string> Func)> GetPlaceholders(); public IEnumerable<(string Name, Func<string> Func)> GetPlaceholders();
}
} }

View File

@@ -1,10 +1,9 @@
using System; using NadekoBot.Common.Yml;
using NadekoBot.Common.Yml;
namespace NadekoBot.Common namespace NadekoBot.Common;
public class ImageUrls
{ {
public class ImageUrls
{
[Comment("DO NOT CHANGE")] [Comment("DO NOT CHANGE")]
public int Version { get; set; } = 3; public int Version { get; set; } = 3;
@@ -46,5 +45,4 @@ namespace NadekoBot.Common
{ {
public Uri Bg { get; set; } public Uri Bg { get; set; }
} }
}
} }

View File

@@ -1,13 +1,12 @@
using System; using System.Globalization;
using System.Globalization;
using System.Text.Json; using System.Text.Json;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
namespace NadekoBot.Common.JsonConverters namespace NadekoBot.Common.JsonConverters;
public class Rgba32Converter : JsonConverter<Rgba32>
{ {
public class Rgba32Converter : JsonConverter<Rgba32>
{
public override Rgba32 Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) public override Rgba32 Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{ {
return Rgba32.ParseHex(reader.GetString()); return Rgba32.ParseHex(reader.GetString());
@@ -17,10 +16,10 @@ namespace NadekoBot.Common.JsonConverters
{ {
writer.WriteStringValue(value.ToHex()); writer.WriteStringValue(value.ToHex());
} }
} }
public class CultureInfoConverter : JsonConverter<CultureInfo> public class CultureInfoConverter : JsonConverter<CultureInfo>
{ {
public override CultureInfo Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) public override CultureInfo Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{ {
return new CultureInfo(reader.GetString()); return new CultureInfo(reader.GetString());
@@ -30,5 +29,4 @@ namespace NadekoBot.Common.JsonConverters
{ {
writer.WriteStringValue(value.Name); writer.WriteStringValue(value.Name);
} }
}
} }

View File

@@ -1,12 +1,11 @@
using System; using System.Runtime.CompilerServices;
using System.Runtime.CompilerServices;
namespace NadekoBot.Common namespace NadekoBot.Common;
// needs proper invalid input check (character array input out of range)
// needs negative number support
public readonly struct kwum : IEquatable<kwum>
{ {
// needs proper invalid input check (character array input out of range)
// needs negative number support
public readonly struct kwum : IEquatable<kwum>
{
private readonly int _value; private readonly int _value;
private const string ValidCharacters = "23456789abcdefghijkmnpqrstuvwxyz"; private const string ValidCharacters = "23456789abcdefghijkmnpqrstuvwxyz";
@@ -94,5 +93,4 @@ namespace NadekoBot.Common
{ {
return _value.GetHashCode(); return _value.GetHashCode();
} }
}
} }

View File

@@ -1,14 +1,13 @@
using CommandLine; using CommandLine;
namespace NadekoBot.Common namespace NadekoBot.Common;
public class LbOpts : INadekoCommandOptions
{ {
public class LbOpts : INadekoCommandOptions
{
[Option('c', "clean", Default = false, HelpText = "Only show users who are on the server.")] [Option('c', "clean", Default = false, HelpText = "Only show users who are on the server.")]
public bool Clean { get; set; } public bool Clean { get; set; }
public void NormalizeOptions() public void NormalizeOptions()
{ {
} }
}
} }

View File

@@ -1,13 +1,11 @@
using System; using System.Net;
using System.Net;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using Discord.Net; using Discord.Net;
using Serilog;
namespace NadekoBot.Common namespace NadekoBot.Common;
public class LoginErrorHandler
{ {
public class LoginErrorHandler
{
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Handle(Exception ex) public static void Handle(Exception ex)
{ {
@@ -53,5 +51,4 @@ namespace NadekoBot.Common
Log.Fatal(ex.ToString()); Log.Fatal(ex.ToString());
} }
}
} }

View File

@@ -1,14 +1,13 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord; using Discord;
namespace NadekoBot.Common.ModuleBehaviors namespace NadekoBot.Common.ModuleBehaviors;
/// <summary>
/// Implemented by modules which block execution before anything is executed
/// </summary>
public interface IEarlyBehavior
{ {
/// <summary>
/// Implemented by modules which block execution before anything is executed
/// </summary>
public interface IEarlyBehavior
{
int Priority { get; } int Priority { get; }
Task<bool> RunBehavior(IGuild guild, IUserMessage msg); Task<bool> RunBehavior(IGuild guild, IUserMessage msg);
}
} }

View File

@@ -1,10 +1,9 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord; using Discord;
namespace NadekoBot.Common.ModuleBehaviors namespace NadekoBot.Common.ModuleBehaviors;
public interface IInputTransformer
{ {
public interface IInputTransformer
{
Task<string> TransformInput(IGuild guild, IMessageChannel channel, IUser user, string input); Task<string> TransformInput(IGuild guild, IMessageChannel channel, IUser user, string input);
}
} }

View File

@@ -1,13 +1,11 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord.Commands; using Discord.Commands;
using Discord.WebSocket;
namespace NadekoBot.Common.ModuleBehaviors namespace NadekoBot.Common.ModuleBehaviors;
public interface ILateBlocker
{ {
public interface ILateBlocker
{
public int Priority { get; } public int Priority { get; }
Task<bool> TryBlockLate(ICommandContext context, string moduleName, CommandInfo command); Task<bool> TryBlockLate(ICommandContext context, string moduleName, CommandInfo command);
}
} }

View File

@@ -1,13 +1,12 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord; using Discord;
namespace NadekoBot.Common.ModuleBehaviors namespace NadekoBot.Common.ModuleBehaviors;
/// <summary>
/// Last thing to be executed, won't stop further executions
/// </summary>
public interface ILateExecutor
{ {
/// <summary>
/// Last thing to be executed, won't stop further executions
/// </summary>
public interface ILateExecutor
{
Task LateExecute(IGuild guild, IUserMessage msg); Task LateExecute(IGuild guild, IUserMessage msg);
}
} }

View File

@@ -2,10 +2,10 @@
using Discord.WebSocket; using Discord.WebSocket;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace NadekoBot.Common.ModuleBehaviors namespace NadekoBot.Common.ModuleBehaviors;
public struct ModuleBehaviorResult
{ {
public struct ModuleBehaviorResult
{
public bool Blocked { get; set; } public bool Blocked { get; set; }
public string NewInput { get; set; } public string NewInput { get; set; }
@@ -20,15 +20,14 @@ namespace NadekoBot.Common.ModuleBehaviors
Blocked = blocked, Blocked = blocked,
NewInput = null, NewInput = null,
}; };
} }
public interface IModuleBehavior public interface IModuleBehavior
{ {
/// <summary> /// <summary>
/// Negative priority means it will try to apply as early as possible /// Negative priority means it will try to apply as early as possible
/// Positive priority menas it will try to apply as late as possible /// Positive priority menas it will try to apply as late as possible
/// </summary> /// </summary>
int Priority { get; } int Priority { get; }
Task<ModuleBehaviorResult> ApplyBehavior(DiscordSocketClient client, IGuild guild, IUserMessage msg); Task<ModuleBehaviorResult> ApplyBehavior(DiscordSocketClient client, IGuild guild, IUserMessage msg);
}
} }

View File

@@ -1,16 +1,15 @@
using System.Threading.Tasks; using System.Threading.Tasks;
namespace NadekoBot.Common.ModuleBehaviors namespace NadekoBot.Common.ModuleBehaviors;
/// <summary>
/// All services which need to execute something after
/// the bot is ready should implement this interface
/// </summary>
public interface IReadyExecutor
{ {
/// <summary>
/// All services which need to execute something after
/// the bot is ready should implement this interface
/// </summary>
public interface IReadyExecutor
{
/// <summary> /// <summary>
/// Executed when bot is ready /// Executed when bot is ready
/// </summary> /// </summary>
public Task OnReadyAsync(); public Task OnReadyAsync();
}
} }

View File

@@ -6,10 +6,10 @@ using NadekoBot.Extensions;
using System.Globalization; using System.Globalization;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace NadekoBot.Modules namespace NadekoBot.Modules;
public abstract class NadekoModule : ModuleBase
{ {
public abstract class NadekoModule : ModuleBase
{
protected CultureInfo _cultureInfo { get; set; } protected CultureInfo _cultureInfo { get; set; }
public IBotStrings Strings { get; set; } public IBotStrings Strings { get; set; }
public CommandHandler CmdHandler { get; set; } public CommandHandler CmdHandler { get; set; }
@@ -132,26 +132,25 @@ namespace NadekoBot.Modules
return Task.CompletedTask; return Task.CompletedTask;
} }
} }
} }
public abstract class NadekoModule<TService> : NadekoModule public abstract class NadekoModule<TService> : NadekoModule
{ {
public TService _service { get; set; } public TService _service { get; set; }
protected NadekoModule() : base() protected NadekoModule() : base()
{ {
} }
} }
public abstract class NadekoSubmodule : NadekoModule public abstract class NadekoSubmodule : NadekoModule
{ {
protected NadekoSubmodule() : base() { } protected NadekoSubmodule() : base() { }
} }
public abstract class NadekoSubmodule<TService> : NadekoModule<TService> public abstract class NadekoSubmodule<TService> : NadekoModule<TService>
{ {
protected NadekoSubmodule() : base() protected NadekoSubmodule() : base()
{ {
} }
}
} }

View File

@@ -1,7 +1,6 @@
namespace NadekoBot.Modules namespace NadekoBot.Modules;
{
public static class NadekoModuleExtensions public static class NadekoModuleExtensions
{ {
}
} }

View File

@@ -1,10 +1,9 @@
using System; using System.Security.Cryptography;
using System.Security.Cryptography;
namespace NadekoBot.Common namespace NadekoBot.Common;
public class NadekoRandom : Random
{ {
public class NadekoRandom : Random
{
readonly RandomNumberGenerator _rng; readonly RandomNumberGenerator _rng;
public NadekoRandom() : base() public NadekoRandom() : base()
@@ -70,5 +69,4 @@ namespace NadekoBot.Common
_rng.GetBytes(bytes); _rng.GetBytes(bytes);
return BitConverter.ToDouble(bytes, 0); return BitConverter.ToDouble(bytes, 0);
} }
}
} }

View File

@@ -1,12 +1,11 @@
using System; using System.Threading.Tasks;
using System.Threading.Tasks;
using Discord.Commands; using Discord.Commands;
namespace NadekoBot.Common namespace NadekoBot.Common;
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)]
public sealed class NoPublicBotAttribute : PreconditionAttribute
{ {
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)]
public sealed class NoPublicBotAttribute : PreconditionAttribute
{
public override Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services) public override Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services)
{ {
#if GLOBAL_NADEKO #if GLOBAL_NADEKO
@@ -15,5 +14,4 @@ namespace NadekoBot.Common
return Task.FromResult(PreconditionResult.FromSuccess()); return Task.FromResult(PreconditionResult.FromSuccess());
#endif #endif
} }
}
} }

View File

@@ -1,9 +1,7 @@
using System; namespace NadekoBot.Common;
namespace NadekoBot.Common public class OldImageUrls
{ {
public class OldImageUrls
{
public int Version { get; set; } = 2; public int Version { get; set; } = 2;
public CoinData Coins { get; set; } public CoinData Coins { get; set; }
@@ -45,5 +43,4 @@ namespace NadekoBot.Common
{ {
public Uri Bg { get; set; } public Uri Bg { get; set; }
} }
}
} }

View File

@@ -1,9 +1,9 @@
using CommandLine; using CommandLine;
namespace NadekoBot.Common namespace NadekoBot.Common;
public static class OptionsParser
{ {
public static class OptionsParser
{
public static T ParseFrom<T>(string[] args) where T : INadekoCommandOptions, new() public static T ParseFrom<T>(string[] args) where T : INadekoCommandOptions, new()
=> ParseFrom(new T(), args).Item1; => ParseFrom(new T(), args).Item1;
@@ -20,5 +20,4 @@ namespace NadekoBot.Common
return (options, res.Tag == ParserResultType.Parsed); return (options, res.Tag == ParserResultType.Parsed);
} }
} }
}
} }

View File

@@ -1,9 +1,8 @@
namespace NadekoBot.Common namespace NadekoBot.Common;
public class OsuMapData
{ {
public class OsuMapData
{
public string Title { get; set; } public string Title { get; set; }
public string Artist { get; set; } public string Artist { get; set; }
public string Version { get; set; } public string Version { get; set; }
}
} }

View File

@@ -1,9 +1,9 @@
using Newtonsoft.Json; using Newtonsoft.Json;
namespace NadekoBot.Common namespace NadekoBot.Common;
public class OsuUserBests
{ {
public class OsuUserBests
{
[JsonProperty("beatmap_id")] public string BeatmapId { get; set; } [JsonProperty("beatmap_id")] public string BeatmapId { get; set; }
[JsonProperty("score_id")] public string ScoreId { get; set; } [JsonProperty("score_id")] public string ScoreId { get; set; }
@@ -37,5 +37,4 @@ namespace NadekoBot.Common
[JsonProperty("pp")] public double Pp { get; set; } [JsonProperty("pp")] public double Pp { get; set; }
[JsonProperty("replay_available")] public string ReplayAvailable { get; set; } [JsonProperty("replay_available")] public string ReplayAvailable { get; set; }
}
} }

View File

@@ -1,9 +1,7 @@
using System; namespace NadekoBot.Common;
namespace NadekoBot.Common public static class PlatformHelper
{ {
public static class PlatformHelper
{
private const int ProcessorCountRefreshIntervalMs = 30000; private const int ProcessorCountRefreshIntervalMs = 30000;
private static volatile int _processorCount; private static volatile int _processorCount;
@@ -21,5 +19,4 @@ namespace NadekoBot.Common
return _processorCount; return _processorCount;
} }
} }
}
} }

View File

@@ -1,8 +1,7 @@
namespace NadekoBot.Common.Pokemon namespace NadekoBot.Common.Pokemon;
public class PokemonNameId
{ {
public class PokemonNameId
{
public int Id { get; set; } public int Id { get; set; }
public string Name { get; set; } public string Name { get; set; }
}
} }

View File

@@ -1,10 +1,9 @@
using Newtonsoft.Json; using Newtonsoft.Json;
using System.Collections.Generic;
namespace NadekoBot.Common.Pokemon namespace NadekoBot.Common.Pokemon;
public class SearchPokemon
{ {
public class SearchPokemon
{
public class GenderRatioClass public class GenderRatioClass
{ {
public float M { get; set; } public float M { get; set; }
@@ -36,5 +35,4 @@ namespace NadekoBot.Common.Pokemon
public string Color { get; set; } public string Color { get; set; }
public string[] Evos { get; set; } public string[] Evos { get; set; }
public string[] EggGroups { get; set; } public string[] EggGroups { get; set; }
}
} }

View File

@@ -1,10 +1,9 @@
namespace NadekoBot.Common.Pokemon namespace NadekoBot.Common.Pokemon;
public class SearchPokemonAbility
{ {
public class SearchPokemonAbility
{
public string Desc { get; set; } public string Desc { get; set; }
public string ShortDesc { get; set; } public string ShortDesc { get; set; }
public string Name { get; set; } public string Name { get; set; }
public float Rating { get; set; } public float Rating { get; set; }
}
} }

View File

@@ -1,12 +1,9 @@
using System; using System.Threading.Tasks;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace NadekoBot.Common namespace NadekoBot.Common;
public class EventPubSub : IPubSub
{ {
public class EventPubSub : IPubSub
{
private readonly Dictionary<string, Dictionary<Delegate, List<Func<object, ValueTask>>>> _actions private readonly Dictionary<string, Dictionary<Delegate, List<Func<object, ValueTask>>>> _actions
= new Dictionary<string, Dictionary<Delegate, List<Func<object, ValueTask>>>>(); = new Dictionary<string, Dictionary<Delegate, List<Func<object, ValueTask>>>>();
private readonly object locker = new object(); private readonly object locker = new object();
@@ -90,6 +87,4 @@ namespace NadekoBot.Common
return Task.CompletedTask; return Task.CompletedTask;
} }
} }
}
} }

View File

@@ -1,11 +1,9 @@
using System; using System.Threading.Tasks;
using System.Threading.Tasks;
namespace NadekoBot.Common namespace NadekoBot.Common;
public interface IPubSub
{ {
public interface IPubSub
{
public Task Pub<TData>(in TypedKey<TData> key, TData data); public Task Pub<TData>(in TypedKey<TData> key, TData data);
public Task Sub<TData>(in TypedKey<TData> key, Func<TData, ValueTask> action); public Task Sub<TData>(in TypedKey<TData> key, Func<TData, ValueTask> action);
}
} }

View File

@@ -1,8 +1,7 @@
namespace NadekoBot.Common namespace NadekoBot.Common;
public interface ISeria
{ {
public interface ISeria
{
byte[] Serialize<T>(T data); byte[] Serialize<T>(T data);
T Deserialize<T>(byte[] data); T Deserialize<T>(byte[] data);
}
} }

View File

@@ -1,10 +1,10 @@
using System.Text.Json; using System.Text.Json;
using NadekoBot.Common.JsonConverters; using NadekoBot.Common.JsonConverters;
namespace NadekoBot.Common namespace NadekoBot.Common;
public class JsonSeria : ISeria
{ {
public class JsonSeria : ISeria
{
private JsonSerializerOptions serializerOptions = new JsonSerializerOptions() private JsonSerializerOptions serializerOptions = new JsonSerializerOptions()
{ {
Converters = Converters =
@@ -24,5 +24,4 @@ namespace NadekoBot.Common
return JsonSerializer.Deserialize<T>(data, serializerOptions); return JsonSerializer.Deserialize<T>(data, serializerOptions);
} }
}
} }

View File

@@ -1,14 +1,11 @@
using System; using System.Threading.Tasks;
using System.Threading.Tasks;
using NadekoBot.Services;
using NadekoBot.Extensions; using NadekoBot.Extensions;
using Serilog;
using StackExchange.Redis; using StackExchange.Redis;
namespace NadekoBot.Common namespace NadekoBot.Common;
public sealed class RedisPubSub : IPubSub
{ {
public sealed class RedisPubSub : IPubSub
{
private readonly ConnectionMultiplexer _multi; private readonly ConnectionMultiplexer _multi;
private readonly ISeria _serializer; private readonly ISeria _serializer;
private readonly IBotCredentials _creds; private readonly IBotCredentials _creds;
@@ -42,5 +39,4 @@ namespace NadekoBot.Common
} }
}); });
} }
}
} }

View File

@@ -1,7 +1,7 @@
namespace NadekoBot.Common namespace NadekoBot.Common;
public readonly struct TypedKey<TData>
{ {
public readonly struct TypedKey<TData>
{
public readonly string Key; public readonly string Key;
public TypedKey(in string key) public TypedKey(in string key)
@@ -25,5 +25,4 @@
public override int GetHashCode() => Key?.GetHashCode() ?? 0; public override int GetHashCode() => Key?.GetHashCode() ?? 0;
public override string ToString() => Key; public override string ToString() => Key;
}
} }

View File

@@ -3,10 +3,10 @@ using NadekoBot.Common.Yml;
using NadekoBot.Common.Configs; using NadekoBot.Common.Configs;
using YamlDotNet.Serialization; using YamlDotNet.Serialization;
namespace NadekoBot.Common namespace NadekoBot.Common;
public class YamlSeria : IConfigSeria
{ {
public class YamlSeria : IConfigSeria
{
private readonly ISerializer _serializer; private readonly ISerializer _serializer;
private readonly IDeserializer _deserializer; private readonly IDeserializer _deserializer;
@@ -34,5 +34,4 @@ namespace NadekoBot.Common
public T Deserialize<T>(string data) public T Deserialize<T>(string data)
=> _deserializer.Deserialize<T>(data); => _deserializer.Deserialize<T>(data);
}
} }

View File

@@ -3,18 +3,13 @@ using Discord.Commands;
using Discord.WebSocket; using Discord.WebSocket;
using NadekoBot.Extensions; using NadekoBot.Extensions;
using NadekoBot.Modules.Administration.Services; using NadekoBot.Modules.Administration.Services;
using NadekoBot.Modules.Music.Services;
using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using NadekoBot.Common;
namespace NadekoBot.Common.Replacements namespace NadekoBot.Common.Replacements;
public class ReplacementBuilder
{ {
public class ReplacementBuilder
{
private static readonly Regex rngRegex = new Regex("%rng(?:(?<from>(?:-)?\\d+)-(?<to>(?:-)?\\d+))?%", RegexOptions.Compiled); private static readonly Regex rngRegex = new Regex("%rng(?:(?<from>(?:-)?\\d+)-(?<to>(?:-)?\\d+))?%", RegexOptions.Compiled);
private ConcurrentDictionary<string, Func<string>> _reps = new ConcurrentDictionary<string, Func<string>>(); private ConcurrentDictionary<string, Func<string>> _reps = new ConcurrentDictionary<string, Func<string>>();
private ConcurrentDictionary<Regex, Func<Match, string>> _regex = new ConcurrentDictionary<Regex, Func<Match, string>>(); private ConcurrentDictionary<Regex, Func<Match, string>> _regex = new ConcurrentDictionary<Regex, Func<Match, string>>();
@@ -233,5 +228,4 @@ namespace NadekoBot.Common.Replacements
return this; return this;
} }
}
} }

View File

@@ -1,11 +1,9 @@
using System; using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Text.RegularExpressions;
namespace NadekoBot.Common.Replacements namespace NadekoBot.Common.Replacements;
public class Replacer
{ {
public class Replacer
{
private readonly IEnumerable<(string Key, Func<string> Text)> _replacements; private readonly IEnumerable<(string Key, Func<string> Text)> _replacements;
private readonly IEnumerable<(Regex Regex, Func<Match, string> Replacement)> _regex; private readonly IEnumerable<(Regex Regex, Func<Match, string> Replacement)> _regex;
@@ -87,5 +85,4 @@ namespace NadekoBot.Common.Replacements
return newEmbedData; return newEmbedData;
} }
}
} }

View File

@@ -1,16 +1,14 @@
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Serialization; using Newtonsoft.Json.Serialization;
using System;
namespace NadekoBot.Common namespace NadekoBot.Common;
public class RequireObjectPropertiesContractResolver : DefaultContractResolver
{ {
public class RequireObjectPropertiesContractResolver : DefaultContractResolver
{
protected override JsonObjectContract CreateObjectContract(Type objectType) protected override JsonObjectContract CreateObjectContract(Type objectType)
{ {
var contract = base.CreateObjectContract(objectType); var contract = base.CreateObjectContract(objectType);
contract.ItemRequired = Required.DisallowNull; contract.ItemRequired = Required.DisallowNull;
return contract; return contract;
} }
}
} }

View File

@@ -1,9 +1,7 @@
using System; namespace NadekoBot.Common;
namespace NadekoBot.Common public struct ShmartNumber : IEquatable<ShmartNumber>
{ {
public struct ShmartNumber : IEquatable<ShmartNumber>
{
public long Value { get; } public long Value { get; }
public string Input { get; } public string Input { get; }
@@ -59,5 +57,4 @@ namespace NadekoBot.Common
{ {
return !(left == right); return !(left == right);
} }
}
} }

View File

@@ -1,13 +1,10 @@
using System; using Discord;
using System.Linq;
using Discord;
using NadekoBot.Extensions; using NadekoBot.Extensions;
using NadekoBot.Services;
namespace NadekoBot namespace NadekoBot;
public sealed record SmartEmbedText : SmartText
{ {
public sealed record SmartEmbedText : SmartText
{
public string PlainText { get; set; } public string PlainText { get; set; }
public string Title { get; set; } public string Title { get; set; }
public string Description { get; set; } public string Description { get; set; }
@@ -134,5 +131,4 @@ namespace NadekoBot
} }
} }
} }
}
} }

View File

@@ -1,7 +1,7 @@
namespace NadekoBot namespace NadekoBot;
public sealed record SmartPlainText : SmartText
{ {
public sealed record SmartPlainText : SmartText
{
public string Text { get; init; } public string Text { get; init; }
public SmartPlainText(string text) public SmartPlainText(string text)
@@ -19,5 +19,4 @@
{ {
return Text; return Text;
} }
}
} }

View File

@@ -1,10 +1,9 @@
using System; using Newtonsoft.Json;
using Newtonsoft.Json;
namespace NadekoBot namespace NadekoBot;
public abstract record SmartText
{ {
public abstract record SmartText
{
public bool IsEmbed => this is SmartEmbedText; public bool IsEmbed => this is SmartEmbedText;
public bool IsPlainText => this is SmartPlainText; public bool IsPlainText => this is SmartPlainText;
@@ -49,5 +48,4 @@ namespace NadekoBot
return new SmartPlainText(input); return new SmartPlainText(input);
} }
} }
}
} }

View File

@@ -1,13 +1,12 @@
using Newtonsoft.Json; using Newtonsoft.Json;
namespace NadekoBot namespace NadekoBot;
public class SmartTextEmbedAuthor
{ {
public class SmartTextEmbedAuthor
{
public string Name { get; set; } public string Name { get; set; }
public string IconUrl { get; set; } public string IconUrl { get; set; }
[JsonProperty("icon_url")] [JsonProperty("icon_url")]
private string Icon_Url { set => IconUrl = value; } private string Icon_Url { set => IconUrl = value; }
public string Url { get; set; } public string Url { get; set; }
}
} }

View File

@@ -1,9 +1,8 @@
namespace NadekoBot namespace NadekoBot;
public class SmartTextEmbedField
{ {
public class SmartTextEmbedField
{
public string Name { get; set; } public string Name { get; set; }
public string Value { get; set; } public string Value { get; set; }
public bool Inline { get; set; } public bool Inline { get; set; }
}
} }

View File

@@ -1,12 +1,11 @@
using Newtonsoft.Json; using Newtonsoft.Json;
namespace NadekoBot namespace NadekoBot;
public class SmartTextEmbedFooter
{ {
public class SmartTextEmbedFooter
{
public string Text { get; set; } public string Text { get; set; }
public string IconUrl { get; set; } public string IconUrl { get; set; }
[JsonProperty("icon_url")] [JsonProperty("icon_url")]
private string Icon_Url { set => IconUrl = value; } private string Icon_Url { set => IconUrl = value; }
}
} }

View File

@@ -1,12 +1,11 @@
using Discord; using Discord;
using Discord.WebSocket; using Discord.WebSocket;
using System;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace NadekoBot.Common namespace NadekoBot.Common;
public sealed class ReactionEventWrapper : IDisposable
{ {
public sealed class ReactionEventWrapper : IDisposable
{
public IUserMessage Message { get; } public IUserMessage Message { get; }
public event Action<SocketReaction> OnReactionAdded = delegate { }; public event Action<SocketReaction> OnReactionAdded = delegate { };
public event Action<SocketReaction> OnReactionRemoved = delegate { }; public event Action<SocketReaction> OnReactionRemoved = delegate { };
@@ -87,5 +86,4 @@ namespace NadekoBot.Common
disposing = true; disposing = true;
UnsubAll(); UnsubAll();
} }
}
} }

View File

@@ -1,9 +1,8 @@
namespace NadekoBot.Common.TypeReaders namespace NadekoBot.Common.TypeReaders;
public enum AddRemove
{ {
public enum AddRemove
{
Add = int.MinValue, Add = int.MinValue,
Rem = int.MinValue + 1, Rem = int.MinValue + 1,
Rm = int.MinValue + 1, Rm = int.MinValue + 1,
}
} }

View File

@@ -1,14 +1,12 @@
using System; using System.Threading.Tasks;
using System.Linq;
using System.Threading.Tasks;
using Discord.Commands; using Discord.Commands;
using NadekoBot.Services; using NadekoBot.Services;
using NadekoBot.Modules.CustomReactions.Services; using NadekoBot.Modules.CustomReactions.Services;
namespace NadekoBot.Common.TypeReaders namespace NadekoBot.Common.TypeReaders;
public sealed class CommandTypeReader : NadekoTypeReader<CommandInfo>
{ {
public sealed class CommandTypeReader : NadekoTypeReader<CommandInfo>
{
private readonly CommandHandler _handler; private readonly CommandHandler _handler;
private readonly CommandService _cmds; private readonly CommandService _cmds;
@@ -33,10 +31,10 @@ namespace NadekoBot.Common.TypeReaders
return Task.FromResult(TypeReaderResult.FromSuccess(cmd)); return Task.FromResult(TypeReaderResult.FromSuccess(cmd));
} }
} }
public sealed class CommandOrCrTypeReader : NadekoTypeReader<CommandOrCrInfo> public sealed class CommandOrCrTypeReader : NadekoTypeReader<CommandOrCrInfo>
{ {
private readonly CommandService _cmds; private readonly CommandService _cmds;
private readonly CustomReactionsService _crs; private readonly CustomReactionsService _crs;
private readonly CommandHandler _commandHandler; private readonly CommandHandler _commandHandler;
@@ -67,10 +65,10 @@ namespace NadekoBot.Common.TypeReaders
} }
return TypeReaderResult.FromError(CommandError.ParseFailed, "No such command or cr found."); return TypeReaderResult.FromError(CommandError.ParseFailed, "No such command or cr found.");
} }
} }
public class CommandOrCrInfo public class CommandOrCrInfo
{ {
public enum Type public enum Type
{ {
Normal, Normal,
@@ -86,5 +84,4 @@ namespace NadekoBot.Common.TypeReaders
this.Name = input; this.Name = input;
this.CmdType = type; this.CmdType = type;
} }
}
} }

View File

@@ -2,10 +2,10 @@
using Discord; using Discord;
using Discord.Commands; using Discord.Commands;
namespace NadekoBot.Common.TypeReaders namespace NadekoBot.Common.TypeReaders;
public sealed class EmoteTypeReader : NadekoTypeReader<Emote>
{ {
public sealed class EmoteTypeReader : NadekoTypeReader<Emote>
{
public override Task<TypeReaderResult> ReadAsync(ICommandContext ctx, string input) public override Task<TypeReaderResult> ReadAsync(ICommandContext ctx, string input)
{ {
if (!Emote.TryParse(input, out var emote)) if (!Emote.TryParse(input, out var emote))
@@ -13,5 +13,4 @@ namespace NadekoBot.Common.TypeReaders
return Task.FromResult(TypeReaderResult.FromSuccess(emote)); return Task.FromResult(TypeReaderResult.FromSuccess(emote));
} }
}
} }

View File

@@ -1,12 +1,11 @@
using System; using System.Threading.Tasks;
using System.Threading.Tasks;
using Discord.Commands; using Discord.Commands;
using NadekoBot.Modules.Administration.Services; using NadekoBot.Modules.Administration.Services;
namespace NadekoBot.Common.TypeReaders namespace NadekoBot.Common.TypeReaders;
public sealed class GuildDateTimeTypeReader : NadekoTypeReader<GuildDateTime>
{ {
public sealed class GuildDateTimeTypeReader : NadekoTypeReader<GuildDateTime>
{
private readonly GuildTimezoneService _gts; private readonly GuildTimezoneService _gts;
public GuildDateTimeTypeReader(GuildTimezoneService gts) public GuildDateTimeTypeReader(GuildTimezoneService gts)
@@ -32,10 +31,10 @@ namespace NadekoBot.Common.TypeReaders
return new(tz, dt); return new(tz, dt);
} }
} }
public class GuildDateTime public class GuildDateTime
{ {
public TimeZoneInfo Timezone { get; } public TimeZoneInfo Timezone { get; }
public DateTime CurrentGuildTime { get; } public DateTime CurrentGuildTime { get; }
public DateTime InputTime { get; } public DateTime InputTime { get; }
@@ -49,5 +48,4 @@ namespace NadekoBot.Common.TypeReaders
InputTime = inputTime; InputTime = inputTime;
InputTimeUtc = TimeZoneInfo.ConvertTime(inputTime, Timezone, TimeZoneInfo.Utc); InputTimeUtc = TimeZoneInfo.ConvertTime(inputTime, Timezone, TimeZoneInfo.Utc);
} }
}
} }

View File

@@ -1,13 +1,12 @@
using System.Linq; using System.Threading.Tasks;
using System.Threading.Tasks;
using Discord.Commands; using Discord.Commands;
using Discord.WebSocket; using Discord.WebSocket;
using Discord; using Discord;
namespace NadekoBot.Common.TypeReaders namespace NadekoBot.Common.TypeReaders;
public sealed class GuildTypeReader : NadekoTypeReader<IGuild>
{ {
public sealed class GuildTypeReader : NadekoTypeReader<IGuild>
{
private readonly DiscordSocketClient _client; private readonly DiscordSocketClient _client;
public GuildTypeReader(DiscordSocketClient client) public GuildTypeReader(DiscordSocketClient client)
@@ -27,5 +26,4 @@ namespace NadekoBot.Common.TypeReaders
return Task.FromResult(TypeReaderResult.FromError(CommandError.ParseFailed, "No guild by that name or Id found")); return Task.FromResult(TypeReaderResult.FromError(CommandError.ParseFailed, "No guild by that name or Id found"));
} }
}
} }

View File

@@ -1,10 +1,10 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord.Commands; using Discord.Commands;
namespace NadekoBot.Common.TypeReaders namespace NadekoBot.Common.TypeReaders;
public sealed class KwumTypeReader : NadekoTypeReader<kwum>
{ {
public sealed class KwumTypeReader : NadekoTypeReader<kwum>
{
public override Task<TypeReaderResult> ReadAsync(ICommandContext context, string input) public override Task<TypeReaderResult> ReadAsync(ICommandContext context, string input)
{ {
if (kwum.TryParse(input, out var val)) if (kwum.TryParse(input, out var val))
@@ -12,13 +12,12 @@ namespace NadekoBot.Common.TypeReaders
return Task.FromResult(TypeReaderResult.FromError(CommandError.ParseFailed, "Input is not a valid kwum")); return Task.FromResult(TypeReaderResult.FromError(CommandError.ParseFailed, "Input is not a valid kwum"));
} }
} }
public sealed class SmartTextTypeReader : NadekoTypeReader<SmartText> public sealed class SmartTextTypeReader : NadekoTypeReader<SmartText>
{ {
public override Task<TypeReaderResult> ReadAsync(ICommandContext ctx, string input) public override Task<TypeReaderResult> ReadAsync(ICommandContext ctx, string input)
{ {
return Task.FromResult(TypeReaderResult.FromSuccess(SmartText.CreateFrom(input))); return Task.FromResult(TypeReaderResult.FromSuccess(SmartText.CreateFrom(input)));
} }
}
} }

View File

@@ -1,7 +1,7 @@
namespace NadekoBot.Common.TypeReaders.Models namespace NadekoBot.Common.TypeReaders.Models;
public class PermissionAction
{ {
public class PermissionAction
{
public static PermissionAction Enable => new PermissionAction(true); public static PermissionAction Enable => new PermissionAction(true);
public static PermissionAction Disable => new PermissionAction(false); public static PermissionAction Disable => new PermissionAction(false);
@@ -23,5 +23,4 @@
} }
public override int GetHashCode() => Value.GetHashCode(); public override int GetHashCode() => Value.GetHashCode();
}
} }

View File

@@ -1,16 +1,14 @@
using System; using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Text.RegularExpressions;
namespace NadekoBot.Common.TypeReaders.Models namespace NadekoBot.Common.TypeReaders.Models;
public class StoopidTime
{ {
public class StoopidTime
{
public string Input { get; set; } public string Input { get; set; }
public TimeSpan Time { get; set; } public TimeSpan Time { get; set; }
private static readonly Regex _regex = new Regex( private static readonly Regex _regex = new Regex(
@"^(?:(?<months>\d)mo)?(?:(?<weeks>\d{1,2})w)?(?:(?<days>\d{1,2})d)?(?:(?<hours>\d{1,4})h)?(?:(?<minutes>\d{1,5})m)?(?:(?<seconds>\d{1,6})s)?$", @"^(?:(?<months>\d)mo)?(?:(?<weeks>\d{1,2})w)?(?:(?<days>\d{1,2})d)?(?:(?<hours>\d{1,4})h)?(?:(?<minutes>\d{1,5})m)?(?:(?<seconds>\d{1,6})s)?$",
RegexOptions.Compiled | RegexOptions.Multiline); RegexOptions.Compiled | RegexOptions.Multiline);
private StoopidTime() { } private StoopidTime() { }
@@ -61,5 +59,4 @@ namespace NadekoBot.Common.TypeReaders.Models
Time = ts, Time = ts,
}; };
} }
}
} }

View File

@@ -1,12 +1,11 @@
using System.Linq; using System.Threading.Tasks;
using System.Threading.Tasks;
using Discord.Commands; using Discord.Commands;
using NadekoBot.Extensions; using NadekoBot.Extensions;
namespace NadekoBot.Common.TypeReaders namespace NadekoBot.Common.TypeReaders;
public sealed class ModuleTypeReader : NadekoTypeReader<ModuleInfo>
{ {
public sealed class ModuleTypeReader : NadekoTypeReader<ModuleInfo>
{
private readonly CommandService _cmds; private readonly CommandService _cmds;
public ModuleTypeReader(CommandService cmds) public ModuleTypeReader(CommandService cmds)
@@ -23,10 +22,10 @@ namespace NadekoBot.Common.TypeReaders
return Task.FromResult(TypeReaderResult.FromSuccess(module)); return Task.FromResult(TypeReaderResult.FromSuccess(module));
} }
} }
public sealed class ModuleOrCrTypeReader : NadekoTypeReader<ModuleOrCrInfo> public sealed class ModuleOrCrTypeReader : NadekoTypeReader<ModuleOrCrInfo>
{ {
private readonly CommandService _cmds; private readonly CommandService _cmds;
public ModuleOrCrTypeReader(CommandService cmds) public ModuleOrCrTypeReader(CommandService cmds)
@@ -46,10 +45,9 @@ namespace NadekoBot.Common.TypeReaders
Name = input, Name = input,
})); }));
} }
} }
public sealed class ModuleOrCrInfo public sealed class ModuleOrCrInfo
{ {
public string Name { get; set; } public string Name { get; set; }
}
} }

View File

@@ -1,14 +1,12 @@
using System; using System.Threading.Tasks;
using System.Threading.Tasks;
using Discord.Commands; using Discord.Commands;
namespace NadekoBot.Common.TypeReaders namespace NadekoBot.Common.TypeReaders;
public abstract class NadekoTypeReader<T> : TypeReader
{ {
public abstract class NadekoTypeReader<T> : TypeReader
{
public abstract Task<TypeReaderResult> ReadAsync(ICommandContext ctx, string input); public abstract Task<TypeReaderResult> ReadAsync(ICommandContext ctx, string input);
public override Task<TypeReaderResult> ReadAsync(ICommandContext ctx, string input, IServiceProvider services) public override Task<TypeReaderResult> ReadAsync(ICommandContext ctx, string input, IServiceProvider services)
=> ReadAsync(ctx, input); => ReadAsync(ctx, input);
}
} }

View File

@@ -2,13 +2,13 @@
using Discord.Commands; using Discord.Commands;
using NadekoBot.Common.TypeReaders.Models; using NadekoBot.Common.TypeReaders.Models;
namespace NadekoBot.Common.TypeReaders namespace NadekoBot.Common.TypeReaders;
/// <summary>
/// Used instead of bool for more flexible keywords for true/false only in the permission module
/// </summary>
public sealed class PermissionActionTypeReader : NadekoTypeReader<PermissionAction>
{ {
/// <summary>
/// Used instead of bool for more flexible keywords for true/false only in the permission module
/// </summary>
public sealed class PermissionActionTypeReader : NadekoTypeReader<PermissionAction>
{
public override Task<TypeReaderResult> ReadAsync(ICommandContext context, string input) public override Task<TypeReaderResult> ReadAsync(ICommandContext context, string input)
{ {
input = input.ToUpperInvariant(); input = input.ToUpperInvariant();
@@ -36,5 +36,4 @@ namespace NadekoBot.Common.TypeReaders
return Task.FromResult(TypeReaderResult.FromError(CommandError.ParseFailed, "Did not receive a valid boolean value")); return Task.FromResult(TypeReaderResult.FromError(CommandError.ParseFailed, "Did not receive a valid boolean value"));
} }
} }
}
} }

View File

@@ -1,12 +1,11 @@
using System; using System.Threading.Tasks;
using System.Threading.Tasks;
using Discord.Commands; using Discord.Commands;
using SixLabors.ImageSharp; using SixLabors.ImageSharp;
namespace NadekoBot.Common.TypeReaders namespace NadekoBot.Common.TypeReaders;
public sealed class Rgba32TypeReader : NadekoTypeReader<Color>
{ {
public sealed class Rgba32TypeReader : NadekoTypeReader<Color>
{
public override async Task<TypeReaderResult> ReadAsync(ICommandContext context, string input) public override async Task<TypeReaderResult> ReadAsync(ICommandContext context, string input)
{ {
await Task.Yield(); await Task.Yield();
@@ -21,5 +20,4 @@ namespace NadekoBot.Common.TypeReaders
return TypeReaderResult.FromError(CommandError.ParseFailed, "Parameter is not a valid color hex."); return TypeReaderResult.FromError(CommandError.ParseFailed, "Parameter is not a valid color hex.");
} }
} }
}
} }

View File

@@ -1,15 +1,14 @@
using Discord.Commands; using Discord.Commands;
using System;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using NadekoBot.Db; using NadekoBot.Db;
using NadekoBot.Modules.Gambling.Services; using NadekoBot.Modules.Gambling.Services;
using NadekoBot.Services; using NadekoBot.Services;
namespace NadekoBot.Common.TypeReaders namespace NadekoBot.Common.TypeReaders;
public sealed class ShmartNumberTypeReader : NadekoTypeReader<ShmartNumber>
{ {
public sealed class ShmartNumberTypeReader : NadekoTypeReader<ShmartNumber>
{
private readonly DbService _db; private readonly DbService _db;
private readonly GamblingConfigService _gambling; private readonly GamblingConfigService _gambling;
@@ -103,5 +102,4 @@ namespace NadekoBot.Common.TypeReaders
} }
return false; return false;
} }
}
} }

View File

@@ -1,12 +1,11 @@
using Discord.Commands; using Discord.Commands;
using NadekoBot.Common.TypeReaders.Models; using NadekoBot.Common.TypeReaders.Models;
using System;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace NadekoBot.Common.TypeReaders namespace NadekoBot.Common.TypeReaders;
public sealed class StoopidTimeTypeReader : NadekoTypeReader<StoopidTime>
{ {
public sealed class StoopidTimeTypeReader : NadekoTypeReader<StoopidTime>
{
public override Task<TypeReaderResult> ReadAsync(ICommandContext context, string input) public override Task<TypeReaderResult> ReadAsync(ICommandContext context, string input)
{ {
if (string.IsNullOrWhiteSpace(input)) if (string.IsNullOrWhiteSpace(input))
@@ -21,5 +20,4 @@ namespace NadekoBot.Common.TypeReaders
return Task.FromResult(TypeReaderResult.FromError(CommandError.Exception, ex.Message)); return Task.FromResult(TypeReaderResult.FromError(CommandError.Exception, ex.Message));
} }
} }
}
} }

View File

@@ -1,14 +1,11 @@
using System; namespace NadekoBot.Common.Yml;
namespace NadekoBot.Common.Yml public class CommentAttribute : Attribute
{ {
public class CommentAttribute : Attribute
{
public string Comment { get; } public string Comment { get; }
public CommentAttribute(string comment) public CommentAttribute(string comment)
{ {
Comment = comment; Comment = comment;
} }
}
} }

View File

@@ -1,14 +1,11 @@
using System; using YamlDotNet.Core;
using System.Collections.Generic;
using System.Linq;
using YamlDotNet.Core;
using YamlDotNet.Serialization; using YamlDotNet.Serialization;
using YamlDotNet.Serialization.TypeInspectors; using YamlDotNet.Serialization.TypeInspectors;
namespace NadekoBot.Common.Yml namespace NadekoBot.Common.Yml;
public class CommentGatheringTypeInspector : TypeInspectorSkeleton
{ {
public class CommentGatheringTypeInspector : TypeInspectorSkeleton
{
private readonly ITypeInspector innerTypeDescriptor; private readonly ITypeInspector innerTypeDescriptor;
public CommentGatheringTypeInspector(ITypeInspector innerTypeDescriptor) public CommentGatheringTypeInspector(ITypeInspector innerTypeDescriptor)
@@ -69,5 +66,4 @@ namespace NadekoBot.Common.Yml
: baseDescriptor.Read(target); : baseDescriptor.Read(target);
} }
} }
}
} }

View File

@@ -1,11 +1,10 @@
using System; using YamlDotNet.Core;
using YamlDotNet.Core;
using YamlDotNet.Serialization; using YamlDotNet.Serialization;
namespace NadekoBot.Common.Yml namespace NadekoBot.Common.Yml;
public sealed class CommentsObjectDescriptor : IObjectDescriptor
{ {
public sealed class CommentsObjectDescriptor : IObjectDescriptor
{
private readonly IObjectDescriptor innerDescriptor; private readonly IObjectDescriptor innerDescriptor;
public CommentsObjectDescriptor(IObjectDescriptor innerDescriptor, string comment) public CommentsObjectDescriptor(IObjectDescriptor innerDescriptor, string comment)
@@ -20,5 +19,4 @@ namespace NadekoBot.Common.Yml
public Type Type { get { return innerDescriptor.Type; } } public Type Type { get { return innerDescriptor.Type; } }
public Type StaticType { get { return innerDescriptor.StaticType; } } public Type StaticType { get { return innerDescriptor.StaticType; } }
public ScalarStyle ScalarStyle { get { return innerDescriptor.ScalarStyle; } } public ScalarStyle ScalarStyle { get { return innerDescriptor.ScalarStyle; } }
}
} }

View File

@@ -3,10 +3,10 @@ using YamlDotNet.Core.Events;
using YamlDotNet.Serialization; using YamlDotNet.Serialization;
using YamlDotNet.Serialization.ObjectGraphVisitors; using YamlDotNet.Serialization.ObjectGraphVisitors;
namespace NadekoBot.Common.Yml namespace NadekoBot.Common.Yml;
public class CommentsObjectGraphVisitor : ChainedObjectGraphVisitor
{ {
public class CommentsObjectGraphVisitor : ChainedObjectGraphVisitor
{
public CommentsObjectGraphVisitor(IObjectGraphVisitor<IEmitter> nextVisitor) public CommentsObjectGraphVisitor(IObjectGraphVisitor<IEmitter> nextVisitor)
: base(nextVisitor) : base(nextVisitor)
{ {
@@ -22,5 +22,4 @@ namespace NadekoBot.Common.Yml
return base.EnterMapping(key, value, context); return base.EnterMapping(key, value, context);
} }
}
} }

View File

@@ -2,10 +2,10 @@
using YamlDotNet.Serialization; using YamlDotNet.Serialization;
using YamlDotNet.Serialization.EventEmitters; using YamlDotNet.Serialization.EventEmitters;
namespace NadekoBot.Common.Yml namespace NadekoBot.Common.Yml;
public class MultilineScalarFlowStyleEmitter : ChainedEventEmitter
{ {
public class MultilineScalarFlowStyleEmitter : ChainedEventEmitter
{
public MultilineScalarFlowStyleEmitter(IEventEmitter nextEmitter) public MultilineScalarFlowStyleEmitter(IEventEmitter nextEmitter)
: base(nextEmitter) { } : base(nextEmitter) { }
@@ -28,5 +28,4 @@ namespace NadekoBot.Common.Yml
nextEmitter.Emit(eventInfo, emitter); nextEmitter.Emit(eventInfo, emitter);
} }
}
} }

View File

@@ -1,14 +1,13 @@
using System; using System.Globalization;
using System.Globalization;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using YamlDotNet.Core; using YamlDotNet.Core;
using YamlDotNet.Core.Events; using YamlDotNet.Core.Events;
using YamlDotNet.Serialization; using YamlDotNet.Serialization;
namespace NadekoBot.Common.Yml namespace NadekoBot.Common.Yml;
public class Rgba32Converter : IYamlTypeConverter
{ {
public class Rgba32Converter : IYamlTypeConverter
{
public bool Accepts(Type type) public bool Accepts(Type type)
{ {
return type == typeof(Rgba32); return type == typeof(Rgba32);
@@ -27,10 +26,10 @@ namespace NadekoBot.Common.Yml
var val = (uint) (color.B << 0 | color.G << 8 | color.R << 16); var val = (uint) (color.B << 0 | color.G << 8 | color.R << 16);
emitter.Emit(new Scalar(val.ToString("X6").ToLower())); emitter.Emit(new Scalar(val.ToString("X6").ToLower()));
} }
} }
public class CultureInfoConverter : IYamlTypeConverter public class CultureInfoConverter : IYamlTypeConverter
{ {
public bool Accepts(Type type) public bool Accepts(Type type)
{ {
return type == typeof(CultureInfo); return type == typeof(CultureInfo);
@@ -48,5 +47,4 @@ namespace NadekoBot.Common.Yml
var ci = (CultureInfo)value; var ci = (CultureInfo)value;
emitter.Emit(new Scalar(ci.Name)); emitter.Emit(new Scalar(ci.Name));
} }
}
} }

View File

@@ -1,12 +1,11 @@
using System; using YamlDotNet.Core;
using YamlDotNet.Core;
using YamlDotNet.Core.Events; using YamlDotNet.Core.Events;
using YamlDotNet.Serialization; using YamlDotNet.Serialization;
namespace NadekoBot.Common.Yml namespace NadekoBot.Common.Yml;
public class UriConverter : IYamlTypeConverter
{ {
public class UriConverter : IYamlTypeConverter
{
public bool Accepts(Type type) public bool Accepts(Type type)
{ {
return type == typeof(Uri); return type == typeof(Uri);
@@ -24,5 +23,4 @@ namespace NadekoBot.Common.Yml
var uri = (Uri)value; var uri = (Uri)value;
emitter.Emit(new Scalar(uri.ToString())); emitter.Emit(new Scalar(uri.ToString()));
} }
}
} }

View File

@@ -1,9 +1,9 @@
using YamlDotNet.Serialization; using YamlDotNet.Serialization;
namespace NadekoBot.Common.Yml namespace NadekoBot.Common.Yml;
public class Yaml
{ {
public class Yaml
{
public static ISerializer Serializer => new SerializerBuilder() public static ISerializer Serializer => new SerializerBuilder()
.WithTypeInspector(inner => new CommentGatheringTypeInspector(inner)) .WithTypeInspector(inner => new CommentGatheringTypeInspector(inner))
.WithEmissionPhaseObjectGraphVisitor(args => new CommentsObjectGraphVisitor(args.InnerVisitor)) .WithEmissionPhaseObjectGraphVisitor(args => new CommentsObjectGraphVisitor(args.InnerVisitor))
@@ -22,5 +22,4 @@ namespace NadekoBot.Common.Yml
.WithTypeConverter(new UriConverter()) .WithTypeConverter(new UriConverter())
.IgnoreUnmatchedProperties() .IgnoreUnmatchedProperties()
.Build(); .Build();
}
} }

View File

@@ -1,7 +1,7 @@
namespace NadekoBot.Common.Yml namespace NadekoBot.Common.Yml;
public class YamlHelper
{ {
public class YamlHelper
{
// https://github.com/aaubry/YamlDotNet/blob/0f4cc205e8b2dd8ef6589d96de32bf608a687c6f/YamlDotNet/Core/Scanner.cs#L1687 // https://github.com/aaubry/YamlDotNet/blob/0f4cc205e8b2dd8ef6589d96de32bf608a687c6f/YamlDotNet/Core/Scanner.cs#L1687
/// <summary> /// <summary>
/// This is modified code from yamldotnet's repo which handles parsing unicode code points /// This is modified code from yamldotnet's repo which handles parsing unicode code points
@@ -54,5 +54,4 @@
} }
return c - 'a' + 10; return c - 'a' + 10;
} }
}
} }

View File

@@ -1,12 +1,10 @@
using System.Linq; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using NadekoBot.Db.Models; using NadekoBot.Db.Models;
namespace NadekoBot.Db namespace NadekoBot.Db;
public static class ClubExtensions
{ {
public static class ClubExtensions
{
private static IQueryable<ClubInfo> Include(this DbSet<ClubInfo> clubs) private static IQueryable<ClubInfo> Include(this DbSet<ClubInfo> clubs)
=> clubs.Include(x => x.Owner) => clubs.Include(x => x.Owner)
.Include(x => x.Applicants) .Include(x => x.Applicants)
@@ -44,5 +42,4 @@ namespace NadekoBot.Db
.Take(9) .Take(9)
.ToList(); .ToList();
} }
}
} }

View File

@@ -1,12 +1,10 @@
using System.Collections.Generic; using Microsoft.EntityFrameworkCore;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using NadekoBot.Services.Database.Models; using NadekoBot.Services.Database.Models;
namespace NadekoBot.Db namespace NadekoBot.Db;
public static class CurrencyTransactionExtensions
{ {
public static class CurrencyTransactionExtensions
{
public static List<CurrencyTransaction> GetPageFor(this DbSet<CurrencyTransaction> set, ulong userId, int page) public static List<CurrencyTransaction> GetPageFor(this DbSet<CurrencyTransaction> set, ulong userId, int page)
{ {
return set.AsQueryable() return set.AsQueryable()
@@ -17,5 +15,4 @@ namespace NadekoBot.Db
.Take(15) .Take(15)
.ToList(); .ToList();
} }
}
} }

View File

@@ -1,13 +1,11 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using LinqToDB; using LinqToDB;
using NadekoBot.Services.Database.Models; using NadekoBot.Services.Database.Models;
namespace NadekoBot.Db namespace NadekoBot.Db;
public static class CustomReactionsExtensions
{ {
public static class CustomReactionsExtensions
{
public static int ClearFromGuild(this DbSet<CustomReaction> crs, ulong guildId) public static int ClearFromGuild(this DbSet<CustomReaction> crs, ulong guildId)
{ {
return crs.Delete(x => x.GuildId == guildId); return crs.Delete(x => x.GuildId == guildId);
@@ -26,5 +24,4 @@ namespace NadekoBot.Db
{ {
return crs.FirstOrDefault(x => x.GuildId == guildId && x.Trigger.ToUpper() == input); return crs.FirstOrDefault(x => x.GuildId == guildId && x.Trigger.ToUpper() == input);
} }
}
} }

Some files were not shown because too many files have changed in this diff Show More