Esempio n. 1
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("ChooseCommandTitle", "Raid template configuration"));
        builder.WithDescription(LocalizationGroup.GetText("ChooseCommandDescription", "With this assistant you are able to configure the raid template."));

        using (var dbFactory = RepositoryFactory.CreateInstance())
        {
            var templateId = DialogContext.GetValue <long>("TemplateId");

            var data = await dbFactory.GetRepository <RaidDayTemplateRepository>()
                       .GetQuery()
                       .Where(obj => obj.Id == templateId)
                       .Select(obj => new
            {
                obj.AliasName,
                obj.Title,
                obj.Description,
                obj.Thumbnail
            })
                       .FirstAsync()
                       .ConfigureAwait(false);

            builder.AddField(LocalizationGroup.GetText("AliasName", "Alias name"), data.AliasName);
            builder.AddField(LocalizationGroup.GetText("Title", "Title"), data.Title);
            builder.AddField(LocalizationGroup.GetText("Description", "Description"), data.Description);
            builder.WithThumbnail(data.Thumbnail);
        }
    }
Esempio n. 2
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("ChooseCommandTitle", "Account configuration"));
        builder.WithDescription(LocalizationGroup.GetText("ChooseCommandDescription", "With this assistant you are able to configure your Guild Wars 2 account configuration."));

        using (var dbFactory = RepositoryFactory.CreateInstance())
        {
            var name = DialogContext.GetValue <string>("AccountName");

            var data = await dbFactory.GetRepository <AccountRepository>()
                       .GetQuery()
                       .Where(obj => obj.User.DiscordAccounts.Any(obj2 => obj2.Id == CommandContext.User.Id) &&
                              obj.Name == name)
                       .Select(obj => new
            {
                obj.Name,
                IsApiKeyAvailable = obj.ApiKey != null,
                obj.DpsReportUserToken,
            })
                       .FirstAsync()
                       .ConfigureAwait(false);

            var stringBuilder = new StringBuilder();

            stringBuilder.AppendLine($"{Formatter.InlineCode(LocalizationGroup.GetText("Name", "Name"))}: {data.Name}");
            stringBuilder.AppendLine($"{Formatter.InlineCode(LocalizationGroup.GetText("IsApiKeyAvailable", "Api Key"))}: {(data.IsApiKeyAvailable ? DiscordEmojiService.GetCheckEmoji(CommandContext.Client) : DiscordEmojiService.GetCrossEmoji(CommandContext.Client))}");
            stringBuilder.AppendLine($"{Formatter.InlineCode(LocalizationGroup.GetText("DpsReportUserToken", "dps.report user token"))}: {(string.IsNullOrWhiteSpace(data.DpsReportUserToken) ? DiscordEmojiService.GetCrossEmoji(CommandContext.Client) : data.DpsReportUserToken)}");

            builder.AddField(LocalizationGroup.GetText("Data", "Data"), stringBuilder.ToString());
        }
    }
