private List<IMBotMessage> CreateQueuedMessages(IMBotMessage message) { List<IMBotMessage> queuedMessages = new List<IMBotMessage>(); StringBuilder chunkBuilder = new StringBuilder(); int index = 0; while (index < message.BodyText.Length) { int nextIndex = message.BodyText.IndexOf(Environment.NewLine, index); int lineLength; if (nextIndex < 0) { nextIndex = message.BodyText.Length; } else { nextIndex += Environment.NewLine.Length; } lineLength = nextIndex - index; if (chunkBuilder.Length + message.FooterLength + lineLength > this.MaxMessageLength) { chunkBuilder.Remove(chunkBuilder.Length - Environment.NewLine.Length, Environment.NewLine.Length); AppendQueuedMessage(queuedMessages, message, chunkBuilder, true); chunkBuilder = new StringBuilder(); } chunkBuilder.Append(message.BodyText, index, lineLength); index = nextIndex; } AppendQueuedMessage(queuedMessages, message, chunkBuilder, false); return queuedMessages; }
private List <IMBotMessage> CreateQueuedMessages(IMBotMessage message) { List <IMBotMessage> queuedMessages = new List <IMBotMessage>(); StringBuilder chunkBuilder = new StringBuilder(); int index = 0; while (index < message.BodyText.Length) { int nextIndex = message.BodyText.IndexOf(Environment.NewLine, index); int lineLength; if (nextIndex < 0) { nextIndex = message.BodyText.Length; } else { nextIndex += Environment.NewLine.Length; } lineLength = nextIndex - index; if (chunkBuilder.Length + message.FooterLength + lineLength > this.MaxMessageLength) { chunkBuilder.Remove(chunkBuilder.Length - Environment.NewLine.Length, Environment.NewLine.Length); AppendQueuedMessage(queuedMessages, message, chunkBuilder, true); chunkBuilder = new StringBuilder(); } chunkBuilder.Append(message.BodyText, index, lineLength); index = nextIndex; } AppendQueuedMessage(queuedMessages, message, chunkBuilder, false); return(queuedMessages); }
private void AppendQueuedMessage(List <IMBotMessage> queuedMessages, IMBotMessage message, StringBuilder chunkBuilder, bool addMore) { if (chunkBuilder.Length > 0) { IMBotMessage queuedMessage = new IMBotMessage(chunkBuilder.ToString()); queuedMessage.Font = message.Font; queuedMessage.TextColor = message.TextColor; queuedMessage.Footer = message.Footer; queuedMessage.AddMore = addMore; queuedMessages.Add(queuedMessage); } }
private IMBotMessage GetNextQueuedMessage() { IMBotMessage result = null; if (_queuedMessages.Count > 0) { result = _queuedMessages[0]; _queuedMessages.RemoveAt(0); } else { result = new IMBotMessage("There is no more.", System.Drawing.Color.Red); } return(result); }
private IMBotMessage DoCancelCommand(IMBotConversation conversation, IList <string> arguments, bool cancel) { if (arguments.Count == 0) { return(new IMBotMessage("Program number is missing.", IMBotMessage.ErrorColor)); } using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent()) { UpcomingProgram upcomingRecording; IMBotMessage result = FindUpcomingRecording(tvSchedulerAgent, conversation, arguments, out upcomingRecording); if (result == null) { StringBuilder replyText = new StringBuilder(); if (cancel) { if (upcomingRecording.IsPartOfSeries) { tvSchedulerAgent.CancelUpcomingProgram(upcomingRecording.ScheduleId, upcomingRecording.GuideProgramId, upcomingRecording.Channel.ChannelId, upcomingRecording.StartTime); replyText.Append("Cancelled "); } else { tvSchedulerAgent.DeleteSchedule(upcomingRecording.ScheduleId); replyText.Append("Deleted schedule for "); } } else { tvSchedulerAgent.UncancelUpcomingProgram(upcomingRecording.ScheduleId, upcomingRecording.GuideProgramId, upcomingRecording.Channel.ChannelId, upcomingRecording.StartTime); replyText.Append("Uncancelled "); } Utility.AppendProgramDetails(replyText, upcomingRecording.Channel, upcomingRecording); replyText.Append("."); result = new IMBotMessage(replyText.ToString()); } return(result); } }
private IMBotMessage DoDeleteScheduleCommand(IMBotConversation conversation, IList <string> arguments) { if (arguments.Count == 0) { return(new IMBotMessage("Program number is missing.", IMBotMessage.ErrorColor)); } UpcomingProgram upcomingRecording; IMBotMessage result = FindUpcomingRecording(conversation, arguments, out upcomingRecording); if (result == null) { StringBuilder replyText = new StringBuilder(); Proxies.SchedulerService.DeleteSchedule(upcomingRecording.ScheduleId).Wait(); replyText.Append("Deleted schedule for "); Utility.AppendProgramDetails(replyText, upcomingRecording.Channel, upcomingRecording); replyText.Append("."); result = new IMBotMessage(replyText.ToString()); } return(result); }
protected IMBotMessage HandleIncomingMessage(string text) { DoKeepAlive(); if (text.Equals("more", StringComparison.CurrentCultureIgnoreCase) || text.Equals("m", StringComparison.CurrentCultureIgnoreCase)) { return(GetNextQueuedMessage()); } else { IMBotMessage reply = _imCommands.ProcessIMCommand(this, text); int chunks = 1 + (int)Math.Floor(reply.TotalLength / (decimal)this.MaxMessageLength); if (chunks > 1) { _queuedMessages = CreateQueuedMessages(reply); reply = GetNextQueuedMessage(); } return(reply); } }
public IMBotMessage ProcessIMCommand(IMBotConversation conversation, string commandLine) { IMBotMessage reply = new IMBotMessage(); if (!Proxies.IsInitialized) { reply.BodyText = "Not connected to ARGUS TV, check configuration."; reply.TextColor = IMBotMessage.ErrorColor; } else { try { commandLine = commandLine.TrimStart(); reply = _commandParser.ProcessIMCommand(conversation, ArgusTV.Common.Utility.ParseCommandArguments(commandLine)); } catch { reply.BodyText = "Internal error occurred."; reply.TextColor = IMBotMessage.ErrorColor; } } return reply; }
public IMBotMessage ProcessIMCommand(IMBotConversation conversation, string commandLine) { IMBotMessage reply = new IMBotMessage(); if (!Proxies.IsInitialized) { reply.BodyText = "Not connected to ARGUS TV, check configuration."; reply.TextColor = IMBotMessage.ErrorColor; } else { try { commandLine = commandLine.TrimStart(); reply = _commandParser.ProcessIMCommand(conversation, ArgusTV.Common.Utility.ParseCommandArguments(commandLine)); } catch { reply.BodyText = "Internal error occurred."; reply.TextColor = IMBotMessage.ErrorColor; } } return(reply); }
private IMBotMessage DoDeleteScheduleCommand(IMBotConversation conversation, IList<string> arguments) { if (arguments.Count == 0) { return new IMBotMessage("Program number is missing.", IMBotMessage.ErrorColor); } using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent()) { UpcomingProgram upcomingRecording; IMBotMessage result = FindUpcomingRecording(tvSchedulerAgent, conversation, arguments, out upcomingRecording); if (result == null) { StringBuilder replyText = new StringBuilder(); tvSchedulerAgent.DeleteSchedule(upcomingRecording.ScheduleId); replyText.Append("Deleted schedule for "); Utility.AppendProgramDetails(replyText, upcomingRecording.Channel, upcomingRecording); replyText.Append("."); result = new IMBotMessage(replyText.ToString()); } return result; } }
private IMBotMessage DoCancelCommand(IMBotConversation conversation, IList<string> arguments, bool cancel) { if (arguments.Count == 0) { return new IMBotMessage("Program number is missing.", IMBotMessage.ErrorColor); } using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent()) { UpcomingProgram upcomingRecording; IMBotMessage result = FindUpcomingRecording(tvSchedulerAgent, conversation, arguments, out upcomingRecording); if (result == null) { StringBuilder replyText = new StringBuilder(); if (cancel) { if (upcomingRecording.IsPartOfSeries) { tvSchedulerAgent.CancelUpcomingProgram(upcomingRecording.ScheduleId, upcomingRecording.GuideProgramId, upcomingRecording.Channel.ChannelId, upcomingRecording.StartTime); replyText.Append("Cancelled "); } else { tvSchedulerAgent.DeleteSchedule(upcomingRecording.ScheduleId); replyText.Append("Deleted schedule for "); } } else { tvSchedulerAgent.UncancelUpcomingProgram(upcomingRecording.ScheduleId, upcomingRecording.GuideProgramId, upcomingRecording.Channel.ChannelId, upcomingRecording.StartTime); replyText.Append("Uncancelled "); } Utility.AppendProgramDetails(replyText, upcomingRecording.Channel, upcomingRecording); replyText.Append("."); result = new IMBotMessage(replyText.ToString()); } return result; } }
private IMBotMessage GetNextQueuedMessage() { IMBotMessage result = null; if (_queuedMessages.Count > 0) { result = _queuedMessages[0]; _queuedMessages.RemoveAt(0); } else { result = new IMBotMessage("There is no more.", System.Drawing.Color.Red); } return result; }
private void AppendQueuedMessage(List<IMBotMessage> queuedMessages, IMBotMessage message, StringBuilder chunkBuilder, bool addMore) { if (chunkBuilder.Length > 0) { IMBotMessage queuedMessage = new IMBotMessage(chunkBuilder.ToString()); queuedMessage.Font = message.Font; queuedMessage.TextColor = message.TextColor; queuedMessage.Footer = message.Footer; queuedMessage.AddMore = addMore; queuedMessages.Add(queuedMessage); } }