public static Embed FetchRandImage(string type)
        {
            var    embed    = new EmbedBuilder();
            string url      = String.Empty;
            string jsonData = String.Empty;

            switch (type.ToLower())
            {
            case "cat":
                url      = "http://aws.random.cat/meow";
                jsonData = new WebClient().DownloadString(url);
                RandomCat randCat = JsonConvert.DeserializeObject <RandomCat>(jsonData);
                return(embed.WithTitle("Cat").WithImageUrl(randCat.ImageUrl).Build());

            case "dog":
                url      = "https://dog.ceo/api/breeds/image/random";
                jsonData = new WebClient().DownloadString(url);
                RandomDog randDog = JsonConvert.DeserializeObject <RandomDog>(jsonData);
                return(embed.WithTitle("Dog").WithImageUrl(randDog.ImageUrl).Build());

            case "meme":
                url      = "https://api-to.get-a.life/meme";
                jsonData = new WebClient().DownloadString(url);
                RandomMeme randMeme = JsonConvert.DeserializeObject <RandomMeme>(jsonData);
                return(embed.WithTitle("Meme").WithDescription(randMeme.Text).WithImageUrl(randMeme.ImageUrl).Build());

            default:
                return(embed.WithTitle("ERROR").Build());
            }
        }
Exemple #2
0
        public async Task <ActionResult <RandomDog> > GetRandomDog()
        {
            RandomDog randomDog = await _service.FetchRandomDog();

            if (randomDog.DogFound)
            {
                _logger.LogTrace($"Fetched random dog with image url: {randomDog.ImageUrl}");
            }
            else
            {
                _logger.LogWarning("Error fetching random dog.");
            }

            return(Ok(randomDog));
        }
Exemple #3
0
    public static string Get()
    {
        RandomDog picture = new RandomDog {
        };

        using (WebClient client = new WebClient()) {
            var json = client.DownloadString("https://random.dog/woof.json");
            JsonConvert.PopulateObject(json, picture);
        }
        //var client = _httpClientFactory.CreateClient();
        //client.BaseAddress = new Uri("https://random.dog/");
        //RandomDog result = await client.GetFromJsonAsync("/woof.json");
        //return result.url;

        // * der tage nimmt man httpclient, nicht webclient
        // * httpclient hat dann GetFromJsonAsync: smile:

        return(picture.url);
    }
Exemple #4
0
        public async Task Dog()
        {
            RandomDog randomDog = null;

            using (WebClient webClient = new WebClient())
            {
                try
                {
                    webClient.UseDefaultCredentials = true;
                    string json = webClient.DownloadString("https://some-random-api.ml/img/dog");
                    randomDog = JsonConvert.DeserializeObject <RandomDog>(json);
                }
                catch (Exception ex)
                {
                    await ReplyAsync($"The API used for dog images has failed and isn't responding. Please try again. If this problem persists, let us know in the support server (<https://discord.gg/kbtu49S>).");

                    Console.WriteLine(ex);
                }
            }

            Random random   = new Random();
            int    redRnd   = random.Next(0, 255);
            Random random2  = new Random();
            int    greenRnd = random.Next(0, 255);
            Random random3  = new Random();
            int    blueRnd  = random.Next(0, 255);

            var foot = new EmbedFooterBuilder()
            {
                Text = $"Powered by https://some-random-api.ml/",
            };

            var embed = new EmbedBuilder()
            {
                Title    = "Random Dog Generator",
                ImageUrl = $"{randomDog.Url}",
                Color    = new Color(redRnd, greenRnd, blueRnd),
                Footer   = foot,
            };

            await ReplyAsync("", false, embed.Build());
        }
Exemple #5
0
    public static void OnMessage(object sender, IrcEventArgs e)
    {
        switch (e.Data.MessageArray[0].ToLower())
        {
        // LIST
        case "!list":
            System.Console.WriteLine("[" + DateTime.Now.ToString("HH:mm:ss") + "] " + e.Data.Channel + " - " + e.Data.Nick + " | " + e.Data.Message);
            irc.SendMessage(SendType.Message, e.Data.Channel, "!dog !dogpic !dogpics");
            irc.SendMessage(SendType.Message, e.Data.Channel, "!randomdog !random.dog");
            irc.SendMessage(SendType.Message, e.Data.Channel, "!randomcat !random.cat");
            irc.SendMessage(SendType.Message, e.Data.Channel, "!awoo !woof !meow");
            irc.SendMessage(SendType.Message, e.Data.Channel, "!oida");
            break;

        // RANDOM DOG SELFHOSTED
        case "!dog":
        case "!dogpic":
        case "!dogpics":
            System.Console.WriteLine("[" + DateTime.Now.ToString("HH:mm:ss") + "] " + e.Data.Channel + " - " + e.Data.Nick + " | " + e.Data.Message);
            irc.SendMessage(SendType.Message, e.Data.Channel, RandomDogFromFile.Get() + " 🐾");
            break;

        case "!add":
            if (e.Data.MessageArray.Length > 1)
            {
                RandomDogFromFile.Add(e.Data.MessageArray[1]);
            }
            break;

        // RANDOM DOG
        case "!drecksvieh":
        case "!randomdog":
        case "!random.dog":
            System.Console.WriteLine("[" + DateTime.Now.ToString("HH:mm:ss") + "] " + e.Data.Channel + " - " + e.Data.Nick + " | " + e.Data.Message);
            irc.SendMessage(SendType.Message, e.Data.Channel, RandomDog.Get() + " 🐾");
            break;

        // RANDOM CAT
        case "!randomcat":
        case "!random.cat":
            Console.WriteLine("[" + DateTime.Now.ToString("HH:mm:ss") + "] " + e.Data.Channel + " - " + e.Data.Nick + " | " + e.Data.Message);
            irc.SendMessage(SendType.Message, e.Data.Channel, RandomCat.Get() + " 🐾");
            break;

        // REACTION COMMANDS
        case "!awoo":
            Console.WriteLine("[" + DateTime.Now.ToString("HH:mm:ss") + "] " + e.Data.Channel + " - " + e.Data.Nick + " | " + e.Data.Message);
            irc.SendMessage(SendType.Message, e.Data.Channel, "Awoo!");
            break;

        case "!woof":
            Console.WriteLine("[" + DateTime.Now.ToString("HH:mm:ss") + "] " + e.Data.Channel + " - " + e.Data.Nick + " | " + e.Data.Message);
            irc.SendMessage(SendType.Message, e.Data.Channel, "Woof!");
            break;

        case "!meow":
            Console.WriteLine("[" + DateTime.Now.ToString("HH:mm:ss") + "] " + e.Data.Channel + " - " + e.Data.Nick + " | " + e.Data.Message);
            irc.SendMessage(SendType.Message, e.Data.Channel, "meow!");
            break;

        case "!oida":
            if (e.Data.MessageArray.Length > 1)
            {
                Console.WriteLine("[" + DateTime.Now.ToString("HH:mm:ss") + "] " + e.Data.Channel + " - " + e.Data.Nick + " | " + e.Data.Message);
                irc.SendMessage(SendType.Message, e.Data.Channel, "Oida " + e.Data.MessageArray[1] + "!");
                break;
            }
            else
            {
                Console.WriteLine("[" + DateTime.Now.ToString("HH:mm:ss") + "] " + e.Data.Channel + " - " + e.Data.Nick + " | " + e.Data.Message);
                irc.SendMessage(SendType.Message, e.Data.Channel, "Oida!");
                break;
            }
        }
    }