Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using ZeroBot.Endfield.Api.Skland.Authorize;

namespace ZeroBot.Endfield.Playground;

public class MemoryDeviceIdRepository : IDeviceIdRepository
{
private readonly Dictionary<string, string> _deviceIds = new();
public ValueTask<string?> GetAsync(string oAuthToken, CancellationToken cancellationToken = default)
{
_deviceIds.TryGetValue(oAuthToken, out var deviceId);

return ValueTask.FromResult(deviceId);
}

public ValueTask SetAsync(string oAuthToken, string deviceId, CancellationToken cancellationToken = default)
{
_deviceIds.Add(oAuthToken, deviceId);
return default;
}
}
3 changes: 2 additions & 1 deletion src/plugins/ZeroBot.Endfield.Playground/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

var credentialRepository = new JsonCredentialRepository("credentials.json");
var hypergryphClient = new HypergryphClient();
var credentialManager = new CredentialManager(hypergryphClient, credentialRepository);
var deviceIdService = new DeviceIdService(new MemoryDeviceIdRepository());
var credentialManager = new CredentialManager(hypergryphClient, credentialRepository, deviceIdService);
using var cts = new CancellationTokenSource();
var cancellationToken = cts.Token;

Expand Down
7 changes: 5 additions & 2 deletions src/plugins/ZeroBot.Repository.Mongo/MongoRepositoryPlugin.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
using EmberFramework.Abstraction.Layer.Plugin;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using MongoDB.Driver;
using ZeroBot.Abstraction.Bot;

namespace ZeroBot.Repository.Mongo;

public class MongoRepositoryPlugin(IOptions<MongoRepositoryOptions> options, IBotContext botContext) : IPlugin.IWithInitializer
public class MongoRepositoryPlugin(IConfiguration config, IBotContext botContext) : IPlugin.IWithInitializer
{
public ValueTask<IServiceCollection> BuildComponents(CancellationToken cancellationToken = default)
{
IServiceCollection services = new ServiceCollection();
services.AddSingleton(_ =>
services.Configure<MongoRepositoryOptions>(config.GetSection(nameof(MongoRepositoryOptions)));
services.AddSingleton(container =>
{
var options = container.GetRequiredService<IOptions<MongoRepositoryOptions>>();
var mongoSettings = MongoClientSettings.FromConnectionString(options.Value.ConnectionString);
mongoSettings.MaxConnectionPoolSize = options.Value.PoolSize;
return mongoSettings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="MongoDB.Driver" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" />
</ItemGroup>
</Project>
Loading