예제 #1
0
    /// <summary>
    /// Return the message of element
    /// </summary>
    /// <returns>Message</returns>
    public override DiscordEmbedBuilder GetMessage()
    {
        var builder = new DiscordEmbedBuilder();

        builder.WithTitle(LocalizationGroup.GetText("ChooseLevelTitle", "Raid role selection"));
        builder.WithDescription(LocalizationGroup.GetText("ChooseLevelDescription", "Please choose one of the following roles:"));

        _roles = new Dictionary <int, long?>();
        var levelsFieldsText = new StringBuilder();

        using (var dbFactory = RepositoryFactory.CreateInstance())
        {
            var mainRoles = dbFactory.GetRepository <RaidRoleRepository>()
                            .GetQuery()
                            .Where(obj => obj.MainRoleId == _mainRoleId &&
                                   obj.IsDeleted == false)
                            .Select(obj => new
            {
                obj.Id,
                obj.Description,
                obj.DiscordEmojiId
            })
                            .OrderBy(obj => obj.Description)
                            .ToList();

            levelsFieldsText.Append("`0` - ");
            levelsFieldsText.Append(LocalizationGroup.GetText("NoRole", "No additional role"));
            levelsFieldsText.Append('\n');
            _roles[0] = null;

            var i            = 1;
            var fieldCounter = 1;

            foreach (var role in mainRoles)
            {
                var currentLine = $"`{i}` -  {DiscordEmojiService.GetGuildEmoji(CommandContext.Client, role.DiscordEmojiId)} {role.Description}{'\n'}";

                _roles[i] = role.Id;
                i++;

                if (currentLine.Length + levelsFieldsText.Length > 1024)
                {
                    builder.AddField(LocalizationGroup.GetText("RolesField", "Roles") + " #" + fieldCounter, levelsFieldsText.ToString());
                    levelsFieldsText.Clear();
                    fieldCounter++;
                }

                levelsFieldsText.Append(currentLine);
            }

            builder.AddField(LocalizationGroup.GetText("RolesField", "Roles") + " #" + fieldCounter, levelsFieldsText.ToString());
        }

        return(builder);
    }
