示例#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);
            }
        }
示例#2
0
        public async Task Remove([Name("Queue name"), Summary("Optional, if empty the !clear command will be used."), Remainder] string queueName = "")
        {
            if (!PickupHelpers.IsInPickupChannel((IGuildChannel)Context.Channel))
            {
                return;
            }

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

            if (string.IsNullOrWhiteSpace(queueName))
            {
                await Clear();

                return;
            }

            //find queue with name {queueName}
            var queue = await _miscCommandService.VerifyQueueByName(queueName, (IGuildChannel)Context.Channel);

            if (queue == null)
            {
                return;
            }

            await _subscriberCommandService.Leave(queue, Context.Channel, (IGuildUser)Context.User, messageReference : Context.Message.Reference);
        }