Ejemplo n.º 1
0
        public static PoeCharacterInfo GetCharacterData()
        {
            PoeCharacterInfo characterInfo = new PoeCharacterInfo();

            if (string.IsNullOrEmpty(Properties.Settings.Default.AccountName))
            {
                Logger.Get.Error("Account name is not set!");
                return(null);
            }

            try
            {
                if (!string.IsNullOrEmpty(Properties.Settings.Default.SessionId))
                {
                    _webclient.Headers.Add("POESESSID", Properties.Settings.Default.SessionId);
                }

                var rawData = _webclient.DownloadString(
                    "https://www.pathofexile.com/character-window/get-characters?accountName=" + Properties.Settings.Default.AccountName);

                if (rawData.Length == 0)
                {
                    Logger.Get.Error("Data retrived from PoE api was empty");
                    return(null);
                }

                characterInfo = Array.Find(JsonConvert.DeserializeObject <PoeCharacterInfo[]>(rawData), x => x.LastActive);
            }
            catch (WebException ex)
            {
                // profile probably private or wrong name/id
                if (ex.Status == WebExceptionStatus.ProtocolError &&
                    ((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.Forbidden &&
                    string.IsNullOrEmpty(Properties.Settings.Default.SessionId))
                {
                    Logger.Get.Error($"Failed to retrieve data from PoE api, profile is probably private: {ex.Message}");
                    // TODO: notify user
                }
                else
                {
                    Logger.Get.Error($"Failed to retrieve data from PoE api: {ex.Message}");
                }

                return(null);
            }

            Logger.Get.Success($"Updated character info for {characterInfo.Name}!");

            return(characterInfo);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets triggered when the player connects to a new instance
        /// </summary>
        /// <param name="line"></param>
        /// <param name="match"></param>
        private void OnInstanceConnect(string line, Match match)
        {
            Logger.Get.Debug($"Connected to server instance {match.Groups[1]}");

            _characterInfo = PoeApi.GetCharacterData();

            if (_characterInfo is null)
            {
                return;
            }

            _discord.RichPresenceData.Details        = $"{_characterInfo.League} League";
            _discord.RichPresenceData.LargeImageKey  = _characterInfo.Class.ToLower();
            _discord.RichPresenceData.LargeImageText = $"{_characterInfo.Class} ({_characterInfo.Level})";
        }