コード例 #1
0
ファイル: BotControl.cs プロジェクト: NitroXenon/WinterBot
        public void Kill(WinterBot bot, TwitchUser user, string cmd, string value)
        {
            bot.WriteDiagnostic(DiagnosticFacility.Info, "Bot killed by streamer.");
            WinterBotSource.Log.Kill();

            bot.Shutdown();
        }
コード例 #2
0
        void bot_StreamOnline(WinterBot sender)
        {
            WriteLine("Stream online.");

            m_lastUpdate = DateTime.Now;
            m_viewerSeconds = 0;
        }
コード例 #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);
        }
コード例 #4
0
ファイル: TimeoutController.cs プロジェクト: hasaki/WinterBot
        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);
        }
コード例 #5
0
ファイル: Plugin.cs プロジェクト: BigAbboTT/WinterBot
 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));
 }
コード例 #6
0
ファイル: BotControl.cs プロジェクト: gamenew09/WinterBot
        public void Kill(WinterBot bot, TwitchUser user, string cmd, string value)
        {
            bot.WriteDiagnostic(DiagnosticFacility.Info, "Bot killed by streamer.");
            WinterBotSource.Log.Kill();

            bot.Shutdown();
        }
コード例 #7
0
ファイル: Automessage.cs プロジェクト: hasaki/WinterBot
        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);
            }
        }
コード例 #8
0
ファイル: Automessage.cs プロジェクト: hasaki/WinterBot
 void bot_StreamOnline(WinterBot sender)
 {
     if (ShouldEnable)
     {
         Enable();
     }
 }
コード例 #9
0
ファイル: Automessage.cs プロジェクト: hasaki/WinterBot
        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");
            }
        }
コード例 #10
0
ファイル: Automessage.cs プロジェクト: hasaki/WinterBot
        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;
        }
コード例 #11
0
ファイル: AutoPoll.cs プロジェクト: hasaki/WinterBot
        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;
        }
コード例 #12
0
ファイル: UserCommands.cs プロジェクト: hasaki/WinterBot
        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));
            }
        }
コード例 #13
0
ファイル: TimeoutController.cs プロジェクト: hasaki/WinterBot
        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);
        }
コード例 #14
0
ファイル: Automessage.cs プロジェクト: hasaki/WinterBot
 void bot_StreamOffline(WinterBot sender)
 {
     if (m_running)
     {
         Disable();
     }
 }
コード例 #15
0
ファイル: AutoPoll.cs プロジェクト: holyjaw/WinterBot
        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;
                }
            }
        }
コード例 #16
0
ファイル: JukeBox.cs プロジェクト: NitroXenon/WinterBot
        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);
                }
            }
        }
コード例 #17
0
        public ViewerCountLogger(WinterBot bot)
        {
            m_queue = new StringQueue(bot, "viewers");

            bot.ViewerCountChanged += bot_ViewerCountChanged;
            bot.StreamOnline += bot_StreamOnline;
            bot.StreamOffline += bot_StreamOffline;
        }
コード例 #18
0
ファイル: Betting.cs プロジェクト: KnightRobby/WinterBot
        public BettingSystem(WinterBot bot, WinterOptions options)
        {
            m_options = options;
            m_bot = bot;
            Enabled = true;

            HttpManager.Instance.GetAsync("points.php", LoadPoints);
        }
コード例 #19
0
ファイル: Automessage.cs プロジェクト: hasaki/WinterBot
        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);
            }
        }
コード例 #20
0
ファイル: Automessage.cs プロジェクト: hasaki/WinterBot
        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);
            }
        }
コード例 #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;
        }
コード例 #22
0
ファイル: AutoPoll.cs プロジェクト: holyjaw/WinterBot
        public AutoPoll(WinterBot bot)
        {
            m_options = bot.Options.AutoPollOptions;
            if (!m_options.Enabled)
                return;

            bot.MessageReceived += bot_MessageReceived;
            bot.Tick += bot_Tick;
        }
コード例 #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);
        }
コード例 #24
0
ファイル: Betting.cs プロジェクト: NitroXenon/WinterBot
        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);
        }
コード例 #25
0
ファイル: Plugin.cs プロジェクト: NitroXenon/WinterBot
        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));
        }
