Beispiel #1
0
        public async Task Create(
            [Name("Queue name")] string queueName,
            [Name("Team size")]
            int?teamSize = null,
            [Remainder, Name("Operator flags")] string operators = "")
        {
            if (!PickupHelpers.IsInPickupChannel((IGuildChannel)Context.Channel))
            {
                return;
            }

            if (!teamSize.HasValue)
            {
                teamSize = 4;
            }

            if (teamSize > 16)
            {
                teamSize = 16;
            }

            if (!await _miscCommandService.VerifyUserFlaggedStatus((IGuildUser)Context.User, Context.Channel))
            {
                return;
            }

            queueName = queueName.Trim(' ', '"').Trim();

            //find queue with name {queueName}
            var queue = await _queueRepository.FindQueue(queueName, Context.Guild.Id.ToString());

            if (queue != null)
            {
                await Context.Channel.SendMessageAsync(
                    $"`Queue with the name '{queueName}' already exists!`",
                    messageReference : new MessageReference(Context.Message.Id))
                .AutoRemoveMessage(10);

                return;
            }

            var activity = await _activitiesRepository.Find((IGuildUser)Context.User);

            activity.PickupCreate += 1;
            activity.PickupAdd    += 1;
            await _activitiesRepository.Update(activity);

            queue = await _listCommandService.Create(queueName, teamSize, operators, (SocketGuildUser)Context.User);

            await Context.Channel.SendMessageAsync(
                $"`Queue '{queue.Name}' was added by {PickupHelpers.GetNickname(Context.User)}`",
                messageReference : new MessageReference(Context.Message.Id));
        }
Beispiel #2
0
        public async Task <PickupQueue> Create(string queueName, int?teamSize, string operators, SocketGuildUser user)
        {
            var ops         = OperatorParser.Parse(operators);
            var rconEnabled = ops?.ContainsKey("-rcon") ?? true;

            if (ops?.ContainsKey("-norcon") == true)
            {
                rconEnabled = false;
            }

            var queue = new PickupQueue(user.Guild.Id.ToString(), queueName)
            {
                Name        = queueName,
                GuildId     = user.Guild.Id.ToString(),
                OwnerName   = PickupHelpers.GetNickname(user),
                OwnerId     = user.Id.ToString(),
                Created     = DateTime.UtcNow,
                Updated     = DateTime.UtcNow,
                TeamSize    = teamSize ?? 4,
                IsCoop      = ops?.ContainsKey("-coop") ?? false,
                Rcon        = rconEnabled,
                Subscribers = new List <Subscriber>
                {
                    new Subscriber {
                        Id = user.Id, Name = PickupHelpers.GetNickname(user)
                    }
                },
                Host  = ops?.ContainsKey("-host") ?? false ? ops["-host"]?.FirstOrDefault() : null,
                Port  = int.Parse((ops?.ContainsKey("-port") ?? false ? ops["-port"]?.FirstOrDefault() : null) ?? "0"),
                Games = ops?.ContainsKey("-game") ?? false ? ops["-game"] : Enumerable.Empty <string>(),
            };

            await _queueRepository.AddQueue(queue);

            queue = await _queueRepository.FindQueue(queue.Name, user.Guild.Id.ToString());

            queue = await SaveStaticQueueMessage(queue, user.Guild);

            await _queueRepository.UpdateQueue(queue);

            return(queue);
        }
        public async Task <PickupQueue> VerifyQueueByName(string queueName, IGuildChannel channel)
        {
            var queue = await _queueRepository.FindQueue(queueName, channel.Guild.Id.ToString());

            if (queue != null)
            {
                return(queue);
            }

            await((ITextChannel)channel).SendMessageAsync($"`Queue with the name '{queueName}' doesn't exists!`").AutoRemoveMessage(10);
            return(null);
        }
