Skip to content

Commit 435cb36

Browse files
author
James (KingLuxor)
committed
Adds two examples to the TestRedditSharp project.
First example shows how to iterate unread private messages Second example shows how to iterate unread replies to comments
1 parent 9678b97 commit 435cb36

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

TestRedditSharp/Program.cs

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,60 @@ static void Main(string[] args)
6464
var sub = reddit.GetSubreddit(subname);
6565
foreach (var post in sub.GetTop(FromTime.Week).Take(10))
6666
Console.WriteLine("\"{0}\" by {1}", post.Title, post.Author);
67-
}*/
67+
}
68+
Console.Write("Check inbox for unread private messages? (y/n) [n]: ");
69+
var choicePM = Console.ReadLine();
70+
if (!string.IsNullOrEmpty(choicePM) && choicePM.ToLower()[0] == 'y')
71+
{
72+
if (reddit.User.HasMail)
73+
{
74+
int i = 1;
75+
foreach (PrivateMessage message in reddit.User.UnreadMessages.OfType<PrivateMessage>())
76+
{
77+
Console.WriteLine("({0}) Sender: {1}", i, message.Author);
78+
Console.WriteLine("Subject: {0}", message.Subject);
79+
Console.WriteLine("Message:");
80+
Console.WriteLine("{0}", message.Body);
81+
Console.WriteLine("---- ---- ---- ---- ---- ---- ---- ----");
82+
i++;
83+
}
84+
Console.WriteLine("End of unread private messages");
85+
Console.WriteLine("");
86+
87+
}
88+
else
89+
{
90+
Console.WriteLine("No unread private messages found");
91+
Console.WriteLine("");
92+
}
93+
}
94+
95+
Console.Write("Check for replies to comments? (y/n) [n]: ");
96+
var choiceCR = Console.ReadLine();
97+
if (!string.IsNullOrEmpty(choiceCR) && choiceCR.ToLower()[0] == 'y')
98+
{
99+
if (reddit.User.HasMail)
100+
{
101+
int i = 1;
102+
foreach (Comment commentReply in reddit.User.UnreadMessages.OfType<Comment>())
103+
{
104+
Console.WriteLine("({0}) Sender: {1}", i, commentReply.Author);
105+
Console.WriteLine("Thread Title: {0}", commentReply.LinkTitle);
106+
Console.WriteLine("Message:");
107+
Console.WriteLine("{0}", commentReply.Body);
108+
Console.WriteLine("---- ---- ---- ---- ---- ---- ---- ----");
109+
i++;
110+
}
111+
Console.WriteLine("End of unread replies to comments");
112+
Console.WriteLine("");
113+
}
114+
else
115+
{
116+
Console.WriteLine("No unread replies to comments found");
117+
Console.WriteLine("");
118+
}
119+
}
120+
*/
68121
Comment comment = (Comment)reddit.GetThingByFullname("t1_ciif2g7");
69122
Post post = (Post)reddit.GetThingByFullname("t3_298g7j");
70123
PrivateMessage pm = (PrivateMessage)reddit.GetThingByFullname("t4_20oi3a"); // Use your own PM here, as you don't have permission to view this one

0 commit comments

Comments
 (0)