Esempio n. 1
0
        public static Response GptResponse()
        {
            WherePredicate unsaidResponses = new WherePredicate()
            {
                Source     = "returned",
                Comparitor = "=",
                Target     = false
            };

            List <GptResponse> results = Database.GetMany <GptResponse>(new[] { unsaidResponses }, 1, true);

            if (results.Count == 0)
            {
                return(new Response("I have nothing more to say..."));
            }

            GptResponse gpt = results[0];

            gpt.Returned = true;
            gpt.Update();

            return(new Response(gpt.Message));
        }
Esempio n. 2
0
        public static Response ProcessNewGptResponses()
        {
            Database.CreateTable <GptResponse>();

            const string kumaRootWindows = @"C:\KumaRoot\GPT\";
            string       kumaRootLinux   = $"/srv/KumaRoot/GPT/";
            string       kumaRoot        = Helpers.IsLinux() ? kumaRootLinux : kumaRootWindows;
            string       newGptDir       = kumaRoot + "New";
            string       processedGptDir = kumaRoot + "Processed";

            string[] files          = Directory.GetFiles(newGptDir);
            int      responsesAdded = 0;

            if (files.Length == 0)
            {
                return(new Response("There are no new responses to add."));
            }

            foreach (string sourceFile in files)
            {
                using (StreamReader reader = new StreamReader(sourceFile))
                {
                    string   content   = reader.ReadToEnd();
                    string[] responses = content.Split("\n====================\n");

                    foreach (string response in responses)
                    {
                        string message = response
                                         .Replace("<|startoftext|>", "")
                                         .Replace("@everyone", "everyone");
                        string[] words = message.Split(" ");

                        string spamCheck = message;
                        if (words.Length > 1)
                        {
                            spamCheck = message.Replace(words[0], "").Replace(" ", "");
                        }

                        if (spamCheck.Length > 0 && message.Length <= 2000 && words.Length >= 3)
                        {
                            GptResponse gpt = new GptResponse()
                            {
                                Message  = message,
                                Returned = false
                            };

                            gpt.Insert();
                            responsesAdded++;
                        }
                    }
                }

                string filename        = Path.GetFileName(sourceFile);
                string destinationFile = Path.Combine(processedGptDir, filename);

                Directory.CreateDirectory(processedGptDir);
                File.Move(sourceFile, destinationFile);
            }

            return(new Response($"{responsesAdded} new responses added."));
        }