Esempio n. 3
0
    /// <summary>
    /// Returns the reactions which should be added to the message
    /// </summary>
    /// <returns>Reactions</returns>
    public override IReadOnlyList <ReactionData <bool> > GetReactions()
    {
        return(_reactions ??= new List <ReactionData <bool> >
        {
            new ()
            {
                Emoji = DiscordEmojiService.GetCheckEmoji(CommandContext.Client),
                Func = () =>
                {
                    using (var dbFactory = RepositoryFactory.CreateInstance())
                    {
                        var templateId = DialogContext.GetValue <long>("CalendarTemplateId");

                        if (dbFactory.GetRepository <CalendarAppointmentTemplateRepository>()
                            .Refresh(obj => obj.Id == templateId, obj => obj.IsDeleted = true))
                        {
                            var now = DateTime.Now;

                            dbFactory.GetRepository <CalendarAppointmentRepository>()
                            .RemoveRange(obj => obj.CalendarAppointmentTemplateId == templateId &&
                                         obj.TimeStamp > now);
                        }
                    }

                    return Task.FromResult(true);
                }
            },
Esempio n. 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("ChooseCommandTitle", "Raid experience level configuration"));
        builder.WithDescription(LocalizationGroup.GetText("ChooseCommandDescription", "With this assistant you are able to configure the raid experience level."));

        using (var dbFactory = RepositoryFactory.CreateInstance())
        {
            var templateId = DialogContext.GetValue <long>("ExperienceLevelId");

            var data = await dbFactory.GetRepository <RaidExperienceLevelRepository>()
                       .GetQuery()
                       .Where(obj => obj.Id == templateId)
                       .Select(obj => new
            {
                obj.Description,
                obj.AliasName,
                obj.DiscordEmoji,
                obj.DiscordRoleId
            })
                       .FirstAsync()
                       .ConfigureAwait(false);

            builder.AddField(LocalizationGroup.GetText("Description", "Description"), data.Description);
            builder.AddField(LocalizationGroup.GetText("AliasName", "Alias name"), data.AliasName);
            builder.AddField(LocalizationGroup.GetText("Emoji", "Emoji"), DiscordEmoji.FromGuildEmote(CommandContext.Client, data.DiscordEmoji));

            if (data.DiscordRoleId != null)
            {
                builder.AddField(LocalizationGroup.GetText("Role", "Role"), CommandContext.Guild.Roles[data.DiscordRoleId.Value].Mention);
            }
        }
    }
Esempio n. 5
0
    /// <summary>
    /// Returns the reactions which should be added to the message
    /// </summary>
    /// <returns>Reactions</returns>
    public override IReadOnlyList <ReactionData <bool> > GetReactions()
    {
        return(_reactions ??= new List <ReactionData <bool> >
        {
            new ()
            {
                Emoji = DiscordEmojiService.GetCheckEmoji(CommandContext.Client),
                Func = () =>
                {
                    using (var dbFactory = RepositoryFactory.CreateInstance())
                    {
                        var rankId = DialogContext.GetValue <int>("RankId");

                        if (dbFactory.GetRepository <GuildRankRepository>()
                            .Remove(obj => obj.Id == rankId))
                        {
                            var order = 0;

                            foreach (var currentRankId in dbFactory.GetRepository <GuildRankRepository>()
                                     .GetQuery()
                                     .OrderBy(obj => obj.Order)
                                     .Select(obj => obj.Id))
                            {
                                dbFactory.GetRepository <GuildRankRepository>()
                                .Refresh(obj => obj.Id == currentRankId,
                                         obj => obj.Order = order);
                                order++;
                            }
                        }
                    }

                    return Task.FromResult(true);
                }
            },
Esempio n. 6
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("ChooseCommandTitle", "Special rank configuration"));
        builder.WithDescription(LocalizationGroup.GetText("ChooseCommandDescription", "With this assistant you are able to configure the special rank."));

        using (var dbFactory = RepositoryFactory.CreateInstance())
        {
            var rankId = DialogContext.GetValue <long>("RankId");

            var data = await dbFactory.GetRepository <GuildSpecialRankConfigurationRepository>()
                       .GetQuery()
                       .Where(obj => obj.Id == rankId)
                       .Select(obj => new
            {
                obj.Description,
                obj.DiscordRoleId,
                obj.MaximumPoints,
                obj.GrantThreshold,
                obj.RemoveThreshold,
                Roles = obj.GuildSpecialRankRoleAssignments
                        .Select(obj2 => new
                {
                    obj2.DiscordRoleId,
                    obj2.Points
                }),
                IgnoreRoles = obj.GuildSpecialRankIgnoreRoleAssignments
                              .Select(obj => obj.DiscordRoleId)
            })
                       .FirstAsync()
                       .ConfigureAwait(false);

            var fieldBuilder = new StringBuilder();
            fieldBuilder.AppendLine($"{Formatter.Bold(LocalizationGroup.GetText("Description", "Description"))}: {data.Description}");
            fieldBuilder.AppendLine($"{Formatter.Bold(LocalizationGroup.GetText("DiscordRole", "Discord role"))}: {CommandContext.Guild.GetRole(data.DiscordRoleId).Mention}");
            fieldBuilder.AppendLine($"{Formatter.Bold(LocalizationGroup.GetText("MaximumPoints", "Maximum points"))}: {data.MaximumPoints.ToString(LocalizationGroup.CultureInfo)}");
            fieldBuilder.AppendLine($"{Formatter.Bold(LocalizationGroup.GetText("GrantThreshold", "Grant threshold"))}: {data.GrantThreshold.ToString(LocalizationGroup.CultureInfo)}");
            fieldBuilder.AppendLine($"{Formatter.Bold(LocalizationGroup.GetText("RemoveThreshold", "Remove threshold"))}: {data.RemoveThreshold.ToString(LocalizationGroup.CultureInfo)}");
            builder.AddField(LocalizationGroup.GetText("General", "General"), fieldBuilder.ToString());

            fieldBuilder.Clear();

            foreach (var role in data.Roles)
            {
                fieldBuilder.AppendLine($"{CommandContext.Guild.GetRole(role.DiscordRoleId).Mention}: {role.Points.ToString(LocalizationGroup.CultureInfo)}");
            }

            fieldBuilder.Append("\u200B");
            builder.AddField(LocalizationGroup.GetText("Roles", "Point roles"), fieldBuilder.ToString());

            fieldBuilder.Clear();

            foreach (var role in data.IgnoreRoles)
            {
                fieldBuilder.AppendLine(CommandContext.Guild.GetRole(role).Mention);
            }

            fieldBuilder.Append("\u200B");
            builder.AddField(LocalizationGroup.GetText("IgnoreRoles", "Ignore roles"), fieldBuilder.ToString());
        }
    }
Esempio n. 7
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("ChooseCommandTitle", "Rank configuration"));
        builder.WithDescription(LocalizationGroup.GetText("ChooseCommandDescription", "With this assistant you are able to configure the rank."));

        using (var dbFactory = RepositoryFactory.CreateInstance())
        {
            var rankId = DialogContext.GetValue <int>("RankId");

            var data = await dbFactory.GetRepository <GuildRankRepository>()
                       .GetQuery()
                       .Where(obj => obj.Id == rankId)
                       .Select(obj => new
            {
                obj.InGameName,
                obj.DiscordRoleId,
                obj.Percentage
            })
                       .FirstAsync()
                       .ConfigureAwait(false);

            var fieldBuilder = new StringBuilder();
            fieldBuilder.AppendLine($"{Formatter.Bold(LocalizationGroup.GetText("InGameName", "In game name"))}: {data.InGameName}");
            fieldBuilder.AppendLine($"{Formatter.Bold(LocalizationGroup.GetText("DiscordRoleId", "Discord role"))}: {CommandContext.Guild.GetRole(data.DiscordRoleId).Mention}");
            fieldBuilder.AppendLine($"{Formatter.Bold(LocalizationGroup.GetText("Percentage", "Percentage quota"))}: {data.Percentage.ToString(LocalizationGroup.CultureInfo)}");
            builder.AddField(LocalizationGroup.GetText("General", "General"), fieldBuilder.ToString());
        }
    }
