Ejemplo n.º 1
0
        public SelfService(DiscordSocketClient client, Mitternacht.MitternachtBot bot, CommandHandler cmdHandler, DbService db,
                           IBotConfigProvider bc, ILocalization localization, StringService strings, IBotCredentials creds)
        {
            _bot          = bot;
            _cmdHandler   = cmdHandler;
            _db           = db;
            _log          = LogManager.GetCurrentClassLogger();
            _localization = localization;
            _strings      = strings;
            _client       = client;
            _creds        = creds;
            _bc           = bc;

            var _ = Task.Run(async() =>
            {
                await bot.Ready.Task.ConfigureAwait(false);

                foreach (var cmd in bc.BotConfig.StartupCommands)
                {
                    await cmdHandler.ExecuteExternal(cmd.GuildId, cmd.ChannelId, cmd.CommandText);
                    await Task.Delay(400).ConfigureAwait(false);
                }
            });

            var ___ = Task.Run(async() =>
            {
                await bot.Ready.Task.ConfigureAwait(false);

                await Task.Delay(5000);

                _client.Guilds.SelectMany(g => g.Users);

                if (client.ShardId == 0)
                {
                    LoadOwnerChannels();
                }
            });
        }
        public MessageRepeaterService(Mitternacht.MitternachtBot bot, DiscordSocketClient client, IEnumerable <GuildConfig> gcs)
        {
            var _ = Task.Run(async() =>
            {
                await bot.Ready.Task.ConfigureAwait(false);

                Repeaters = new ConcurrentDictionary <ulong, ConcurrentQueue <RepeatRunner> >(gcs
                                                                                              .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;
            });
        }