vassago/ConsoleService.cs

50 lines
1.7 KiB
C#
Raw Normal View History

2023-07-03 12:51:23 -04:00
namespace vassago
{
2023-12-05 23:15:09 -05:00
using Microsoft.EntityFrameworkCore;
2023-07-03 12:51:23 -04:00
using vassago;
using vassago.Models;
using vassago.TwitchInterface;
2023-07-03 12:51:23 -04:00
internal class ConsoleService : IHostedService
{
public ConsoleService(IConfiguration aspConfig)
{
2023-07-04 19:25:04 -04:00
Shared.DBConnectionString = aspConfig["DBConnectionString"];
DiscordTokens = aspConfig.GetSection("DiscordTokens").Get<IEnumerable<string>>();
TwitchConfigs = aspConfig.GetSection("TwitchConfigs").Get<IEnumerable<TwitchConfig>>();
Conversion.Converter.Load(aspConfig["ExchangePairsLocation"]);
2023-07-03 12:51:23 -04:00
}
2023-07-04 19:25:04 -04:00
IEnumerable<string> DiscordTokens { get; }
IEnumerable<TwitchConfig> TwitchConfigs { get; }
2023-07-03 12:51:23 -04:00
public async Task StartAsync(CancellationToken cancellationToken)
{
var dbc = new ChattingContext();
await dbc.Database.MigrateAsync();
2023-07-03 12:51:23 -04:00
2023-07-04 19:25:04 -04:00
if (DiscordTokens?.Any() ?? false)
foreach (var dt in DiscordTokens)
2023-07-03 12:51:23 -04:00
{
var d = new DiscordInterface.DiscordInterface();
await d.Init(dt);
ProtocolInterfaces.ProtocolList.discords.Add(d);
2023-07-03 12:51:23 -04:00
}
2023-07-04 19:25:04 -04:00
if (TwitchConfigs?.Any() ?? false)
foreach (var tc in TwitchConfigs)
{
var t = new TwitchInterface.TwitchInterface();
await t.Init(tc);
ProtocolInterfaces.ProtocolList.twitchs.Add(t);
}
Console.WriteLine("survived initting");
2023-07-03 12:51:23 -04:00
}
public Task StopAsync(CancellationToken cancellationToken)
{
return null;
2023-07-03 12:51:23 -04:00
}
}
}