Exemplo n.º 1
0
        public void Kill(WinterBot bot, TwitchUser user, string cmd, string value)
        {
            bot.WriteDiagnostic(DiagnosticFacility.Info, "Bot killed by streamer.");
            WinterBotSource.Log.Kill();

            bot.Shutdown();
        }
Exemplo n.º 2
0
        void bot_StreamOnline(WinterBot sender)
        {
            WriteLine("Stream online.");

            m_lastUpdate = DateTime.Now;
            m_viewerSeconds = 0;
        }
Exemplo n.º 3
0
        void bot_ViewerCountChanged(WinterBot sender, int currentViewerCount)
        {
            m_viewerSeconds += (long)m_lastUpdate.Elapsed().TotalSeconds * currentViewerCount;
            m_lastUpdate = DateTime.Now;

            WriteLine("{0} viewers.", currentViewerCount);
        }
Exemplo n.º 4
0
        public void Deny(WinterBot sender, TwitchUser user, string cmd, string value)
        {
            value = value.Trim();

            if (!TwitchUsers.IsValidUserName(value))
            {
                sender.SendResponse(Importance.Med, "{0}: Usage: !deny [user]", user.Name);
                return;
            }

            var target = sender.Users.GetUser(value);

            if (target.IsModerator)
            {
                return;
            }

            if (m_permit.Contains(target))
            {
                m_permit.Remove(target);
            }

            m_denyList.Add(target);
            sender.SendResponse(Importance.High, "{0}: {1} is no longer allowed to post links.", user.Name, target.Name);
        }
Exemplo n.º 5
0
 public static void Init(WinterBot bot)
 {
     bot.AddCommands(new JukeBox(bot));
     bot.AddCommands(new Betting(bot));
     bot.AddCommands(new ViewerCountLogger(bot));
     bot.AddCommands(new Insult(bot));
 }
Exemplo n.º 6
0
        public void Kill(WinterBot bot, TwitchUser user, string cmd, string value)
        {
            bot.WriteDiagnostic(DiagnosticFacility.Info, "Bot killed by streamer.");
            WinterBotSource.Log.Kill();

            bot.Shutdown();
        }
Exemplo n.º 7
0
        void bot_Tick(WinterBot sender, TimeSpan timeSinceLastUpdate)
        {
            if (m_lastMessage.Elapsed().TotalMinutes >= m_msgOptions.Delay &&
                m_totalMessages >= m_msgOptions.MessageDelay &&
                sender.LastMessageSent.Elapsed().TotalSeconds >= 45)
            {
                m_lastMessage   = DateTime.Now;
                m_totalMessages = 0;

                var messages = m_msgOptions.Messages;
                if (messages.Length == 0)
                {
                    return;
                }

                m_curr %= messages.Length;

                string msg = null;
                if (m_random != null)
                {
                    msg = messages[m_random.Next(messages.Length)];
                }
                else
                {
                    msg = messages[m_curr++];
                }

                sender.SendMessage(Importance.Low, msg);
            }
        }
Exemplo n.º 8
0
 void bot_StreamOnline(WinterBot sender)
 {
     if (ShouldEnable)
     {
         Enable();
     }
 }
Exemplo n.º 9
0
        public void AutoMessageMode(WinterBot sender, TwitchUser user, string cmd, string value)
        {
            bool shouldEnable = false;

            if (value.Trim().ParseBool(ref shouldEnable))
            {
                m_msgOptions.Enabled = shouldEnable;
                if (shouldEnable)
                {
                    if (ShouldEnable)
                    {
                        Enable();
                    }
                    else
                    {
                        Disable();
                    }
                }

                sender.SendResponse(Importance.Med, "Auto message now {0}.", shouldEnable ? "enabled" : "disabled");
            }
            else
            {
                sender.SendResponse(Importance.Med, "Auto message is currently {0}.", m_msgOptions.Enabled ? "enabled" : "disabled");
            }
        }
Exemplo n.º 10
0
        public AutoMessage(WinterBot bot)
        {
            m_bot = bot;
            var options = bot.Options;

            m_msgOptions  = options.AutoMessageOptions;
            m_chatOptions = options.ChatOptions;

            if (ShouldEnable)
            {
                Enable();
            }

            if (!string.IsNullOrEmpty(m_chatOptions.SubscribeMessage))
            {
                bot.UserSubscribed += bot_UserSubscribed;
            }

            if (!string.IsNullOrEmpty(m_chatOptions.FollowMessage))
            {
                bot.UserFollowed += bot_UserFollowed;
            }

            bot.StreamOnline  += bot_StreamOnline;
            bot.StreamOffline += bot_StreamOffline;
        }
