public async Task PriceCheck(string coin, string cur = "USD", string expanded = null) { Console.WriteLine("Command: crypto pricecheck"); //get the api-correct name for the coin string guildid = Context.Guild.Id.ToString(); string guildpath = FileDirUtil.GetGuildDir(guildid); Dictionary <string, string> coindict = JSONUtil.GetJsonToDic <string, string>(Path.Combine(guildpath, FileDirUtil.COINS)); string coinname = GetFullCoinName(coindict, coin); string message = "Could not find the coin mentioned, try updating my record!"; if (coinname != null) { if (cur == "full") { cur = "usd"; expanded = "full"; } string response = Request(coinname, cur); message = FormatCoinPriceResponse(response, cur.ToLower(), expanded); } await ReplyAsync(message); }
public async Task CheckLive(SocketUserMessage msg, string guildid) { string guildids = FileDirUtil.GetGuildFile(guildid, FileDirUtil.JSONIDS); string guildlive = FileDirUtil.GetGuildFile(guildid, FileDirUtil.JSONLIVE); string guildstream = FileDirUtil.GetGuildFile(guildid, FileDirUtil.JSONSTREAMS); //dic of users to check; dic of last known live, list of currently live Dictionary <string, string> users = JSONUtil.GetJsonToDic <string, string>(guildids); Dictionary <string, string> live = JSONUtil.GetJsonToDic <string, string>(guildlive); List <string> liveusers = new List <string>(); string s = string.Join("&channel=", users.Select(x => x.Value)); string response = SendRequest(BaseString + "streams/?channel=", s, "Requesting live channels for " + s); Console.WriteLine("channelresponse" + response); JSONUtil.WriteJsonToFile(null, guildstream, response); Streams streams = JsonConvert.DeserializeObject <Streams>(response); //if any live streams, check if already noted as live, if not, set to "live" and notify if (streams._total > 0) { foreach (Stream x in streams.streams) { liveusers.Add(x.channel.name); if (live[x.channel.name] != "live") { live[x.channel.name] = "live"; SocketGuildUser guilduser = msg.Author as SocketGuildUser; SocketRole guildrole = guilduser.Guild.Roles.FirstOrDefault(y => y.Name == "notify"); string mention = ""; if (guildrole != null) { mention = guildrole.Mention; } await msg.Channel.SendMessageAsync($"{mention} {x.channel.name} has just gone live playing {x.channel.game}! \n" + "https://www.twitch.tv/" + x.channel.name); } } } Console.WriteLine("check1"); //check the current live against previous live //if set as live when not currently live, set to offline Dictionary <string, string> newDictionary = live.ToDictionary(entry => entry.Key, entry => entry.Value); Console.WriteLine("check2"); foreach (KeyValuePair <string, string> entry in live) { if (entry.Value == "live") { if (!liveusers.Any(x => x == entry.Key)) { newDictionary[entry.Key] = "offline"; } } } Console.WriteLine("check3"); live = newDictionary.ToDictionary(entry => entry.Key, entry => entry.Value); Console.WriteLine("check4"); JSONUtil.WriteJsonToFile(live, guildlive); Console.WriteLine("Completed check\n"); }