예제 #2
0
    /// <summary>
    /// Refresh the message
    /// </summary>
    /// <param name="configurationId">Id of the configuration</param>
    /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
    public async Task RefreshMessageAsync(long configurationId)
    {
        using (var dbFactory = RepositoryFactory.CreateInstance())
        {
            var currentRaidPoints = dbFactory.GetRepository <RaidCurrentUserPointsRepository>()
                                    .GetQuery()
                                    .Select(obj => obj);

            var appointment = dbFactory.GetRepository <RaidAppointmentRepository>()
                              .GetQuery()
                              .Where(obj => obj.ConfigurationId == configurationId &&
                                     obj.IsCommitted == false)
                              .OrderByDescending(obj => obj.TimeStamp)
                              .Select(obj => new
            {
                obj.TimeStamp,
                ChannelId = obj.RaidDayConfiguration.DiscordChannelId,
                MessageId = obj.RaidDayConfiguration.DiscordMessageId,
                obj.RaidDayTemplate.Thumbnail,
                obj.RaidDayTemplate.Title,
                obj.RaidDayTemplate.Description,
                obj.GroupCount,

                ExperienceLevels = obj.RaidDayTemplate
                                   .RaidExperienceAssignments
                                   .Select(obj2 => new
                {
                    RaidExperienceLevelId = obj2.RaidExperienceLevel.Id,
                    obj2.RaidExperienceLevel.DiscordEmoji,
                    obj2.RaidExperienceLevel.Description,
                    obj2.RaidExperienceLevel.Rank,
                    obj2.Count
                })
                                   .ToList(),

                Registrations = obj.RaidRegistrations
                                .Select(obj3 => new
                {
                    UserId = obj3.User
                             .DiscordAccounts
                             .Select(obj4 => obj4.Id)
                             .FirstOrDefault(),
                    Points = currentRaidPoints.Where(obj4 => obj4.UserId == obj3.UserId)
                             .Select(obj4 => obj4.Points).FirstOrDefault(),
                    obj3.LineupExperienceLevelId,
                    ExperienceLevelId           = (int?)obj3.User.RaidExperienceLevel.Id,
                    ExperienceLevelDiscordEmoji = (ulong?)obj3.User.RaidExperienceLevel.DiscordEmoji,
                    Roles = obj3.RaidRegistrationRoleAssignments
                            .Select(obj4 => new
                    {
                        MainRoleEmoji = obj4.MainRaidRole.DiscordEmojiId,
                        SubRoleEmoji  = (ulong?)obj4.SubRaidRole.DiscordEmojiId
                    })
                            .ToList()
                })
                                .ToList()
            })
                              .FirstOrDefault();

            if (appointment != null)
            {
                var builder = new DiscordEmbedBuilder();

                var channel = await _client.GetChannelAsync(appointment.ChannelId)
                              .ConfigureAwait(false);

                if (channel != null)
                {
                    var message = await channel.GetMessageAsync(appointment.MessageId)
                                  .ConfigureAwait(false);

                    if (message != null)
                    {
                        var fieldBuilder = new StringBuilder();

                        int fieldCounter;

                        // Building the message
                        foreach (var slot in appointment.ExperienceLevels
                                 .OrderBy(obj => obj.Rank))
                        {
                            fieldCounter = 1;

                            var registrations = appointment.Registrations
                                                .Where(obj => obj.LineupExperienceLevelId == slot.RaidExperienceLevelId)
                                                .OrderByDescending(obj => obj.Points)
                                                .ToList();

                            foreach (var registration in registrations)
                            {
                                var discordUser = await _client.GetUserAsync(registration.UserId)
                                                  .ConfigureAwait(false);

                                var lineBuilder = new StringBuilder();
                                lineBuilder.Append(" > ");

                                if (registration.Roles.Count > 0)
                                {
                                    var first = true;

                                    foreach (var role in registration.Roles)
                                    {
                                        if (first == false)
                                        {
                                            lineBuilder.Append(", ");
                                        }
                                        else
                                        {
                                            first = false;
                                        }

                                        lineBuilder.Append(DiscordEmojiService.GetGuildEmoji(_client, role.MainRoleEmoji));

                                        if (role.SubRoleEmoji != null)
                                        {
                                            lineBuilder.Append(DiscordEmojiService.GetGuildEmoji(_client, role.SubRoleEmoji.Value));
                                        }
                                    }
                                }
                                else
                                {
                                    lineBuilder.Append(DiscordEmojiService.GetQuestionMarkEmoji(_client));
                                }

                                lineBuilder.Append($" {discordUser.Mention}");

                                if (registration.LineupExperienceLevelId != registration.ExperienceLevelId &&
                                    registration.ExperienceLevelDiscordEmoji != null)
                                {
                                    lineBuilder.Append(' ');
                                    lineBuilder.Append(DiscordEmojiService.GetGuildEmoji(_client, registration.ExperienceLevelDiscordEmoji.Value));
                                }

                                lineBuilder.Append('\n');

                                if (lineBuilder.Length + fieldBuilder.Length > 1024)
                                {
                                    builder.AddField($"{DiscordEmojiService.GetGuildEmoji(_client, slot.DiscordEmoji)} {slot.Description} ({registrations.Count}/{slot.Count * appointment.GroupCount}) #{fieldCounter}", fieldBuilder.ToString());
                                    fieldBuilder = new StringBuilder();
                                    fieldCounter++;
                                }

                                fieldBuilder.Append(lineBuilder);
                            }

                            fieldBuilder.Append('\u200B');

                            var fieldName = $"{DiscordEmojiService.GetGuildEmoji(_client, slot.DiscordEmoji)} {slot.Description} ({registrations.Count}/{slot.Count * appointment.GroupCount})";
                            if (fieldCounter > 1)
                            {
                                fieldName = $"{fieldName} #{fieldCounter}";
                            }

                            builder.AddField(fieldName, fieldBuilder.ToString());

                            fieldBuilder.Clear();
                        }

                        fieldCounter = 1;

                        foreach (var entry in appointment.Registrations
                                 .Where(obj => obj.LineupExperienceLevelId == null)
                                 .OrderByDescending(obj => obj.Points))
                        {
                            var discordUser = await _client.GetUserAsync(entry.UserId)
                                              .ConfigureAwait(false);

                            var lineBuilder = new StringBuilder();
                            lineBuilder.Append(" > ");

                            if (entry.Roles?.Count > 0)
                            {
                                var first = true;

                                foreach (var role in entry.Roles)
                                {
                                    if (first == false)
                                    {
                                        lineBuilder.Append(", ");
                                    }
                                    else
                                    {
                                        first = false;
                                    }

                                    lineBuilder.Append(DiscordEmojiService.GetGuildEmoji(_client, role.MainRoleEmoji));

                                    if (role.SubRoleEmoji != null)
                                    {
                                        lineBuilder.Append(DiscordEmojiService.GetGuildEmoji(_client, role.SubRoleEmoji.Value));
                                    }
                                }
                            }
                            else
                            {
                                lineBuilder.Append(DiscordEmojiService.GetQuestionMarkEmoji(_client));
                            }

                            lineBuilder.AppendLine($" {discordUser.Mention} {(entry.ExperienceLevelDiscordEmoji != null ? DiscordEmojiService.GetGuildEmoji(_client, entry.ExperienceLevelDiscordEmoji.Value) : null)}");

                            if (lineBuilder.Length + fieldBuilder.Length > 1024)
                            {
                                builder.AddField($"{LocalizationGroup.GetText("SubstitutesBench", "Substitutes bench")} #{fieldCounter}", fieldBuilder.ToString());
                                fieldBuilder = new StringBuilder();
                                fieldCounter++;
                            }

                            fieldBuilder.Append(lineBuilder);
                        }

                        fieldBuilder.Append('\u200B');

                        var substitutesBenchFieldName = LocalizationGroup.GetText("SubstitutesBench", "Substitutes bench");
                        if (fieldCounter > 1)
                        {
                            substitutesBenchFieldName = $"{substitutesBenchFieldName} #{fieldCounter}";
                        }

                        builder.AddField(substitutesBenchFieldName, fieldBuilder.ToString());

                        builder.WithTitle($"{appointment.Title} - {appointment.TimeStamp.ToString("g", LocalizationGroup.CultureInfo)}");
                        builder.WithDescription(appointment.Description);
                        builder.WithThumbnail(appointment.Thumbnail);
                        builder.WithColor(DiscordColor.Green);
                        builder.WithFooter("Scruffy", "https://cdn.discordapp.com/app-icons/838381119585648650/823930922cbe1e5a9fa8552ed4b2a392.png?size=64");
                        builder.WithTimestamp(DateTime.Now);

                        await message.ModifyAsync(null, builder.Build())
                        .ConfigureAwait(false);
                    }
                }
            }
        }
    }
