Ejemplo n.º 1
0
        public async Task Rename([Name("Queue name")] string queueName, [Name("New name")] string newName)
        {
            if (!PickupHelpers.IsInPickupChannel((IGuildChannel)Context.Channel))
            {
                return;
            }

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

            var queue = await _miscCommandService.VerifyQueueByName(queueName, (IGuildChannel)Context.Channel);

            if (queue == null)
            {
                return;
            }

            var isAdmin = (Context.User as IGuildUser)?.GuildPermissions.Has(GuildPermission.Administrator) ?? false;

            if (isAdmin || queue.OwnerId == Context.User.Id.ToString())
            {
                var newQueueCheck = await _queueRepository.FindQueue(newName, Context.Guild.Id.ToString());

                if (newQueueCheck != null)
                {
                    await Context.Message.ReplyAsync($"`A queue with the name '{newName}' already exists.`").AutoRemoveMessage(10);

                    return;
                }

                var newQueue = (PickupQueue)queue.Clone();
                newQueue.RowKey = newName.ToLowerInvariant();
                newQueue.Name   = newName;

                var result = await _queueRepository.AddQueue(newQueue);

                if (result)
                {
                    await _queueRepository.RemoveQueue(queue);

                    await Context.Message.ReplyAsync($"The queue '{queue.Name}' has been renamed to '{newQueue.Name}'");

                    await Context.Message.ReplyAsync($"`{newQueue.Name} - {PickupHelpers.ParseSubscribers(newQueue)}`");

                    if (!string.IsNullOrEmpty(queue.StaticMessageId))
                    {
                        await _listCommandService.SaveStaticQueueMessage(newQueue, Context.Guild);
                    }
                    return;
                }

                await Context.Message.ReplyAsync("An error occured when trying to update the queue name, try again.")
                .AutoRemoveMessage(10);
            }
            else
            {
                await Context.Message.ReplyAsync("`You do not have permission to rename this queue, you have to be either the owner or a server admin`")
                .AutoRemoveMessage(10);
            }
        }
Ejemplo n.º 2
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)}`");
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
 public int AddQ(string PrinterName, string Filename)
 {
     return(_queueRepository.AddQueue(PrinterName, Filename));
 }