protected override void PerformAdmin(Domain.IncomingSmsMessage message) { int id; if (TryCrackId(message.Message, out id)) { IDataStore store = DataStore.GetInstance(); Subscription sub = store.Subscriptions.Where(s => s.Id == id).FirstOrDefault(); if (sub != null) { Say(message.From, "Subscription {0} has phone {1} and is due on {2}", sub.Id, sub.Phone, sub.Next); } else { Say(message.From, "Subscription Not Found: {0}", id); } } else { Say(message.From, "Unable to parse input. Usage: SUB <id> Example: SUB 10"); } }
protected override void PerformAdmin(Domain.IncomingSmsMessage message) { string newIdea; if (TryCrackMessage(message.Message, out newIdea)) { IDataStore store = DataStore.GetInstance(); DailyIdea idea = store.DailyIdeas.Where(i => i.Idea == newIdea).FirstOrDefault(); if (idea == null) { idea = new DailyIdea { Idea = newIdea, }; store.Save(idea); Say(message.From, SmsResponseStrings.Add_Success_AddedNewIdea(idea.Id)); } else { Say(message.From, SmsResponseStrings.Add_Failed_ExistingIdea(idea.Id)); } } else { Say(message.From, SmsResponseStrings.Add_Help()); } }
protected override void PerformAdmin(Domain.IncomingSmsMessage message) { int id; string editedIdea; if (TryCrackIdMessage(message.Message, out id, out editedIdea)) { IDataStore store = DataStore.GetInstance(); DailyIdea idea = store.DailyIdeas.Where(i => i.Id == id).FirstOrDefault(); if (idea != null) { if (editedIdea.Length < 10) { Say(message.From, "EDIT failed. Your idea is really short ... probably a mistake. Want to try again?"); } else { idea.Idea = editedIdea; store.Save(idea); Say(message.From, "Idea {0} has been updated to your new text", idea.Id); } } else { Say(message.From, "Idea {0} does not exist. Use add to create a new idea", id); } } else { Say(message.From, "Unable to parse input. Usage: EDIT <id> <new message> Example: EDIT 1 this is the new idea"); } }
private static void DoQuit(Domain.IncomingSmsMessage message) { IDataStore store = DataStore.GetInstance(); store.RemoveAllForPhone(message.From); Say(message.From, SmsResponseStrings.Quit_AllRemoved(message.From)); }
private void RepeatToday(Domain.IncomingSmsMessage message) { DailyIdea idea = DailyIdea.TodaysIdea(DateTime.UtcNow); string ideaMsg = idea == null ? "ERROR: There is no idea for today!" : idea.Idea; Say(message.From, ideaMsg); }
protected override void PerformAdmin(Domain.IncomingSmsMessage message) { IDataStore store = DataStore.GetInstance(); DateTime fromWhen = DateTime.UtcNow.AddDays(-1); Say(message.From, "Subscriptions: {0} Last 24/hr Received: {1}, Send Success {2}, Send fail {3}, Pending Send {4}", store.Subscriptions.Count(), store.IncomingMessageLogs.Count(m => m.Date > fromWhen), store.SentSmsMessageLogEntries.Count(m => m.Date > fromWhen && m.Status == (int)MessageSendStatus.Success), store.SentSmsMessageLogEntries.Count(m => m.Date > fromWhen && m.Status != (int)MessageSendStatus.Success), store.OutgoingMessages.Count()); }
protected override void PerformAdmin(Domain.IncomingSmsMessage message) { IDataStore store = DataStore.GetInstance(); if (!store.Subscriptions.Any(s => s.Phone == message.From)) { PerformUnknownUser(message); } else { PerformSubscriber(message); } }
protected override void PerformAdmin(Domain.IncomingSmsMessage message) { int id; if (TryCrackId(message.Message, out id)) { IDataStore store = DataStore.GetInstance(); DailyIdea idea = store.DailyIdeas.Where(i => i.Id == id).FirstOrDefault(); if (idea != null) { Say(message.From, idea.Idea); } } }
protected override void PerformAdmin(Domain.IncomingSmsMessage message) { string phone; if (TryCrackMessage(message.Message, out phone)) { NumberBlocker.Unblock(phone); Say(message.From, "All blocks for number {0} have been removed."); } else { Say(message.From, "Usage: UNBLOCK <+1222333444> Example: UNBLOCK +19005551212"); } }
protected override void PerformAdmin(Domain.IncomingSmsMessage message) { string[] parts = message.Message.Split(new char[] { ' ' }, 4, StringSplitOptions.RemoveEmptyEntries); if (parts.Length != 3) { Say(message.From, "Usage: BLOCK <+1222333444> <days> Example: BLOCK +19005551212 7"); } string number = parts[1]; int days; if (!int.TryParse(parts[2], out days)) { Say(message.From, "Usage: BLOCK <+1222333444> <days> Example: BLOCK +19005551212 7"); } NumberBlocker.Block(number, days); Say(message.From, "The number {0} has been blocked for {1} days.", number, days); }
protected override void PerformAdmin(Domain.IncomingSmsMessage message) { string action; if (TryCrackMessage(message.Message, out action)) { switch (action.ToLowerInvariant()) { case "error": SayLastError(message); break; case "log": SayLostLog(message); break; default: Say(message.From, SmsResponseStrings.Last_Help()); break; } } }
protected override void PerformUnknownUser(Domain.IncomingSmsMessage message) { IDataStore store = DataStore.GetInstance(); IConfiguration config = Configuration.GetInstance(); if (store.Subscriptions.Count() < config.BetaLimit) { Subscription s = new Subscription { Phone = message.From, Next = DateTime.UtcNow, }; store.Save(s); Say(message.From, SmsResponseStrings.Join_Created()); } else { Say(message.From, SmsResponseStrings.Join_SorryBetaFull()); Say(config.AdminNumber, SmsResponseStrings.Join_AdminBetaReject()); } }
private void SayLostLog(Domain.IncomingSmsMessage message) { IDataStore store = DataStore.GetInstance(); LogItem lastLog = store.LogItems.OrderByDescending(l => l.Date).FirstOrDefault(); if (lastLog != null) { // send at most 3 messages List <string> parts = new List <string>(); parts.Add(SubOrNull(lastLog.Message, 0, 140)); parts.Add(SubOrNull(lastLog.Message, 140, 140)); parts.Add(SubOrNull(lastLog.Message, 280, 140)); foreach (string part in parts) { if (part != null) { Say(message.From, part); } } } }
private void SayLastError(Domain.IncomingSmsMessage message) { IDataStore store = DataStore.GetInstance(); LogItem lastError = store.LogItems.Where(l => l.Exception != null).OrderByDescending(l => l.Date).FirstOrDefault(); if (lastError != null) { Say(message.From, "Error entry {0} at occurred at {1} (UTC)", lastError.ID, lastError.Date); if (!string.IsNullOrEmpty(lastError.Message)) { Say(message.From, SubOrNull(lastError.Message, 0, 140)); } // send at most 3 messages List <string> parts = new List <string>(); parts.Add(SubOrNull(lastError.Exception, 0, 140)); parts.Add(SubOrNull(lastError.Exception, 140, 140)); parts.Add(SubOrNull(lastError.Exception, 280, 140)); foreach (string part in parts) { if (part != null) { Say(message.From, part); } } } else { Say(message.From, "No errors in the log. Hurray?"); } }
protected override void PerformAdmin(Domain.IncomingSmsMessage message) { int id; if (TryCrackId(message.Message, out id)) { IDataStore store = DataStore.GetInstance(); DailyIdea lookup = store.DailyIdeas.Where(l => l.Id == id).FirstOrDefault(); if (lookup != null) { store.Remove(lookup); Say(message.From, "Removed idea with ID {0}", id); } else { Say(message.From, "Idea Not Found: {0}", id); } } else { Say(message.From, "Unable to parse input. Usage: REMOVE <id> Example: REMOVE 10"); } }
protected override void PerformAdmin(Domain.IncomingSmsMessage message) { RepeatToday(message); }
protected override void PerformAdmin(Domain.IncomingSmsMessage message) { DoQuit(message); }
protected override void PerformSubscriber(Domain.IncomingSmsMessage message) { DoQuit(message); }
protected override void PerformUnknownUser(Domain.IncomingSmsMessage message) { DoQuit(message); }
protected override void PerformAdmin(Domain.IncomingSmsMessage message) { SaveSuggestion(message); }
private void SaveSuggestion(Domain.IncomingSmsMessage message) { Say(Configuration.GetInstance().AdminNumber, string.Format("sug: {0}", message.Message)); Say(message.From, "Thanks for the feedback! You can also contact me as @tellhernow on Twitter"); }
protected override void PerformAdmin(Domain.IncomingSmsMessage message) { Say(message.From, "join, quit, help, say <id>, remove <id>, edit <id> <new>, add <new>"); }
protected override void PerformSubscriber(Domain.IncomingSmsMessage message) { Say(message.From, SmsResponseStrings.Join_AlreadyExists()); }
protected override void PerformSubscriber(Domain.IncomingSmsMessage message) { RepeatToday(message); }