예제 #3
0
    /// <summary>
    /// Post overview of experience roles
    /// </summary>
    /// <param name="commandContextContainer">Command context</param>
    /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
    public async Task PostExperienceLevelOverview(CommandContextContainer commandContextContainer)
    {
        using (var dbFactory = RepositoryFactory.CreateInstance())
        {
            var levels = await dbFactory.GetRepository <RaidExperienceLevelRepository>()
                         .GetQuery()
                         .OrderBy(obj => obj.Description)
                         .Select(obj => new
            {
                obj.DiscordEmoji,
                obj.Description,

                Users = obj.Users.SelectMany(obj2 => obj2.DiscordAccounts)
                        .OrderBy(obj2 => obj2.Id)
                        .Select(obj2 => obj2.Id)
            })
                         .ToListAsync()
                         .ConfigureAwait(false);

            var embedBuilder = new DiscordEmbedBuilder
            {
                Color       = DiscordColor.Green,
                Description = LocalizationGroup.GetText("ExperienceLevels", "Experience levels")
            };

            var stringBuilder     = new StringBuilder();
            var fieldCounter      = 1;
            var currentFieldTitle = string.Empty;

            foreach (var level in levels)
            {
                var levelFieldCounter = 1;

                currentFieldTitle = $"{DiscordEmojiService.GetGuildEmoji(commandContextContainer.Client, level.DiscordEmoji)} {level.Description} #{levelFieldCounter}";

                foreach (var entry in level.Users)
                {
                    var user = await commandContextContainer.Client
                               .GetUserAsync(entry)
                               .ConfigureAwait(false);

                    var currentLine = $"{user.Mention}\n";

                    if (currentLine.Length + stringBuilder.Length > 1024)
                    {
                        stringBuilder.Append('\u200B');
                        embedBuilder.AddField(currentFieldTitle, stringBuilder.ToString());

                        if (fieldCounter == 6)
                        {
                            fieldCounter = 1;

                            await commandContextContainer.Channel
                            .SendMessageAsync(embedBuilder)
                            .ConfigureAwait(false);

                            embedBuilder = new DiscordEmbedBuilder
                            {
                                Color = DiscordColor.Green
                            };
                        }
                        else
                        {
                            fieldCounter++;
                        }

                        levelFieldCounter++;

                        currentFieldTitle = $"{DiscordEmojiService.GetGuildEmoji(commandContextContainer.Client, level.DiscordEmoji)} {level.Description} #{levelFieldCounter}";

                        stringBuilder = new StringBuilder();
                    }

                    stringBuilder.Append(currentLine);
                }

                stringBuilder.Append('\u200B');

                embedBuilder.AddField(currentFieldTitle, stringBuilder.ToString());

                stringBuilder = new StringBuilder();
            }

            await commandContextContainer.Channel
            .SendMessageAsync(embedBuilder)
            .ConfigureAwait(false);
        }
    }
