Beispiel #1
0
        public void Distinguish(DistinguishType distinguishType)
        {
            if (Reddit.User == null)
            {
                throw new AuthenticationException("No user logged in.");
            }
            var    request = WebAgent.CreatePost(DistinguishUrl);
            var    stream  = request.GetRequestStream();
            string how;

            switch (distinguishType)
            {
            case DistinguishType.Admin:
                how = "admin";
                break;

            case DistinguishType.Moderator:
                how = "yes";
                break;

            case DistinguishType.None:
                how = "no";
                break;

            default:
                how = "special";
                break;
            }
            WebAgent.WritePostBody(stream, new
            {
                how,
                id = Id,
                uh = Reddit.User.Modhash
            });
            stream.Close();
            var response = request.GetResponse();
            var data     = WebAgent.GetResponseString(response.GetResponseStream());
            var json     = JObject.Parse(data);

            if (
                json["jquery"].Count(
                    i =>
                    Extensions.Value <int>(i[0]) == 11 &&
                    Extensions.Value <int>(i[1]) == 12) == 0)
            {
                throw new AuthenticationException("You are not permitted to distinguish this comment.");
            }
        }
Beispiel #2
0
 public static U Value <U>(this IEnumerable <JToken> value)
 {
     return(Extensions.Value <JToken, U>(value));
 }