private void OnTimer2MinTick(object sender, EventArgs e) { var posts = Instagram.GetPosts(); if (posts.Count > 0) { bool petsExist = File.Exists($"{BotTools.BasePath}\\resources\\raz_pets.json"); var pastPets = petsExist ? BotTools.ReadFromJson <List <string> >("resources\\raz_pets") : new List <string>(); try { var newPets = posts.Where(p => !pastPets.Contains(p["permalink"])); if (newPets.Count() > 0) { foreach (var post in newPets) { BotTools.LogLine($"Saw new Raz pet -> {post["permalink"]}"); DiscordBot.PostToPetsChannel(post); pastPets.Add(post["permalink"]); using (var webClient = new System.Net.WebClient()) { webClient.DownloadFile(post["media_url"], $"{BotTools.BasePath}\\datasources\\raz.jpg"); } } BotTools.WriteToJson(pastPets, "resources\\raz_pets"); } } catch (Exception petsException) { BotTools.LogToSessionLogFile(petsException.ToString()); BotTools.LogLine("There was a problem loading past Raz Pets! See the session log for details."); } } }
private static void Client_OnModeratorsReceived(object sender, OnModeratorsReceivedArgs e) { var mods = String.Join(", ", e.Moderators); BotTools.LogLine($"Channel Moderators: {mods}"); BotTools.WriteToJson(e.Moderators, "resources\\moderators"); }
private static Dictionary <string, Playlist> LoadPlaylists() { string filePath = $"{BotTools.BasePath}\\resources\\playlists.json"; if (File.Exists(filePath)) { var pl = BotTools.ReadFromJson <Dictionary <string, Playlist> >("resources\\playlists"); return(pl); } else { var newPL = new Dictionary <string, Playlist>() { ["request"] = new Playlist(), ["default"] = new Playlist() }; BotTools.WriteToJson(newPL, "resources\\playlists"); return(newPL); } }
public static void SaveSettings() { BotTools.WriteToJson(Settings, "resources\\bot_settings"); }
public static void SavePlaylists() { BotTools.WriteToJson(Playlists, "resources\\playlists"); }
public void SaveCustomCommands() { BotTools.WriteToJson(CustomMap, "resources\\custom_commands"); }
public static void FetchInventoryData() { try { // Fetch NA item data var inventoryData = new Dictionary <string, Dictionary <string, dynamic> >() { ["na"] = new Dictionary <string, dynamic>(), ["eu"] = new Dictionary <string, dynamic>() }; List <string> naCharacterNames = GetCharacters("na").ToObject <List <string> >(); foreach (var characterName in naCharacterNames) { string encodedCharacterName = characterName.Replace(" ", "%20"); JObject upperInventoryData = WebTools.GetJObjectResponse($"{BaseURL}/characters/{encodedCharacterName}/inventory", DefaultHeaders("na")); if (upperInventoryData != null && upperInventoryData.HasValues) { JToken bags = upperInventoryData["bags"]; inventoryData["na"][characterName] = new List <Dictionary <string, dynamic> >(); foreach (JToken bag in bags) { if (bag.HasValues) { JToken bagContents = bag["inventory"]; foreach (JToken item in bagContents) { inventoryData["na"][characterName].Add(item.ToObject <Dictionary <string, dynamic> >()); } } } } } JArray naSharedBankData = WebTools.GetJArrayResponse($"{BaseURL}/account/bank", DefaultHeaders("na")); JArray naSharedInventoryData = WebTools.GetJArrayResponse($"{BaseURL}/account/inventory", DefaultHeaders("na")); JArray naMaterialsData = WebTools.GetJArrayResponse($"{BaseURL}/account/materials", DefaultHeaders("na")); JArray naWalletData = WebTools.GetJArrayResponse($"{BaseURL}/account/wallet", DefaultHeaders("na")); inventoryData["na"]["Shared Bank"] = naSharedBankData.ToObject <List <Dictionary <string, dynamic> > >(); inventoryData["na"]["Shared Inventory"] = naSharedInventoryData.ToObject <List <Dictionary <string, dynamic> > >(); inventoryData["na"]["Materials"] = naMaterialsData.ToObject <List <Dictionary <string, dynamic> > >(); inventoryData["na"]["Wallet"] = naWalletData.ToObject <List <Dictionary <string, dynamic> > >(); // Fetch EU item data List <string> euCharacterNames = GetCharacters("eu").ToObject <List <string> >(); foreach (var characterName in euCharacterNames) { string encodedCharacterName = characterName.Replace(" ", "%20"); JObject upperInventoryData = WebTools.GetJObjectResponse($"{BaseURL}/characters/{encodedCharacterName}/inventory", DefaultHeaders("eu")); if (upperInventoryData != null && upperInventoryData.HasValues) { JToken bags = upperInventoryData["bags"]; inventoryData["eu"][characterName] = new List <Dictionary <string, dynamic> >(); foreach (JToken bag in bags) { if (bag.HasValues) { JToken bagContents = bag["inventory"]; foreach (JToken item in bagContents) { inventoryData["eu"][characterName].Add(item.ToObject <Dictionary <string, dynamic> >()); } } } } } JArray euSharedBankData = WebTools.GetJArrayResponse($"{BaseURL}/account/bank", DefaultHeaders("eu")); JArray euSharedInventoryData = WebTools.GetJArrayResponse($"{BaseURL}/account/inventory", DefaultHeaders("eu")); JArray euMaterialsData = WebTools.GetJArrayResponse($"{BaseURL}/account/materials", DefaultHeaders("eu")); JArray euWalletData = WebTools.GetJArrayResponse($"{BaseURL}/account/wallet", DefaultHeaders("eu")); inventoryData["eu"]["Shared Bank"] = euSharedBankData.ToObject <List <Dictionary <string, dynamic> > >(); inventoryData["eu"]["Shared Inventory"] = euSharedInventoryData.ToObject <List <Dictionary <string, dynamic> > >(); inventoryData["eu"]["Materials"] = euMaterialsData.ToObject <List <Dictionary <string, dynamic> > >(); inventoryData["eu"]["Wallet"] = euWalletData.ToObject <List <Dictionary <string, dynamic> > >(); BotTools.WriteToJson(inventoryData, "resources\\inventory_data"); } catch (NullReferenceException e) { BotTools.LogToSessionLogFile(e.ToString()); } }