Base for 4.3 work. Split Nadeko.Common into a separate project

This commit is contained in:
Kwoth
2022-07-11 00:06:19 +02:00
parent 1396d9d55a
commit f41b1fb93c
113 changed files with 271 additions and 255 deletions

View File

@@ -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;

View File

@@ -1,20 +0,0 @@
#nullable disable
using System.Runtime.CompilerServices;
namespace NadekoBot.Common;
public class AsyncLazy<T> : Lazy<Task<T>>
{
public AsyncLazy(Func<T> valueFactory)
: base(() => Task.Run(valueFactory))
{
}
public AsyncLazy(Func<Task<T>> taskFactory)
: base(() => Task.Run(taskFactory))
{
}
public TaskAwaiter<T> GetAwaiter()
=> Value.GetAwaiter();
}

View File

@@ -1,93 +0,0 @@
#nullable enable
#pragma warning disable
// License MIT
// Source: https://github.com/i3arnon/ConcurrentHashSet
using System.Diagnostics;
namespace System.Collections.Generic;
[DebuggerDisplay("{_backingStore.Count}")]
public sealed class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ICollection<T>
{
private readonly ConcurrentDictionary<T, bool> _backingStore;
public ConcurrentHashSet()
=> _backingStore = new();
public ConcurrentHashSet(IEnumerable<T> values, IEqualityComparer<T>? comparer = null)
=> _backingStore = new(values.Select(x => new KeyValuePair<T, bool>(x, true)), comparer);
public IEnumerator<T> GetEnumerator()
=> _backingStore.Keys.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator()
=> GetEnumerator();
/// <summary>
/// Adds the specified item to the <see cref="ConcurrentHashSet{T}" />.
/// </summary>
/// <param name="item">The item to add.</param>
/// <returns>
/// true if the items was added to the <see cref="ConcurrentHashSet{T}" />
/// successfully; false if it already exists.
/// </returns>
/// <exception cref="T:System.OverflowException">
/// The <see cref="ConcurrentHashSet{T}" />
/// contains too many items.
/// </exception>
public bool Add(T item)
=> _backingStore.TryAdd(item, true);
void ICollection<T>.Add(T item)
=> Add(item);
public void Clear()
=> _backingStore.Clear();
public bool Contains(T item)
=> _backingStore.ContainsKey(item);
public void CopyTo(T[] array, int arrayIndex)
{
ArgumentNullException.ThrowIfNull(array);
if (arrayIndex < 0)
throw new ArgumentOutOfRangeException(nameof(arrayIndex));
if (arrayIndex >= array.Length)
throw new ArgumentOutOfRangeException(nameof(arrayIndex));
CopyToInternal(array, arrayIndex);
}
private void CopyToInternal(T[] array, int arrayIndex)
{
var len = array.Length;
foreach (var (k, _) in _backingStore)
{
if (arrayIndex >= len)
throw new IndexOutOfRangeException(nameof(arrayIndex));
array[arrayIndex++] = k;
}
}
bool ICollection<T>.Remove(T item)
=> TryRemove(item);
public bool TryRemove(T item)
=> _backingStore.TryRemove(item, out _);
public void RemoveWhere(Func<T, bool> predicate)
{
foreach (var elem in this.Where(predicate))
TryRemove(elem);
}
public int Count
=> _backingStore.Count;
public bool IsReadOnly
=> false;
}

View File

