Beispiel #1
0
        static void Main(string[] args)
        {
            ChatBot bot = new ChatBot(@"C:\Users\Bacha\Desktop\1.txt");

            bot.GetStr += bot_GetStr;

            while (true)
            {
                string q = Console.ReadLine();
                bot.Ans(q);
            }
        }
Beispiel #2
0
        public void SaveHistory(ChatBot c)
        {
            SaveFileDialog saveFile = new SaveFileDialog();

            saveFile.Filter           = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            saveFile.FilterIndex      = 2;
            saveFile.RestoreDirectory = true;
            if (saveFile.ShowDialog() == DialogResult.OK)
            {
                File.WriteAllText(saveFile.FileName, c.richTextBox_messages.Text);
            }
        }
        static void Main(string[] args)
        {
            // init
            ChatBot bot = null;

            while (true)
            {
                try {
                    bot = Init();
                    break;
                }
                catch (Exception ex) {
                    Console.WriteLine(ex.Message);
                }
            }
            do
            {
                bot.AnswerDo();
                try {
                    var fromUser = Console.ReadLine();
                    if (fromUser.IndexOf("calculate:") == 0)
                    {
                        Console.WriteLine("Функціональність в розробці");
                    }
                    if (fromUser.IndexOf("strategy:") == 0)
                    {
                        var toParse = fromUser.Replace("strategy:", string.Empty).Replace(" ", string.Empty);
                        bot.Strategy = (EStrategy)Enum.Parse(typeof(EStrategy), toParse);
                        Console.WriteLine($">Как советовать, так все чатлане. Использую стратегию: {bot.Strategy} ");
                    }
                }
                catch {
                    Console.WriteLine("У тебя в голове мозги или кю?!");
                }
            }while (true);
        }
Beispiel #4
0
        public CoreModule(ChatBot bot)
        {
            this.bot = bot;
            this.AddCommand(new Command()
            {
                Name = "butts",
                Args = null,
                IsAdminOnly = false,
                Action = ((args) => { return "http://derpicdn.net/img/view/2013/8/13/399233.gif"; })
            });

            this.AddCommand(new Command()
            {
                Name = "greet",
                Args = new String[] { "user" },
                Action = ((args) => { return "Hi, " + args[0] + "!"; })
            });

            this.AddCommand(new Command()
            {
                Name = "mute",
                Args = null,
                IsAdminOnly = false,
                Action = ((args) => { bot.Mute(); return "Okay, shutting up now."; }) });
            this.AddCommand(new Command()
            {
                Name = "unmute",
                Args = null,
                IsAdminOnly = false,
                Action = ((args) => { bot.Unmute(); return "Talking again."; }) });
            this.AddCommand(new Command()
                {
                    Name = "name",
                    Args = new String[] { "name" },
                    IsAdminOnly = true,
                    Action = ((args) => {
                        ((SteamInterface)bot.interfaces.First(i => i.GetName() == "Steam")).
                            friends.SetPersonaName(args[0].Replace('_', ' ')); return "Duru sucks.";
                    })
                });

            this.AddCommand(new Command()
            {
                Name = "bacc",
                Args = null,
                IsAdminOnly = false,
                Action = ((args) => { return "http://www.laminate-direct.co.uk/laminate-flooring.html"; })
            });

            this.AddCommand(new Command()
            {
                Name = "duru",
                Args = null,
                IsAdminOnly = false,
                Action = ((args) => { return "duru sucks"; })
            });

            this.AddCommand(new Command()
            {
                Name = "admins",
                Args = null,
                IsAdminOnly = false,
                Action = ((args) => { return "only sloot, f**k the rest of you"; })
            });

            this.AddCommand(new Command()
            {
                Name = "wt",
                Args = new String[] { "url" },
                Action =
                    ((args) =>
                    {
                        byte[] download = new byte[8192];
                        HttpWebRequest request;
                        try
                        {
                            request = (HttpWebRequest)WebRequest.Create(args[0]);
                        }
                        catch (UriFormatException e)
                        {
                            return "Not a valid URL.";
                        }
                        request.Timeout = 5000;
                        try
                        {
                            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                            download = new BinaryReader(response.GetResponseStream()).ReadBytes(4096);
                        }
                        catch(WebException ex)
                        {
                            return "Timed out, or something.";
                        }
                        String titlehtml = System.Web.HttpUtility.HtmlDecode(System.Text.Encoding.UTF8.GetString(download));
                        string title = Regex.Match(titlehtml, @"\<title\b[^>]*\>\s*(?<Title>[\s\S]*?)\</title\>", RegexOptions.IgnoreCase).Groups["Title"].Value;
                        if (title == "")
                            return "Could not find a title for that webpage";
                        return title;
                    })
            });
        }