Example #1
0
        public async Task Delete([Name("Queue name"), Summary("Queue name"), Remainder] string queueName)
        {
            if (!PickupHelpers.IsInPickupChannel((IGuildChannel)Context.Channel))
            {
                return;
            }

            queueName = queueName.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())
            {
                await Context.Channel.SendMessageAsync(
                    "You do not have permission to remove the queue.",
                    messageReference : new MessageReference(Context.Message.Id))
                .AutoRemoveMessage(10);

                return;
            }

            if (!queue.Started)
            {
                var queuesChannel = await PickupHelpers.GetPickupQueuesChannel(Context.Guild);

                var result = await _queueRepository.RemoveQueue(queueName, Context.Guild.Id.ToString());

                var message = result
                    ? $"`Queue '{queueName}' has been canceled`"
                    : $"`Queue with the name '{queueName}' doesn't exists or you are not the owner of the queue!`";
                await Context.Channel.SendMessageAsync(message).AutoRemoveMessage(10);

                if (!string.IsNullOrEmpty(queue.StaticMessageId))
                {
                    await queuesChannel.DeleteMessageAsync(Convert.ToUInt64(queue.StaticMessageId));
                }
            }
            else
            {
                await Context.Channel.SendMessageAsync(
                    "Queue is started, you have to run `!stop` to clean up efter yourself first",
                    messageReference : new MessageReference(Context.Message.Id))
                .AutoRemoveMessage(15);
            }
        }
Example #2
0
        public async Task Clear()
        {
            if (!PickupHelpers.IsInPickupChannel((IGuildChannel)Context.Channel))
            {
                return;
            }

            //find queues with user in it
            var allQueues = await _queueRepository.AllQueues(Context.Guild.Id.ToString());

            var matchingQueues = allQueues.Where(q => q.Subscribers.Any(s => s.Id == Context.User.Id) || q.WaitingList.Any(w => w.Id == Context.User.Id));

            var pickupQueues = matchingQueues as PickupQueue[] ?? matchingQueues.ToArray();

            if (pickupQueues.Any())
            {
                foreach (var queue in pickupQueues)
                {
                    queue.WaitingList.RemoveAll(w => w.Id == Context.User.Id);
                    queue.Updated = DateTime.UtcNow;

                    var updatedQueue = await _subscriberCommandService.Leave(queue, Context.Channel, (IGuildUser)Context.User, false);

                    updatedQueue ??= queue;

                    if (!updatedQueue.Subscribers.Any() && !updatedQueue.WaitingList.Any())
                    {
                        await _queueRepository.RemoveQueue(updatedQueue.Name, updatedQueue.GuildId); //Try to remove queue if its empty.

                        if (string.IsNullOrEmpty(queue.StaticMessageId))
                        {
                            continue;
                        }
                        var queuesChannel = await PickupHelpers.GetPickupQueuesChannel(Context.Guild);

                        await queuesChannel.DeleteMessageAsync(Convert.ToUInt64(queue.StaticMessageId));
                    }
                    else
                    {
                        await _queueRepository.UpdateQueue(updatedQueue);
                    }
                }

                //if queues found and user is in queue
                await Context.Channel.SendMessageAsync(
                    $"{PickupHelpers.GetMention(Context.User)} - You have been removed from all queues",
                    messageReference : new MessageReference(Context.Message.Id))
                .AutoRemoveMessage(10);
            }
        }
Example #3
0
        public async Task <PickupQueue> SaveStaticQueueMessage(PickupQueue queue, SocketGuild guild)
        {
            var queuesChannel = await PickupHelpers.GetPickupQueuesChannel(guild);

            var user = guild.GetUser(Convert.ToUInt64(queue.OwnerId));

            var embed = CreateStaticQueueMessageEmbed(queue, user);

            AddSubscriberFieldsToStaticQueueMessageFields(queue, embed);
            AddWaitingListFieldsToStaticQueueMessageFields(queue, embed);

            embed.WithFields(
                new EmbedFieldBuilder {
                Name = "\u200b", Value = "\u200b"
            },
                new EmbedFieldBuilder
            {
                Name  = "**Available actions**",
                Value = $"\u2705 - Add to pickup / remove from pickup\r\n" +
                        $"\uD83D\uDCE2 - Promote pickup"
            }
                );

            if (string.IsNullOrEmpty(queue.StaticMessageId))
            {
                var message = await queuesChannel.SendMessageAsync(embed : embed.Build());

                await message.AddReactionsAsync(new IEmote[] { new Emoji("\u2705"), new Emoji("\uD83D\uDCE2") }); // timer , new Emoji("\u23F2")

                queue.StaticMessageId = message.Id.ToString();
            }
            else
            {
                if (await queuesChannel.GetMessageAsync(Convert.ToUInt64(queue.StaticMessageId)) is IUserMessage message)
                {
                    await message.ModifyAsync(m => { m.Embed = embed.Build(); });
                }
            }

            return(queue);
        }
Example #4
0
        public async Task <bool> DeleteEmptyQueue(PickupQueue queue, SocketGuild guild, ISocketMessageChannel channel, bool notify)
        {
            var result = await _queueRepository.RemoveQueue(queue.Name, queue.GuildId); //Try to remove queue if its empty

            if (result)
            {
                var queuesChannel = await PickupHelpers.GetPickupQueuesChannel(guild);

                if (!string.IsNullOrEmpty(queue.StaticMessageId))
                {
                    await queuesChannel.DeleteMessageAsync(Convert.ToUInt64(queue.StaticMessageId));
                }
            }

            if (!notify)
            {
                return(false);
            }

            await channel.SendMessageAsync($"`{queue.Name} has been removed since everyone left.`").AutoRemoveMessage(10);

            return(false);
        }