Exemplo n.º 11
0
        private void ReportTotal(WinterBot sender)
        {
            if (!m_dirty || m_result.Count < m_options.VoteThreshold)
            {
                return;
            }

            var votes = from item in m_result
                        group item by item.Value into g
                        let key                         = g.Key
                                              let count = g.Sum(p => p.Key.IsSubscriber ? m_options.SubVoteCount : 1)
                                                          orderby key
                                                          select new
            {
                Option = key,
                Votes  = count
            };

            var top = (from vote in votes orderby vote.Votes descending select vote).First();

            string msg = "@winter Current vote is for {0} with {1} votes. {2}";

            if (!m_active)
            {
                msg = "@winter Voting closed.  Result: {0} with {1} votes. {2}";
            }

            sender.SendResponse(Importance.Med, msg, top.Option, top.Votes, "(" + string.Join(", ", votes.Select(v => string.Format("Option {0}: {1} votes", v.Option, v.Votes))) + ".)");
            m_lastMessage = DateTime.Now;
            m_dirty       = false;
        }
Exemplo n.º 12
0
        public void RemoveCommand(WinterBot sender, TwitchUser user, string c, string a)
        {
            if (!m_options.UserCommandsEnabled)
            {
                return;
            }

            Args   args = a.ParseArguments(m_bot);
            string cmd  = args.GetOneWord();

            if (cmd == null)
            {
                sender.SendResponse(Importance.Med, m_removeCommandUsage);
                return;
            }

            if (cmd[0] == '!')
            {
                cmd = cmd.Substring(1);
            }

            cmd = cmd.ToLower();
            if (m_commands.ContainsKey(cmd))
            {
                m_commands.Remove(cmd);
            }
            else
            {
                sender.SendResponse(Importance.Med, string.Format("Command {0} not found.", cmd));
            }
        }
Exemplo n.º 13
0
        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);
        }
Exemplo n.º 14
0
 void bot_StreamOffline(WinterBot sender)
 {
     if (m_running)
     {
         Disable();
     }
 }
Exemplo n.º 15
0
        void bot_MessageReceived(WinterBot sender, TwitchUser user, string text)
        {
            if (m_lastStop.Elapsed().TotalSeconds < m_options.VoteClearTimer)
                return;

            if (m_active && m_lastVote.Elapsed().TotalSeconds >= m_options.VoteTimeout)
                Reset(sender);

            int result = -1;
            for (int i = 1; i <= m_options.MaxVoteValue; ++i)
            {
                if (text.Contains(i.ToString()))
                {
                    if (result != -1)
                    {
                        result = -1;
                        break;
                    }

                    result = i;
                }
            }

            if (result != -1)
            {
                m_result[user] = result;
                m_lastVote = DateTime.Now;
                m_dirty = true;
                if (!m_active)
                {
                    m_lastMessage = DateTime.Now;
                    m_active = true;
                }
            }
        }
Exemplo n.º 16
0
        public void JukeBoxCommand(WinterBot sender, TwitchUser user, string cmd, string value)
        {
            if (!m_enabled)
            {
                if (!sender.CanUseCommand(user, AccessLevel.Mod))
                {
                    if (m_lastMessage.Elapsed().TotalSeconds <= 30)
                        return;

                    m_lastMessage = DateTime.Now;
                    sender.SendResponse(Importance.Low, "The jukebox is CLOSED. No additional requests are being accepted.");
                    return;
                }

                value = value.Trim().ToLower();

                if (value == "on")
                {
                    m_enabled = true;
                    m_lastMessage = DateTime.Now;
                    sender.SendResponse(Importance.Med, "Jukebox activated.  Use '!JukeboxMode off' to deactivate.");
                }
                else if (value == "off")
                {
                    sender.SendResponse(Importance.Med, "Jukebox mode is off.");
                }
                else
                {
                    sender.SendResponse(Importance.Low, "Usage: '!jukebox on' and '!jukebox off'.  Mod only.");
                }
            }
            else
            {
                if (sender.CanUseCommand(user, AccessLevel.Mod))
                {
                    if (value == "on")
                    {
                        sender.SendResponse(Importance.Low, "Jukebox mode is already enabled.");
                    }
                    else if (value == "off")
                    {
                        sender.SendResponse(Importance.High, "The jukebox is shutting down for the night. Please hold your song requests for next time.");
                        m_enabled = false;
                    }
                    else
                    {
                        SendMessage(sender);
                    }
                }
                else
                {
                    if (m_lastMessage.Elapsed().TotalSeconds <= 10)
                        return;

                    m_lastMessage = DateTime.Now;
                    SendMessage(sender);
                }
            }
        }
