Skip to content

Commit e3e1d94

Browse files
committed
Add static method to reply to comments
1 parent 5c830e4 commit e3e1d94

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

RedditSharp/Things/Comment.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,5 +256,38 @@ private async Task SetReadStatusAsync(string statusUrl)
256256
api_type = "json"
257257
}).ConfigureAwait(false);
258258
}
259+
260+
#region Static Methods
261+
/// <summary>
262+
/// Post a reply to a specific comment
263+
/// </summary>
264+
/// <param name="webAgent"></param>
265+
/// <param name="commentFullName">e.g. "t1_12345"</param>
266+
/// <param name="message"></param>
267+
/// <returns></returns>
268+
public static async Task Reply(IWebAgent webAgent, string commentFullName, string message) {
269+
// TODO actual error handling. This just hides the error and returns null
270+
//try
271+
//{
272+
var json = await webAgent.Post(CommentUrl, new {
273+
text = message,
274+
thing_id = commentFullName,
275+
api_type = "json"
276+
//r = Subreddit
277+
}).ConfigureAwait(false);
278+
if (json["json"]["ratelimit"] != null) {
279+
throw new RateLimitException(TimeSpan.FromSeconds(json["json"]["ratelimit"].ValueOrDefault<double>()));
280+
}
281+
282+
283+
//}
284+
//catch (HttpRequestException ex)
285+
//{
286+
// var error = new StreamReader(ex..GetResponseStream()).ReadToEnd();
287+
// return null;
288+
//}
289+
}
290+
#endregion
291+
259292
}
260293
}

0 commit comments

Comments
 (0)