Beispiel #4
0
        public async Task Create(
            [Name("Queue name"), Summary("Queue name")] string queueName,
            [Name("Team size"), Summary("Team size (how many are in each team **NOT** total number of players)")]
            int teamSize)
        {
            if (teamSize > 16)
            {
                teamSize = 16;
            }

            if (!await VerifyUserFlaggedStatus())
            {
                return;
            }

            //find queue with name {queueName}
            var queue = await _queueRepository.FindQueue(queueName, Context.Guild.Id.ToString());

            if (queue != null)
            {
                await Context.Channel.SendMessageAsync($"`Queue with the name '{queueName}' already exists!`");

                return;
            }

            await _queueRepository.AddQueue(new PickupQueue(Context.Guild.Id.ToString(), queueName)
            {
                Name        = queueName,
                GuildId     = Context.Guild.Id.ToString(),
                OwnerName   = GetNickname(Context.User),
                OwnerId     = Context.User.Id.ToString(),
                Created     = DateTime.UtcNow,
                Updated     = DateTime.UtcNow,
                TeamSize    = teamSize,
                Subscribers = new List <Subscriber> {
                    new Subscriber {
                        Id = Context.User.Id, Name = GetNickname(Context.User)
                    }
                }
            });

            await Context.Channel.SendMessageAsync($"`Queue '{queueName}' was added by {GetNickname(Context.User)}`");
        }
Beispiel #5
0
        public async Task Add(string queueName, ISocketMessageChannel channel, IGuildUser user)
        {
            var         guild = (SocketGuild)user.Guild;
            PickupQueue queue;

            if (!string.IsNullOrWhiteSpace(queueName))
            {
                queue = await _queueRepository.FindQueue(queueName, guild.Id.ToString());
            }
            else
            {
                var queues = (await _queueRepository.AllQueues(guild.Id.ToString())).OrderByDescending(w => w.Readiness).ToList();
                queue = queues.Any(q => q.Readiness < 100) ? queues.FirstOrDefault(q => q.Readiness < 100) : queues.FirstOrDefault();
            }

            if (queue == null)
            {
                await channel.SendMessageAsync($"`Queue with the name '{queueName}' doesn't exists!`").AutoRemoveMessage(10);

                return;
            }

            if (!await _miscCommandService.VerifyUserFlaggedStatus(user, channel))
            {
                return;
            }

            if (queue.Subscribers.Any(w => w.Id == user.Id))
            {
                await channel.SendMessageAsync($"`{queue.Name} - {PickupHelpers.ParseSubscribers(queue)}`");

                return;
            }

            var activity = await _activitiesRepository.Find(user);

            activity.PickupAdd += 1;

            queue.Updated = DateTime.UtcNow;

            bool updateStaticMessage = false;

            if (queue.Subscribers.Count >= queue.MaxInQueue)
            {
                if (queue.WaitingList.All(w => w.Id != user.Id))
                {
                    queue.WaitingList.Add(new Subscriber {
                        Id = user.Id, Name = PickupHelpers.GetNickname(user)
                    });
                    updateStaticMessage = true;

                    if (channel.Name != ChannelNames.ActivePickups)
                    {
                        await channel.SendMessageAsync($"`You have been added to the '{queue.Name}' waiting list`").AutoRemoveMessage(10);
                    }
                }
                else
                {
                    if (channel.Name != ChannelNames.ActivePickups)
                    {
                        await channel.SendMessageAsync($"`You are already on the '{queue.Name}' waiting list`").AutoRemoveMessage(10);
                    }
                }
            }
            else
            {
                updateStaticMessage = true;
                queue.Subscribers.Add(new Subscriber {
                    Id = user.Id, Name = PickupHelpers.GetNickname(user)
                });

                if (queue.Subscribers.Count == queue.MaxInQueue)
                {
                    await PickupHelpers.NotifyUsers(
                        queue,
                        guild.Name,
                        user,
                        queue.Subscribers.Select(s => guild.GetUser(s.Id)).Where(u => u != null).ToArray());
                }

                if (channel.Name != ChannelNames.ActivePickups)
                {
                    await channel.SendMessageAsync($"`{queue.Name} - {PickupHelpers.ParseSubscribers(queue)}`");
                }
            }

            if (updateStaticMessage)
            {
                queue = await _listCommandService.SaveStaticQueueMessage(queue, guild);
            }

            await _queueRepository.UpdateQueue(queue);

            await _activitiesRepository.Update(activity);
        }