示例#1
0
 /// <summary>
 /// Sets the target of the post target defined by the name to the given channel in the database. Does not reload the Global object.
 /// In case the post target was valid, but not yet defined, this method creates a new one.
 /// </summary>
 /// <param name="name">Name of the post target to change</param>
 /// <param name="channel">The <see cref="Discord.IChannel"/> object the posts of this post target should be posted towards</param>
 /// <exception cref="OnePlusBot.Base.Errors.NotFoundException">In case the desired post target is not found</exception>
 public void SetPostTarget(string name, IChannel channel)
 {
     using (var db = new Database())
     {
         var        existingTarget = db.PostTargets.Where(pt => pt.Name == name);
         PostTarget newPostTarget;
         if (existingTarget.Any())
         {
             newPostTarget           = existingTarget.First();
             newPostTarget.ChannelId = channel.Id;
         }
         else
         {
             if (!PostTarget.POST_TARGETS.Where(t => t == name).Any())
             {
                 throw new NotFoundException("Post target does not exist.");
             }
             newPostTarget           = new PostTarget();
             newPostTarget.Name      = name;
             newPostTarget.ChannelId = channel.Id;
             db.PostTargets.Add(newPostTarget);
         }
         db.SaveChanges();
     }
 }
示例#2
0
        public void postTo(PostTarget network)
        {
            var usr = repository.GetUserById(sessionid.Value, subdomainid.Value);

            if (usr != null)
            {
                switch (network)
                {
                case PostTarget.BLOGGER:
                    usr.settings ^= ((int)UserSettings.POST_TO_BLOGGER);
                    break;

                case PostTarget.EBAY:
                    usr.settings ^= ((int)UserSettings.POST_TO_EBAY);
                    break;

                case PostTarget.GBASE:
                    usr.settings ^= ((int)UserSettings.POST_TO_GOOGLE);
                    break;

                case PostTarget.FACEBOOK:
                    usr.settings ^= ((int)UserSettings.POST_TO_FACEBOOK);
                    break;

                case PostTarget.TRADEME:
                    usr.settings ^= ((int)UserSettings.POST_TO_TRADEME);
                    break;

                case PostTarget.TUMBLR:
                    usr.settings ^= ((int)UserSettings.POST_TO_TUMBLR);
                    break;

                case PostTarget.WORDPRESS:
                    usr.settings ^= ((int)UserSettings.POST_TO_WORDPRESS);
                    break;
                }
                repository.Save();
            }
        }
示例#3
0
 public TestSceneNowPlayingCommand()
 {
     Add(postTarget = new PostTarget());
 }
示例#4
0
        public async Task <PostResult> PostOnWallAsync(string privacy, int video_id, string message, string url, PostTarget target, int subjectId, Stream[] photos)
        {
            string type = string.IsNullOrEmpty(url) ? "" : "link";

            if (video_id != 0)
            {
                type = "video";
                url  = "";
            }
            string subject_type = target == PostTarget.User ? "user" : "sitepage_page";

            var req = new KoobecaPostRequest()
            {
                body         = message,
                type         = type,
                video_id     = video_id,
                uri          = url,
                subject_type = subject_type,
                subject_id   = subjectId,
                post_attach  = 1,
                photos       = photos,
                auth_view    = privacy
            };

            var result = await PostKoobecaRequestAsync <PostResult>(req);

            if (result == null)
            {
                result = new PostResult()
                {
                    error = true, message = "got null result"
                };
            }
            else
            {
                result.error = result.status_code != 200;
            }

            return(result);
        }