Esempio n. 8
0
    /// <summary>
    /// Return the message of element
    /// </summary>
    /// <returns>Message</returns>
    public override DiscordEmbedBuilder GetMessage()
    {
        var builder = new DiscordEmbedBuilder();

        builder.WithTitle(LocalizationGroup.GetText("ChooseAssignmentTitle", "Assignment selection"));
        builder.WithDescription(LocalizationGroup.GetText("ChooseAssignmentDescription", "Please choose one of the following assignments:"));

        _ranks = new Dictionary <int, ulong>();
        var levelsFieldsText = new StringBuilder();

        using (var dbFactory = RepositoryFactory.CreateInstance())
        {
            var rankId = DialogContext.GetValue <long>("RankId");

            var mainRoles = dbFactory.GetRepository <GuildSpecialRankRoleAssignmentRepository>()
                            .GetQuery()
                            .Where(obj => obj.ConfigurationId == rankId)
                            .Select(obj => new
            {
                obj.DiscordRoleId
            })
                            .ToList();

            var i = 1;
            foreach (var role in mainRoles)
            {
                levelsFieldsText.Append('`');
                levelsFieldsText.Append(i);
                levelsFieldsText.Append("` - ");
                levelsFieldsText.Append(' ');
                levelsFieldsText.Append(CommandContext.Guild.GetRole(role.DiscordRoleId).Mention);
                levelsFieldsText.Append('\n');

                _ranks[i] = role.DiscordRoleId;

                i++;
            }

            builder.AddField(LocalizationGroup.GetText("AssignmentsField", "Assignments"), levelsFieldsText.ToString());
        }

        return(builder);
    }