Exemplo n.º 17
0
        public ViewerCountLogger(WinterBot bot)
        {
            m_queue = new StringQueue(bot, "viewers");

            bot.ViewerCountChanged += bot_ViewerCountChanged;
            bot.StreamOnline += bot_StreamOnline;
            bot.StreamOffline += bot_StreamOffline;
        }
Exemplo n.º 18
0
        public BettingSystem(WinterBot bot, WinterOptions options)
        {
            m_options = options;
            m_bot = bot;
            Enabled = true;

            HttpManager.Instance.GetAsync("points.php", LoadPoints);
        }
Exemplo n.º 19
0
        private void bot_UserFollowed(WinterBot sender, TwitchUser user)
        {
            var msg = m_chatOptions.FollowMessage;

            if (!string.IsNullOrWhiteSpace(msg))
            {
                sender.SendMessage(Importance.Low, "{0}: {1}", user.Name, msg);
            }
        }
Exemplo n.º 20
0
        void bot_UserSubscribed(WinterBot sender, TwitchUser user)
        {
            var subMessage = m_chatOptions.SubscribeMessage;

            if (!string.IsNullOrWhiteSpace(subMessage))
            {
                sender.SendMessage(Importance.High, "{0}: {1}", user.Name, subMessage);
            }
        }
Exemplo n.º 21
0
        public ViewerCountLogger(WinterBot bot, WinterOptions options)
            : base(bot)
        {
            m_bot = bot;
            m_options = options;

            m_http = new HttpManager(options);
            bot.ViewerCountChanged += bot_ViewerCountChanged;
        }
Exemplo n.º 22
0
        public AutoPoll(WinterBot bot)
        {
            m_options = bot.Options.AutoPollOptions;
            if (!m_options.Enabled)
                return;

            bot.MessageReceived += bot_MessageReceived;
            bot.Tick += bot_Tick;
        }
Exemplo n.º 23
0
        public void Banliust(WinterBot sender, TwitchUser user, string cmd, string value)
        {
            if (string.IsNullOrWhiteSpace(value))
                return;

            UrlMatch match = new UrlMatch(sender, value);
            m_urlBanlist.Add(match);
            sender.SendResponse(Importance.Med, "Added {0} to the url ban list.", value);
        }
Exemplo n.º 24
0
        public BettingSystem(WinterBot bot, WinterOptions options)
        {
            m_options = options;
            m_bot = bot;
            Enabled = true;

            m_http = new HttpManager(options);
            m_http.GetAsync("points.php", LoadPoints);
        }
Exemplo n.º 25
0
        public static void Init(WinterBot bot)
        {
            WinterOptions options = new WinterOptions(bot.Options);

            bot.AddCommands(new JukeBox(bot, options));
            bot.AddCommands(new BettingSystem(bot, options));
            bot.AddCommands(new ViewerCountLogger(bot, options));
            new ChatSaver(bot, options);
            bot.AddCommands(new BetterCommands(bot, options));
        }
Exemplo n.º 26
0
        public TwitchUsers(WinterBot bot)
        {
            m_users = new Dictionary <string, TwitchUser>();
            Bot     = bot;

            var streamer = GetUser(bot.Channel);

            streamer.IsStreamer  = true;
            streamer.IsModerator = true;
        }
Exemplo n.º 27
0
        public TimeoutController(WinterBot bot)
        {
            m_winterBot = bot;
            LoadOptions(bot.Options);

            m_denyList = new UserSet(bot, "deny");

            m_winterBot.MessageReceived += CheckMessage;
            ThreadPool.QueueUserWorkItem(LoadEmoticons);
        }
