internal static async Task MarkovListenAsync(SocketMessage arg, string server)
        {
            // don't save bot commands
            if (arg.Content.StartsWith("!"))
            {
                return;
            }

            var who = arg.Author.GetNicknameOrUsername();

            Posts.Data.Add(new Post(server, arg.Channel.Name, who, arg.Content, arg.Timestamp.ToUniversalTime().UtcDateTime));

            if (!Generators.ContainsKey(who))
            {
                Generators.Add(who, CreateMarkovGenerator(who));
            }
            Generators[who].ReadChain(arg.Content);
            if (who != "Chancellor Gerath")
            {
                if (EveryoneGenerator is null)
                {
                    EveryoneGenerator = CreateMarkovGenerator(null);
                }
                EveryoneGenerator.ReadChain(arg.Content);
            }
            if (!Directory.Exists(PostsJsonPath))
            {
                Directory.CreateDirectory(PostsJsonPath);
            }
            SavePosts();
        }
 public void AddGeneratorInner(GeneratorInfo generator)
 {
     if (!Generators.ContainsKey(generator.GeneratorId))
     {
         Generators.Add(generator.GeneratorId, generator);
         generatorList.Add(generator);
     }
 }
        public IQuestionGenerator GetGenerator(string reference)
        {
            if (!Generators.ContainsKey(reference))
            {
                throw new NoSuchQuestionTemplateException(reference);
            }

            return(Generators[reference]);
        }
Esempio n. 4
0
 /// <summary>Gets the generator for the tag name or creates a new one.</summary>
 /// <typeparam name="TGenerator">The type of the generator.</typeparam>
 /// <param name="tagName">Name of the tag.</param>
 /// <returns>The generator.</returns>
 public TGenerator GetGenerator <TGenerator>(string tagName)
     where TGenerator : IControlGenerator, new()
 {
     if (Generators.ContainsKey(tagName))
     {
         return((TGenerator)Generators[tagName]);
     }
     Generators[tagName] = new TGenerator();
     return((TGenerator)Generators[tagName]);
 }
Esempio n. 5
0
 /// <summary>
 /// Registers a generator with a type
 /// </summary>
 /// <param name="Rand">Random number generator</param>
 /// <param name="Generator">Generator to associate with the type</param>
 /// <param name="Type">Type to associate with the generator</param>
 /// <returns>The random number generator</returns>
 public static System.Random RegisterGenerator(this System.Random Rand, Type Type, IGenerator Generator)
 {
     if (Generators.ContainsKey(Type))
     {
         Generators[Type] = Generator;
     }
     else
     {
         Generators.Add(Type, Generator);
     }
     return(Rand);
 }
 /// <summary>
 /// Randomly generates a value of the specified type
 /// </summary>
 /// <typeparam name="T">Type to generate</typeparam>
 /// <param name="Random">Random object</param>
 /// <param name="Max">Maximum value (inclusive)</param>
 /// <param name="Min">Minimum value (inclusive)</param>
 /// <param name="Generator">Generator to be used (if not included, default generator is used)</param>
 /// <returns>The randomly generated value</returns>
 public static T Next <T>(this System.Random Random, T Min, T Max, IGenerator <T> Generator = null)
 {
     Contract.Requires <ArgumentNullException>(Random != null, "Random");
     SetupGenerators();
     if (Generator == null)
     {
         if (!Generators.ContainsKey(typeof(T)))
         {
             throw new ArgumentOutOfRangeException("The type specified, " + typeof(T).Name + ", does not have a default generator.");
         }
         Generator = (IGenerator <T>)Generators[typeof(T)];
     }
     return(Generator.Next(Random, Min, Max));
 }
Esempio n. 7
0
 public void Append(IEnumerable <GeneratorData> generators, GeneratorType type)
 {
     if (IsLoaded)
     {
         foreach (var gen in generators)
         {
             //GeneratorData newData = new GeneratorData(jsonData, type);
             if (!Generators.ContainsKey(gen.Id))
             {
                 Generators.Add(gen.Id, gen);
             }
             else
             {
                 throw new UnityException($"Repository already contains generator => {gen.Id}");
             }
         }
     }
 }
        public Task JabberAsync([Remainder][Summary("Who to mimic")] string who)
        {
            Generator gen;

            if (!Generators.ContainsKey(who))
            {
                Generators.Add(who, CreateMarkovGenerator(who));
            }
            gen = Generators[who];

            if (!gen.Lexicon.Any() || !IsUserKnownInCurrentServer(who))
            {
                return(ReplyAsync($"I don't have any conversation history for {who}!"));
            }

            var preferredLength = Extensions.Random.Next(8, 32);
            var maxLength       = preferredLength + Extensions.Random.Next(8, 32);

            return(ReplyAsync(gen.WriteSentence(preferredLength, maxLength).Text));
        }
 public bool Contains(int generatorId)
 => Generators.ContainsKey(generatorId);
Esempio n. 10
0
 public GeneratorData GetGeneratorData(int id)
 => Generators.ContainsKey(id) ? Generators[id] : null;
Esempio n. 11
0
        public object Generate()
        {
            var obj = new TSource();

            foreach (var prop in typeof(TSource).GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                if (Ignore.Contains(prop.Name))
                {
                    continue;
                }

                if (Values.ContainsKey(prop.Name))
                {
                    prop.SetValue(obj, Values[prop.Name], null);
                    continue;
                }

                if (Generators.ContainsKey(prop.Name))
                {
                    try {
                        prop.SetValue(obj, Generators[prop.Name].Generate(), null);
                    } catch (ArgumentException) {
                        throw new ArgumentException($"Mismatching generator type for property {prop.Name}");
                    }
                    continue;
                }

                if (OnlyCustom)
                {
                    continue;
                }

                if (TypeGenerators.ContainsKey(prop.PropertyType))
                {
                    try {
                        prop.SetValue(obj, TypeGenerators[prop.PropertyType].Generate(), null);
                    } catch (ArgumentException) {
                        throw new ArgumentException($"Mismatching generator type for type {prop.PropertyType}");
                    }
                    continue;
                }

                Type type = prop.PropertyType;

                if (type == typeof(string))
                {
                    prop.SetValue(obj, ExtendedRandom.NextString(10), null);
                }
                else if (type == typeof(int) || type == typeof(long) || type == typeof(uint) || type == typeof(ulong))
                {
                    prop.SetValue(obj, Random.Next(1, 500), null);
                }
                else if (type == typeof(byte))
                {
                    prop.SetValue(obj, Random.Next(0, 256), null);
                }
                else if (type == typeof(sbyte))
                {
                    prop.SetValue(obj, Random.Next(-128, 128), null);
                }
                else if (type == typeof(short) || type == typeof(ushort))
                {
                    prop.SetValue(obj, Random.Next(0, 32768), null);
                }
                else if (type == typeof(float) || type == typeof(double) || type == typeof(decimal))
                {
                    prop.SetValue(obj, Convert.ChangeType(ExtendedRandom.NextDouble(0, 500), type), null);
                }
                else if (type == typeof(bool))
                {
                    prop.SetValue(obj, ExtendedRandom.NextBoolean(), null);
                }
                else if (type == typeof(char))
                {
                    prop.SetValue(obj, ExtendedRandom.NextChar(), null);
                }
                else if (type == typeof(Guid))
                {
                    prop.SetValue(obj, Guid.NewGuid(), null);
                }
                else if (type == typeof(DateTime))
                {
                    prop.SetValue(obj, ExtendedRandom.NextDateTime(), null);
                }
            }
            return(obj);
        }