コード例 #26
0
ファイル: TwitchData.cs プロジェクト: hasaki/WinterBot
        public TwitchUsers(WinterBot bot)
        {
            m_users = new Dictionary <string, TwitchUser>();
            Bot     = bot;

            var streamer = GetUser(bot.Channel);

            streamer.IsStreamer  = true;
            streamer.IsModerator = true;
        }
コード例 #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);
        }
コード例 #28
0
ファイル: UserCommands.cs プロジェクト: hasaki/WinterBot
        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));
            }
        }
コード例 #29
0
ファイル: AsyncTaskManager.cs プロジェクト: hasaki/WinterBot
        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;
            }
        }
コード例 #30
0
ファイル: Program.cs プロジェクト: BigAbboTT/WinterBot
        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();
            }
        }
コード例 #31
0
ファイル: Insult.cs プロジェクト: BigAbboTT/WinterBot
        //[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;
        }
コード例 #32
0
ファイル: AutoPoll.cs プロジェクト: hasaki/WinterBot
        public AutoPoll(WinterBot bot)
        {
            m_options = bot.Options.AutoPollOptions;
            if (!m_options.Enabled)
            {
                return;
            }

            bot.MessageReceived += bot_MessageReceived;
            bot.Tick            += bot_Tick;
        }
コード例 #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;
        }
コード例 #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);
        }
コード例 #35
0
ファイル: UserCommands.cs プロジェクト: hasaki/WinterBot
        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;
        }
コード例 #36
0
ファイル: UserCommands.cs プロジェクト: hasaki/WinterBot
        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));
            }
        }
コード例 #37
0
ファイル: TimeoutController.cs プロジェクト: hasaki/WinterBot
        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;
        }
コード例 #38
0
ファイル: TimeoutController.cs プロジェクト: hasaki/WinterBot
        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);
        }
コード例 #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;
        }
コード例 #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);
            }
        }
コード例 #41
0
ファイル: Program.cs プロジェクト: NitroXenon/WinterBot
        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;
            }
        }
コード例 #42
0
ファイル: Insult.cs プロジェクト: BigAbboTT/WinterBot
        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;
        }
コード例 #43
0
ファイル: Regulars.cs プロジェクト: NitroXenon/WinterBot
        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");
        }
コード例 #44
0
ファイル: TimeoutController.cs プロジェクト: hasaki/WinterBot
        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);
        }
コード例 #45
0
ファイル: Regulars.cs プロジェクト: hasaki/WinterBot
        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");
        }
コード例 #46
0
ファイル: TimeoutController.cs プロジェクト: hasaki/WinterBot
 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);
         }
     }
 }
コード例 #47
0
ファイル: AutoPoll.cs プロジェクト: hasaki/WinterBot
        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;
        }
コード例 #48
0
ファイル: TimeoutController.cs プロジェクト: hasaki/WinterBot
        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);
            }
        }
コード例 #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);
        }
コード例 #50
0
ファイル: Program.cs プロジェクト: hasaki/WinterBot
        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;
            }
        }
コード例 #51
0
ファイル: AutoPoll.cs プロジェクト: hasaki/WinterBot
        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);
            }
        }
コード例 #52
0
ファイル: TimeoutController.cs プロジェクト: hasaki/WinterBot
        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);
                }
            }
        }
コード例 #53
0
ファイル: Automessage.cs プロジェクト: NitroXenon/WinterBot
        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;
        }
コード例 #54
0
ファイル: TimeoutController.cs プロジェクト: hasaki/WinterBot
        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)));
        }
コード例 #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);
        }
コード例 #56
0
ファイル: TimeoutController.cs プロジェクト: hasaki/WinterBot
        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);
                }
            }
        }
コード例 #57
0
ファイル: Regulars.cs プロジェクト: BigAbboTT/WinterBot
        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);
            }
        }
コード例 #58
0
ファイル: Automessage.cs プロジェクト: NitroXenon/WinterBot
        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");
            }
        }
コード例 #59
0
ファイル: Automessage.cs プロジェクト: BigAbboTT/WinterBot
        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;
        }
コード例 #60
0
ファイル: Automessage.cs プロジェクト: BigAbboTT/WinterBot
        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);
            }
        }