Fixed converter?

This commit is contained in:
Master Kwoth 2017-07-05 16:41:51 +02:00
parent 3a71f63754
commit ab07199a1e
2 changed files with 30 additions and 22 deletions

View File

@ -162,7 +162,7 @@ namespace NadekoBot
#region utility
var remindService = new RemindService(Client, BotConfig, Db, startingGuildIdList, uow);
var repeaterService = new MessageRepeaterService(this, Client, AllGuildConfigs);
//var converterService = new ConverterService(Db);
var converterService = new ConverterService(Client, Db);
var commandMapService = new CommandMapService(AllGuildConfigs);
var patreonRewardsService = new PatreonRewardsService(Credentials, Db, Currency, Client);
var verboseErrorsService = new VerboseErrorsService(AllGuildConfigs, Db, CommandHandler, helpService);
@ -232,7 +232,7 @@ namespace NadekoBot
.Add(commandMapService)
.Add(remindService)
.Add(repeaterService)
//.Add(converterService)
.Add(converterService)
.Add(verboseErrorsService)
.Add(patreonRewardsService)
.Add(pruneService)

View File

@ -25,33 +25,41 @@ namespace NadekoBot.Services.Utility
{
_log = LogManager.GetCurrentClassLogger();
_db = db;
try
{
var data = JsonConvert.DeserializeObject<List<MeasurementUnit>>(
File.ReadAllText("data/units.json"))
.Select(u => new ConvertUnit()
{
Modifier = u.Modifier,
UnitType = u.UnitType,
InternalTrigger = string.Join("|", u.Triggers)
}).ToArray();
using (var uow = _db.UnitOfWork)
if (client.ShardId == 0)
{
try
{
if (uow.ConverterUnits.Empty())
var data = JsonConvert.DeserializeObject<List<MeasurementUnit>>(
File.ReadAllText("data/units.json"))
.Select(u => new ConvertUnit()
{
Modifier = u.Modifier,
UnitType = u.UnitType,
InternalTrigger = string.Join("|", u.Triggers)
}).ToArray();
using (var uow = _db.UnitOfWork)
{
uow.ConverterUnits.AddRange(data);
uow.Complete();
if (uow.ConverterUnits.Empty())
{
uow.ConverterUnits.AddRange(data);
Units = uow.ConverterUnits.GetAll().ToList();
uow.Complete();
}
}
}
Units = data.ToList();
}
catch (Exception ex)
{
_log.Warn("Could not load units: " + ex.Message);
catch (Exception ex)
{
_log.Warn("Could not load units: " + ex.Message);
}
}
_currencyUpdater = new Timer(async (shouldLoad) => await UpdateCurrency((bool)shouldLoad), client.ShardId == 0, _updateInterval, _updateInterval);
_currencyUpdater = new Timer(async (shouldLoad) => await UpdateCurrency((bool)shouldLoad),
client.ShardId == 0,
TimeSpan.FromSeconds(1),
_updateInterval);
}
private async Task<Rates> GetCurrencyRates()