@@ -31,6 +31,7 @@ public class Subreddit : Thing
31
31
private const string AcceptModeratorInviteUrl = "/api/accept_moderator_invite" ;
32
32
private const string LeaveModerationUrl = "/api/unfriend" ;
33
33
private const string BanUserUrl = "/api/friend" ;
34
+ private const string UnBanUserUrl = "/api/unfriend" ;
34
35
private const string AddModeratorUrl = "/api/friend" ;
35
36
private const string AddContributorUrl = "/api/friend" ;
36
37
private const string ModeratorsUrl = "/r/{0}/about/moderators.json" ;
@@ -42,6 +43,7 @@ public class Subreddit : Thing
42
43
private const string SearchUrlDate = "/r/{0}/search.json?q=timestamp:{1}..{2}&restrict_sr=on&sort={3}&syntax=cloudsearch" ;
43
44
private const string ModLogUrl = "/r/{0}/about/log.json" ;
44
45
private const string ContributorsUrl = "/r/{0}/about/contributors.json" ;
46
+ private const string BannedUsersUrl = "/r/{0}/about/banned.json" ;
45
47
46
48
[ JsonIgnore ]
47
49
private Reddit Reddit { get ; set ; }
@@ -346,6 +348,13 @@ public Listing<Contributor> Contributors
346
348
}
347
349
}
348
350
351
+ public Listing < BannedUser > BannedUsers
352
+ {
353
+ get
354
+ {
355
+ return new Listing < BannedUser > ( Reddit , string . Format ( BannedUsersUrl , Name ) , WebAgent ) ;
356
+ }
357
+ }
349
358
350
359
public async Task < Subreddit > InitAsync ( Reddit reddit , JToken json , IWebAgent webAgent )
351
360
{
@@ -691,6 +700,7 @@ public void RemoveContributor(string id)
691
700
var response = request . GetResponse ( ) ;
692
701
var result = WebAgent . GetResponseString ( response . GetResponseStream ( ) ) ;
693
702
}
703
+
694
704
public async Task RemoveContributorAsync ( string id )
695
705
{
696
706
var request = WebAgent . CreatePost ( LeaveModerationUrl ) ;
@@ -705,42 +715,101 @@ public async Task RemoveContributorAsync(string id)
705
715
var response = request . GetResponse ( ) ;
706
716
var result = WebAgent . GetResponseString ( response . GetResponseStream ( ) ) ;
707
717
}
708
- public void BanUser ( string user , string reason )
718
+
719
+ /// <summary>
720
+ /// Bans a user
721
+ /// </summary>
722
+ /// <param name="user">User to ban, by username</param>
723
+ /// <param name="reason">Reason for ban, shows in ban note as 'reason: note' or just 'note' if blank</param>
724
+ /// <param name="note">Mod notes about ban, shows in ban note as 'reason: note'</param>
725
+ /// <param name="duration">Number of days to ban user, 0 for permanent</param>
726
+ /// <param name="message">Message to include in ban PM</param>
727
+ public void BanUser ( string user , string reason , string note , int duration , string message )
709
728
{
710
729
var request = WebAgent . CreatePost ( BanUserUrl ) ;
711
730
WebAgent . WritePostBody ( request . GetRequestStream ( ) , new
712
731
{
713
732
api_type = "json" ,
714
733
uh = Reddit . User . Modhash ,
715
734
r = Name ,
735
+ container = FullName ,
716
736
type = "banned" ,
717
- id = "#banned" ,
718
737
name = user ,
719
- note = reason ,
720
- action = "add" ,
721
- container = FullName
738
+ ban_reason = reason ,
739
+ note = note ,
740
+ duration = duration <= 0 ? "" : duration . ToString ( ) ,
741
+ ban_message = message
722
742
} ) ;
723
743
var response = request . GetResponse ( ) ;
724
744
var result = WebAgent . GetResponseString ( response . GetResponseStream ( ) ) ;
725
745
}
726
- public async Task BanUserAsync ( string user , string reason )
746
+
747
+ public async Task BanUserAsync ( string user , string reason , string note , int duration , string message )
727
748
{
728
749
var request = WebAgent . CreatePost ( BanUserUrl ) ;
729
750
WebAgent . WritePostBody ( await request . GetRequestStreamAsync ( ) , new
730
751
{
731
752
api_type = "json" ,
732
753
uh = Reddit . User . Modhash ,
733
754
r = Name ,
755
+ container = FullName ,
734
756
type = "banned" ,
735
- id = "#banned" ,
736
757
name = user ,
737
- note = reason ,
738
- action = "add" ,
739
- container = FullName
758
+ ban_reason = reason ,
759
+ note = note ,
760
+ duration = duration <= 0 ? "" : duration . ToString ( ) ,
761
+ ban_message = message
740
762
} ) ;
741
763
var response = await request . GetResponseAsync ( ) ;
742
764
var result = WebAgent . GetResponseString ( response . GetResponseStream ( ) ) ;
743
765
}
766
+
767
+ public void BanUser ( string user , string note )
768
+ {
769
+ BanUser ( user , "" , note , 0 , "" ) ;
770
+ }
771
+
772
+ public async Task BanUserAsync ( string user , string note )
773
+ {
774
+ await BanUserAsync ( user , "" , note , 0 , "" ) ;
775
+ }
776
+
777
+ /// <summary>
778
+ /// Unbans a user
779
+ /// </summary>
780
+ /// <param name="user">User to unban, by username</param>
781
+ public void UnBanUser ( string user )
782
+ {
783
+ var request = WebAgent . CreatePost ( UnBanUserUrl ) ;
784
+ WebAgent . WritePostBody ( request . GetRequestStream ( ) , new
785
+ {
786
+ uh = Reddit . User . Modhash ,
787
+ r = Name ,
788
+ type = "banned" ,
789
+ container = FullName ,
790
+ executed = "removed" ,
791
+ name = user ,
792
+ } ) ;
793
+ var response = request . GetResponse ( ) ;
794
+ var result = WebAgent . GetResponseString ( response . GetResponseStream ( ) ) ;
795
+ }
796
+
797
+ public async Task UnBanUserAsync ( string user )
798
+ {
799
+ var request = WebAgent . CreatePost ( UnBanUserUrl ) ;
800
+ WebAgent . WritePostBody ( await request . GetRequestStreamAsync ( ) , new
801
+ {
802
+ uh = Reddit . User . Modhash ,
803
+ r = Name ,
804
+ type = "banned" ,
805
+ container = FullName ,
806
+ executed = "removed" ,
807
+ name = user ,
808
+ } ) ;
809
+ var response = await request . GetResponseAsync ( ) ;
810
+ var result = WebAgent . GetResponseString ( response . GetResponseStream ( ) ) ;
811
+ }
812
+
744
813
private Post Submit ( SubmitData data )
745
814
{
746
815
if ( Reddit . User == null )
0 commit comments