Exemplo n.º 28
0
        public void AddCommand(WinterBot sender, TwitchUser user, string c, string v)
        {
            if (!m_options.UserCommandsEnabled)
            {
                return;
            }

            Args args = v.ParseArguments(m_bot);

            AccessLevel level   = args.GetAccessFlag("ul", AccessLevel.Mod);
            string      cmdName = args.GetOneWord();
            string      cmdText = args.GetString();

            if (string.IsNullOrWhiteSpace(cmdName) || string.IsNullOrWhiteSpace(cmdText) || args.Error != null)
            {
                sender.SendResponse(Importance.Med, m_addCommandUsage);
                return;
            }

            if (cmdName[0] != '!')
            {
                sender.SendResponse(Importance.Med, string.Format("User commands must start with a '!'. {0}", m_addCommandUsage));
                return;
            }
            else
            {
                cmdName = cmdName.Substring(1);
            }

            if (cmdText[0] == '.' || cmdText[0] == '/')
            {
                sender.SendResponse(Importance.Med, string.Format("Cannot create a command which starts with a '{0}'.", cmdText[0]));
                return;
            }

            UserCommand userCommand = new UserCommand();

            userCommand.Value          = cmdText;
            userCommand.AccessRequired = level;
            userCommand.Command        = cmdName;

            cmdName = cmdName.ToLower();
            bool exists = m_commands.ContainsKey(cmdName);

            m_commands[cmdName] = userCommand;

            if (exists)
            {
                sender.SendResponse(Importance.Med, string.Format("Updated command: !{0}.", cmdName));
            }
            else
            {
                sender.SendResponse(Importance.Med, string.Format("Successfully added command: !{0}.", cmdName));
            }
        }
Exemplo n.º 29
0
        public AsyncTaskManager(WinterBot bot)
        {
            m_thread = new Thread(ThreadProc);
            m_thread.Start();

            if (bot != null)
            {
                bot.BeginShutdown += m_bot_BeginShutdown;
                bot.EndShutdown   += m_bot_EndShutdown;
            }
        }
Exemplo n.º 30
0
        static void bot_Tick(WinterBot sender, TimeSpan timeSinceLastUpdate)
        {
            s_lastHeartbeat += timeSinceLastUpdate;

            if (s_messages > 0 && s_lastHeartbeat.TotalMinutes >= 5)
            {
                WriteLine("Messsages: {0}", s_messages);
                s_messages = 0;
                s_lastHeartbeat = new TimeSpan();
            }
        }
Exemplo n.º 31
0
        //[BotCommand(AccessLevel.Normal, "insult")]
        public void InsultUser(WinterBot sender, TwitchUser user, string cmd, string value)
        {
            value = value.Trim().ToLower();
            if (TwitchUsers.IsValidUserName(value))
                user = sender.Users.GetUser(value);

            if (m_last.Elapsed().Minutes >= 1)
                sender.SendMessage("{0}, {1}", user.Name, m_insults[m_random.Next(m_insults.Length)]);

            m_last = DateTime.Now;
        }
Exemplo n.º 32
0
        public AutoPoll(WinterBot bot)
        {
            m_options = bot.Options.AutoPollOptions;
            if (!m_options.Enabled)
            {
                return;
            }

            bot.MessageReceived += bot_MessageReceived;
            bot.Tick            += bot_Tick;
        }
Exemplo n.º 33
0
        public ViewerCountLogger(WinterBot bot, WinterOptions options)
            : base(bot)
        {
            if (!bot.Channel.Equals("zlfreebird", StringComparison.CurrentCultureIgnoreCase))
                return;

            m_bot = bot;
            m_options = options;

            bot.ViewerCountChanged += bot_ViewerCountChanged;
        }
Exemplo n.º 34
0
        public BetterCommands(WinterBot bot, WinterOptions options)
            : base(bot)
        {
            if (bot.Options.ChatOptions.UserCommandsEnabled)
                return;

            m_bot = bot;
            m_options = options;
            m_bot.UnknownCommandReceived += UnknownCommandReceived;

            HttpManager.Instance.GetAsync("api.php", "GETCMDS=1", Load);
        }
Exemplo n.º 35
0
        public UserCommands(WinterBot bot)
        {
            m_bot = bot;
            var options = bot.Options;

            m_options       = options.ChatOptions;
            m_stream        = options.Channel;
            m_dataDirectory = bot.Options.DataDirectory;
            m_commands      = new UserCommandTable(bot);

            bot.UnknownCommandReceived += UnknownCommandReceived;
        }
