slight cleanup

This commit is contained in:
Master Kwoth 2017-07-26 18:19:39 +02:00
parent 263a95a6ad
commit bf7585cd83
3 changed files with 16 additions and 13 deletions

View File

@ -22,18 +22,15 @@ namespace NadekoBot.Modules.Utility.Common
private IUserMessage oldMsg = null;
private Timer _t;
public RepeatRunner(DiscordSocketClient client, Repeater repeater)
public RepeatRunner(DiscordSocketClient client, SocketGuild guild, Repeater repeater)
{
_log = LogManager.GetCurrentClassLogger();
Repeater = repeater;
//todo 40 @.@ fix all of this
Guild = client.GetGuild(repeater.GuildId);
Guild = guild;
InitialInterval = Repeater.Interval;
if (Guild != null)
Run();
Run();
}
private void Run()

View File

@ -131,7 +131,7 @@ namespace NadekoBot.Modules.Utility
await uow.CompleteAsync().ConfigureAwait(false);
}
var rep = new RepeatRunner(_client, toAdd);
var rep = new RepeatRunner(_client, (SocketGuild)Context.Guild, toAdd);
_service.Repeaters.AddOrUpdate(Context.Guild.Id, new ConcurrentQueue<RepeatRunner>(new[] {rep}), (key, old) =>
{
@ -179,7 +179,7 @@ namespace NadekoBot.Modules.Utility
await uow.CompleteAsync().ConfigureAwait(false);
}
var rep = new RepeatRunner(_client, toAdd);
var rep = new RepeatRunner(_client, (SocketGuild)Context.Guild, toAdd);
_service.Repeaters.AddOrUpdate(Context.Guild.Id, new ConcurrentQueue<RepeatRunner>(new[] { rep }), (key, old) =>
{

View File

@ -9,7 +9,6 @@ using NadekoBot.Services.Database.Models;
namespace NadekoBot.Modules.Utility.Services
{
//todo 50 rewrite
public class MessageRepeaterService : INService
{
//messagerepeater
@ -24,10 +23,17 @@ namespace NadekoBot.Modules.Utility.Services
await bot.Ready.Task.ConfigureAwait(false);
Repeaters = new ConcurrentDictionary<ulong, ConcurrentQueue<RepeatRunner>>(gcs
.ToDictionary(gc => gc.GuildId,
gc => new ConcurrentQueue<RepeatRunner>(gc.GuildRepeaters
.Select(gr => new RepeatRunner(client, gr))
.Where(x => x.Guild != null))));
.Select(gc =>
{
var guild = client.GetGuild(gc.GuildId);
if (guild == null)
return (0, null);
return (gc.GuildId, new ConcurrentQueue<RepeatRunner>(gc.GuildRepeaters
.Select(gr => new RepeatRunner(client, guild, gr))
.Where(x => x.Guild != null)));
})
.Where(x => x.Item2 != null)
.ToDictionary(x => x.Item1, x => x.Item2));
RepeaterReady = true;
});
}