Exemple #1
0
 private Task Client_Ready(ReadyEventArgs e)
 {
     // Create a log message
     e.Client.DebugLogger.LogMessage(LogLevel.Info, "ArtifactWikiBot", "Client is online and ready.", DateTime.Now);
     // Signal that the client is ready now
     IsReady = true;
     BotStates.SetReady();
     return(Task.CompletedTask);
 }
        public static async Task <TimeSpan> UpdateAllCards()
        {
            await BotStates.SetUpdating();

            DateTime start = DateTime.Now;

            await UpdateAbilities();
            await UpdateHeroes();
            await UpdateItems();
            await UpdateSpells();
            await UpdateCreatures();
            await UpdateImprovements();

            DateTime end = DateTime.Now;
            await BotStates.SetReady();

            TimeSpan time = end - start;

            Client.DebugLogger.LogMessage(LogLevel.Info, "APIManager", $"Card lists updated in {time}.", DateTime.Now);
            return(time);
        }
        public static async Task <TimeSpan> UpdateRecentChanges()
        {
            await BotStates.SetUpdating();

            DateTime start = DateTime.Now;

            using (var client = new System.Net.WebClient())
            {
                client.DownloadFile(changesAPI, "changes_download.json");
            }

            string json = "";

            using (var fs = File.OpenRead("changes_download.json"))
                using (var sr = new StreamReader(fs, new UTF8Encoding(false)))
                    json = await sr.ReadToEndAsync();

            JObject o = JObject.Parse(json);

            JToken[] _changes = o["query"]["recentchanges"].Children().ToArray();

            WikiChange[] changes = new WikiChange[_changes.Length];

            for (int i = 0; i < changes.Length; i++)
            {
                changes[i] = JsonConvert.DeserializeObject <WikiChange>(_changes[i].ToString());
            }

            Array.Sort(changes);
            RecentChanges = changes;
            Client.DebugLogger.LogMessage(LogLevel.Debug, "JsonManager", "'changes.json' updated.", DateTime.Now);
            DateTime end = DateTime.Now;
            await BotStates.SetReady();

            return(end - start);
        }