Esempio n. 9
0
    /// <summary>
    /// Returns the reactions which should be added to the message
    /// </summary>
    /// <returns>Reactions</returns>
    public override IReadOnlyList <ReactionData <bool> > GetReactions()
    {
        return(_reactions ??= new List <ReactionData <bool> >
        {
            new ()
            {
                Emoji = DiscordEmojiService.GetCheckEmoji(CommandContext.Client),
                Func = () =>
                {
                    using (var dbFactory = RepositoryFactory.CreateInstance())
                    {
                        var templateId = DialogContext.GetValue <long>("TemplateId");

                        dbFactory.GetRepository <RaidDayTemplateRepository>()
                        .Refresh(obj => obj.Id == templateId, obj => obj.IsDeleted = true);
                    }

                    return Task.FromResult(true);
                }
            },
Esempio n. 10
0
    /// <summary>
    /// Return the message of element
    /// </summary>
    /// <returns>Message</returns>
    public override DiscordEmbedBuilder GetMessage()
    {
        var builder = new DiscordEmbedBuilder();

        builder.WithTitle(LocalizationGroup.GetText("ChooseGuildTitle", "Guild selection"));
        builder.WithDescription(LocalizationGroup.GetText("ChooseGuildDescription", "Please choose one of the following guilds:"));

        _guilds = new Dictionary <int, string>();

        using (var connector = new GuidWars2ApiConnector(DialogContext.GetValue <string>("ApiKey")))
        {
            var fieldText = new StringBuilder();
            var i         = 1;

            // TODO GetMessage -> GetMessageAsync
            var accountInformation = connector.GetAccountInformationAsync().Result;

            foreach (var guildId in accountInformation.GuildLeader)
            {
                var guildInformation = connector.GetGuildInformation(guildId).Result;

                fieldText.Append('`');
                fieldText.Append(i);
                fieldText.Append("` - ");
                fieldText.Append(' ');
                fieldText.Append(guildInformation.Name);
                fieldText.Append('[');
                fieldText.Append(guildInformation.Tag);
                fieldText.Append(']');
                fieldText.Append('\n');

                _guilds[i] = guildId;

                i++;
            }

            builder.AddField(LocalizationGroup.GetText("GuildsField", "Guilds"), fieldText.ToString());
        }

        return(builder);
    }
Esempio n. 11
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("ChooseCommandTitle", "Calendar template configuration"));
        builder.WithDescription(LocalizationGroup.GetText("ChooseCommandDescription", "With this assistant you are able to configure the calendar template"));

        using (var dbFactory = RepositoryFactory.CreateInstance())
        {
            var templateId = DialogContext.GetValue <long>("CalendarTemplateId");

            var data = await dbFactory.GetRepository <CalendarAppointmentTemplateRepository>()
                       .GetQuery()
                       .Where(obj => obj.Id == templateId)
                       .Select(obj => new
            {
                obj.Description,
                obj.ReminderTime,
                obj.ReminderMessage,
                obj.GuildPoints
            })
                       .FirstAsync()
                       .ConfigureAwait(false);

            builder.AddField(LocalizationGroup.GetText("Description", "Description"), data.Description);

            if (data.ReminderTime != null)
            {
                builder.AddField(LocalizationGroup.GetText("ReminderTime", "Reminder time"), data.ReminderTime.Value.ToString("hh\\:mm\\:ss"));
            }

            if (data.ReminderMessage != null)
            {
                builder.AddField(LocalizationGroup.GetText("ReminderMessage", "Reminder message"), data.ReminderMessage);
            }

            if (data.GuildPoints != null)
            {
                builder.AddField(LocalizationGroup.GetText("GuildPoints", "Points"), data.GuildPoints.Value.ToString());
            }
        }
    }
Esempio n. 12
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("ChooseCommandTitle", "Calendar schedule configuration"));
        builder.WithDescription(LocalizationGroup.GetText("ChooseCommandDescription", "With this assistant you are able to configure the calendar schedule"));

        using (var dbFactory = RepositoryFactory.CreateInstance())
        {
            var scheduleId = DialogContext.GetValue <long>("CalendarScheduleId");

            var data = await dbFactory.GetRepository <CalendarAppointmentScheduleRepository>()
                       .GetQuery()
                       .Where(obj => obj.Id == scheduleId)
                       .Select(obj => new
            {
                obj.Description
            })
                       .FirstAsync()
                       .ConfigureAwait(false);

            builder.AddField(LocalizationGroup.GetText("Description", "Description"), data.Description);
        }
    }