Exemplo n.º 36
0
        public void ListCommands(WinterBot sender, TwitchUser user, string cmd, string value)
        {
            if (!m_options.UserCommandsEnabled)
            {
                return;
            }

            int delay = m_options.UserCommandDelay;
            //if (m_lastMessage.Elapsed().TotalSeconds < delay || m_lastCommand.Elapsed().TotalSeconds < delay)
            //    return;

            Args        args  = value.ParseArguments(m_bot);
            AccessLevel level = args.GetAccessFlag("ul", user.Access);

            string part;

            switch (level)
            {
            case AccessLevel.Streamer:
                part = "streamer";
                break;

            case AccessLevel.Mod:
                part = "moderators";
                break;

            case AccessLevel.Normal:
                part = "anyone";
                break;

            case AccessLevel.Regular:
                part = "regulars";
                break;

            case AccessLevel.Subscriber:
                part = "subscribers";
                break;

            default:
                return;
            }

            string[] cmds = (from c in m_commands.Values where c.AccessRequired <= level orderby c.Command select c.Command).ToArray();

            if (cmds.Length == 0)
            {
                sender.SendResponse(Importance.Low, "No commands available.", part);
            }
            else
            {
                sender.SendResponse(Importance.Low, "Commands {0} can use: {1}", part, string.Join(", ", cmds));
            }
        }
Exemplo n.º 37
0
        public TimeoutController(WinterBot bot)
        {
            m_winterBot = bot;
            LoadOptions(bot);

            m_denyList = new UserSet(bot, "deny");

            m_winterBot.MessageReceived += CheckMessage;
            m_winterBot.ActionReceived  += CheckAction;
            m_winterBot.StreamOffline   += StreamStateChange;
            m_winterBot.StreamOnline    += StreamStateChange;
        }
Exemplo n.º 38
0
        public void Banliust(WinterBot sender, TwitchUser user, string cmd, string value)
        {
            if (string.IsNullOrWhiteSpace(value))
            {
                return;
            }

            UrlMatch match = new UrlMatch(sender, value);

            m_urlBanlist.Add(match);
            sender.SendResponse(Importance.Med, "Added {0} to the url ban list.", value);
        }
Exemplo n.º 39
0
        public TimeoutController(WinterBot bot)
        {
            m_winterBot = bot;
            LoadOptions(bot);

            m_denyList = new UserSet(bot, "deny");

            m_winterBot.MessageReceived += CheckMessage;
            m_winterBot.ActionReceived += CheckAction;
            m_winterBot.StreamOffline += StreamStateChange;
            m_winterBot.StreamOnline += StreamStateChange;
        }
Exemplo n.º 40
0
        public void AddCommand(WinterBot sender, TwitchUser user, string c, string v)
        {
            Args args = v.ParseArguments(m_bot);

            AccessLevel level = args.GetAccessFlag("ul", AccessLevel.Mod);
            string cmdName = args.GetOneWord();
            string cmdText = args.GetString();

            if (string.IsNullOrWhiteSpace(cmdName) || string.IsNullOrWhiteSpace(cmdText) || args.Error != null)
            {
                sender.SendResponse(Importance.Med, m_addCommandUsage);
                return;
            }

            if (cmdName[0] != '!')
            {
                sender.SendResponse(Importance.Med, string.Format("User commands must start with a '!'. {0}", m_addCommandUsage));
                return;
            }
            else
            {
                cmdName = cmdName.Substring(1);
            }

            if (cmdText[0] == '.' || cmdText[0] == '/')
            {
                sender.SendResponse(Importance.Med, string.Format("Cannot create a command which starts with a '{0}'.", cmdText[0]));
                return;
            }

            cmdName = cmdName.ToLower();
            Command userCommand = new Command(level, cmdText);

            bool exists;
            lock (m_sync)
            {
                exists = m_commands.ContainsKey(cmdName);
                m_commands[cmdName] = userCommand;
                m_dirty = true;
            }

            if (exists)
            {
                sender.SendResponse(Importance.Med, string.Format("Updated command: !{0}.", cmdName));
                WinterBotSource.Log.AddCommand(user.Name, cmdName, cmdText);
            }
            else
            {
                sender.SendResponse(Importance.Med, string.Format("Successfully added command: !{0}.", cmdName));
                WinterBotSource.Log.UpdateCommand(user.Name, cmdName, cmdText);
            }
        }
Exemplo n.º 41
0
        static void bot_Tick(WinterBot sender, TimeSpan timeSinceLastUpdate)
        {
            if (s_messages > 0 && s_lastHeartbeat.Elapsed().TotalMinutes >= 5)
            {
                if (sender.IsStreamLive)
                    WriteLine("Messsages: {0,3} Viewers: {1,3}", s_messages, sender.CurrentViewers);
                else
                    WriteLine("Messsages: {0}", s_messages);

                s_messages = 0;
                s_lastHeartbeat = DateTime.Now;
            }
        }
