Beispiel #1
0
        private async Task onShardReady(DiscordSocketClient client)
        {
            shardsReady++;
            await MopsLog(new LogMessage(LogSeverity.Verbose, "", $"Shard {shardsReady} is ready."));

            if (shardsReady == 1)
            {
                Task.Run(() =>
                {
                    foreach (var shard in Client.Shards)
                    {
                        failsafe.Add(new ReliabilityService(shard, ClientLog));
                    }
                });
            }

            if (shardsReady == Client.Shards.Count)
            {
                var map = new ServiceCollection().AddSingleton(Client)
                          .AddSingleton(new InteractiveService(Client));
                provider = map.BuildServiceProvider();

                ReactionHandler = new ReactionHandler();
                ReactionHandler.Install(provider);
                Handler = new CommandHandler();
                Handler.Install(provider).Wait();

                Task.Run(() =>
                {
                    StaticBase.initTracking();
                });
            }
        }
Beispiel #2
0
        private async Task Start()
        {
            Client = new DiscordSocketClient(new DiscordSocketConfig()
            {
                LogLevel = LogSeverity.Info,
                //AlwaysDownloadUsers = true
            });
            RestClient = new DiscordRestClient();

            using (StreamReader sr = new StreamReader(new FileStream("mopsdata//Config.json", FileMode.Open)))
                Config = JsonConvert.DeserializeObject <Dictionary <string, string> >(sr.ReadToEnd());

            await Client.LoginAsync(TokenType.Bot, Config["Discord"]);

            await Client.StartAsync();

            await RestClient.LoginAsync(TokenType.Bot, Config["Discord"]);

            Client.Log   += ClientLog;
            Client.Ready += onClientReady;

            var map = new ServiceCollection().AddSingleton(Client)
                      // .AddSingleton(new AudioService())
                      .AddSingleton(new ReliabilityService(Client, ClientLog))
                      .AddSingleton(new InteractiveService(Client));

            var provider = map.BuildServiceProvider();

            Handler = new CommandHandler();
            await Handler.Install(provider);

            ReactionHandler = new ReactionHandler();
            ReactionHandler.Install(provider);

            await Task.Delay(-1);
        }