private void TryExecute(ircmsg msg) { if (!_entertain) { return; } string text = msg.FullTail; string origin = msg.Origin; if (msg.Tail.Count >= 1 && msg.Tail[0].Length >= 2 && msg.Tail[0].Substring(1) == "bb") { } else { Console.WriteLine(msg); } if (msg.Tail.Count >= 1) { for (int i = 0; i < msg.Tail.Count; i++) { if (msg.Tail[i] == "Kappa" || msg.Tail[i] == "KappaClaus" || msg.Tail[i] == "KappaPride" || msg.Tail[i] == "KappaRoss" || msg.Tail[i] == "KappaWealth" || msg.Tail[i] == "Keepo") { _numkappa++; Virilib.WriteFile("kappacount.txt", new string[] { _numkappa.ToString() }); } } } StringBuilder sb = new StringBuilder(); if (!string.IsNullOrWhiteSpace(msg.Origin)) { sb.AppendFormat("{0}: ", msg.Origin); } if (text[0] == '!' && text.Length > 1) { _ap.Origin = msg.Origin; object[] message; // await Task.Run<Lieutenant.executereturn>(() => _lt.Execute(text.Substring(1), msg.Origin)); _lt.Execute(text.Substring(1), _ap, out message); if (message.Length >= 1 && message[0] != null && (!string.IsNullOrWhiteSpace(message[0].ToString()))) { sb.Append(message[0]); viribot.Say(sb.ToString()); } _ap.Origin = ""; } }
public void WriteFields(string filename, object o) { List <string> lines = new List <string>(); foreach (FieldInfo field in o.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public)) { lines.Add(field.Name + "=" + field.GetValue(o)); } foreach (PropertyInfo pi in o.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public)) { lines.Add(pi.Name + "=" + pi.GetValue(o)); } Virilib.WriteFile(filename, lines); }
/// <summary> /// Rolls the specified number of die each with the specified number of /// sides and returns the numeric result as a string. I had to introduce a /// call to Thread.Sleep() so that the random num gen would seed differently on /// each iteration. /// </summary> /// <param name="numberOfDice">The number of die to roll.</param> /// <param name="numberOfSides">The number of faces on each dice rolled.</param> /// <param name="rollMod"></param> /// <returns>A string containing the result of the roll.</returns> string Roll(int numberOfDice, int numberOfSides, int rollMod) { // don't allow a Number of Dice less than or equal to zero if (numberOfDice <= 0) { throw new ApplicationException("Number of die must be greater than zero."); } // don't allow a Number of Sides less than or equal to zero if (numberOfSides <= 0) { throw new ApplicationException("Number of sides must be greater than zero."); } //// Create the string builder class used to build the string //// we return with the result of the die rolls. //// See: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemtextstringbuilderclasstopic.asp //StringBuilder result = new StringBuilder(); // Declare the integer in which we will keep the total of the rolls int total = 0; // repeat once for each number of dice for (int i = 0; i < numberOfDice; i++) { // Create the random class used to generate random numbers. // See: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemRandomClassTopic.asp // Get a pseudo-random result for this roll int roll = Virilib.SecRandom(numberOfSides) + 1; // Add the result of this roll to the total total += roll; //// Add the result of this roll to the string builder //result.AppendFormat("Dice {0:00}:\t{1}\n", i + 1, roll); } return((total + rollMod).ToString()); //// Add a line to the result to seperate the rolls from the total //result.Append("\t\t--\n"); //// Add the total to the result //result.AppendFormat("TOTAL:\t\t{0}\n", total); //// Now that we've finished building the result, get the string //// that we've been building and return it. //return result.ToString(); }
public bool ReadFields <T>(string filename, T o) { if (!File.Exists(filename)) { return(false); } Dictionary <string, FieldInfo> fields = new Dictionary <string, FieldInfo>(); Dictionary <string, PropertyInfo> properties = new Dictionary <string, PropertyInfo>(); foreach (FieldInfo field in o.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public)) { fields.Add(field.Name, field); } foreach (PropertyInfo pi in o.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public)) { properties.Add(pi.Name, pi); } Virilib.ReadFile(filename, (word) => { if (word.Count == 2) { if (fields.ContainsKey(word[0])) { IConvertible iConv = word[1]; object converted = _convert[fields[word[0]].FieldType].Invoke(iConv, new object[] { null }); string fieldname = word[0]; fields[fieldname].SetValue(o, converted); //eg. fields["Username"].SetValue(o,"my username"); if (word[0] == "Username") { Console.WriteLine(fields[fieldname].GetValue(o)); int a = 1; } } if (properties.ContainsKey(word[0])) { IConvertible iConv = word[1]; properties[word[0]].SetValue(o, _convert[properties[word[0]].PropertyType].Invoke(iConv, new object[] { })); Console.WriteLine(word[1]); } } }); return(true); }
void _viribot_OnPrivMsg(ircmsg themsg) { //Console.WriteLine(themsg.Function + " " + themsg.Origin + " " + themsg.FullTail); this.Invoke((MethodInvoker)(() => { if (themsg.Function == "PRIVMSG") { if (string.IsNullOrWhiteSpace(themsg.FullTail)) { return; } TryExecute(themsg); } else if (themsg.Function == "JOIN") { if (_entertain) { //Console.WriteLine(themsg.Origin + " joined"); if (Virilib.SecRandom(2) == 1) { Console.Error.WriteLine("Ugh, it's " + themsg.Origin); } else { Console.Error.WriteLine("<3 <3 <3 It's " + themsg.Origin); } _lblviewercount.Text = "Viewers: " + viribot.ViewerCount; } } else if (themsg.Function == "PART") { if (_entertain) { Console.WriteLine(themsg.Origin + " left"); _lblviewercount.Text = "Viewers: " + viribot.ViewerCount; } } })); }
public int Random(int min, int max) { return(Virilib.SecRandom(max - min + 1) + min);//_random.Next(max - min+1) + min; }