forked from sirkris/Reddit.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMonitor Modmail.cs
More file actions
37 lines (30 loc) · 1.28 KB
/
Monitor Modmail.cs
File metadata and controls
37 lines (30 loc) · 1.28 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
using Reddit;
using Reddit.Controllers.EventArgs;
using Reddit.Things;
using System.Collections.Generic;
namespace MonitorModmail
{
class Program
{
public static List<ConversationMessage> NewMessages;
static void Main(string[] args)
{
var reddit = new RedditClient("YourRedditAppID", "YourBotUserRefreshToken");
NewMessages = new List<ConversationMessage>();
// Start monitoring unread modmail messages and register the callback function. --Kris
reddit.Account.Modmail.MonitorUnread();
reddit.Account.Modmail.UnreadUpdated += C_UnreadMessagesUpdated;
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
reddit.Account.Modmail.MonitorUnread();
reddit.Account.Modmail.UnreadUpdated -= C_UnreadMessagesUpdated;
}
private static void C_UnreadMessagesUpdated(object sender, ModmailConversationsEventArgs e)
{
foreach (KeyValuePair<string, ConversationMessage> pair in e.AddedMessages)
{
NewMessages.Add(pair.Value);
}
}
}
}