示例#1
0
        static async Task Main(string[] args)
        {
            IPayloadLoader payloadLoader = new LocalPayloadLoader();
            var            payloads      = await payloadLoader.GetPayloadsAsync();

            _ = CommandQueue.StartCommandProcessingAsync(CancellationToken.None);

            if (args.Length == 2 && args[0] == "--chaos" && uint.TryParse(args[1], out var wait))
            {
                await RunChaosModAsync(payloads, wait);
            }
            else if (args.Any() && args[0] == "--bot")
            {
                var bot = new Bot();
                bot.OnCommandSelected = async index => {
                    if (index > 22 || index < 0)
                    {
                        return;
                    }

                    var p = payloads.ElementAt(index);
                    await CommandQueue.AddPayloadAsync(p);
                };
                bot.OnMessageSent = async msg => {
                    await Amnesia.DisplayTextAsync(msg);
                };
                bot.OnDeathSet = msg => {
                    Amnesia.SetDeathHintTextAsync(msg);
                };
            }
            else if (args.Length == 2 && args[0] == "--run")
            {
                await CommandQueue.AddPayloadAsync(payloads.First(p => p.Name.Contains(args[1])));
            }

            for (var i = 0; i < payloads.Count(); i++)
            {
                var p = payloads.ElementAt(i);
                Console.WriteLine($"{i} - {p.Name}");
            }

            await Task.Delay(-1);
        }
示例#2
0
        public async Task StartLoop()
        {
            var            poll          = new CommandPolling();
            IPayloadLoader payloadLoader = new LocalPayloadLoader();

            CommandQueue cmdQueue = new CommandQueue();

            _ = cmdQueue.StartCommandProcessingAsync(CancellationToken.None);

            var payloads = await payloadLoader.GetPayloadsAsync();

            var bot = new Bot();

            bot.OnVoted = (displayname, vote) => {
                if (vote < 0)
                {
                    return;
                }

                poll.Vote(displayname, vote);
            };
            bot.OnDeathSet = text => {
                Amnesia.SetDeathHintTextAsync(text);
            };
            bot.OnMessageSent = text => {
                Amnesia.DisplayTextAsync(text);
            };

            var      cooldown    = true;
            DateTime?cooldownEnd = null;

            var pollStartDateTime = DateTime.Now;
            var pollEndDateTime   = DateTime.Now;

            var per = 0.0;

            while (true)
            {
                await Task.Delay(TimeSpan.FromSeconds(1));

                if (cooldown)
                {
                    if (!cooldownEnd.HasValue)
                    {
                        cooldownEnd = DateTime.Now.Add(TimeSpan.FromSeconds(5));
                    }

                    if (DateTime.Now < cooldownEnd)
                    {
                        // maybe push an update about how long until
                        // cooldown ends
                        continue;
                    }
                    else
                    {
                        cooldownEnd       = null;
                        cooldown          = false;
                        pollStartDateTime = DateTime.Now;
                        pollEndDateTime   = DateTime.Now.Add(TimeSpan.FromSeconds(40));

                        poll.GeneratePoll(payloads);
                    }
                }

                var max     = (pollEndDateTime - pollStartDateTime).TotalSeconds;
                var current = (DateTime.Now - pollStartDateTime).TotalSeconds;

                per = (current / max) * 100.0;

                if (per < 100.0)
                {
                    await SendCurrentStatusAsync(per, poll.GetPollOptions());
                }
                else
                {
                    await SendClearStatusAsync();

                    var payload = poll.GetPayloadWithMostVotes();
                    await cmdQueue.AddPayloadAsync(payload);

                    cooldown = true;
                }
            }
        }