예제 #4
0
    /// <summary>
    /// Editing the embedded message
    /// </summary>
    /// <param name="builder">Builder</param>
    /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
    public override async Task EditMessage(DiscordEmbedBuilder builder)
    {
        builder.WithTitle(LocalizationGroup.GetText("CommitTitle", "Raid points commit"));
        builder.WithDescription(LocalizationGroup.GetText("CommitText", "The following points will be committed:"));
        builder.WithColor(DiscordColor.Green);
        builder.WithFooter("Scruffy", "https://cdn.discordapp.com/app-icons/838381119585648650/823930922cbe1e5a9fa8552ed4b2a392.png?size=64");
        builder.WithTimestamp(DateTime.Now);

        var message = new StringBuilder();

        var fieldCounter = 1;

        foreach (var user in _commitData.Users
                 .OrderByDescending(obj => obj.Points))
        {
            var discordUser = await CommandContext.Client
                              .GetUserAsync(user.DiscordUserId)
                              .ConfigureAwait(false);

            var currentLine = $"{Formatter.InlineCode(user.Points.ToString("0.0"))} - {DiscordEmojiService.GetGuildEmoji(CommandContext.Client, user.DiscordEmoji)} {discordUser.Mention}";
            if (currentLine.Length + message.Length > 1024)
            {
                builder.AddField(LocalizationGroup.GetText("Users", "Users") + " #" + fieldCounter, message.ToString());
                fieldCounter++;

                message = new StringBuilder();
            }

            message.AppendLine(currentLine);
        }

        message.AppendLine("\u200b");

        var fieldName = LocalizationGroup.GetText("Users", "Users");

        if (fieldCounter > 1)
        {
            fieldName = fieldName + " #" + fieldCounter;
        }

        builder.AddField(fieldName, message.ToString());
    }
