Beispiel #1
0
 private async Task sendGWItemsXMLCommand()
 {
     try
     {
         await this.Context.Message.Channel.SendFileAsync(FileLocations.gwItemNames());
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
Beispiel #2
0
        private async Task BackupGWCommand()
        {
            XmlDocument xmlParameters = new XmlDocument();

            try
            {
                xmlParameters.Load(FileLocations.gwItemNames());
                xmlParameters.Save(FileLocations.gwItemNamesBackup());

                await ReplyAsync($"XML database file backed up to {FileLocations.gwItemNamesBackup()}");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Beispiel #3
0
        private string itemNameFromId(int itemId)
        {
            XmlDocument gwItemsDocument = new XmlDocument();

            gwItemsDocument.Load(FileLocations.gwItemNames());
            XmlElement  gwRoot          = gwItemsDocument.DocumentElement;
            IEnumerator itemsEnumerator = gwRoot.GetEnumerator();
            XmlNode     itemNode        = null;

            while (itemsEnumerator.MoveNext())
            {
                XmlElement curNode = itemsEnumerator.Current as XmlElement;

                if (curNode.GetAttribute("id") == itemId.ToString())
                {
                    itemNode = curNode;
                    break;
                }
            }

            return(itemNode.InnerText);
        }
Beispiel #4
0
        private async Task RestoreAllCommand()
        {
            XmlDocument xmlParameters = new XmlDocument();
            XmlDocument gwItems       = new XmlDocument();
            XmlDocument xmlDB         = new XmlDocument();

            try
            {
                xmlParameters.Load(FileLocations.backupXMLParameters());
                xmlParameters.Save(FileLocations.xmlParameters());
                gwItems.Load(FileLocations.gwItemNamesBackup());
                gwItems.Save(FileLocations.gwItemNames());
                xmlDB.Load(FileLocations.backupXMLDatabase());
                xmlDB.Save(FileLocations.xmlDatabase());

                await ReplyAsync("XML parameters restored");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Beispiel #5
0
        private List <itemResult> itemSearch(string queryStr)
        {
            string            itemName;
            Hashtable         itemList   = new Hashtable();
            int               matchcount = 0;
            List <itemResult> results    = new List <itemResult>();

            XmlDocument gwItemsDocument = new XmlDocument();

            gwItemsDocument.Load(FileLocations.gwItemNames());
            XmlElement  gwRoot          = gwItemsDocument.DocumentElement;
            IEnumerator itemsEnumerator = gwRoot.GetEnumerator();

            while (itemsEnumerator.MoveNext())
            {
                XmlElement curNode = itemsEnumerator.Current as XmlElement;

                itemList.Add(curNode.GetAttribute("id"), curNode.InnerText);
            }


            foreach (DictionaryEntry curItem in itemList)
            {
                //curGame = games[i] as Hashtable;
                itemName = Regex.Replace(curItem.Value.ToString().ToLower(), @"\s+", "");
                if (itemName.Contains(queryStr))
                {
                    matchcount++;
                    int        similarity  = LevenshteinDistance.Compute(itemName, queryStr);
                    itemResult resultClass = new itemResult
                    {
                        Name       = curItem.Value.ToString(),
                        id         = curItem.Key.ToString(),
                        similarity = similarity
                    };
                    results.Add(resultClass);
                }
            }

            if (results.Count == 0)
            {
                foreach (DictionaryEntry curItem in itemList)
                {
                    //curGame = games[i] as Hashtable;
                    itemName = Regex.Replace(curItem.Value.ToString().ToLower(), @"\s+", "");
                    matchcount++;
                    int similarity = LevenshteinDistance.Compute(itemName, queryStr);
                    if (similarity < 15)
                    {
                        itemResult resultClass = new itemResult
                        {
                            Name       = curItem.Value.ToString(),
                            id         = curItem.Key.ToString(),
                            similarity = similarity
                        };
                        results.Add(resultClass);
                    }
                }
            }
            return(results);
        }
Beispiel #6
0
        private async Task <int> getAmountStored(int itemId, IUser user)
        {
            string apiKey;
            string url;
            Array  materialStorage;
            int    materialCount = 0;
            int    amountStored  = 0;

            if (user == null)
            {
                user = this.Context.Message.Author;
            }

            apiKey = await getUserAPIKey(user);

            url             = CoOpGlobal.API.guildWarsPrefix + "/account/materials?access_token=" + apiKey;
            materialStorage = getAPIResponse(url);

            materialCount = materialStorage.Length;

            XmlDocument gwItemsDocument = new XmlDocument();

            gwItemsDocument.Load(FileLocations.gwItemNames());
            XmlElement gwRoot    = gwItemsDocument.DocumentElement;
            Boolean    fileIsNew = gwRoot.HasChildNodes;
            Boolean    saveFile  = false;

            for (int i = 0; i < materialCount; i++)
            {
                Hashtable  curMaterial = materialStorage.GetValue(i) as Hashtable;
                XmlElement gwItem      = null;

                if (fileIsNew)
                {
                    IEnumerator filteredEnumerator = gwItemsDocument.SelectNodes($"//Item[@id={curMaterial["id"].ToString()}]").GetEnumerator();
                    filteredEnumerator.MoveNext();
                    gwItem = filteredEnumerator.Current as XmlElement;
                }

                if (gwItem == null)
                {
                    string    itemurl     = CoOpGlobal.API.guildWarsPrefix + "/items?id=" + curMaterial["id"].ToString();
                    Hashtable itemDetails = getAPIResponse(itemurl, true).GetValue(0) as Hashtable;

                    gwItem = gwItemsDocument.CreateElement($"Item");
                    gwItem.SetAttribute("id", $"{curMaterial["id"].ToString()}");
                    gwItem.InnerText = itemDetails["name"].ToString();
                    gwRoot.AppendChild(gwItem);

                    saveFile = true;
                }

                if (int.Parse(curMaterial["id"].ToString()) == itemId)
                {
                    amountStored = int.Parse(curMaterial["count"].ToString());
                }
            }

            if (saveFile)
            {
                gwItemsDocument.Save(FileLocations.gwItemNames());
            }

            return(amountStored);
        }