Esempio n. 13
0
    /// <summary>
    /// Returns the reactions which should be added to the message
    /// </summary>
    /// <returns>Reactions</returns>
    public override IReadOnlyList <ReactionData <bool> > GetReactions()
    {
        return(_reactions ??= new List <ReactionData <bool> >
        {
            new ()
            {
                Emoji = DiscordEmojiService.GetEditEmoji(CommandContext.Client),
                CommandText = LocalizationGroup.GetFormattedText("EditSuperiorRoleCommand", "{0} Edit superior role", DiscordEmojiService.GetEditEmoji(CommandContext.Client)),
                Func = async() =>
                {
                    var newSuperiorLevelId = await RunSubElement <RaidExperienceLevelSuperiorLevelDialogElement, long?>()
                                             .ConfigureAwait(false);

                    using (var dbFactory = RepositoryFactory.CreateInstance())
                    {
                        var levelId = DialogContext.GetValue <long>("ExperienceLevelId");

                        dbFactory.GetRepository <RaidExperienceLevelRepository>()
                        .Refresh(obj => obj.SuperiorExperienceLevelId == levelId,
                                 obj => obj.SuperiorExperienceLevelId = obj.SuperiorRaidExperienceLevel.SuperiorExperienceLevelId);

                        if (dbFactory.GetRepository <RaidExperienceLevelRepository>()
                            .RefreshRange(obj => obj.Id != levelId,
                                          obj => obj.SuperiorExperienceLevelId = newSuperiorLevelId))
                        {
                            if (dbFactory.GetRepository <RaidExperienceLevelRepository>()
                                .RefreshRange(obj => obj.SuperiorExperienceLevelId == newSuperiorLevelId &&
                                              obj.Id != levelId,
                                              obj => obj.SuperiorExperienceLevelId = levelId))
                            {
                                dbFactory.GetRepository <RaidExperienceLevelRepository>()
                                .RefreshRanks();
                            }
                        }
                    }

                    return true;
                }
            },
Esempio n. 14
0
    /// <summary>
    /// Returns the reactions which should be added to the message
    /// </summary>
    /// <returns>Reactions</returns>
    public override IReadOnlyList <ReactionData <bool> > GetReactions()
    {
        return(_reactions ??= new List <ReactionData <bool> >
        {
            new ()
            {
                Emoji = DiscordEmojiService.GetEditEmoji(CommandContext.Client),
                CommandText = LocalizationGroup.GetFormattedText("EditAliasCommand", "{0} Edit alias name", DiscordEmojiService.GetEditEmoji(CommandContext.Client)),
                Func = async() =>
                {
                    var aliasName = await RunSubElement <RaidTemplateAliasNameDialogElement, string>()
                                    .ConfigureAwait(false);

                    using (var dbFactory = RepositoryFactory.CreateInstance())
                    {
                        var templateId = DialogContext.GetValue <long>("TemplateId");

                        dbFactory.GetRepository <RaidDayTemplateRepository>()
                        .Refresh(obj => obj.Id == templateId, obj => obj.AliasName = aliasName);
                    }

                    return true;
                }
            },
Esempio n. 15
0
    /// <summary>
    /// Returns the reactions which should be added to the message
    /// </summary>
    /// <returns>Reactions</returns>
    public override IReadOnlyList <ReactionData <bool> > GetReactions()
    {
        return(_reactions ??= new List <ReactionData <bool> >
        {
            new ()
            {
                Emoji = DiscordEmojiService.GetEditEmoji(CommandContext.Client),
                CommandText = LocalizationGroup.GetFormattedText("EditInGameNameCommand", "{0} Edit in game name", DiscordEmojiService.GetEditEmoji(CommandContext.Client)),
                Func = async() =>
                {
                    var inGameName = await RunSubElement <GuildRankInGameNameDialogElement, string>().ConfigureAwait(false);

                    using (var dbFactory = RepositoryFactory.CreateInstance())
                    {
                        var rankId = DialogContext.GetValue <int>("RankId");

                        dbFactory.GetRepository <GuildRankRepository>()
                        .Refresh(obj => obj.Id == rankId,
                                 obj => obj.InGameName = inGameName);
                    }

                    return true;
                }
            },
Esempio n. 16
0
    /// <summary>
    /// Returns the reactions which should be added to the message
    /// </summary>
    /// <returns>Reactions</returns>
    public override IReadOnlyList <ReactionData <bool> > GetReactions()
    {
        return(_reactions ??= new List <ReactionData <bool> >
        {
            new ()
            {
                Emoji = DiscordEmojiService.GetEditEmoji(CommandContext.Client),
                CommandText = LocalizationGroup.GetFormattedText("EditDescriptionCommand", "{0} Edit description", DiscordEmojiService.GetEditEmoji(CommandContext.Client)),
                Func = async() =>
                {
                    var description = await RunSubElement <CalendarTemplateDescriptionDialogElement, string>()
                                      .ConfigureAwait(false);

                    using (var dbFactory = RepositoryFactory.CreateInstance())
                    {
                        var templateId = DialogContext.GetValue <long>("CalendarTemplateId");

                        dbFactory.GetRepository <CalendarAppointmentTemplateRepository>()
                        .Refresh(obj => obj.Id == templateId, obj => obj.Description = description);
                    }

                    return true;
                }
            },
Esempio n. 17
0
 /// <summary>
 /// Return the message of element
 /// </summary>
 /// <returns>Message</returns>
 public override string GetMessage() => LocalizationGroup.GetFormattedText("Message", "Please enter on which {0} of the month the appointment should be created or zero if it should be created every week.", LocalizationGroup.CultureInfo.DateTimeFormat.GetDayName(DialogContext.GetValue <DayOfWeek>("DayOfWeek")));
Esempio n. 18
0
    /// <summary>
    /// Returns the reactions which should be added to the message
    /// </summary>
    /// <returns>Reactions</returns>
    public override IReadOnlyList <ReactionData <bool> > GetReactions()
    {
        return(_reactions ??= new List <ReactionData <bool> >
        {
            new ()
            {
                Emoji = DiscordEmojiService.GetEditEmoji(CommandContext.Client),
                CommandText = LocalizationGroup.GetFormattedText("EditApiKeyCommand", "{0} Edit api key", DiscordEmojiService.GetEditEmoji(CommandContext.Client)),
                Func = async() =>
                {
                    var success = false;

                    var apiKey = await RunSubElement <AccountApiKeyDialogElement, string>().ConfigureAwait(false);

                    apiKey = apiKey?.Trim();

                    if (string.IsNullOrWhiteSpace(apiKey) == false)
                    {
                        try
                        {
                            var connector = new GuidWars2ApiConnector(apiKey);
                            await using (connector.ConfigureAwait(false))
                            {
                                var tokenInformation = await connector.GetTokenInformationAsync()
                                                       .ConfigureAwait(false);

                                if (tokenInformation?.Permissions != null &&
                                    tokenInformation.Permissions.Contains(TokenInformation.Permission.Account) &&
                                    tokenInformation.Permissions.Contains(TokenInformation.Permission.Characters) &&
                                    tokenInformation.Permissions.Contains(TokenInformation.Permission.Progression))
                                {
                                    var accountInformation = await connector.GetAccountInformationAsync()
                                                             .ConfigureAwait(false);

                                    if (accountInformation.Name == DialogContext.GetValue <string>("AccountName"))
                                    {
                                        using (var dbFactory = RepositoryFactory.CreateInstance())
                                        {
                                            var user = await CommandContext.GetCurrentUser()
                                                       .ConfigureAwait(false);

                                            if (dbFactory.GetRepository <AccountRepository>()
                                                .Refresh(obj => obj.UserId == user.Id &&
                                                         obj.Name == accountInformation.Name,
                                                         obj =>
                                            {
                                                obj.ApiKey = apiKey;
                                                obj.Permissions = GuildWars2ApiPermissionConverter.ToPermission(tokenInformation.Permissions);
                                            }))
                                            {
                                                success = true;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        await CommandContext.Channel
                                        .SendMessageAsync(LocalizationGroup.GetText("AccountNameMismatch", "The provided api key doesn't match the current account name."))
                                        .ConfigureAwait(false);
                                    }
                                }
                                else
                                {
                                    await CommandContext.Channel
                                    .SendMessageAsync(LocalizationGroup.GetText("InvalidToken", "The provided token is invalid or doesn't have the required permissions."))
                                    .ConfigureAwait(false);
                                }
                            }
                        }
                        catch (HttpRequestException ex) when(ex.StatusCode is HttpStatusCode.Unauthorized or HttpStatusCode.Forbidden)
                        {
                            await CommandContext.Channel
                            .SendMessageAsync(LocalizationGroup.GetText("InvalidToken", "The provided token is invalid or doesn't have the required permissions."))
                            .ConfigureAwait(false);
                        }
                    }

                    return success;
                }
            },
            new ()
            {
                Emoji = DiscordEmojiService.GetEdit2Emoji(CommandContext.Client),
                CommandText = LocalizationGroup.GetFormattedText("EditDpsReportUserTokenCommand", "{0} Edit dps report user token", DiscordEmojiService.GetEdit2Emoji(CommandContext.Client)),
                Func = async() =>
                {
                    var token = await RunSubElement <AccountDpsReportUserTokenDialogElement, string>()
                                .ConfigureAwait(false);

                    using (var dbFactory = RepositoryFactory.CreateInstance())
                    {
                        var accountName = DialogContext.GetValue <string>("AccountName");

                        var user = await CommandContext.GetCurrentUser()
                                   .ConfigureAwait(false);

                        dbFactory.GetRepository <AccountRepository>()
                        .Refresh(obj => obj.UserId == user.Id &&
                                 obj.Name == accountName,
                                 obj => obj.DpsReportUserToken = token);
                    }

                    return true;
                }
            },
            new ()
            {
                Emoji = DiscordEmojiService.GetCrossEmoji(CommandContext.Client),
                CommandText = LocalizationGroup.GetFormattedText("CancelCommand", "{0} Cancel", DiscordEmojiService.GetCrossEmoji(CommandContext.Client)),
                Func = () => Task.FromResult(false)
            }
        });