コード例 #1
0
        public static string Markov(string input)
        {
            //Load Markov.bin or create new
            Markov mkv = new Markov();

            if (File.Exists("Markov.bin"))
            {
                try { mkv.LoadChainState("Markov"); } catch { }
            }

            //Feed input
            mkv.Feed(input);

            //Generate new sentence
            Random rnd    = new Random();
            string markov = MarkovGenerator.Create(rnd.Next(50, 150), mkv);

            markov = MarkovGenerator.Create(mkv);

            //Save
            mkv.SaveChainState("Markov");

            //Return new sentence
            return(markov);
        }
コード例 #2
0
ファイル: Processing.cs プロジェクト: jpmac26/JackFrost-Bot
        //Log replies and respond with a random reply
        public static async Task Markov(string message, SocketGuildChannel channel, int frequency)
        {
            string binFilePath = $"Servers\\{channel.Guild.Id.ToString()}\\{channel.Guild.Id.ToString()}";
            Markov mkv         = new Markov();

            try { mkv.LoadChainState(binFilePath); }
            catch { }
            //Sanitize message content
            string newMessage = message;
            var    links      = newMessage.Split("\t\n ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Where(s => s.StartsWith("http://") || s.StartsWith("www.") || s.StartsWith("https://") || s.StartsWith("@"));

            foreach (var link in links)
            {
                newMessage = newMessage.Replace(link, "");
            }

            if (newMessage != "" && Moderation.IsPublicChannel(channel))
            {
                mkv.Feed(newMessage);
            }

            mkv.SaveChainState(binFilePath);

            var    socketChannel = (ISocketMessageChannel)channel;
            Random rnd           = new Random();
            string markov        = MarkovGenerator.Create(mkv);
            int    runs          = 0;

            while (markov.Length < UserSettings.BotOptions.MarkovMinimumLength(channel.Guild.Id) && runs < 20)
            {
                markov = MarkovGenerator.Create(mkv);
                runs++;
            }

            if (rnd.Next(1, 100) <= frequency)
            {
                if (!UserSettings.BotOptions.MarkovBotChannelOnly(channel.Guild.Id))
                {
                    await socketChannel.SendMessageAsync(markov);
                }
                else if (channel.Id == UserSettings.Channels.BotChannelId(channel.Guild.Id))
                {
                    await socketChannel.SendMessageAsync(markov);
                }
            }

            return;
        }