@@ -1,145 +0,0 @@
#nullable disable
using NadekoBot.Services.Database.Models;
using System.Collections;
namespace NadekoBot.Common.Collections;
public class IndexedCollection<T> : IList<T>
where T : class, IIndexed
{
public List<T> Source { get; }
public int Count
=> Source.Count;
public bool IsReadOnly
=> false;
public virtual T this[int index]
{
get => Source[index];
set
{
lock (_locker)
{
value.Index = index;
Source[index] = value;
}
}
}
private readonly object _locker = new();
public IndexedCollection()
=> Source = new();
public IndexedCollection(IEnumerable<T> source)
{
lock (_locker)
{
Source = source.OrderBy(x => x.Index).ToList();
UpdateIndexes();
}
}
public int IndexOf(T item)
=> item?.Index ?? -1;
public IEnumerator<T> GetEnumerator()
=> Source.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator()
=> Source.GetEnumerator();
public void Add(T item)
{
ArgumentNullException.ThrowIfNull(item);
lock (_locker)
{
item.Index = Source.Count;
Source.Add(item);
}
}
public virtual void Clear()
{
lock (_locker)
{
Source.Clear();
}
}
public bool Contains(T item)
{
lock (_locker)
{
return Source.Contains(item);
}
}
public void CopyTo(T[] array, int arrayIndex)
{
lock (_locker)
{
Source.CopyTo(array, arrayIndex);
}
}
public virtual bool Remove(T item)
{
lock (_locker)
{
if (Source.Remove(item))
{
for (var i = 0; i < Source.Count; i++)
{
if (Source[i].Index != i)
Source[i].Index = i;
}
return true;
}
}
return false;
}
public virtual void Insert(int index, T item)
{
lock (_locker)
{
Source.Insert(index, item);
for (var i = index; i < Source.Count; i++)
Source[i].Index = i;
}
}
public virtual void RemoveAt(int index)
{
lock (_locker)
{
Source.RemoveAt(index);
for (var i = index; i < Source.Count; i++)
Source[i].Index = i;
}
}
public void UpdateIndexes()
{
lock (_locker)
{
for (var i = 0; i < Source.Count; i++)
{
if (Source[i].Index != i)
Source[i].Index = i;
}
}
}
public static implicit operator List<T>(IndexedCollection<T> x)
=> x.Source;
public List<T> ToList()
=> Source.ToList();
}

View File

@@ -1,101 +0,0 @@
#nullable disable
using System.Runtime.CompilerServices;
namespace NadekoBot.Common;
// needs proper invalid input check (character array input out of range)
// needs negative number support
// ReSharper disable once InconsistentNaming
#pragma warning disable IDE1006
public readonly struct kwum : IEquatable<kwum>
#pragma warning restore IDE1006
{
private const string VALID_CHARACTERS = "23456789abcdefghijkmnpqrstuvwxyz";
private readonly int _value;
public kwum(int num)
=> _value = num;
public kwum(in char c)
{
if (!IsValidChar(c))
throw new ArgumentException("Character needs to be a valid kwum character.", nameof(c));
_value = InternalCharToValue(c);
}
public kwum(in ReadOnlySpan<char> input)
{
_value = 0;
for (var index = 0; index < input.Length; index++)
{
var c = input[index];
if (!IsValidChar(c))
throw new ArgumentException("All characters need to be a valid kwum characters.", nameof(input));
_value += VALID_CHARACTERS.IndexOf(c) * (int)Math.Pow(VALID_CHARACTERS.Length, input.Length - index - 1);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static int InternalCharToValue(in char c)
=> VALID_CHARACTERS.IndexOf(c);
public static bool TryParse(in ReadOnlySpan<char> input, out kwum value)
{
value = default;
foreach (var c in input)
{
if (!IsValidChar(c))
return false;
}
value = new(input);
return true;
}
public static kwum operator +(kwum left, kwum right)
=> new(left._value + right._value);
public static bool operator ==(kwum left, kwum right)
=> left._value == right._value;
public static bool operator !=(kwum left, kwum right)
=> !(left == right);
public static implicit operator long(kwum kwum)
=> kwum._value;
public static implicit operator int(kwum kwum)
=> kwum._value;
public static implicit operator kwum(int num)
=> new(num);
public static bool IsValidChar(char c)
=> VALID_CHARACTERS.Contains(c);
public override string ToString()
{
var count = VALID_CHARACTERS.Length;
var localValue = _value;
var arrSize = (int)Math.Log(localValue, count) + 1;
Span<char> chars = new char[arrSize];
while (localValue > 0)
{
localValue = Math.DivRem(localValue, count, out var rem);
chars[--arrSize] = VALID_CHARACTERS[rem];
}
return new(chars);
}
public override bool Equals(object obj)
=> obj is kwum kw && kw == this;
public bool Equals(kwum other)
=> other == this;
public override int GetHashCode()
=> _value.GetHashCode();
}

View File

@@ -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; }
}
}

View File

@@ -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;
}
}
}

View File

