Пример #1
0
    public async Task Verify(string verifiedRoleName, [Remainder] string remainder)
    {
        using var setTyping = Context.Channel.EnterTypingState();

        var role = Context.Guild.Roles.FirstOrDefault(x => x.Name == verifiedRoleName);

        if (role is null)
        {
            await ReplyAsync($"I couldn't find any roles by the name of '{verifiedRoleName}' on this server.");

            return;
        }

        var criteria = new SetVerificationCriteria()
        {
            GuildId = Context.Guild.Id,
            RoleId  = role.Id,
            FreeCompanyAndServer = remainder
        };

        var result = await _guildOptionsManager.SetVerification(criteria);

        if (result.Status == SetVerificationStatus.FreeCompanyNotFound)
        {
            await ReplyAsync($"I could not find any free company with '{remainder}'. Please provide full free company name and FFXIV server.");

            return;
        }

        await ReplyAsync("Done.");
    }
Пример #2
0
    public async Task <SetVerificationResult> SetVerification(SetVerificationCriteria criteria)
    {
        _setVerificationValidator.ValidateAndThrow(criteria);

        _logger.LogDebug("Setting verification options for guild '{GuildId}' with role '{RoleId}' and free company '{Query}'.", criteria.GuildId, criteria.RoleId, criteria.FreeCompanyAndServer);

        var(name, server) = NameServerEngine.Parse(criteria.FreeCompanyAndServer);

        var fcSearchQuery = new SearchFreeCompanyQuery()
        {
            Name   = name,
            Server = server
        };

        _logger.LogDebug("Searching for free company '{FreeCompanyName}' on server '{ServerName}'", name, server);

        var fcSearchData = await _xivApiAccessor.SearchFreeCompany(fcSearchQuery);

        // Find single, exact match.
        var fc = fcSearchData.Results?.SingleOrDefault(x =>
                                                       (x.Name?.Equals(name, StringComparison.OrdinalIgnoreCase) ?? false) &&
                                                       (x.Server?.Equals(server, StringComparison.OrdinalIgnoreCase) ?? false));

        if (fc is null)
        {
            _logger.LogDebug("Could not find single exact match of '{FreeCompanyName}' on server '{ServerName}'", name, server);

            return(new SetVerificationResult()
            {
                Status = SetVerificationStatus.FreeCompanyNotFound
            });
        }

        _logger.LogDebug("Found free company '{FreeCompanyName}' with Id '{FreeCompanyId}'. Saving verification options to database.", fc.Name, fc.Id);

        var getOptionsQuery = new GetOptionsQuery()
        {
            GuildId = criteria.GuildId
        };

        var options = await _guildAccessor.GetOptions(getOptionsQuery) ?? new GuildOptions();

        options.Id             = criteria.GuildId;
        options.VerifiedRoleId = criteria.RoleId;
        options.FreeCompany    = new Abstractions.Data.Storage.Models.Guild.FreeCompany()
        {
            Id     = fc.Id,
            Name   = fc.Name,
            Server = fc.Server
        };

        var saveOptionsQuery = new SaveOptionsQuery()
        {
            Options = options
        };

        await _guildAccessor.SaveOptions(saveOptionsQuery);

        return(new SetVerificationResult()
        {
            Status = SetVerificationStatus.Success
        });
    }