Beispiel #1
0
    /// <summary>
    /// Editing a sub role
    /// </summary>
    /// <param name="commandContextContainer">Current command context</param>
    /// <param name="mainRoleId">Id of the role</param>
    /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
    private async Task RunEditSubRoleAssistantAsync(CommandContextContainer commandContextContainer, long mainRoleId)
    {
        var roleId = await SelectRoleAsync(commandContextContainer, mainRoleId).ConfigureAwait(false);

        if (roleId != null)
        {
            var builder = new DiscordEmbedBuilder();
            builder.WithTitle(LocalizationGroup.GetText("RoleEditTitle", "Raid role configuration"));

            var descriptionEmoji = DiscordEmojiService.GetEditEmoji(commandContextContainer.Client);
            var emojiEmoji       = DiscordEmojiService.GetEmojiEmoji(commandContextContainer.Client);
            var cancelEmoji      = DiscordEmojiService.GetCrossEmoji(commandContextContainer.Client);

            var commands = new StringBuilder();
            commands.AppendLine(LocalizationGroup.GetFormattedText("RoleEditEditDescriptionCommand", "{0} Edit description", descriptionEmoji));
            commands.AppendLine(LocalizationGroup.GetFormattedText("RoleEditEditEmojiCommand", "{0} Edit emoji", emojiEmoji));
            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(descriptionEmoji).ConfigureAwait(false);

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

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

            var userReaction = await userReactionTask.ConfigureAwait(false);

            if (userReaction.TimedOut == false)
            {
                if (userReaction.Result.Emoji.Id == descriptionEmoji.Id)
                {
                    await RunEditDescriptionAssistantAsync(commandContextContainer, roleId.Value).ConfigureAwait(false);
                }
                else if (userReaction.Result.Emoji.Id == emojiEmoji.Id)
                {
                    await RunEditEmojiAssistantAsync(commandContextContainer, roleId.Value).ConfigureAwait(false);
                }
            }
        }
    }
Beispiel #2
0
    /// <summary>
    /// Starting the role editing assistant
    /// </summary>
    /// <param name="commandContextContainer">Current command context</param>
    /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
    private async Task RunEditAssistantAsync(CommandContextContainer commandContextContainer)
    {
        var roleId = await SelectRoleAsync(commandContextContainer, null).ConfigureAwait(false);

        if (roleId != null)
        {
            var builder = new DiscordEmbedBuilder();
            builder.WithTitle(LocalizationGroup.GetText("RoleEditTitle", "Raid role configuration"));

            var areRolesAvailable = false;

            using (var dbFactory = RepositoryFactory.CreateInstance())
            {
                var rolesFieldText = new StringBuilder();
                var roles          = dbFactory.GetRepository <RaidRoleRepository>()
                                     .GetQuery()
                                     .Where(obj => obj.Id == roleId.Value &&
                                            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)
                                     .First();

                builder.WithDescription($"{DiscordEmoji.FromGuildEmote(commandContextContainer.Client, roles.DiscordEmojiId)} - {roles.Description}");

                if (roles.SubRoles.Any())
                {
                    areRolesAvailable = true;

                    foreach (var role in roles.SubRoles)
                    {
                        rolesFieldText.Append(DiscordEmoji.FromGuildEmote(commandContextContainer.Client, role.DiscordEmojiId));
                        rolesFieldText.Append(" - ");
                        rolesFieldText.Append(role.Description);
                        rolesFieldText.Append('\n');
                    }

                    builder.AddField(LocalizationGroup.GetText("AssistantRolesField", "Roles"), rolesFieldText.ToString());
                }
            }

            var addSubRoleEmoji    = DiscordEmojiService.GetAddEmoji(commandContextContainer.Client);
            var descriptionEmoji   = DiscordEmojiService.GetEditEmoji(commandContextContainer.Client);
            var editSubRoleEmoji   = DiscordEmojiService.GetEdit2Emoji(commandContextContainer.Client);
            var emojiEmoji         = DiscordEmojiService.GetEmojiEmoji(commandContextContainer.Client);
            var deleteSubRoleEmoji = DiscordEmojiService.GetTrashCanEmoji(commandContextContainer.Client);
            var cancelEmoji        = DiscordEmojiService.GetCrossEmoji(commandContextContainer.Client);

            var commands = new StringBuilder();
            commands.AppendLine(LocalizationGroup.GetFormattedText("RoleEditEditDescriptionCommand", "{0} Edit description", descriptionEmoji));
            commands.AppendLine(LocalizationGroup.GetFormattedText("RoleEditEditEmojiCommand", "{0} Edit emoji", emojiEmoji));
            commands.AppendLine(LocalizationGroup.GetFormattedText("RoleEditAddSubRoleCommand", "{0} Add sub role", addSubRoleEmoji));

            if (areRolesAvailable)
            {
                commands.AppendLine(LocalizationGroup.GetFormattedText("RoleEditEditSubRoleCommand", "{0} Edit sub role", editSubRoleEmoji));
                commands.AppendLine(LocalizationGroup.GetFormattedText("RoleEditDeleteSubRoleCommand", "{0} Delete sub role", deleteSubRoleEmoji));
            }

            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(descriptionEmoji).ConfigureAwait(false);

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

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

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

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

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

            var userReaction = await userReactionTask.ConfigureAwait(false);

            if (userReaction.TimedOut == false)
            {
                if (userReaction.Result.Emoji.Id == addSubRoleEmoji.Id)
                {
                    await RunAddSubRoleAssistantAsync(commandContextContainer, roleId.Value).ConfigureAwait(false);
                }
                else if (userReaction.Result.Emoji.Id == descriptionEmoji.Id)
                {
                    await RunEditDescriptionAssistantAsync(commandContextContainer, roleId.Value).ConfigureAwait(false);
                }
                else if (userReaction.Result.Emoji.Id == editSubRoleEmoji.Id)
                {
                    await RunEditSubRoleAssistantAsync(commandContextContainer, roleId.Value).ConfigureAwait(false);
                }
                else if (userReaction.Result.Emoji.Id == emojiEmoji.Id)
                {
                    await RunEditEmojiAssistantAsync(commandContextContainer, roleId.Value).ConfigureAwait(false);
                }
                else if (userReaction.Result.Emoji.Id == deleteSubRoleEmoji.Id)
                {
                    await RunDeleteSubRoleAssistantAsync(commandContextContainer, roleId.Value).ConfigureAwait(false);
                }
            }
        }
    }