コード例 #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();
                });
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: matisxd123/MopsBot-2.0
 private Task onClientReady()
 {
     Task.Run(() => {
         StaticBase.UpdateStatusAsync();
         StaticBase.initTracking();
     });
     return(Task.CompletedTask);
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: Marilyth/Tracker-Server
        private async Task Start()
        {
            using (StreamReader sr = new StreamReader(new FileStream("mopsdata//Config.json", FileMode.Open)))
                Config = JsonConvert.DeserializeObject <Dictionary <string, string> >(sr.ReadToEnd());

            StaticBase.UpdateStatusAsync();
            StaticBase.initTracking();

            await Task.Delay(-1);
        }
コード例 #4
0
        private async Task CheckStateAsync()
        {
            // Client reconnected, no need to reset
            if (_discord.ConnectionState == ConnectionState.Connected)
            {
                return;
            }
            if (_attemptReset)
            {
                await InfoAsync("Attempting to reset the client");

                var timeout = Task.Delay(_timeout);

                lock (resetLock){
                    while ((DateTime.UtcNow - lastDisconnect).TotalSeconds <= 30 || StaticBase.GetMopsRAM() > 2200)
                    {
                        Task.Delay(30000).Wait();
                    }

                    lastDisconnect = DateTime.UtcNow;
                }

                var connect = _discord.StartAsync();
                var task    = await Task.WhenAny(timeout, connect);

                if (task == timeout)
                {
                    await CriticalAsync("Client reset timed out (task deadlocked?), killing process");

                    //FailFast();
                }
                else if (connect.IsFaulted)
                {
                    await CriticalAsync("Client reset faulted, killing process", connect.Exception);

                    FailFast();
                }
                else if (connect.IsCompletedSuccessfully)
                {
                    await InfoAsync("Client reset succesfully!");
                }
                return;
            }

            await CriticalAsync("Client did not reconnect in time, killing process");

            FailFast();
        }
コード例 #5
0
        public static async Task UserVoted(IDblEntity user)
        {
            await Program.MopsLog(new LogMessage(LogSeverity.Info, "", $"User {user.ToString()}({user.Id}) voted. Adding 10 VP to balance!"));

            await MopsBot.Data.Entities.User.ModifyUserAsync(user.Id, x => x.Money += 10);

            try
            {
                if (Program.Client.CurrentUser.Id == 305398845389406209)
                {
                    await(await(await StaticBase.GetUserAsync(user.Id)).GetOrCreateDMChannelAsync()).SendMessageAsync("Thanks for voting for me!\nI have added 10 Votepoints to your balance!");
                }
            }
            catch (Exception e)
            {
                await Program.MopsLog(new LogMessage(LogSeverity.Error, "", "messaging voter failed", e));
            }
        }
コード例 #6
0
        private async Task Start()
        {
            Client = new DiscordShardedClient(new DiscordSocketConfig()
            {
                LogLevel = LogSeverity.Info,
                //TotalShards = 2,
                LargeThreshold      = 50,
                MessageCacheSize    = 0,
                AlwaysDownloadUsers = false,
            });

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

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


            Client.Log        += ClientLog;
            Client.ShardReady += onShardReady;

            Task.Run(() => {
                StaticBase.UpdateStatusAsync();
            });

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

            foreach (var shard in Client.Shards)
            {
                await shard.StartAsync();

                do
                {
                    await Task.Delay(30000);
                } while(StaticBase.GetMopsRAM() > 2200);
            }

            await Task.Delay(-1);
        }