<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Discord.Modules;
using System.Net;
using System.IO;
using Newtonsoft.Json.Linq;
using System.Text.RegularExpressions;
using System.Reflection;
using System.Xml;
using Newtonsoft.Json;
using System.Net.Http;
using Discord.Legacy;

namespace NadekoBot.Modules
{
    class Searches : DiscordModule
    {
        public Searches() : base()
        {

        }

        public override void Install(ModuleManager manager)
        {
            var client = NadekoBot.client;

            manager.CreateCommands("",cgb =>
            {
                cgb.CreateCommand("~yt")
                    .Parameter("query",Discord.Commands.ParameterType.Unparsed)
                    .Description("Queries youtubes and embeds the first result")
                    .Do(async e =>
                    {
                        if (!(await ValidateQuery(e.Channel, e.GetArg("query")))) return;

                        var str = ShortenUrl(FindYoutubeUrlByKeywords(e.GetArg("query")));
                        if (string.IsNullOrEmpty(str.Trim()))
                        {
                            await e.Send( "Query failed");
                            return;
                        }
                        await e.Send( str);
                    });

                cgb.CreateCommand("~ani")
                    .Alias("~anime").Alias("~aq")
                    .Parameter("query", Discord.Commands.ParameterType.Unparsed)
                    .Description("Queries anilist for an anime and shows the first result.")
                    .Do(async e =>
                    {
                        if (!(await ValidateQuery(e.Channel, e.GetArg("query")))) return;

                        var result = GetAnimeQueryResultLink(e.GetArg("query"));
                        if (result == null) { 
                            await e.Send( "Failed to find that anime.");
                            return;
                        }

                        await e.Send(result.ToString());
                    });

                cgb.CreateCommand("~mang")
                    .Alias("~manga").Alias("~mq")
                    .Parameter("query", Discord.Commands.ParameterType.Unparsed)
                    .Description("Queries anilist for a manga and shows the first result.")
                    .Do(async e =>
                    {
                        if (!(await ValidateQuery(e.Channel, e.GetArg("query")))) return;

                        var result = GetMangaQueryResultLink(e.GetArg("query"));
                        if (result == null)
                        {
                            await e.Send( "Failed to find that anime.");
                            return;
                        }
                        await e.Send( result.ToString());
                    });
            });
        }

        private string token = "";
        private AnimeResult GetAnimeQueryResultLink(string query)
        {
            try<commit_msg>added random cat command to searches module<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Discord.Modules;
using System.Net;
using System.IO;
using Newtonsoft.Json.Linq;
using System.Text.RegularExpressions;
using System.Reflection;
using System.Xml;
using Newtonsoft.Json;
using System.Net.Http;
using Discord.Legacy;

namespace NadekoBot.Modules
{
    class Searches : DiscordModule
    {
        public Searches() : base()
        {

        }

        public override void Install(ModuleManager manager)
        {
            var client = NadekoBot.client;

            manager.CreateCommands("",cgb =>
            {
                cgb.CreateCommand("~yt")
                    .Parameter("query",Discord.Commands.ParameterType.Unparsed)
                    .Description("Queries youtubes and embeds the first result")
                    .Do(async e =>
                    {
                        if (!(await ValidateQuery(e.Channel, e.GetArg("query")))) return;

                        var str = ShortenUrl(FindYoutubeUrlByKeywords(e.GetArg("query")));
                        if (string.IsNullOrEmpty(str.Trim()))
                        {
                            await e.Send( "Query failed");
                            return;
                        }
                        await e.Send( str);
                    });

                cgb.CreateCommand("~ani")
                    .Alias("~anime").Alias("~aq")
                    .Parameter("query", Discord.Commands.ParameterType.Unparsed)
                    .Description("Queries anilist for an anime and shows the first result.")
                    .Do(async e =>
                    {
                        if (!(await ValidateQuery(e.Channel, e.GetArg("query")))) return;

                        var result = GetAnimeQueryResultLink(e.GetArg("query"));
                        if (result == null) { 
                            await e.Send( "Failed to find that anime.");
                            return;
                        }

                        await e.Send(result.ToString());
                    });

                cgb.CreateCommand("~mang")
                    .Alias("~manga").Alias("~mq")
                    .Parameter("query", Discord.Commands.ParameterType.Unparsed)
                    .Description("Queries anilist for a manga and shows the first result.")
                    .Do(async e =>
                    {
                        if (!(await ValidateQuery(e.Channel, e.GetArg("query")))) return;

                        var result = GetMangaQueryResultLink(e.GetArg("query"));
                        if (result == null)
                        {
                            await e.Send( "Failed to find that anime.");
                            return;
                        }
                        await e.Send( result.ToString());
                    });

                cgb.CreateCommand("~randomcat")
                    .Description("Shows a random cat image.")
                    .Do(async e => {
                        try {
                            await e.Send(JObject.Parse(new StreamReader(
                                WebRequest.Create("http://www.random.cat/meow")
                                    .GetResponse()
                                    .GetResponseStream())
                                .ReadToEnd())["file"].ToString());
                        } catch (Exception) { }
                    });
            });
        }

        private string token = "";
        private AnimeResult GetAnimeQueryResultLink(string query)
        {
            try
{'fraction_non_alphanumeric': 0.10354463891748787, 'fraction_numerical': 0.0, 'mean_word_length': 1.197092084006462, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4984644', 'n_tokens_mistral': 1646, 'n_tokens_neox': 1574, 'n_words': 341}