mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-11-04 16:44:28 -05:00
NadekoBot.Extensions should now be fully annotated with nullable reference types as well as many classes from NadekoBot.Common
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
namespace NadekoBot.Common;
|
||||
namespace NadekoBot.Common;
|
||||
|
||||
public class EventPubSub : IPubSub
|
||||
{
|
||||
private readonly Dictionary<string, Dictionary<Delegate, List<Func<object, ValueTask>>>> _actions = new();
|
||||
private readonly Dictionary<string, Dictionary<Delegate, List<Func<object?, ValueTask>>>> _actions = new();
|
||||
private readonly object _locker = new();
|
||||
|
||||
public Task Sub<TData>(in TypedKey<TData> key, Func<TData, ValueTask> action)
|
||||
public Task Sub<TData>(in TypedKey<TData> key, Func<TData?, ValueTask> action)
|
||||
{
|
||||
Func<object, ValueTask> localAction = obj => action((TData)obj);
|
||||
Func<object?, ValueTask> localAction = obj => action((TData?)obj);
|
||||
lock (_locker)
|
||||
{
|
||||
if (!_actions.TryGetValue(key.Key, out var keyActions))
|
||||
@@ -79,4 +79,4 @@ public class EventPubSub : IPubSub
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace NadekoBot.Common;
|
||||
namespace NadekoBot.Common;
|
||||
|
||||
public interface IPubSub
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace NadekoBot.Common;
|
||||
namespace NadekoBot.Common;
|
||||
|
||||
public interface ISeria
|
||||
{
|
||||
byte[] Serialize<T>(T data);
|
||||
T Deserialize<T>(byte[] data);
|
||||
}
|
||||
T? Deserialize<T>(byte[]? data);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json;
|
||||
using NadekoBot.Common.JsonConverters;
|
||||
|
||||
namespace NadekoBot.Common;
|
||||
@@ -13,11 +13,11 @@ public class JsonSeria : ISeria
|
||||
public byte[] Serialize<T>(T data)
|
||||
=> JsonSerializer.SerializeToUtf8Bytes(data, _serializerOptions);
|
||||
|
||||
public T Deserialize<T>(byte[] data)
|
||||
public T? Deserialize<T>(byte[]? data)
|
||||
{
|
||||
if (data is null)
|
||||
return default;
|
||||
|
||||
return JsonSerializer.Deserialize<T>(data, _serializerOptions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using StackExchange.Redis;
|
||||
using StackExchange.Redis;
|
||||
|
||||
namespace NadekoBot.Common;
|
||||
|
||||
@@ -22,7 +22,7 @@ public sealed class RedisPubSub : IPubSub
|
||||
.PublishAsync($"{_creds.RedisKey()}:{key.Key}", serialized, CommandFlags.FireAndForget);
|
||||
}
|
||||
|
||||
public Task Sub<TData>(in TypedKey<TData> key, Func<TData, ValueTask> action)
|
||||
public Task Sub<TData>(in TypedKey<TData> key, Func<TData?, ValueTask> action)
|
||||
{
|
||||
var eventName = key.Key;
|
||||
|
||||
@@ -41,4 +41,4 @@ public sealed class RedisPubSub : IPubSub
|
||||
|
||||
return _multi.GetSubscriber().SubscribeAsync($"{_creds.RedisKey()}:{eventName}", OnSubscribeHandler);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace NadekoBot.Common;
|
||||
namespace NadekoBot.Common;
|
||||
|
||||
public readonly struct TypedKey<TData>
|
||||
{
|
||||
@@ -19,7 +19,7 @@ public readonly struct TypedKey<TData>
|
||||
public static bool operator !=(in TypedKey<TData> left, in TypedKey<TData> right)
|
||||
=> !(left == right);
|
||||
|
||||
public override bool Equals(object obj)
|
||||
public override bool Equals(object? obj)
|
||||
=> obj is TypedKey<TData> o && o == this;
|
||||
|
||||
public override int GetHashCode()
|
||||
@@ -27,4 +27,4 @@ public readonly struct TypedKey<TData>
|
||||
|
||||
public override string ToString()
|
||||
=> Key;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ public class YamlSeria : IConfigSeria
|
||||
}
|
||||
|
||||
public string Serialize<T>(T obj)
|
||||
where T: notnull
|
||||
{
|
||||
var escapedOutput = _serializer.Serialize(obj);
|
||||
var output = _codePointRegex.Replace(escapedOutput,
|
||||
@@ -37,4 +38,4 @@ public class YamlSeria : IConfigSeria
|
||||
|
||||
public T Deserialize<T>(string data)
|
||||
=> _deserializer.Deserialize<T>(data);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user