Removed old cleverbot stuff
This commit is contained in:
		@@ -1,11 +1,9 @@
 | 
			
		||||
using Discord;
 | 
			
		||||
using Discord.Commands;
 | 
			
		||||
using Discord.WebSocket;
 | 
			
		||||
using NadekoBot.Attributes;
 | 
			
		||||
using NadekoBot.Extensions;
 | 
			
		||||
using NadekoBot.Services;
 | 
			
		||||
using NLog;
 | 
			
		||||
//using Services.CleverBotApi;
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Concurrent;
 | 
			
		||||
using System.Diagnostics;
 | 
			
		||||
@@ -13,7 +11,6 @@ using System.Linq;
 | 
			
		||||
using System.Net.Http;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using Newtonsoft.Json;
 | 
			
		||||
using Services.CleverBotApi;
 | 
			
		||||
 | 
			
		||||
namespace NadekoBot.Modules.Games
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
@@ -1,25 +0,0 @@
 | 
			
		||||
 /*
 | 
			
		||||
    ChatterBotAPI
 | 
			
		||||
    Copyright (C) 2011 pierredavidbelanger@gmail.com
 | 
			
		||||
 
 | 
			
		||||
    This program is free software: you can redistribute it and/or modify
 | 
			
		||||
    it under the terms of the GNU Lesser General Public License as published by
 | 
			
		||||
    the Free Software Foundation, either version 3 of the License, or
 | 
			
		||||
    (at your option) any later version.
 | 
			
		||||
 | 
			
		||||
    This program is distributed in the hope that it will be useful,
 | 
			
		||||
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
    GNU Lesser General Public License for more details.
 | 
			
		||||
 | 
			
		||||
    You should have received a copy of the GNU Lesser General Public License
 | 
			
		||||
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
namespace Services.CleverBotApi
 | 
			
		||||
{
 | 
			
		||||
    public interface ChatterBot
 | 
			
		||||
    {
 | 
			
		||||
        ChatterBotSession CreateSession();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,51 +0,0 @@
 | 
			
		||||
using System;
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
    ChatterBotAPI
 | 
			
		||||
    Copyright (C) 2011 pierredavidbelanger@gmail.com
 | 
			
		||||
 
 | 
			
		||||
    This program is free software: you can redistribute it and/or modify
 | 
			
		||||
    it under the terms of the GNU Lesser General Public License as published by
 | 
			
		||||
    the Free Software Foundation, either version 3 of the License, or
 | 
			
		||||
    (at your option) any later version.
 | 
			
		||||
 | 
			
		||||
    This program is distributed in the hope that it will be useful,
 | 
			
		||||
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
    GNU Lesser General Public License for more details.
 | 
			
		||||
 | 
			
		||||
    You should have received a copy of the GNU Lesser General Public License
 | 
			
		||||
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
namespace Services.CleverBotApi
 | 
			
		||||
{
 | 
			
		||||
    public class ChatterBotFactory
 | 
			
		||||
    {
 | 
			
		||||
        public static ChatterBot Create(ChatterBotType type)
 | 
			
		||||
        {
 | 
			
		||||
            return Create(type, null);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static ChatterBot Create(ChatterBotType type, object arg)
 | 
			
		||||
        {
 | 
			
		||||
#if GLOBAL_NADEKO
 | 
			
		||||
            var url = "http://www.cleverbot.com/webservicemin?uc=777&botapi=nadekobot";
 | 
			
		||||
#else
 | 
			
		||||
            var url = "http://www.cleverbot.com/webservicemin?uc=777&botapi=chatterbotapi";
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
            switch (type)
 | 
			
		||||
            {
 | 
			
		||||
                case ChatterBotType.CLEVERBOT:
 | 
			
		||||
                    return new Cleverbot("http://www.cleverbot.com/", url, 26);
 | 
			
		||||
                case ChatterBotType.JABBERWACKY:
 | 
			
		||||
                    return new Cleverbot("http://jabberwacky.com", "http://jabberwacky.com/webservicemin", 20);
 | 
			
		||||
                case ChatterBotType.PANDORABOTS:
 | 
			
		||||
                    if (arg == null) throw new ArgumentException("PANDORABOTS needs a botid arg", nameof(arg));
 | 
			
		||||
                    return new Pandorabots(arg.ToString());
 | 
			
		||||
            }
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,28 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
   ChatterBotAPI
 | 
			
		||||
   Copyright (C) 2011 pierredavidbelanger@gmail.com
 | 
			
		||||
 | 
			
		||||
   This program is free software: you can redistribute it and/or modify
 | 
			
		||||
   it under the terms of the GNU Lesser General Public License as published by
 | 
			
		||||
   the Free Software Foundation, either version 3 of the License, or
 | 
			
		||||
   (at your option) any later version.
 | 
			
		||||
 | 
			
		||||
   This program is distributed in the hope that it will be useful,
 | 
			
		||||
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
   GNU Lesser General Public License for more details.
 | 
			
		||||
 | 
			
		||||
   You should have received a copy of the GNU Lesser General Public License
 | 
			
		||||
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
 | 
			
		||||
namespace Services.CleverBotApi
 | 
			
		||||
{
 | 
			
		||||
    public interface ChatterBotSession
 | 
			
		||||
    {
 | 
			
		||||
        Task<ChatterBotThought> Think(ChatterBotThought thought);
 | 
			
		||||
        Task<string> Think(string text);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,26 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
   ChatterBotAPI
 | 
			
		||||
   Copyright (C) 2011 pierredavidbelanger@gmail.com
 | 
			
		||||
 | 
			
		||||
   This program is free software: you can redistribute it and/or modify
 | 
			
		||||
   it under the terms of the GNU Lesser General Public License as published by
 | 
			
		||||
   the Free Software Foundation, either version 3 of the License, or
 | 
			
		||||
   (at your option) any later version.
 | 
			
		||||
 | 
			
		||||
   This program is distributed in the hope that it will be useful,
 | 
			
		||||
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
   GNU Lesser General Public License for more details.
 | 
			
		||||
 | 
			
		||||
   You should have received a copy of the GNU Lesser General Public License
 | 
			
		||||
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
namespace Services.CleverBotApi
 | 
			
		||||
{
 | 
			
		||||
    public class ChatterBotThought
 | 
			
		||||
    {
 | 
			
		||||
        public string[] Emotions { get; set; }
 | 
			
		||||
        public string Text { get; set; }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,27 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
   ChatterBotAPI
 | 
			
		||||
   Copyright (C) 2011 pierredavidbelanger@gmail.com
 | 
			
		||||
 | 
			
		||||
   This program is free software: you can redistribute it and/or modify
 | 
			
		||||
   it under the terms of the GNU Lesser General Public License as published by
 | 
			
		||||
   the Free Software Foundation, either version 3 of the License, or
 | 
			
		||||
   (at your option) any later version.
 | 
			
		||||
 | 
			
		||||
   This program is distributed in the hope that it will be useful,
 | 
			
		||||
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
   GNU Lesser General Public License for more details.
 | 
			
		||||
 | 
			
		||||
   You should have received a copy of the GNU Lesser General Public License
 | 
			
		||||
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
namespace Services.CleverBotApi
 | 
			
		||||
{
 | 
			
		||||
    public enum ChatterBotType
 | 
			
		||||
    {
 | 
			
		||||
        CLEVERBOT,
 | 
			
		||||
        JABBERWACKY,
 | 
			
		||||
        PANDORABOTS
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,116 +0,0 @@
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Net;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
    ChatterBotAPI
 | 
			
		||||
    Copyright (C) 2011 pierredavidbelanger@gmail.com
 | 
			
		||||
 
 | 
			
		||||
    This program is free software: you can redistribute it and/or modify
 | 
			
		||||
    it under the terms of the GNU Lesser General Public License as published by
 | 
			
		||||
    the Free Software Foundation, either version 3 of the License, or
 | 
			
		||||
    (at your option) any later version.
 | 
			
		||||
 | 
			
		||||
    This program is distributed in the hope that it will be useful,
 | 
			
		||||
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
    GNU Lesser General Public License for more details.
 | 
			
		||||
 | 
			
		||||
    You should have received a copy of the GNU Lesser General Public License
 | 
			
		||||
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
namespace Services.CleverBotApi
 | 
			
		||||
{
 | 
			
		||||
    public class Cleverbot : ChatterBot
 | 
			
		||||
    {
 | 
			
		||||
        private readonly int endIndex;
 | 
			
		||||
        private readonly string baseUrl;
 | 
			
		||||
        private readonly string url;
 | 
			
		||||
 | 
			
		||||
        public Cleverbot(string baseUrl, string url, int endIndex)
 | 
			
		||||
        {
 | 
			
		||||
            this.baseUrl = baseUrl;
 | 
			
		||||
            this.url = url;
 | 
			
		||||
            this.endIndex = endIndex;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public ChatterBotSession CreateSession()
 | 
			
		||||
        {
 | 
			
		||||
            return new CleverbotSession(baseUrl, url, endIndex);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public class CleverbotSession : ChatterBotSession
 | 
			
		||||
    {
 | 
			
		||||
        private readonly int endIndex;
 | 
			
		||||
        private readonly string url;
 | 
			
		||||
        private readonly IDictionary<string, string> vars;
 | 
			
		||||
        private readonly CookieCollection cookies;
 | 
			
		||||
 | 
			
		||||
        public CleverbotSession(string baseUrl, string url, int endIndex)
 | 
			
		||||
        {
 | 
			
		||||
            this.url = url;
 | 
			
		||||
            this.endIndex = endIndex;
 | 
			
		||||
            vars = new Dictionary<string, string>();
 | 
			
		||||
            //vars["start"] = "y";
 | 
			
		||||
            vars["stimulus"] = "";
 | 
			
		||||
            vars["islearning"] = "1";
 | 
			
		||||
            vars["icognoid"] = "wsf";
 | 
			
		||||
            //vars["fno"] = "0";
 | 
			
		||||
            //vars["sub"] = "Say";
 | 
			
		||||
            //vars["cleanslate"] = "false";
 | 
			
		||||
            cookies = Utils.GetCookies(baseUrl);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public async Task<ChatterBotThought> Think(ChatterBotThought thought)
 | 
			
		||||
        {
 | 
			
		||||
            vars["stimulus"] = thought.Text;
 | 
			
		||||
 | 
			
		||||
            var formData = Utils.ParametersToWWWFormURLEncoded(vars);
 | 
			
		||||
            var formDataToDigest = formData.Substring(9, endIndex);
 | 
			
		||||
            var formDataDigest = Utils.MD5(formDataToDigest);
 | 
			
		||||
            vars["icognocheck"] = formDataDigest;
 | 
			
		||||
 | 
			
		||||
            var response = await Utils.Post(url, vars, cookies).ConfigureAwait(false);
 | 
			
		||||
 | 
			
		||||
            var responseValues = response.Split('\r');
 | 
			
		||||
 | 
			
		||||
            //vars[""] = Utils.StringAtIndex(responseValues, 0); ??
 | 
			
		||||
            vars["sessionid"] = Utils.StringAtIndex(responseValues, 1);
 | 
			
		||||
            vars["logurl"] = Utils.StringAtIndex(responseValues, 2);
 | 
			
		||||
            vars["vText8"] = Utils.StringAtIndex(responseValues, 3);
 | 
			
		||||
            vars["vText7"] = Utils.StringAtIndex(responseValues, 4);
 | 
			
		||||
            vars["vText6"] = Utils.StringAtIndex(responseValues, 5);
 | 
			
		||||
            vars["vText5"] = Utils.StringAtIndex(responseValues, 6);
 | 
			
		||||
            vars["vText4"] = Utils.StringAtIndex(responseValues, 7);
 | 
			
		||||
            vars["vText3"] = Utils.StringAtIndex(responseValues, 8);
 | 
			
		||||
            vars["vText2"] = Utils.StringAtIndex(responseValues, 9);
 | 
			
		||||
            vars["prevref"] = Utils.StringAtIndex(responseValues, 10);
 | 
			
		||||
            //vars[""] = Utils.StringAtIndex(responseValues, 11); ??
 | 
			
		||||
//            vars["emotionalhistory"] = Utils.StringAtIndex(responseValues, 12);
 | 
			
		||||
//            vars["ttsLocMP3"] = Utils.StringAtIndex(responseValues, 13);
 | 
			
		||||
//            vars["ttsLocTXT"] = Utils.StringAtIndex(responseValues, 14);
 | 
			
		||||
//            vars["ttsLocTXT3"] = Utils.StringAtIndex(responseValues, 15);
 | 
			
		||||
//            vars["ttsText"] = Utils.StringAtIndex(responseValues, 16);
 | 
			
		||||
//            vars["lineRef"] = Utils.StringAtIndex(responseValues, 17);
 | 
			
		||||
//            vars["lineURL"] = Utils.StringAtIndex(responseValues, 18);
 | 
			
		||||
//            vars["linePOST"] = Utils.StringAtIndex(responseValues, 19);
 | 
			
		||||
//            vars["lineChoices"] = Utils.StringAtIndex(responseValues, 20);
 | 
			
		||||
//            vars["lineChoicesAbbrev"] = Utils.StringAtIndex(responseValues, 21);
 | 
			
		||||
//            vars["typingData"] = Utils.StringAtIndex(responseValues, 22);
 | 
			
		||||
//            vars["divert"] = Utils.StringAtIndex(responseValues, 23);
 | 
			
		||||
 | 
			
		||||
            var responseThought = new ChatterBotThought();
 | 
			
		||||
 | 
			
		||||
            responseThought.Text = Utils.StringAtIndex(responseValues, 0);
 | 
			
		||||
 | 
			
		||||
            return responseThought;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public async Task<string> Think(string text)
 | 
			
		||||
        {
 | 
			
		||||
            return (await Think(new ChatterBotThought {Text = text}).ConfigureAwait(false)).Text;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,68 +0,0 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
    ChatterBotAPI
 | 
			
		||||
    Copyright (C) 2011 pierredavidbelanger@gmail.com
 | 
			
		||||
 
 | 
			
		||||
    This program is free software: you can redistribute it and/or modify
 | 
			
		||||
    it under the terms of the GNU Lesser General Public License as published by
 | 
			
		||||
    the Free Software Foundation, either version 3 of the License, or
 | 
			
		||||
    (at your option) any later version.
 | 
			
		||||
 | 
			
		||||
    This program is distributed in the hope that it will be useful,
 | 
			
		||||
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
    GNU Lesser General Public License for more details.
 | 
			
		||||
 | 
			
		||||
    You should have received a copy of the GNU Lesser General Public License
 | 
			
		||||
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
namespace Services.CleverBotApi
 | 
			
		||||
{
 | 
			
		||||
    public class Pandorabots : ChatterBot
 | 
			
		||||
    {
 | 
			
		||||
        private readonly string botid;
 | 
			
		||||
 | 
			
		||||
        public Pandorabots(string botid)
 | 
			
		||||
        {
 | 
			
		||||
            this.botid = botid;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public ChatterBotSession CreateSession()
 | 
			
		||||
        {
 | 
			
		||||
            return new PandorabotsSession(botid);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public class PandorabotsSession : ChatterBotSession
 | 
			
		||||
    {
 | 
			
		||||
        private readonly IDictionary<string, string> vars;
 | 
			
		||||
 | 
			
		||||
        public PandorabotsSession(string botid)
 | 
			
		||||
        {
 | 
			
		||||
            vars = new Dictionary<string, string>();
 | 
			
		||||
            vars["botid"] = botid;
 | 
			
		||||
            vars["custid"] = Guid.NewGuid().ToString();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public async Task<ChatterBotThought> Think(ChatterBotThought thought)
 | 
			
		||||
        {
 | 
			
		||||
            vars["input"] = thought.Text;
 | 
			
		||||
 | 
			
		||||
            var response = await Utils.Post("http://www.pandorabots.com/pandora/talk-xml", vars, null).ConfigureAwait(false);
 | 
			
		||||
 | 
			
		||||
            var responseThought = new ChatterBotThought();
 | 
			
		||||
            responseThought.Text = Utils.XPathSearch(response, "//result/that/text()");
 | 
			
		||||
 | 
			
		||||
            return responseThought;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public async Task<string> Think(string text)
 | 
			
		||||
        {
 | 
			
		||||
            return (await Think(new ChatterBotThought {Text = text}).ConfigureAwait(false)).Text;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,148 +0,0 @@
 | 
			
		||||
using NadekoBot.Extensions;
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.IO;
 | 
			
		||||
using System.Net;
 | 
			
		||||
using System.Net.Http;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using System.Xml.XPath;
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
    ChatterBotAPI
 | 
			
		||||
    Copyright (C) 2011 pierredavidbelanger@gmail.com
 | 
			
		||||
 
 | 
			
		||||
    This program is free software: you can redistribute it and/or modify
 | 
			
		||||
    it under the terms of the GNU Lesser General Public License as published by
 | 
			
		||||
    the Free Software Foundation, either version 3 of the License, or
 | 
			
		||||
    (at your option) any later version.
 | 
			
		||||
 | 
			
		||||
    This program is distributed in the hope that it will be useful,
 | 
			
		||||
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
    GNU Lesser General Public License for more details.
 | 
			
		||||
 | 
			
		||||
    You should have received a copy of the GNU Lesser General Public License
 | 
			
		||||
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
namespace Services.CleverBotApi
 | 
			
		||||
{
 | 
			
		||||
    public static class Utils
 | 
			
		||||
    {
 | 
			
		||||
        public static string ParametersToWWWFormURLEncoded(IDictionary<string, string> parameters)
 | 
			
		||||
        {
 | 
			
		||||
            string wwwFormUrlEncoded = null;
 | 
			
		||||
            foreach (var parameterKey in parameters.Keys)
 | 
			
		||||
            {
 | 
			
		||||
                var parameterValue = parameters[parameterKey];
 | 
			
		||||
                var parameter = string.Format("{0}={1}", System.Uri.EscapeDataString(parameterKey), System.Uri.EscapeDataString(parameterValue)); 
 | 
			
		||||
                if (wwwFormUrlEncoded == null)
 | 
			
		||||
                {
 | 
			
		||||
                    wwwFormUrlEncoded = parameter;
 | 
			
		||||
                }
 | 
			
		||||
                else
 | 
			
		||||
                {
 | 
			
		||||
                    wwwFormUrlEncoded = string.Format("{0}&{1}", wwwFormUrlEncoded, parameter);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            return wwwFormUrlEncoded;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static string MD5(string input)
 | 
			
		||||
        {
 | 
			
		||||
            // step 1, calculate MD5 hash from input
 | 
			
		||||
            var md5 = System.Security.Cryptography.MD5.Create();
 | 
			
		||||
            var inputBytes = Encoding.ASCII.GetBytes(input);
 | 
			
		||||
            var hash = md5.ComputeHash(inputBytes);
 | 
			
		||||
 | 
			
		||||
            // step 2, convert byte array to hex string
 | 
			
		||||
            var sb = new StringBuilder();
 | 
			
		||||
            for (var i = 0; i < hash.Length; i++)
 | 
			
		||||
            {
 | 
			
		||||
                sb.Append(hash[i].ToString("X2"));
 | 
			
		||||
            }
 | 
			
		||||
            return sb.ToString();
 | 
			
		||||
        
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static CookieCollection GetCookies(string url)
 | 
			
		||||
        {
 | 
			
		||||
            CookieContainer container = new CookieContainer();
 | 
			
		||||
 | 
			
		||||
            HttpResponseMessage res;
 | 
			
		||||
            using (var handler = new HttpClientHandler() { CookieContainer = container })
 | 
			
		||||
            using (var http = new HttpClient(handler))
 | 
			
		||||
            {
 | 
			
		||||
                http.AddFakeHeaders();
 | 
			
		||||
                http.DefaultRequestHeaders.Add("ContentType", "text/html");
 | 
			
		||||
                res = http.GetAsync(url).GetAwaiter().GetResult();
 | 
			
		||||
            }
 | 
			
		||||
            var response = res.Content.ReadAsStringAsync().GetAwaiter().GetResult();
 | 
			
		||||
            
 | 
			
		||||
            return container.GetCookies(res.RequestMessage.RequestUri);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static async Task<string> Post(string url, IDictionary<string, string> parameters, CookieCollection cookies)
 | 
			
		||||
        {
 | 
			
		||||
            var postData = ParametersToWWWFormURLEncoded(parameters);
 | 
			
		||||
            var postDataBytes = Encoding.ASCII.GetBytes(postData);
 | 
			
		||||
 | 
			
		||||
            var request = (HttpWebRequest)WebRequest.Create(url);
 | 
			
		||||
 | 
			
		||||
            if (cookies != null)
 | 
			
		||||
            {
 | 
			
		||||
                var container = new CookieContainer();
 | 
			
		||||
                container.Add(new Uri(url), cookies);
 | 
			
		||||
                request.CookieContainer = container;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            request.Method = "POST";
 | 
			
		||||
            request.ContentType = "application/x-www-form-urlencoded";
 | 
			
		||||
 | 
			
		||||
            using (var outputStream = await request.GetRequestStreamAsync())
 | 
			
		||||
            {
 | 
			
		||||
                outputStream.Write(postDataBytes, 0, postDataBytes.Length);
 | 
			
		||||
                outputStream.Flush();
 | 
			
		||||
 | 
			
		||||
                var response = (HttpWebResponse)await request.GetResponseAsync();
 | 
			
		||||
                using (var responseStreamReader = new StreamReader(response.GetResponseStream()))
 | 
			
		||||
                {
 | 
			
		||||
                    return responseStreamReader.ReadToEnd().Trim();
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            //HttpClientHandler handler;
 | 
			
		||||
            //var uri = new Uri(url);
 | 
			
		||||
            //if (cookies == null)
 | 
			
		||||
            //    handler = new HttpClientHandler();
 | 
			
		||||
            //else
 | 
			
		||||
            //{
 | 
			
		||||
            //    var cookieContainer = new CookieContainer();
 | 
			
		||||
            //    cookieContainer.Add(uri, cookies);
 | 
			
		||||
            //    handler = new HttpClientHandler() { CookieContainer = cookieContainer };
 | 
			
		||||
            //}
 | 
			
		||||
            //using (handler)
 | 
			
		||||
            //using (var http = new HttpClient(handler))
 | 
			
		||||
            //{
 | 
			
		||||
            //    var res = await http.PostAsync(url, new FormUrlEncodedContent(parameters)).ConfigureAwait(false);
 | 
			
		||||
            //    return await res.Content.ReadAsStringAsync().ConfigureAwait(false);
 | 
			
		||||
            //}
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        public static string XPathSearch(string input, string expression)
 | 
			
		||||
        {
 | 
			
		||||
            var document = new XPathDocument(new MemoryStream(Encoding.ASCII.GetBytes(input)));
 | 
			
		||||
            var navigator = document.CreateNavigator();
 | 
			
		||||
            return navigator.SelectSingleNode(expression).Value.Trim();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static string StringAtIndex(string[] strings, int index)
 | 
			
		||||
        {
 | 
			
		||||
            if (index >= strings.Length) return "";
 | 
			
		||||
            return strings[index];
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -16,9 +16,7 @@ using NadekoBot.Modules.CustomReactions;
 | 
			
		||||
using NadekoBot.Modules.Games;
 | 
			
		||||
using System.Collections.Concurrent;
 | 
			
		||||
using System.Threading;
 | 
			
		||||
using Microsoft.EntityFrameworkCore;
 | 
			
		||||
using NadekoBot.DataStructures;
 | 
			
		||||
using Services.CleverBotApi;
 | 
			
		||||
 | 
			
		||||
namespace NadekoBot.Services
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user