forked from sirkris/Reddit.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMonitor Subreddit Comments.cs
More file actions
43 lines (35 loc) · 1.29 KB
/
Copy pathMonitor Subreddit Comments.cs
File metadata and controls
43 lines (35 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using Reddit;
using Reddit.Controllers;
using Reddit.Controllers.EventArgs;
using System.Collections.Generic;
namespace MonitorSubredditComments
{
class Program
{
public List<Comment> NewComments;
static void Main(string[] args)
{
var reddit = new RedditClient("YourRedditAppID", "YourBotUserRefreshToken");
NewComments = new List<Comment>();
// Start monitoring the subreddit for new comments and register the callback function. --Kris
var subreddit = reddit.Subreddit("AskReddit");
subreddit.Comments.GetNew(); // This call prevents any existing "new"-sorted comments from triggering the update event. --Kris
subreddit.Comments.MonitorNew();
subreddit.Comments.NewUpdated += C_NewCommentsUpdated;
while(true) { } // Replace this with whatever you've got for a program loop. The monitoring will run asynchronously in a separate thread. --Kris
// Stop monitoring and unregister the callback function. --Kris
subreddit.Comments.MonitorNew();
reddit.Account.Modmail.NewUpdated -= C_NewCommentsUpdated;
}
private void C_NewCommentsUpdated(object sender, CommentsUpdateEventArgs e)
{
foreach (Comment comment in e.Added)
{
if (!NewComments.ContainsKey(comment.Fullname))
{
NewComments.Add(comment.Fullname, comment);
}
}
}
}
}