Exemplo n.º 42
0
        void bot_MessageReceived(WinterBot sender, TwitchUser user, string text)
        {
            if (!user.Name.Equals("frostysc", StringComparison.CurrentCultureIgnoreCase))
                return;

            if (m_random.Next(200) != 7)
                return;

            if (m_last.Elapsed().Minutes >= 5)
                sender.SendMessage("{0}, {1}", user.Name, m_insults[m_random.Next(m_insults.Length)]);

            m_last = DateTime.Now;
        }
Exemplo n.º 43
0
        private void SetRegular(WinterBot sender, string cmd, string value, bool regular)
        {
            value = value.Trim();
            if (!TwitchUsers.IsValidUserName(value))
            {
                sender.WriteDiagnostic(DiagnosticFacility.UserError, "{0}: Invalid username '{1}.", cmd, value);
                return;
            }

            TwitchUser target = sender.Users.GetUser(value);
            target.IsRegular = regular;
            sender.SendResponse(Importance.Med, "{0} {1} the regular list.", target.Name, regular ? "added to " : "removed from");
        }
Exemplo n.º 44
0
        private void StreamStateChange(WinterBot sender)
        {
            // Clean up some memory, no need to keep old timeouts around.
            if (m_timeouts.Count == 0)
            {
                return;
            }

            var items = from item in m_timeouts
                        where GetEffectiveCount(item.Value) > 0
                        select item;

            m_timeouts = items.ToDictionary(t => t.Key, t => t.Value);
        }
Exemplo n.º 45
0
        private void SetRegular(WinterBot sender, string cmd, string value, bool regular)
        {
            value = value.Trim();
            if (!TwitchUsers.IsValidUserName(value))
            {
                sender.WriteDiagnostic(DiagnosticFacility.UserError, "{0}: Invalid username '{1}.", cmd, value);
                return;
            }

            TwitchUser target = sender.Users.GetUser(value);

            target.IsRegular = regular;
            sender.SendResponse(Importance.Med, "{0} {1} the regular list.", target.Name, regular ? "added to " : "removed from");
        }
Exemplo n.º 46
0
 public WordMatch(WinterBot bot, string str)
 {
     m_str = str.ToLower();
     if (str.IsRegex())
     {
         try
         {
             m_reg = new Regex(str, RegexOptions.IgnoreCase);
         }
         catch (ArgumentException)
         {
             bot.WriteDiagnostic(DiagnosticFacility.UserError, "Invalid regex in options: " + str);
         }
     }
 }
Exemplo n.º 47
0
        private void Reset(WinterBot sender)
        {
            if (m_active && m_dirty)
            {
                m_active = false;
                ReportTotal(sender);
            }

            m_result.Clear();

            m_lastVote    = DateTime.Now;
            m_lastMessage = DateTime.Now;
            m_active      = false;
            m_dirty       = false;
        }
Exemplo n.º 48
0
        void CheckAction(WinterBot bot, TwitchUser user, string text)
        {
            if (user.IsModerator)
            {
                return;
            }

            if (m_chatOptions.CheckFakeSubscribe && IsFakeSubscribe(text))
            {
                ClearChat(bot, user, m_chatOptions.FakeSubscriberMessage);
            }
            else
            {
                CheckMessage(bot, user, text);
            }
        }
Exemplo n.º 49
0
        public void CheckMessage(WinterBot bot, TwitchUser user, string text)
        {
            if (user.IsModerator)
                return;

            string clearReason = null;

            List<string> urls;
            if (HasUrls(text, out urls))
            {
                // Check bans.
                if (MatchesAny(urls, m_urlBanlist))
                {
                    m_winterBot.Ban(user);
                    if (!string.IsNullOrEmpty(m_urlOptions.BanMessage))
                        bot.TimeoutMessage("{0}: {1}", user.Name, m_urlOptions.BanMessage);

                    m_winterBot.WriteDiagnostic(DiagnosticFacility.Ban, "Banned {0} for {1}.", user.Name, string.Join(", ", urls));
                }
                else if ((m_urlOptions.ShouldEnforce(user) || m_denyList.Contains(user)) && (!MatchesAll(urls, m_urlWhitelist) || MatchesAny(urls, m_urlBlacklist)))
                {
                    if (m_permit.Contains(user))
                        m_permit.Remove(user);
                    else
                        clearReason = m_urlOptions.Message;
                }
            }
            else if (m_symbolOptions.ShouldEnforce(user) && HasSpecialCharacter(text))
            {
                clearReason = m_symbolOptions.Message;
            }
            else if (m_capsOptions.ShouldEnforce(user) && TooManyCaps(user, text))
            {
                clearReason = m_capsOptions.Message;
            }
            else if (m_emoteOptions.ShouldEnforce(user) && TooManyEmotes(user, text))
            {
                clearReason = m_emoteOptions.Message;
            }
            else if (m_lengthOptions.ShouldEnforce(user) && MessageTooLong(user, text))
            {
                clearReason = m_lengthOptions.Message;
            }

            if (clearReason != null)
                ClearChat(bot, user, clearReason);
        }
