/// <summary>
        /// Adds a new ban to the chat.
        /// Documentation https://developers.google.com/youtube/v3/reference/liveChatBans/insert
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Youtube service.</param>
        /// <param name="part">The part parameter serves two purposes in this operation. It identifies the properties that the write operation will set as well as the properties that the API response returns. Set the parameter value to snippet.</param>
        /// <param name="body">A valid Youtube v3 body.</param>
        /// <returns>LiveChatBanResponse</returns>
        public static LiveChatBan Insert(YoutubeService service, string part, LiveChatBan body)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (body == null)
                {
                    throw new ArgumentNullException("body");
                }
                if (part == null)
                {
                    throw new ArgumentNullException(part);
                }

                // Make the request.
                return(service.LiveChatBans.Insert(body, part).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request LiveChatBans.Insert failed.", ex);
            }
        }
Ejemplo n.º 2
0
        public async Task <ChannelBan> addChatBan(string chatID, ChannelUser channelUser, bool permanent = false, ulong time = 300)
        {
            LiveChatBan liveChatBan;

            if (permanent)
            {
                liveChatBan = new LiveChatBan()
                {
                    Snippet = new LiveChatBanSnippet()
                    {
                        LiveChatId        = chatID,
                        BannedUserDetails = new ChannelProfileDetails()
                        {
                            ChannelId       = channelUser.ChannelID,
                            DisplayName     = channelUser.DisplayName,
                            ChannelUrl      = channelUser.ChannelURL,
                            ProfileImageUrl = channelUser.ProfileImageURL
                        }
                    }
                };
            }
            else
            {
                liveChatBan = new LiveChatBan()
                {
                    Snippet = new LiveChatBanSnippet()
                    {
                        BanDurationSeconds = time,
                        LiveChatId         = chatID,
                        BannedUserDetails  = new ChannelProfileDetails()
                        {
                            ChannelId       = channelUser.ChannelID,
                            DisplayName     = channelUser.DisplayName,
                            ChannelUrl      = channelUser.ChannelURL,
                            ProfileImageUrl = channelUser.ProfileImageURL
                        }
                    }
                };
            }
            var addban = youTubeService.LiveChatBans.Insert(liveChatBan, "snippet");
            var result = await addban.ExecuteAsync();

            ChannelBan channelBan = new ChannelBan()
            {
                ID   = result.Id,
                Kind = result.Kind,
                BanDurationSeconds = result.Snippet.BanDurationSeconds ?? 0L,
                LiveChatID         = result.Snippet.LiveChatId,
                ChannelUser        = new ChannelUser()
                {
                    ChannelID       = result.Snippet.BannedUserDetails.ChannelId,
                    ChannelURL      = result.Snippet.BannedUserDetails.ChannelUrl,
                    DisplayName     = result.Snippet.BannedUserDetails.DisplayName,
                    ProfileImageURL = result.Snippet.BannedUserDetails.ProfileImageUrl,
                }
            };

            return(channelBan);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Unbans the specified user from the channel.
 /// </summary>
 /// <param name="ban">The ban to remove</param>
 /// <returns>An awaitable Task</returns>
 public async Task UnbanUser(LiveChatBan ban)
 {
     Validator.ValidateVariable(ban, "ban");
     await this.YouTubeServiceWrapper <object>(async() =>
     {
         LiveChatBansResource.DeleteRequest request = this.connection.GoogleYouTubeService.LiveChatBans.Delete(ban.Id);
         await request.ExecuteAsync();
         return(null);
     });
 }
Ejemplo n.º 4
0
        private async Task <LiveChatBan> BanUserInternal(LiveBroadcast broadcast, Channel user, string banType, ulong banDuration = 0)
        {
            return(await this.YouTubeServiceWrapper(async() =>
            {
                LiveChatBan ban = new LiveChatBan();
                ban.Snippet = new LiveChatBanSnippet();
                ban.Snippet.LiveChatId = broadcast.Snippet.LiveChatId;
                ban.Snippet.Type = banType;
                if (banDuration > 0)
                {
                    ban.Snippet.BanDurationSeconds = banDuration;
                }
                ban.Snippet.BannedUserDetails = new ChannelProfileDetails();
                ban.Snippet.BannedUserDetails.ChannelId = user.Id;

                LiveChatBansResource.InsertRequest request = this.connection.GoogleYouTubeService.LiveChatBans.Insert(ban, "snippet");
                return await request.ExecuteAsync();
            }));
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Unbans the specified user from the channel.
 /// </summary>
 /// <param name="ban">The ban to remove</param>
 /// <returns>An awaitable Task</returns>
 public async Task UnbanUser(LiveChatBan ban)
 {
     await this.connection.LiveChat.UnbanUser(ban);
 }