Пример #1
0
        public async Task UpdatePinnedMessageForEvent(ISocketMessageChannel channel, EventsWithCount @event)
        {
            IMessage message;

            if (@event.MessageId == null || (message = await channel.GetMessageAsync(Convert.ToUInt64(@event.MessageId))) == null)
            {
                await CreateAndPinParticipantMessage(channel, @event);

                return;
            }
            var messageEmbed = await GetParticipantsEmbed(channel, @event, await _eventSignups.GetAllSignupsForEvent(@event));

            await((IUserMessage)message).ModifyAsync(prop => prop.Embed = messageEmbed);
        }
Пример #2
0
        private async Task UpdateConfirmationCheckForEvent(EventsWithCount @event)
        {
            var confirmationCheck = await _confirmationChecks.GetMostRecentConfirmationCheckForEventAsync(@event.Id);

            if (confirmationCheck == null)
            {
                return;
            }
            var message = await Context.Channel.GetMessageAsync(Convert.ToUInt64(confirmationCheck.MessageId));

            if (message == null)
            {
                return;
            }
            await _confirmationCheckPrinter.WriteMessage(Context.Channel, (IUserMessage)message, @event);
        }
Пример #3
0
        public async Task WriteMessage(ISocketMessageChannel channel, IUserMessage message, EventsWithCount @event)
        {
            var messageContents = $"**Confirmation Check for {@event.Name}!{Environment.NewLine}" +
                                  $"Please confirm your attendance by reacting to this message.**{Environment.NewLine}{Environment.NewLine}";

            if ([email protected] && [email protected])
            {
                messageContents += $"You can still sign up to this event by typing `!event join {@event.DisplayName}`{Environment.NewLine}{Environment.NewLine}";
            }

            var signUps = await _eventSignups.GetAllSignupsForEvent(@event);

            var confirmed = new List <IUser>();

            foreach (var reaction in message.Reactions)
            {
                var reactors = await message.GetReactionUsersAsync(reaction.Key, 999).FlattenAsync();

                confirmed.AddRange(reactors);
            }

            confirmed = confirmed.Distinct(new UserEqualityComparer()).Where(confirmed => signUps.Any(sup => sup.UserId == confirmed.Id.ToString())).ToList();
            var unconfirmed  = signUps.Where(signUp => !confirmed.Any(con => con.Id.ToString() == signUp.UserId));
            var channelUsers = await channel.GetUsersAsync().FlattenAsync();

            var unconfirmedUsers = unconfirmed.Select(u => channelUsers.FirstOrDefault(cu => cu.Id.ToString() == u.UserId)).ToList();

            messageContents += $"**Confirmed:**{Environment.NewLine}" +
                               $"{string.Join(Environment.NewLine, confirmed.Select(con => con?.Mention ?? "Unknown User"))}{Environment.NewLine}";
            messageContents += $"**Unconfirmed:**{Environment.NewLine}" +
                               $"{string.Join(Environment.NewLine, unconfirmedUsers.Select(con => con?.Mention ?? "Unknown User"))}{Environment.NewLine}";


            await message.ModifyAsync((msg) => msg.Content = messageContents);
        }
Пример #4
0
        public async Task <Embed> GetParticipantsEmbed(ISocketMessageChannel channel, EventsWithCount @event, List <EventSignup> signups, bool showJoinPrompt = true)
        {
            var users = new List <SocketGuildUser>();

            foreach (var signup in signups)
            {
                var user = await channel.GetUserAsync(Convert.ToUInt64(signup.UserId)) as SocketGuildUser;

                if (user == null)
                {
                    //handle user that left the guild
                    await _eventSignups.DeleteAsync(signup);

                    continue;
                }
                users.Add(user);
            }

            var usersInEvent = string.Join('\n', users.Select(u => u.GetDisplayName()));
            var message      = "";

            if (@event.SpaceLimited)
            {
                message += $"There's {users.Count} out of {@event.Capacity}";
            }
            else
            {
                message += $"There's {users.Count}";
            }

            message += $" racers signed up for {@event.Name}.\n\n{ usersInEvent}\n";

            var builder = new EmbedBuilder()
                          .WithTitle(@event.Name)
                          .WithDescription(message);

            if (showJoinPrompt)
            {
                if ([email protected])
                {
                    builder.WithFooter(footer => footer.WithText("React to this message to join this event!"));
                }
                else if (@event.SpaceLimited && @event.Full)
                {
                    builder.WithFooter(footer => footer.WithText("This event is currently full. Keep an eye out in case somebody unsigns"));
                }
            }
            return(builder.Build());
        }
Пример #5
0
        public async Task <string> GetParticipantsMessageBody(ISocketMessageChannel channel, EventsWithCount @event, List <EventSignup> signups, bool showJoinPrompt = true)
        {
            var users = await Task.WhenAll(signups.Select(async sup => (await channel.GetUserAsync(Convert.ToUInt64(sup.UserId)) as SocketGuildUser)));

            var usersInEvent = string.Join(Environment.NewLine, users.Select(u => u.GetDisplayName()));
            var message      = $"**{@event.Name}**{Environment.NewLine}";

            if (@event.SpaceLimited)
            {
                message += $"There's {users.Length} out of {@event.Capacity}";
            }
            else
            {
                message += $"There's {users.Length}";
            }

            message += $" racers signed up for {@event.Name}.{Environment.NewLine}{ usersInEvent}{Environment.NewLine}{Environment.NewLine}";

            if (showJoinPrompt)
            {
                if ([email protected])
                {
                    message += $"React to this message to join the event!";
                }
                else if (@event.SpaceLimited && @event.Full)
                {
                    message += "This event is currently full. Keep an eye out in case somebody unsigns.";
                }
            }

            return(message);
        }
Пример #6
0
        public async Task <IMessage> CreateAndPinParticipantMessage(ISocketMessageChannel channel, EventsWithCount @event)
        {
            var signups = await _eventSignups.GetAllSignupsForEvent(@event);

            var embed = await GetParticipantsEmbed(channel, @event, signups);

            var message = await channel.SendMessageAsync(embed : embed);

            await message.PinAsync();

            @event.MessageId = message.Id.ToString();
            await _events.SaveAsync(@event);

            return(message);
        }
Пример #7
0
        public async Task UpdatePinnedMessageForEvent(ISocketMessageChannel channel, EventsWithCount @event, IUserMessage message)
        {
            var messageEmbed = await GetParticipantsEmbed(channel, @event, await _eventSignups.GetAllSignupsForEvent(@event));

            await(message).ModifyAsync(prop => { prop.Embed = messageEmbed; prop.Content = null; });
        }