Exemplo n.º 50
0
        void bot_Tick(WinterBot sender, TimeSpan timeSinceLastUpdate)
        {
            if (m_messages > 0 && m_lastHeartbeat.Elapsed().TotalMinutes >= 5)
            {
                if (sender.IsStreamLive)
                {
                    WriteLine("Messsages: {0,3} Viewers: {1,3}", m_messages, sender.CurrentViewers);
                }
                else
                {
                    WriteLine("Messsages: {0}", m_messages);
                }

                m_messages      = 0;
                m_lastHeartbeat = DateTime.Now;
            }
        }
Exemplo n.º 51
0
        void bot_Tick(WinterBot sender, TimeSpan timeSinceLastUpdate)
        {
            if (!m_active)
            {
                return;
            }

            if (m_lastMessage.Elapsed().TotalSeconds > m_options.ReportTime)
            {
                ReportTotal(sender);
            }

            if (m_lastVote.Elapsed().TotalSeconds >= m_options.VoteTimeout)
            {
                Reset(sender);
            }
        }
Exemplo n.º 52
0
        public void Permit(WinterBot sender, TwitchUser user, string cmd, string value)
        {
            Debug.Assert(m_winterBot == sender);

            value = value.Trim();
            if (!TwitchUsers.IsValidUserName(value))
            {
                m_winterBot.WriteDiagnostic(DiagnosticFacility.UserError, "{0}: Invalid username '{1}.", cmd, value);
                return;
            }

            var target = sender.Users.GetUser(value);

            if (target.IsModerator)
            {
                return;
            }

            bool removed = m_denyList.TryRemove(target);

            if (removed)
            {
                if (m_urlOptions.ShouldEnforce(target))
                {
                    m_winterBot.SendResponse(Importance.Med, "{0}: {1} was removed from the deny list.", user.Name, target.Name);
                }
                else
                {
                    m_winterBot.SendResponse(Importance.Med, "{0}: {1} can now post links again.", user.Name, target.Name);
                }
            }
            else
            {
                if (m_urlOptions.ShouldEnforce(target))
                {
                    m_permit.Add(target);
                    m_winterBot.SendResponse(Importance.Med, "{0} -> {1} has been granted permission to post a single link.", user.Name, target.Name);
                }
                else
                {
                    m_winterBot.SendResponse(Importance.Low, "{0}: {1} can posts links.", user.Name, target.Name);
                }
            }
        }
Exemplo n.º 53
0
        public AutoMessage(WinterBot bot)
        {
            m_bot = bot;
            var options = bot.Options;
            m_msgOptions = options.AutoMessageOptions;
            m_chatOptions = options.ChatOptions;

            if (ShouldEnable)
                Enable();

            if (!string.IsNullOrEmpty(m_chatOptions.SubscribeMessage))
                bot.UserSubscribed += bot_UserSubscribed;

            if (!string.IsNullOrEmpty(m_chatOptions.FollowMessage))
                bot.UserFollowed += bot_UserFollowed;

            bot.StreamOnline += bot_StreamOnline;
            bot.StreamOffline += bot_StreamOffline;
        }
Exemplo n.º 54
0
        void LoadOptions(WinterBot bot)
        {
            Options options = bot.Options;

            m_options        = options;
            m_chatOptions    = options.ChatOptions;
            m_urlOptions     = options.UrlOptions;
            m_capsOptions    = options.CapsOptions;
            m_lengthOptions  = options.LengthOptions;
            m_symbolOptions  = options.SymbolOptions;
            m_emoteOptions   = options.EmoteOptions;
            m_banWordOptions = options.BanWordOptions;

            // Load url lists
            m_urlWhitelist = new List <RegexMatch>(m_urlOptions.Whitelist.Select(s => new UrlMatch(bot, s)));
            m_urlBlacklist = new List <RegexMatch>(m_urlOptions.Blacklist.Select(s => new UrlMatch(bot, s)));
            m_urlBanlist   = new List <RegexMatch>(m_urlOptions.Banlist.Select(s => new UrlMatch(bot, s)));
            m_wordBanlist  = new List <RegexMatch>(m_banWordOptions.BanList.Select(s => new WordMatch(bot, s)));
        }