@@ -1,62 +0,0 @@
using System.Threading.Channels;
namespace NadekoBot.Common;
public sealed class QueueRunner
{
private readonly Channel<Func<Task>> _channel;
private readonly int _delayMs;
public QueueRunner(int delayMs = 0, int maxCapacity = -1)
{
if (delayMs < 0)
throw new ArgumentOutOfRangeException(nameof(delayMs));
_delayMs = delayMs;
_channel = maxCapacity switch
{
0 or < -1 => throw new ArgumentOutOfRangeException(nameof(maxCapacity)),
-1 => Channel.CreateUnbounded<Func<Task>>(new UnboundedChannelOptions()
{
SingleReader = true,
SingleWriter = false,
AllowSynchronousContinuations = true,
}),
_ => Channel.CreateBounded<Func<Task>>(new BoundedChannelOptions(maxCapacity)
{
Capacity = maxCapacity,
FullMode = BoundedChannelFullMode.DropOldest,
SingleReader = true,
SingleWriter = false,
AllowSynchronousContinuations = true
})
};
}
public async Task RunAsync(CancellationToken cancel = default)
{
while (true)
{
var func = await _channel.Reader.ReadAsync(cancel);
try
{
await func();
}
catch (Exception ex)
{
Log.Warning(ex, "Exception executing a staggered func: {ErrorMessage}", ex.Message);
}
finally
{
if (_delayMs != 0)
{
await Task.Delay(_delayMs, cancel);
}
}
}
}
public ValueTask EnqueueAsync(Func<Task> action)
=> _channel.Writer.WriteAsync(action);
}

View File

@@ -1,5 +1,6 @@
#nullable disable
using System.Text.RegularExpressions;
using Nadeko.Common;
namespace NadekoBot.Common;

View File

@@ -1,43 +0,0 @@
#nullable disable
using System;
namespace NadekoBot.Common;
public struct ShmartNumber : IEquatable<ShmartNumber>
{
public long Value { get; }
public string Input { get; }
public ShmartNumber(long val, string input = null)
{
Value = val;
Input = input;
}
public static implicit operator ShmartNumber(long num)
=> new(num);
public static implicit operator long(ShmartNumber num)
=> num.Value;
public static implicit operator ShmartNumber(int num)
=> new(num);
public override string ToString()
=> Value.ToString();
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);
public static bool operator ==(ShmartNumber left, ShmartNumber right)
=> left.Equals(right);
public static bool operator !=(ShmartNumber left, ShmartNumber right)
=> !(left == right);
}

View File

@@ -1,4 +1,6 @@
#nullable disable
using Nadeko.Common;
namespace NadekoBot.Common.TypeReaders;
public sealed class KwumTypeReader : NadekoTypeReader<kwum>

View File

@@ -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;

View File

@@ -1,5 +1,4 @@
#nullable disable
using NadekoBot.Common.Collections;
using NadekoBot.Db.Models;
namespace NadekoBot.Services.Database.Models;

View File

