/// <summary> /// It may throw TimeoutException. It also may throw CarrierException. /// It also may throw CommandException /// </summary> protected void WaitForRespond(RespondType respondType) { string text = string.Empty; TimeSpan d = new TimeSpan(_RespondTimeout); DateTime t = DateTime.Now; while (DateTime.Now.Subtract(t).CompareTo(d) <= 0) { if (!_adaptor.IsDataReady) { System.Threading.Thread.Sleep(_respond_waiting_thread_sleep_delay_); } text += _adaptor.Get(); Respond respond = Respond.Resolve(text); if (respond != null) { if (respond.Type == respondType) { return; } else { throw new CommandException(); } } } throw new TimeoutException(); }
public Respond(RespondType type, string text) { _Type = type; _Text = text; }
public Respond(RespondType type) { _Type = type; }
public RefRespondEntity(RespondType type) { ResultType = type; }
private async Task RespondAsync(Value value, ulong channelId, ulong scanStartedUserId, RespondType type) { if (value == null) { throw new ArgumentNullException(nameof(value)); } if (type == RespondType.Aborted) { await RespondBySayAsync($"{value.WatchingExpr.ToString()} の集計は停止されました。", channelId, scanStartedUserId); return; } string infoText; switch (type) { case RespondType.TochuuKeika: case RespondType.Show: infoText = value.IsArchived ? "(終了)" : "(途中経過)"; break; case RespondType.ShuffledShow: infoText = value.IsArchived ? "(終了: 一時的なシャッフル)" : "(途中経過: 一時的なシャッフル)"; break; default: infoText = ""; break; } var firstLine = $"```{value.WatchingExpr.ToString()} の集計結果{infoText}:"; var text = value .Ranking .Shuffle(type == RespondType.ShuffledShow) .Aggregate(new StringBuilder(firstLine), (resultBuilder, tuple) => { resultBuilder.Append("\r\n"); var(rank, userID, userName, rolledDice) = tuple; var appending = $"{String.Format("{0:D2}", rank + 1)}位 - {userName}({rolledDice})"; resultBuilder.Append(appending); return(resultBuilder); }) .Append("```") .ToString(); await RespondBySayAsync(text, channelId, scanStartedUserId); }
public RefRespondEntity(RespondType type) { ResultType = type; }