Exemplo n.º 55
0
        public void Deny(WinterBot sender, TwitchUser user, string cmd, string value)
        {
            value = value.Trim();

            if (!TwitchUsers.IsValidUserName(value))
            {
                sender.SendResponse(Importance.Med, "{0}: Usage: !deny [user]", user.Name);
                return;
            }

            var target = sender.Users.GetUser(value);
            if (target.IsModerator)
                return;

            if (m_permit.Contains(target))
                m_permit.Remove(target);

            m_denyList.Add(target);
            sender.SendResponse(Importance.High, "{0}: {1} is no longer allowed to post links.", user.Name, target.Name);
        }
Exemplo n.º 56
0
        public UrlMatch(WinterBot bot, string str)
        {
            if (str.StartsWith("http://", StringComparison.CurrentCultureIgnoreCase))
            {
                str = str.Substring(7);
            }

            m_str = str.ToLower();
            if (str.IsRegex())
            {
                try
                {
                    m_reg = new Regex(str, RegexOptions.IgnoreCase);
                }
                catch (ArgumentException)
                {
                    bot.WriteDiagnostic(DiagnosticFacility.UserError, "Invalid regex in options: " + str);
                }
            }
        }
Exemplo n.º 57
0
        private void SetRegular(WinterBot sender, string cmd, string value, bool regular)
        {
            value = value.Trim().ToLower();
            if (!TwitchUsers.IsValidUserName(value))
            {
                sender.WriteDiagnostic(DiagnosticFacility.UserError, "{0}: Invalid username '{1}.", cmd, value);
                return;
            }

            TwitchUser target = sender.Users.GetUser(value);
            if (regular)
            {
                sender.AddRegular(target);
                sender.SendResponse("{0} added to regular list.", value);
            }
            else
            {
                sender.RemoveRegular(target);
                sender.SendResponse("{0} removed from regular list.", value);
            }
        }
Exemplo n.º 58
0
        public void AutoMessageMode(WinterBot sender, TwitchUser user, string cmd, string value)
        {
            bool shouldEnable = false;
            if (value.Trim().ParseBool(ref shouldEnable))
            {
                m_msgOptions.Enabled = shouldEnable;
                if (shouldEnable)
                {
                    if (ShouldEnable)
                        Enable();
                    else
                        Disable();
                }

                sender.SendResponse(Importance.Med, "Auto message now {0}.", shouldEnable ? "enabled" : "disabled");
            }
            else
            {
                sender.SendResponse(Importance.Med, "Auto message is currently {0}.", m_msgOptions.Enabled ? "enabled" : "disabled");
            }
        }
Exemplo n.º 59
0
        public AutoMessage(WinterBot bot)
        {
            var options = bot.Options;
            m_msgOptions = options.AutoMessageOptions;
            m_chatOptions = options.ChatOptions;

            // TODO: respond to property changed on these
            if (m_msgOptions.Enabled)
            {
                if (m_msgOptions.MessageDelay > 0)
                    bot.MessageReceived += bot_MessageReceived;

                bot.Tick += bot_Tick;
            }

            if (!string.IsNullOrEmpty(m_chatOptions.SubscribeMessage))
                bot.UserSubscribed += bot_UserSubscribed;

            if (!string.IsNullOrEmpty(m_chatOptions.FollowMessage))
                bot.UserFollowed += bot_UserFollowed;
        }
Exemplo n.º 60
0
        void bot_Tick(WinterBot sender, TimeSpan timeSinceLastUpdate)
        {
            if (m_lastMessage.Elapsed().TotalMinutes >= m_msgOptions.Delay &&
                m_totalMessages >= m_msgOptions.MessageDelay &&
                sender.LastMessageSent.Elapsed().TotalSeconds >= 45)
            {
                m_lastMessage = DateTime.Now;
                m_totalMessages = 0;

                var messages = m_msgOptions.Messages;
                if (messages.Length == 0)
                    return;

                m_curr %= messages.Length;

                string msg = null;
                if (m_random != null)
                    msg = messages[m_random.Next(messages.Length)];
                else
                    msg = messages[m_curr++];

                sender.SendMessage(msg);
            }
        }