@@ -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
{

View File

@@ -1,6 +1,4 @@
#nullable disable
using NadekoBot.Common.Collections;
namespace NadekoBot.Services.Database.Models;
public class Poll : DbEntity

View File

@@ -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;

View File

@@ -1,5 +1,6 @@
#nullable disable
using Microsoft.EntityFrameworkCore;
using Nadeko.Common;
using NadekoBot.Db;
using NadekoBot.Services.Database.Models;

View File

@@ -1,4 +1,5 @@
#nullable disable
using Nadeko.Common;
using NadekoBot.Modules.Administration.Services;
namespace NadekoBot.Modules.Administration;

View File

@@ -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;

View File

@@ -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;

View File

@@ -1,5 +1,6 @@
#nullable disable
using Microsoft.EntityFrameworkCore;
using Nadeko.Common;
using NadekoBot.Db;
using NadekoBot.Services.Database.Models;

View File

@@ -1,4 +1,5 @@
#nullable disable
using Nadeko.Common;
using NadekoBot.Common.TypeReaders;
using NadekoBot.Modules.Administration.Services;

View File

@@ -1,5 +1,6 @@
#nullable disable
using Microsoft.EntityFrameworkCore;
using Nadeko.Common;
using NadekoBot.Common.ModuleBehaviors;
using NadekoBot.Services.Database.Models;

View File

@@ -1,4 +1,6 @@
#nullable disable
using Nadeko.Common;
namespace NadekoBot.Modules.Administration.Services;
public class PruneService : INService

View File

@@ -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;

View File

@@ -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;

View File

@@ -1,4 +1,5 @@
#nullable disable
using Nadeko.Common;
using NadekoBot.Db;
using NadekoBot.Services.Database.Models;

View File

@@ -1,5 +1,6 @@
#nullable disable
using Microsoft.EntityFrameworkCore;
using Nadeko.Common;
using NadekoBot.Db;
using NadekoBot.Services.Database.Models;

View File

@@ -1,4 +1,5 @@
#nullable disable
using Nadeko.Common;
using NadekoBot.Services.Database.Models;
namespace NadekoBot.Modules.NadekoExpressions;

View File

@@ -1,5 +1,7 @@
#nullable disable
using Nadeko.Common;
namespace NadekoBot.Modules.NadekoExpressions;
[Name("Expressions")]

View File

@@ -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;

View File

@@ -1,4 +1,5 @@
#nullable disable
using Nadeko.Common;
using NadekoBot.Modules.Gambling.Common.AnimalRacing.Exceptions;
using NadekoBot.Modules.Games.Common;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -1,6 +1,7 @@
#nullable disable
using NadekoBot.Services.Database.Models;
using System.Collections.Concurrent;
using Nadeko.Common;
namespace NadekoBot.Modules.Gambling.Common.Events;

View File

@@ -1,4 +1,5 @@
#nullable disable
using Nadeko.Common;
using NadekoBot.Modules.Gambling.Common;
using NadekoBot.Modules.Gambling.Services;
using SixLabors.ImageSharp;

View File

@@ -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;

View File

@@ -1,4 +1,5 @@
#nullable disable
using Nadeko.Common;
using NadekoBot.Modules.Gambling.Common;
using NadekoBot.Modules.Gambling.Services;

View File

@@ -1,4 +1,5 @@
#nullable disable
using Nadeko.Common;
using NadekoBot.Modules.Gambling.Common;
using NadekoBot.Modules.Gambling.Services;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -1,4 +1,6 @@
#nullable disable
using Nadeko.Common;
namespace NadekoBot.Modules.Gambling.Common;
public class Deck

View File

@@ -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;

View File

@@ -1,4 +1,5 @@
#nullable disable
using Nadeko.Common;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Processing;
using Image = SixLabors.ImageSharp.Image;

View File

@@ -1,3 +1,4 @@
using Nadeko.Common;
using NadekoBot.Modules.Games.Hangman;
namespace NadekoBot.Modules.Games;

View File

@@ -1,5 +1,4 @@
#nullable disable
using NadekoBot.Common.Collections;
using NadekoBot.Common.ModuleBehaviors;
using NadekoBot.Db;
using NadekoBot.Modules.Games.Common;

View 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;
}
}

View File

@@ -0,0 +1,6 @@
namespace NadekoBot.Modules.Games.Common.Trivia;
public interface IQuestionPool
{
Task<TriviaQuestion?> GetRandomQuestionAsync(ISet<TriviaQuestion> exclude);
}

View 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"
});
}
}

View File

