2017-07-17 19:42:36 +00:00
|
|
|
|
using System.Collections.Concurrent;
|
2017-05-27 23:51:22 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
2017-07-17 19:42:36 +00:00
|
|
|
|
using Discord.WebSocket;
|
|
|
|
|
using NadekoBot.Modules.Utility.Common;
|
2017-10-13 04:14:54 +00:00
|
|
|
|
using NadekoBot.Core.Services;
|
|
|
|
|
using NadekoBot.Core.Services.Database.Models;
|
2017-05-27 23:51:22 +00:00
|
|
|
|
|
2017-07-17 19:42:36 +00:00
|
|
|
|
namespace NadekoBot.Modules.Utility.Services
|
2017-05-27 23:51:22 +00:00
|
|
|
|
{
|
2017-07-15 03:04:16 +00:00
|
|
|
|
public class MessageRepeaterService : INService
|
2017-05-27 23:51:22 +00:00
|
|
|
|
{
|
|
|
|
|
//messagerepeater
|
|
|
|
|
//guildid/RepeatRunners
|
|
|
|
|
public ConcurrentDictionary<ulong, ConcurrentQueue<RepeatRunner>> Repeaters { get; set; }
|
|
|
|
|
public bool RepeaterReady { get; private set; }
|
|
|
|
|
|
2017-10-13 00:21:39 +00:00
|
|
|
|
public MessageRepeaterService(NadekoBot bot, DiscordSocketClient client)
|
2017-05-27 23:51:22 +00:00
|
|
|
|
{
|
|
|
|
|
var _ = Task.Run(async () =>
|
|
|
|
|
{
|
2017-07-15 03:04:16 +00:00
|
|
|
|
await bot.Ready.Task.ConfigureAwait(false);
|
2017-06-12 23:40:39 +00:00
|
|
|
|
|
2017-10-13 00:21:39 +00:00
|
|
|
|
Repeaters = new ConcurrentDictionary<ulong, ConcurrentQueue<RepeatRunner>>(
|
|
|
|
|
bot.AllGuildConfigs
|
|
|
|
|
.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.GuildId, x => x.Item2));
|
2017-05-27 23:51:22 +00:00
|
|
|
|
RepeaterReady = true;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|