當前位置: 首頁>>代碼示例>>C#>>正文


C# WinterBot.Timeout方法代碼示例

本文整理匯總了C#中Winter.WinterBot.Timeout方法的典型用法代碼示例。如果您正苦於以下問題:C# WinterBot.Timeout方法的具體用法?C# WinterBot.Timeout怎麽用?C# WinterBot.Timeout使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Winter.WinterBot的用法示例。


在下文中一共展示了WinterBot.Timeout方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ClearChat

        private void ClearChat(WinterBot sender, TwitchUser user, string clearReason, int minTimeout=1)
        {
            bool shouldMessage = !string.IsNullOrEmpty(clearReason);
            var now = DateTime.Now;
            TimeoutCount timeout;
            if (!m_timeouts.TryGetValue(user, out timeout))
            {
                timeout = m_timeouts[user] = new TimeoutCount(now);
            }
            else
            {
                shouldMessage &= (DateTime.Now > timeout.LastTimeout) && (DateTime.Now - timeout.LastTimeout).TotalMinutes > 60;
                timeout.Count = GetEffectiveCount(timeout) + 1;
            }

            timeout.LastTimeout = now;
            if (!m_chatOptions.ShouldTimeout(user))
                timeout.Count = 1;

            if (minTimeout < 1)
                minTimeout = 1;

            int duration = 0;
            switch (timeout.Count)
            {
                case 1:
                case 2:
                    duration = 1;
                    break;

                case 3:
                    shouldMessage = !string.IsNullOrEmpty(clearReason);
                    duration = 5 * 60;
                    break;

                case 4:
                    shouldMessage = !string.IsNullOrEmpty(clearReason);
                    duration = 10 * 60;
                    break;

                case 5:
                    shouldMessage = !string.IsNullOrEmpty(clearReason);
                    duration = 8 * 60 * 60;
                    break;
            }

            if (duration < minTimeout)
                duration = minTimeout;

            if (shouldMessage)
            {
                if (duration == 1)
                    sender.Send(MessageType.Timeout, Importance.Med, "{0}: {1} (This is not a timeout.)", user.Name, clearReason);
                else if (duration < 60)
                    sender.Send(MessageType.Timeout, Importance.High, "{0}: {1}", user.Name, clearReason);
                else if (duration < 3600)
                    sender.Send(MessageType.Timeout, Importance.High, "{0}: {1} ({2} minute timeout.)", user.Name, clearReason, duration / 60);
                else
                    sender.Send(MessageType.Timeout, Importance.High, "{0}: {1} ({2} hour timeout.)", user.Name, clearReason, duration / 3600);
            }

            sender.Timeout(user, duration);
            timeout.LastTimeout = now.AddSeconds(duration);
        }
開發者ID:NitroXenon,項目名稱:WinterBot,代碼行數:64,代碼來源:TimeoutController.cs

示例2: CheckAndTimeoutSpam

        private bool CheckAndTimeoutSpam(WinterBot bot, TwitchUser user, string text)
        {
            if (user.IsSubscriber)
                return false;

            if (String.IsNullOrWhiteSpace(m_clearMsg))
                return false;

            if (text.ToLower().Contains(m_clearMsg))
            {
                if (m_spamTimeout == null)
                    bot.Ban(user);
                else
                    bot.Timeout(user, (int)m_spamTimeout);

                return true;
            }

            return false;
        }
開發者ID:NitroXenon,項目名稱:WinterBot,代碼行數:20,代碼來源:TimeoutController.cs

示例3: ClearChat

        private void ClearChat(WinterBot sender, TwitchUser user, string clearReason)
        {
            bool shouldMessage = !string.IsNullOrEmpty(clearReason);
            var now = DateTime.Now;
            TimeoutCount timeout;
            if (!m_timeouts.TryGetValue(user, out timeout))
            {
                timeout = m_timeouts[user] = new TimeoutCount(now);
            }
            else
            {
                shouldMessage &= (DateTime.Now > timeout.LastTimeout) && (DateTime.Now - timeout.LastTimeout).TotalMinutes > 60;

                int curr = timeout.Count;
                int diff = (int)(now - timeout.LastTimeout).TotalMinutes / 15;

                if (diff > 0)
                    curr -= diff;

                if (curr < 0)
                    curr = 0;

                timeout.Count = curr + 1;
            }

            timeout.LastTimeout = now;
            if (!m_chatOptions.ShouldTimeout(user))
                timeout.Count = 1;

            int duration = 0;
            switch (timeout.Count)
            {
                case 1:
                case 2:
                    if (shouldMessage)
                        sender.Send(MessageType.Timeout, "{0}: {1} (This is not a timeout.)", user.Name, clearReason);

                    sender.ClearChat(user);
                    break;

                case 3:
                    duration = 5;
                    sender.Send(MessageType.Timeout, "{0}: {1} ({2} minute timeout.)", user.Name, clearReason, duration);
                    sender.Timeout(user, duration * 60);
                    timeout.LastTimeout = now.AddMinutes(duration);
                    break;

                case 4:
                    duration = 10;
                    sender.Send(MessageType.Timeout, "{0}: {1} ({2} minute timeout.)", user.Name, clearReason, duration);
                    sender.Timeout(user, duration * 60);
                    timeout.LastTimeout = now.AddMinutes(duration);
                    break;

                default:
                    Debug.Assert(timeout.Count > 0);
                    sender.Send(MessageType.Timeout, "{0}: {1} (8 hour timeout.)", user.Name, clearReason);
                    sender.Timeout(user, 8 * 60 * 60);
                    timeout.LastTimeout = now.AddHours(8);
                    break;
            }
        }
開發者ID:BigAbboTT,項目名稱:WinterBot,代碼行數:62,代碼來源:TimeoutController.cs

示例4: Purge

        public void Purge(WinterBot sender, TwitchUser user, string c, string value)
        {
            var cmd = value.ParseArguments(sender);
            int time = cmd.GetIntFlag("time", 0);

            value = cmd.GetString();
            if (string.IsNullOrWhiteSpace(value))
                return;

            value = value.ToLower();
            var users = from msg in m_lastMsgs
                        where msg != null && msg.Item2 != null
                        where msg.Item2.Contains(value)
                        select msg.Item1;

            foreach (var usr in users.Distinct())
                sender.Timeout(usr, time > 0 ? time : 1);
        }
開發者ID:NitroXenon,項目名稱:WinterBot,代碼行數:18,代碼來源:TimeoutController.cs

示例5: Purge

        public void Purge(WinterBot sender, TwitchUser user, string cmd, string value)
        {
            value = value.Trim().ToLower();
            if (string.IsNullOrWhiteSpace(value))
                return;

            var users = from msg in m_lastMsgs
                        where msg != null && msg.Item2 != null
                        where msg.Item2.Contains(value)
                        select msg.Item1;

            foreach (var usr in users.Distinct())
                sender.Timeout(usr, 1);
        }
開發者ID:pandaforks,項目名稱:WinterBot,代碼行數:14,代碼來源:TimeoutController.cs


注:本文中的Winter.WinterBot.Timeout方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。