コード例 #1
0
        public async Task <DateTime> AddTimeout(string recipient, int broadcasterId, string twitchBotApiLink, double seconds = -1.0)
        {
            DateTime timeoutExpiration = seconds == -1.0
                ? timeoutExpiration = DateTime.MaxValue
                : DateTime.UtcNow.AddSeconds(seconds);

            BotTimeout timedoutUser = new BotTimeout();

            if (TimedoutUsers.Any(m => m.Username == recipient))
            {
                timedoutUser = await ApiBotRequest.PatchExecuteAsync <BotTimeout>(
                    twitchBotApiLink + $"bottimeouts/patch/{broadcasterId}?username={recipient}",
                    "timeout",
                    timeoutExpiration);

                TimedoutUsers.RemoveAll(t => t.Username == recipient);
            }
            else
            {
                timedoutUser = await ApiBotRequest.PostExecuteAsync(
                    twitchBotApiLink + $"bottimeouts/create",
                    new BotTimeout { Username = recipient, Timeout = timeoutExpiration, BroadcasterId = broadcasterId }
                    );
            }

            TimedoutUsers.Add(new TimeoutUser
            {
                Username             = recipient,
                TimeoutExpirationUtc = timeoutExpiration,
                HasBeenWarned        = false
            });

            return(timeoutExpiration);
        }