Exemplo n.º 1
0
        /// <summary>Get update check info about a mod.</summary>
        /// <param name="id">The mod ID.</param>
        public async Task <IModPage> GetModData(string id)
        {
            IModPage page = new GenericModPage(this.SiteKey, id);

            if (!uint.TryParse(id, out uint parsedId))
            {
                return(page.SetError(RemoteModStatus.DoesNotExist, $"The value '{id}' isn't a valid Nexus mod ID, must be an integer ID."));
            }

            // Fetch from the Nexus website when possible, since it has no rate limits. Mods with
            // adult content are hidden for anonymous users, so fall back to the API in that case.
            // Note that the API has very restrictive rate limits which means we can't just use it
            // for all cases.
            NexusMod mod = await this.GetModFromWebsiteAsync(parsedId);

            if (mod?.Status == NexusModStatus.AdultContentForbidden)
            {
                mod = await this.GetModFromApiAsync(parsedId);
            }

            // page doesn't exist
            if (mod == null || mod.Status == NexusModStatus.Hidden || mod.Status == NexusModStatus.NotPublished)
            {
                return(page.SetError(RemoteModStatus.DoesNotExist, "Found no Nexus mod with this ID."));
            }

            // return info
            page.SetInfo(name: mod.Name, url: mod.Url, version: mod.Version, downloads: mod.Downloads);
            if (mod.Status != NexusModStatus.Ok)
            {
                page.SetError(RemoteModStatus.TemporaryError, mod.Error);
            }
            return(page);
        }
Exemplo n.º 2
0
        /// <summary>Get metadata about a mod.</summary>
        /// <param name="id">The Nexus mod ID.</param>
        /// <returns>Returns the mod info if found, else <c>null</c>.</returns>
        public async Task <NexusMod> GetModAsync(uint id)
        {
            // Fetch from the Nexus website when possible, since it has no rate limits. Mods with
            // adult content are hidden for anonymous users, so fall back to the API in that case.
            // Note that the API has very restrictive rate limits which means we can't just use it
            // for all cases.
            NexusMod mod = await this.GetModFromWebsiteAsync(id);

            if (mod?.Status == NexusModStatus.AdultContentForbidden)
            {
                mod = await this.GetModFromApiAsync(id);
            }

            return(mod);
        }