mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-08 23:07:54 +00:00
chore: update to .net 8
This commit is contained in:
parent
9716922ab5
commit
2d564535af
26 changed files with 1453 additions and 4487 deletions
|
|
@ -74,8 +74,6 @@ public class Bot
|
|||
}
|
||||
};
|
||||
|
||||
_services.Resolve<RedisGatewayService>().OnEventReceived += (e) => OnEventReceived(e.Item1, e.Item2);
|
||||
|
||||
// Init the shard stuff
|
||||
_services.Resolve<ShardInfoService>().Init();
|
||||
|
||||
|
|
@ -269,7 +267,7 @@ public class Bot
|
|||
_logger.Debug("Running once-per-minute scheduled tasks");
|
||||
|
||||
// Check from a new custom status from Redis and update Discord accordingly
|
||||
if (_redis.Connection != null && _config.RedisGatewayUrl == null)
|
||||
if (true)
|
||||
{
|
||||
var newStatus = await _redis.Connection.GetDatabase().StringGetAsync("pluralkit:botstatus");
|
||||
if (newStatus != CustomStatusMessage)
|
||||
|
|
|
|||
|
|
@ -24,8 +24,6 @@ public class BotConfig
|
|||
public string? HttpCacheUrl { get; set; }
|
||||
public bool HttpUseInnerCache { get; set; } = false;
|
||||
|
||||
public string? RedisGatewayUrl { get; set; }
|
||||
|
||||
public string? DiscordBaseUrl { get; set; }
|
||||
public string? AvatarServiceUrl { get; set; }
|
||||
|
||||
|
|
|
|||
|
|
@ -184,15 +184,7 @@ public class Init
|
|||
var shardMin = (int)Math.Round(totalShards * (float)nodeIndex / totalNodes);
|
||||
var shardMax = (int)Math.Round(totalShards * (float)(nodeIndex + 1) / totalNodes) - 1;
|
||||
|
||||
if (config.RedisGatewayUrl != null)
|
||||
{
|
||||
var shardService = services.Resolve<RedisGatewayService>();
|
||||
|
||||
for (var i = shardMin; i <= shardMax; i++)
|
||||
await shardService.Start(i);
|
||||
}
|
||||
else
|
||||
await cluster.Start(info.Url, shardMin, shardMax, totalShards, info.SessionStartLimit.MaxConcurrency, redis.Connection);
|
||||
await cluster.Start(info.Url, shardMin, shardMax, totalShards, info.SessionStartLimit.MaxConcurrency, redis.Connection);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -43,7 +43,6 @@ public class BotModule: Module
|
|||
};
|
||||
}).AsSelf().SingleInstance();
|
||||
builder.RegisterType<Cluster>().AsSelf().SingleInstance();
|
||||
builder.RegisterType<RedisGatewayService>().AsSelf().SingleInstance();
|
||||
builder.Register<IDiscordCache>(c =>
|
||||
{
|
||||
var botConfig = c.Resolve<BotConfig>();
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>annotations</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
|
@ -22,12 +22,12 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Google.Protobuf" Version="3.13.0" />
|
||||
<PackageReference Include="Grpc.Net.ClientFactory" Version="2.32.0" />
|
||||
<PackageReference Include="Grpc.Tools" Version="2.47.0" PrivateAssets="all" />
|
||||
<PackageReference Include="Humanizer.Core" Version="2.8.26" />
|
||||
<PackageReference Include="Sentry" Version="4.12.1" />
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.5" />
|
||||
<PackageReference Include="Google.Protobuf" Version="3.29.1" />
|
||||
<PackageReference Include="Grpc.Net.ClientFactory" Version="2.67.0" />
|
||||
<PackageReference Include="Grpc.Tools" Version="2.68.1" PrivateAssets="all" />
|
||||
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
|
||||
<PackageReference Include="Sentry" Version="4.13.0" />
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.6" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -1,67 +0,0 @@
|
|||
using System.Text.Json;
|
||||
|
||||
using Serilog;
|
||||
|
||||
using StackExchange.Redis;
|
||||
|
||||
using Myriad.Gateway;
|
||||
using Myriad.Serialization;
|
||||
|
||||
namespace PluralKit.Bot;
|
||||
|
||||
public class RedisGatewayService
|
||||
{
|
||||
private readonly BotConfig _config;
|
||||
private readonly JsonSerializerOptions _jsonSerializerOptions;
|
||||
private ConnectionMultiplexer _redis;
|
||||
private ILogger _logger;
|
||||
|
||||
public RedisGatewayService(BotConfig config, ILogger logger)
|
||||
{
|
||||
_jsonSerializerOptions = new JsonSerializerOptions().ConfigureForMyriad();
|
||||
_config = config;
|
||||
_logger = logger.ForContext<RedisGatewayService>();
|
||||
}
|
||||
|
||||
public event Func<(int, IGatewayEvent), Task>? OnEventReceived;
|
||||
|
||||
public async Task Start(int shardId)
|
||||
{
|
||||
if (_redis == null)
|
||||
_redis = await ConnectionMultiplexer.ConnectAsync(_config.RedisGatewayUrl);
|
||||
|
||||
_logger.Debug("Subscribing to shard {ShardId} on redis", shardId);
|
||||
|
||||
var channel = await _redis.GetSubscriber().SubscribeAsync($"evt-{shardId}");
|
||||
channel.OnMessage((evt) => Handle(shardId, evt));
|
||||
}
|
||||
|
||||
public async Task Handle(int shardId, ChannelMessage message)
|
||||
{
|
||||
var packet = JsonSerializer.Deserialize<GatewayPacket>(message.Message, _jsonSerializerOptions);
|
||||
if (packet.Opcode != GatewayOpcode.Dispatch) return;
|
||||
var evt = DeserializeEvent(packet.EventType, (JsonElement)packet.Payload);
|
||||
if (evt == null) return;
|
||||
await OnEventReceived((shardId, evt));
|
||||
}
|
||||
|
||||
private IGatewayEvent? DeserializeEvent(string eventType, JsonElement payload)
|
||||
{
|
||||
if (!IGatewayEvent.EventTypes.TryGetValue(eventType, out var clrType))
|
||||
{
|
||||
_logger.Debug("Received unknown event type {EventType}", eventType);
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_logger.Verbose("Deserializing {EventType} to {ClrType}", eventType, clrType);
|
||||
return JsonSerializer.Deserialize(payload.GetRawText(), clrType, _jsonSerializerOptions) as IGatewayEvent;
|
||||
}
|
||||
catch (JsonException e)
|
||||
{
|
||||
_logger.Error(e, "Error deserializing event {EventType} to {ClrType}", eventType, clrType);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue