static bool DoExit(Campfire.Room room, Campfire.Message msg) { if (msg.UserID.HasValue && (msg.UserID.Value == RYAN_USER_ID)) { room.Speak("TextMessage", "Leaving."); return(false); } return(true); }
static bool DoEclipsePhaseDice(Campfire.Room room, Campfire.Message msg) { if (!msg.UserID.HasValue) { return(true); } int targetNum; string description = null; string[] diceParams = msg.Body.Remove(0, 3).Trim().Split(new char[] { ' ', '\t' }); if (diceParams.Length == 0) { return(true); } try { targetNum = Convert.ToInt32(diceParams[0]); } catch (FormatException) { return(true); } if (targetNum < 0) { return(true); } if (diceParams.Length > 1) { description = diceParams.Skip(1).Aggregate((first, second) => first + " " + second); } StringBuilder response = new StringBuilder("EPD ("); response.Append(msg.User.Name); if (description != null) { response.Append(' '); response.Append(description); } response.Append(") "); response.Append(" ==> "); DiceRoll roll = m_dice.Roll(1, 100, 0); response.Append(GenerateEclipsePhaseResult(roll.Value, targetNum)); room.Speak("TextMessage", response.ToString()); return(true); }
static bool MessageCallback(Campfire.Room room, Campfire.Message msg) { if (msg.Type == "TextMessage") { if (msg.Body.StartsWith("!roll") || msg.Body.StartsWith("!dice")) { return(DoDice(room, msg)); } else if (msg.Body.StartsWith("!ep")) { return(DoEclipsePhaseDice(room, msg)); } else if (msg.Body.StartsWith("!DEBUG_EPTEST")) { StringBuilder response = new StringBuilder(); response.Append(GenerateEclipsePhaseResult(0, 50)); response.Append("\r\n"); response.Append(GenerateEclipsePhaseResult(20, 50)); response.Append("\r\n"); response.Append(GenerateEclipsePhaseResult(22, 50)); response.Append("\r\n"); response.Append(GenerateEclipsePhaseResult(40, 50)); response.Append("\r\n"); response.Append(GenerateEclipsePhaseResult(44, 50)); response.Append("\r\n"); response.Append(GenerateEclipsePhaseResult(50, 50)); response.Append("\r\n"); response.Append(GenerateEclipsePhaseResult(60, 50)); response.Append("\r\n"); response.Append(GenerateEclipsePhaseResult(66, 50)); response.Append("\r\n"); response.Append(GenerateEclipsePhaseResult(80, 50)); response.Append("\r\n"); response.Append(GenerateEclipsePhaseResult(88, 50)); response.Append("\r\n"); response.Append(GenerateEclipsePhaseResult(99, 50)); response.Append("\r\n"); room.Speak("PasteMessage", response.ToString()); return(true); } else if (msg.Body.StartsWith("!die")) { return(DoExit(room, msg)); } else { Console.WriteLine("RECV: {0} > {1}", msg.UserID.HasValue ? msg.User.Name : "", msg.Body); } } return(true); }
static bool DoDice(Campfire.Room room, Campfire.Message msg) { if (!msg.UserID.HasValue) { return(true); } List <string> diceSpecs = new List <string>(); string description = null; string[] diceParams = msg.Body.Remove(0, 5).Trim().Split(new char[] { ' ', '\t' }); if (diceParams.Length == 0) { return(true); } for (int i = 0; i < diceParams.Length; ++i) { if (DiceRoll.LooksLikeASpec(diceParams[i])) { diceSpecs.Add(diceParams[i]); } else { if (i == 0) { return(true); } description = diceParams.Skip(i).Aggregate((first, second) => first + " " + second); break; } } StringBuilder response = new StringBuilder(); foreach (string diceSpec in diceSpecs) { if (response.Length != 0) { response.Append("\r\n"); } response.Append("DICE ("); response.Append(msg.User.Name); if (description != null) { response.Append(' '); response.Append(description); } response.Append(") "); response.Append(" ==> "); try { DiceRoll roll = m_dice.Roll(diceSpec); response.Append(roll.Description); } catch (ArgumentException) { return(true); } } room.Speak(diceSpecs.Count() == 1 ? "TextMessage" : "PasteMessage", response.ToString()); return(true); }