@@ -234,9 +234,9 @@ public class TriviaGame
if (!guess)
return;
triviaCancelSource.Cancel();
if (_options.WinRequirement != 0 && Users[guildUser] == _options.WinRequirement)
{
ShouldStopGame = true;

View File

@@ -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;

View File

@@ -1,5 +1,6 @@
#nullable disable
using CommandLine;
using Nadeko.Common;
using Nadeko.Medusa;
using NadekoBot.Common.ModuleBehaviors;
using NadekoBot.Modules.Administration.Services;

View File

@@ -1,4 +1,5 @@
using Nadeko.Medusa;
using Nadeko.Common;
using Nadeko.Medusa;
namespace NadekoBot.Modules;

View File

@@ -1,4 +1,5 @@
#nullable disable
using Nadeko.Common;
using NadekoBot.Modules.Music.Services;
using NadekoBot.Services.Database.Models;

View File

@@ -1,6 +1,7 @@
using NadekoBot.Db;
using NadekoBot.Services.Database.Models;
using System.Diagnostics.CodeAnalysis;
using Nadeko.Common;
namespace NadekoBot.Modules.Music.Services;

View File

@@ -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;

View File

@@ -1,6 +1,7 @@
using System.ComponentModel;
using System.Diagnostics;
using System.Text;
using Nadeko.Common;
namespace NadekoBot.Modules.Music.Resolvers;

View File

@@ -1,6 +1,7 @@
using Newtonsoft.Json.Linq;
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
using Nadeko.Common;
namespace NadekoBot.Modules.Music.Resolvers;

View File

@@ -1,4 +1,5 @@
#nullable disable
using Nadeko.Common;
using NadekoBot.Modules.Searches.Common;
using Newtonsoft.Json.Linq;

View File

@@ -1,5 +1,6 @@
#nullable disable
using Microsoft.Extensions.Caching.Memory;
using Nadeko.Common;
namespace NadekoBot.Modules.Nsfw.Common;

View File

@@ -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;

View File

@@ -1,4 +1,5 @@
namespace NadekoBot.Modules.Nsfw;
#nullable disable warnings
namespace NadekoBot.Modules.Nsfw;
public record UrlReply
{

View File

@@ -1,5 +1,6 @@
#nullable disable
using System.Net.Http.Json;
using Nadeko.Common;
namespace NadekoBot.Modules.Nsfw.Common;

View File

@@ -1,5 +1,6 @@
#nullable disable
using System.Net.Http.Json;
using Nadeko.Common;
namespace NadekoBot.Modules.Nsfw.Common;

View File

@@ -1,5 +1,6 @@
#nullable disable
using System.Net.Http.Json;
using Nadeko.Common;
namespace NadekoBot.Modules.Nsfw.Common;

View File

@@ -1,5 +1,6 @@
#nullable disable
using System.Text.Json;
using Nadeko.Common;
namespace NadekoBot.Modules.Nsfw.Common;

View File

@@ -1,4 +1,5 @@
#nullable disable
using Nadeko.Common;
using NadekoBot.Modules.Permissions.Services;
using NadekoBot.Services.Database.Models;

View File

@@ -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>

View File

@@ -1,6 +1,7 @@
#nullable disable
using AngleSharp;
using AngleSharp.Html.Dom;
using Nadeko.Common;
using NadekoBot.Modules.Searches.Services;
namespace NadekoBot.Modules.Searches;

View File

@@ -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;

View File

@@ -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;

View File

@@ -1,4 +1,5 @@
#nullable disable
using Nadeko.Common;
using NadekoBot.Modules.Searches.Common;
using Newtonsoft.Json;

View File

@@ -2,6 +2,7 @@
using StackExchange.Redis;
using System.Net.Http.Json;
using System.Text.Json.Serialization;
using Nadeko.Common;
namespace NadekoBot.Modules.Searches;

View File

@@ -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;

View File

@@ -1,5 +1,6 @@
#nullable disable
using Html2Markdown;
using Nadeko.Common;
using NadekoBot.Modules.Searches.Common;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

View File

@@ -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;

View File

@@ -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;

View File

@@ -1,5 +1,6 @@
using NadekoBot.Db.Models;
using System.Text.RegularExpressions;
using Nadeko.Common;
using TwitchLib.Api;
using JsonSerializer = System.Text.Json.JsonSerializer;

View File

@@ -1,6 +1,7 @@
#nullable disable
using NadekoBot.Modules.Utility.Patronage;
using System.Text;
using Nadeko.Common;
namespace NadekoBot.Modules.Utility;

View File

@@ -1,4 +1,5 @@
#nullable disable warnings
using Nadeko.Common;
using NadekoBot.Common.Yml;
using NadekoBot.Db;
using NadekoBot.Services.Database.Models;

View File

@@ -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;

View File

@@ -1,6 +1,7 @@
using LinqToDB;
using LinqToDB.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Nadeko.Common;
using NadekoBot.Common.ModuleBehaviors;
using NadekoBot.Services.Database.Models;

View File

@@ -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;

View File

@@ -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;

View File

@@ -2,6 +2,7 @@
using LinqToDB;
using LinqToDB.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Nadeko.Common;
using NadekoBot.Db;
using NadekoBot.Db.Models;

View File

@@ -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;

View File

@@ -14,6 +14,7 @@ using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using System.Threading.Channels;
using Nadeko.Common;
using Color = SixLabors.ImageSharp.Color;
using Image = SixLabors.ImageSharp.Image;

View File

@@ -101,6 +101,7 @@
<ItemGroup>
<ProjectReference Include="..\ayu\Ayu.Discord.Voice\Ayu.Discord.Voice.csproj" />
<ProjectReference Include="..\Nadeko.Common\Nadeko.Common.csproj" />
<ProjectReference Include="..\Nadeko.Medusa\Nadeko.Medusa.csproj" />
<ProjectReference Include="..\NadekoBot.Generators\NadekoBot.Generators.csproj" OutputItemType="Analyzer" />
</ItemGroup>
@@ -122,6 +123,9 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Folder Include="Common\Collections" />
</ItemGroup>
<PropertyGroup Condition=" '$(Version)' == '' ">
<VersionPrefix Condition=" '$(VersionPrefix)' == '' ">4.0.0</VersionPrefix>

View File

@@ -1,3 +1,5 @@
using Nadeko.Common;
var pid = Environment.ProcessId;
var shardId = 0;

View File

@@ -3,6 +3,7 @@ using NadekoBot.Common.Configs;
using NadekoBot.Common.ModuleBehaviors;
using NadekoBot.Db;
using System.Collections.Immutable;
using Nadeko.Common;
using ExecuteResult = Discord.Commands.ExecuteResult;
using PreconditionResult = Discord.Commands.PreconditionResult;

View File

@@ -1,6 +1,7 @@
#nullable disable
using Grpc.Core;
using Grpc.Net.Client;
using Nadeko.Common;
using NadekoBot.Common.ModuleBehaviors;
using NadekoBot.Coordinator;

View File

@@ -1,15 +1,14 @@
#nullable disable
using System.Collections;
using System.Collections.Immutable;
namespace NadekoBot.Services;
public class StartingGuildsService : IEnumerable<ulong>, INService
{
private readonly ImmutableList<ulong> _guilds;
private readonly IReadOnlyList<ulong> _guilds;
public StartingGuildsService(DiscordSocketClient client)
=> _guilds = client.Guilds.Select(x => x.Id).ToImmutableList();
=> _guilds = client.Guilds.Select(x => x.Id).ToList();
public IEnumerator<ulong> GetEnumerator()
=> _guilds.GetEnumerator();

View File

@@ -2,6 +2,7 @@
using System.ComponentModel;
using System.Diagnostics;
using System.Text;
using Nadeko.Common;
namespace NadekoBot.Services;

View File

@@ -1,36 +0,0 @@
#nullable disable
using Serilog.Events;
using Serilog.Sinks.SystemConsole.Themes;
using System.Text;
namespace NadekoBot.Services;
public static class LogSetup
{
public static void SetupLogger(object source)
{
Log.Logger = new LoggerConfiguration().MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.MinimumLevel.Override("System", LogEventLevel.Information)
.MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Warning)
.Enrich.FromLogContext()
.WriteTo.Console(LogEventLevel.Information,
theme: GetTheme(),
outputTemplate:
"[{Timestamp:HH:mm:ss} {Level:u3}] | #{LogSource} | {Message:lj}{NewLine}{Exception}")
.Enrich.WithProperty("LogSource", source)
.CreateLogger();
Console.OutputEncoding = Encoding.UTF8;
}
private static ConsoleTheme GetTheme()
{
if (Environment.OSVersion.Platform == PlatformID.Unix)
return AnsiConsoleTheme.Code;
#if DEBUG
return AnsiConsoleTheme.Code;
#else
return ConsoleTheme.None;
#endif
}
}

View File

@@ -1,8 +0,0 @@
#nullable disable
namespace NadekoBot.Services;
public static class StandardConversions
{
public static double CelsiusToFahrenheit(double cel)
=> (cel * 1.8f) + 32;
}

View File

@@ -1,6 +1,7 @@
#nullable disable
using StackExchange.Redis;
using System.Web;
using Nadeko.Common;
namespace NadekoBot.Services;

View File

@@ -1,45 +0,0 @@
using System.Buffers;
namespace NadekoBot.Extensions;
// made for expressions because they almost never get added
// and they get looped through constantly
public static class ArrayExtensions
{
/// <summary>
/// Create a new array from the old array + new element at the end
/// </summary>
/// <param name="input">Input array</param>
/// <param name="added">Item to add to the end of the output array</param>
/// <typeparam name="T">Type of the array</typeparam>
/// <returns>A new array with the new element at the end</returns>
public static T[] With<T>(this T[] input, T added)
{
var newExprs = new T[input.Length + 1];
Array.Copy(input, 0, newExprs, 0, input.Length);
newExprs[input.Length] = added;
return newExprs;
}
/// <summary>
/// Creates a new array by applying the specified function to every element in the input array
/// </summary>
/// <param name="arr">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 TIn[] arr, Func<TIn, TOut> f)
=> Array.ConvertAll(arr, x => f(x));
public static TOut[] Map<TIn, TOut>(this IReadOnlyCollection<TIn> col, Func<TIn, TOut> f)
{
var toReturn = new TOut[col.Count];
var i = 0;
foreach (var item in col)
toReturn[i++] = f(item);
return toReturn;
}
}

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