private async Task ShinyRandom(CommandContext ctx) { string pokedexJson = Path.Combine(DashingWanderer.Globals.AppPath, "maingamepokedex.json"); JObject pokedexArray = JObject.Parse(File.ReadAllText(pokedexJson)); List <KeyValuePair <string, JToken> > allPokedexTokens = new List <KeyValuePair <string, JToken> >(); foreach (KeyValuePair <string, JToken> keyValuePair in pokedexArray) { allPokedexTokens.Add(keyValuePair); } string pokeName = allPokedexTokens[DashingWanderer.Globals.Random.Next(allPokedexTokens.Count - 1)].Key; if (!NetworkFileHelper.RemoteFileExists($"https://play.pokemonshowdown.com/sprites/xyani-shiny/{pokeName}.gif")) { await this.Random(ctx); return; } using (WebClient client = new WebClient()) using (MemoryStream stream = new MemoryStream()) { byte[] gifBytes = client.DownloadData(new Uri($"https://play.pokemonshowdown.com/sprites/xyani-shiny/{pokeName}.gif")); await stream.WriteAsync(gifBytes, 0, gifBytes.Length); stream.Position = 0; await ctx.RespondWithFileAsync($"{pokeName}.gif", stream); } }
public ActionResult Get(string url, string fileName, string contentType) { var fileContents = NetworkFileHelper.GetNetworkFileBinaryContent(url); if (string.IsNullOrWhiteSpace(fileName)) { fileName = GetFileNameFromUrl(url); } if (string.IsNullOrWhiteSpace(contentType)) { contentType = fileExtensionContentTypeMapping.GetValue(Path.GetExtension(fileName).ToLower()); } var contentDisposition = new ContentDisposition { Inline = true, FileName = fileName }; Response.AddHeader("Content-Disposition", contentDisposition.ToString()); return(new FileContentResult(fileContents, contentType)); }
public FileContentResult RenderJavaScript(string url) { return(File(NetworkFileHelper.GetNetworkFileBinaryContent(url), "text/javascript")); }