예제 #5
0
    /// <summary>
    /// Starting the roles assistant
    /// </summary>
    /// <param name="commandContextContainer">Current command context</param>
    /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
    public async Task RunAssistantAsync(CommandContextContainer commandContextContainer)
    {
        var builder = new DiscordEmbedBuilder();

        builder.WithTitle(LocalizationGroup.GetText("AssistantTitle", "Raid role configuration"));
        builder.WithDescription(LocalizationGroup.GetText("AssistantDescription", "With this assistant you are able to configure the raid roles. The following roles are already created:"));

        var areRolesAvailable = false;

        using (var dbFactory = RepositoryFactory.CreateInstance())
        {
            var mainRoles = dbFactory.GetRepository <RaidRoleRepository>()
                            .GetQuery()
                            .Where(obj => obj.MainRoleId == null &&
                                   obj.IsDeleted == false)
                            .Select(obj => new
            {
                obj.DiscordEmojiId,
                obj.Description,
                SubRoles = obj.SubRaidRoles
                           .Where(obj2 => obj2.IsDeleted == false)
                           .Select(obj2 => new
                {
                    obj2.DiscordEmojiId,
                    obj2.Description
                })
            })
                            .OrderBy(obj => obj.Description)
                            .ToList();

            if (mainRoles.Count > 0)
            {
                areRolesAvailable = true;

                foreach (var role in mainRoles)
                {
                    var roles = new StringBuilder(1024, 1024);

                    foreach (var subRole in role.SubRoles)
                    {
                        roles.Append("> ");
                        roles.Append(DiscordEmojiService.GetGuildEmoji(commandContextContainer.Client, subRole.DiscordEmojiId));
                        roles.Append(' ');
                        roles.Append(subRole.Description);
                        roles.Append('\n');
                    }

                    roles.Append('\n');

                    builder.AddField($"{DiscordEmojiService.GetGuildEmoji(commandContextContainer.Client, role.DiscordEmojiId)} {role.Description}", roles.ToString());
                }
            }
        }

        var addEmoji    = DiscordEmojiService.GetAddEmoji(commandContextContainer.Client);
        var editEmoji   = DiscordEmojiService.GetEditEmoji(commandContextContainer.Client);
        var deleteEmoji = DiscordEmojiService.GetTrashCanEmoji(commandContextContainer.Client);
        var cancelEmoji = DiscordEmojiService.GetCrossEmoji(commandContextContainer.Client);

        var commands = new StringBuilder();

        commands.AppendLine(LocalizationGroup.GetFormattedText("AssistantAddCommand", "{0} Add role", addEmoji));

        if (areRolesAvailable)
        {
            commands.AppendLine(LocalizationGroup.GetFormattedText("AssistantEditCommand", "{0} Edit role", editEmoji));
            commands.AppendLine(LocalizationGroup.GetFormattedText("AssistantDeleteCommand", "{0} Delete role", deleteEmoji));
        }

        commands.AppendLine(LocalizationGroup.GetFormattedText("AssistantCancelCommand", "{0} Cancel", cancelEmoji));

        builder.AddField(LocalizationGroup.GetText("AssistantCommandsField", "Commands"), commands.ToString());

        var message = await commandContextContainer.Channel
                      .SendMessageAsync(builder)
                      .ConfigureAwait(false);

        var userReactionTask = commandContextContainer.Client
                               .GetInteractivity()
                               .WaitForReactionAsync(message, commandContextContainer.User);

        await message.CreateReactionAsync(addEmoji).ConfigureAwait(false);

        await message.CreateReactionAsync(editEmoji).ConfigureAwait(false);

        if (areRolesAvailable)
        {
            await message.CreateReactionAsync(deleteEmoji).ConfigureAwait(false);

            await message.CreateReactionAsync(cancelEmoji).ConfigureAwait(false);
        }

        var userReaction = await userReactionTask.ConfigureAwait(false);

        if (userReaction.TimedOut == false)
        {
            if (userReaction.Result.Emoji.Id == addEmoji.Id)
            {
                await RunAddAssistantAsync(commandContextContainer).ConfigureAwait(false);
            }
            else if (userReaction.Result.Emoji.Id == editEmoji.Id && areRolesAvailable)
            {
                await RunEditAssistantAsync(commandContextContainer).ConfigureAwait(false);
            }
            else if (userReaction.Result.Emoji.Id == deleteEmoji.Id)
            {
                await RunDeleteAssistantAsync(commandContextContainer).ConfigureAwait(false);
            }
        }
    }