internal async Task <StreamPrediction> CancelPredictionAsync() { if (BroadcasterID == "") { await GetUserIDAsync(); } if (BroadcasterID != "") { StreamPrediction prediction = TwitchConnection.GetInstance().CurrentPrediction; if (prediction == null) { prediction = await GetCurrentPredictionAsync(); } if (prediction != null && (prediction.Status == StreamPrediction.PredictionStatus.ACTIVE || prediction.Status == StreamPrediction.PredictionStatus.LOCKED)) { DebugLogging.Log("Trying to cancel a cancel prediction (" + prediction.ID + ")", true); var parameters = new StringBuilder(); parameters.AppendLine("{"); parameters.AppendLine("\"broadcaster_id\": \"" + BroadcasterID + "\","); parameters.AppendLine("\"id\": \"" + prediction.ID + "\","); parameters.AppendLine("\"status\": \"" + StreamPrediction.PredictionStatus.CANCELED + "\""); parameters.AppendLine("}"); var response = await PerformPatchRequestAsync(BuildURI(new string[] { "predictions" }, new Tuple <string, string>[] { }), new Dictionary <string, string>() { }, parameters.ToString() ); if (response["data"] != null) { var dataNode = ((IEnumerable <dynamic>)response["data"]).First(); if (dataNode["id"] != null) { if (dataNode["status"] != null) { StreamPrediction newPredictionState = StreamPrediction.ConvertNode(dataNode); if (newPredictionState.Status == StreamPrediction.PredictionStatus.CANCELED) { DebugLogging.Log("Successfully cancelled a new prediction!", true); return(newPredictionState); } else { DebugLogging.Log("Failed to cancelled a new prediction!"); return(null); } } } } DebugLogging.Log("[ERROR] Incorrect response?"); return(null); } DebugLogging.Log("Prediction already closed", true); return(prediction); } DebugLogging.Log("[ERROR] Can not cancel prediction. Broadcaster ID is null!"); return(null); }