Example #1
0
        /// <summary>
        /// Called when somebody joins the room. Should call base.
        /// </summary>
        public virtual void SendHistory(Connection connection)
        {
            if (IsPrivate)
            {
                if (connection.Session == null)
                {
                    ClearScrollbackFor(connection);
                    connection.SendSysMessage("You must login to view this room.");
                    return;
                }

                if (IsBanned(connection.Session.Account.Name))
                {
                    ClearScrollbackFor(connection);
                    connection.SendSysMessage("You are banned from this room.");
                    return;
                }
            }

            var lines       = GetHistoryLines(connection);
            var chatHistory = new ChatHistory {
                ShortName = RoomInfo.ShortName, Requested = false, Lines = lines
            };

            connection.Send(chatHistory);
        }
        public override void Handle(Connection connection)
        {
            var account      = connection.Session.Account;
            var notification = Program.NotificationManager.Get(DeviceToken);

            if (notification == null)
            {
                connection.SendSysMessage("This device is not registered for push notifications.");
                return;
            }

            if (notification.UserId != account.Id)
            {
                connection.SendSysMessage("This device is not registered with your account.");
                return;
            }

            notification.Remove();

            Program.NotificationsDirty = true;

            var notificationSubscription = new NotificationSubscription();

            notificationSubscription.DeviceToken  = DeviceToken;
            notificationSubscription.RegexPattern = RegexPattern;
            notificationSubscription.Registered   = false;

            connection.Send(notificationSubscription);
        }
Example #3
0
        public override void Handle(Connection connection)
        {
            if (Program.DelayManager.AddAndCheck(connection, DelayManager.Database))
            {
                return;
            }

            if (connection.Session == null)
            {
                connection.SendSysMessage("You need to be logged in to do that.");
                return;
            }

            var notification = Program.NotificationManager.Get(DeviceToken);

            if (notification == null)
            {
                connection.SendSysMessage("This device is not registered for push notifications.");
                return;
            }

            notification.Remove();

            Program.NotificationsDirty = true;

            var notificationSubscription = new NotificationSubscription();

            notificationSubscription.DeviceToken  = DeviceToken;
            notificationSubscription.RegexPattern = RegexPattern;
            notificationSubscription.Registered   = false;

            connection.Send(notificationSubscription);
        }
Example #4
0
        public override void Handle(Connection connection)
        {
            if (Program.DelayManager.AddAndCheck(connection, DelayManager.Database))
            {
                return;
            }

            if (connection.Session == null)
            {
                connection.SendSysMessage("You need to be logged in to do that.");
                return;
            }

            if (string.IsNullOrWhiteSpace(RegexPattern) || string.IsNullOrWhiteSpace(DeviceToken))
            {
                connection.SendSysMessage("Missing device token or regex pattern.");
                return;
            }

            if (!IsRegexPatternValid(RegexPattern))
            {
                connection.SendSysMessage("Invalid regex pattern.");
                return;
            }

            var account = connection.Session.Account;

            if (Program.NotificationManager.FindWithId(account.Id).Count() >= 5)
            {
                connection.SendSysMessage("You may only have 5 devices registered for push notifications.");
                return;
            }

            if (Program.NotificationManager.Exists(DeviceToken, out var notification))
            {
                notification.Regex = Notification.CreateRegex(RegexPattern);
                notification.Save();
            }
            else
            {
                notification = new Notification
                {
                    UserId      = account.Id,
                    Regex       = Notification.CreateRegex(RegexPattern),
                    DeviceToken = DeviceToken
                };

                notification.Insert();
            }

            Program.NotificationsDirty = true;

            var notificationSubscription = new NotificationSubscription();

            notificationSubscription.DeviceToken  = DeviceToken;
            notificationSubscription.RegexPattern = RegexPattern;
            notificationSubscription.Registered   = true;

            connection.Send(notificationSubscription);
        }
        public override void Handle(Connection connection)
        {
            var account = connection.Session.Account;
            var notification = Program.NotificationManager.Get(DeviceToken);

            if (notification == null)
            {
                connection.SendSysMessage("This device is not registered for push notifications.");
                return;
            }

            if (notification.UserId != account.Id)
            {
                connection.SendSysMessage("This device is not registered with your account.");
                return;
            }

            notification.Remove();

            Program.NotificationsDirty = true;

            var notificationSubscription = new NotificationSubscription();
            notificationSubscription.DeviceToken = DeviceToken;
            notificationSubscription.RegexPattern = RegexPattern;
            notificationSubscription.Registered = false;

            connection.Send(notificationSubscription);
        }
Example #6
0
        public override void Handle(Connection connection)
        {
            if (connection.Session == null)
            {
                connection.SendSysMessage("Guests can not speak.");
                return;
            }

            Content = (Content ?? "").Trim();

            if (Content.Length == 0)
            {
                return;
            }

            if (Program.DelayManager.AddAndCheck(connection, CalculateMessageCost(Content)))
            {
                return;
            }

            // normalize line endings
            Content = Content.Replace("\r\n", "\n").Replace('\r', '\n');

            // can't send emoticons from web
            Content = Content.Replace('ː', ':');

            // steam discards long messages
            if (Content.Length > 2000)
            {
                Content = Content.Substring(0, 2000) + "...";
            }

            // imgur is scum
            Content = Util.FixImgurLinks(Content);

            var room     = Program.RoomManager.Get(Target);
            var roomName = room != null ? Target : Program.Settings.DefaultRoom;

            var isEscapedCommand = Content.StartsWith("//");

            if (!isEscapedCommand && Command.Handle(new CommandTarget(connection, roomName), Content, "/"))
            {
                return;
            }

            if (isEscapedCommand)
            {
                Content = Content.Substring(1);
            }

            if (room == null)
            {
                connection.SendSysMessage("RohBot is not in this room.");
                return;
            }

            room.SendMessage(connection, Content);
        }
Example #7
0
        public override void Handle(Connection connection)
        {
            if (Program.DelayManager.AddAndCheck(connection, DelayManager.Database))
                return;

            if (connection.Session == null)
            {
                connection.SendSysMessage("You need to be logged in to do that.");
                return;
            }

            if (!connection.Session.IsInRoom(Target))
            {
                connection.SendSysMessage("You are not in that room.");
                return;
            }

            var room = Program.RoomManager.Get(Target);
            if (room == null)
            {
                connection.SendSysMessage("Room does not exist.");
                return;
            }

            if (room.IsPrivate && room.IsBanned(connection.Session.Account.Name))
                return;

            List<HistoryLine> lines;
            if (Util.DateTimeFromTimestamp(AfterDate) < (DateTime.UtcNow - Util.MaximumHistoryRequest))
            {
                lines = new List<HistoryLine>();
            }
            else
            {
                var cmd = new SqlCommand("SELECT * FROM rohbot.chathistory WHERE chat=lower(:chat) AND date<:afterdate ORDER BY date DESC LIMIT 100;");
                cmd["chat"] = Target;
                cmd["afterdate"] = AfterDate;

                lines = cmd.Execute().Select(r => (HistoryLine)HistoryLine.Read(r)).ToList();
                lines.Reverse();
            }

            if (lines.Count == 0)
                lines.Add(new ChatLine(0, Target, "Steam", Program.Settings.PersonaName, "0", "", "No additional history is available.", false));

            var history = new ChatHistory
            {
                ShortName = room.RoomInfo.ShortName,
                Requested = true,
                Lines = lines
            };

            connection.Send(history);
        }
Example #8
0
        public override void Handle(Connection connection)
        {
            if (connection.Session == null)
            {
                connection.SendSysMessage("Guests can not speak.");
                return;
            }

            Content = (Content ?? "").Trim();

            if (Content.Length == 0)
            {
                return;
            }

            // can't send emoticons from web
            Content = Content.Replace('ː', ':');

            // steam discards long messages
            if (Content.Length > 2000)
            {
                Content = Content.Substring(0, 2000) + "...";
            }

            if (Program.DelayManager.AddAndCheck(connection, CalculateMessageCost(Content)))
            {
                return;
            }

            var room = Program.RoomManager.Get(Target);

            if (room == null)
            {
                if (Command.Handle(new CommandTarget(connection, Program.Settings.DefaultRoom), Content, "/"))
                {
                    return;
                }

                if (Command.Handle(new CommandTarget(connection, Program.Settings.DefaultRoom), Content, "~"))
                {
                    return;
                }

                connection.SendSysMessage("RohBot is not in this room.");
                return;
            }

            room.SendMessage(connection, Content);
        }
Example #9
0
        public override void SendHistory(Connection connection)
        {
            base.SendHistory(connection);

            if (Chat == null)
                connection.SendSysMessage("Not connected to Steam.");
        }
        public override void Handle(Connection connection)
        {
            var account = connection.Session.Account;
            var notification = new Notification();

            notification.UserId = account.Id;
            notification.Regex = new Regex(RegexPattern);
            notification.DeviceToken = DeviceToken;

            if (Program.NotificationManager.Exists(DeviceToken))
            {
                notification.Save();
            }
            else
            {
                if (Program.NotificationManager.FindWithId(account.Id).Count() < 5)
                {
                    notification.Insert();
                }
                else
                {
                    connection.SendSysMessage("You may only have 5 devices registered for push notifications.");
                    return;
                }
            }

            Program.NotificationsDirty = true;

            var notificationSubscription = new NotificationSubscription();
            notificationSubscription.DeviceToken = DeviceToken;
            notificationSubscription.RegexPattern = RegexPattern;
            notificationSubscription.Registered = true;

            connection.Send(notificationSubscription);
        }
Example #11
0
        public override void SendHistory(Connection connection)
        {
            base.SendHistory(connection);

            if (Chat == null)
            {
                connection.SendSysMessage("Not connected to Steam.");
            }
        }
Example #12
0
        public override void Handle(Connection connection)
        {
            if (connection.Session == null)
            {
                connection.SendSysMessage("Guests can not speak.");
                return;
            }

            Content = (Content ?? "").Trim();

            if (Content.Length == 0)
                return;

            // can't send emoticons from web
            Content = Content.Replace('ː', ':');

            // steam discards long messages
            if (Content.Length > 2000)
                Content = Content.Substring(0, 2000) + "...";

            if (Program.DelayManager.AddAndCheck(connection, CalculateMessageCost(Content)))
                return;

            var room = Program.RoomManager.Get(Target);
            var roomName = room != null ? Target : Program.Settings.DefaultRoom;

            var isEscapedCommand = Content.StartsWith("//");
            if (!isEscapedCommand && Command.Handle(new CommandTarget(connection, roomName), Content, "/"))
                return;

            if (isEscapedCommand)
                Content = Content.Substring(1);

            if (room == null)
            {
                connection.SendSysMessage("RohBot is not in this room.");
                return;
            }

            room.SendMessage(connection, Content);
        }
Example #13
0
        public override void Handle(Connection connection)
        {
            if (Program.DelayManager.AddAndCheck(connection, 2.5))
                return;

            if (connection.Session == null)
            {
                connection.SendSysMessage("Guests can not speak.");
                return;
            }

            Content = (Content ?? "").Trim();

            if (Content.Length == 0)
                return;

            // can't send emoticons from web
            Content = Content.Replace('ː', ':');

            // steam discards long messages
            if (Content.Length > 1000)
                Content = Content.Substring(0, 1000) + "...";

            var room = Program.RoomManager.Get(Target);
            if (room == null)
            {
                if (Command.Handle(new CommandTarget(connection, Program.Settings.DefaultRoom), Content, "/"))
                    return;

                if (Command.Handle(new CommandTarget(connection, Program.Settings.DefaultRoom), Content, "~"))
                    return;

                connection.SendSysMessage("RohBot is not in this room.");
                return;
            }

            room.SendMessage(connection, Content);
        }
Example #14
0
        /// <summary>
        /// Called when somebody sends a message.
        /// </summary>
        public void SendMessage(Connection connection, string message)
        {
            if (connection.Session == null) // should never happen
            {
                return;
            }

            var roomName = RoomInfo.ShortName;
            var account  = connection.Session.Account;

            if (!message.StartsWith("//") && Command.Handle(new CommandTarget(connection, roomName), message, "/"))
            {
                return;
            }

            if (!message.StartsWith("~~") && Command.Handle(new CommandTarget(connection, roomName), message, "~"))
            {
                return;
            }

            if (message.StartsWith("//") || message.StartsWith("~~"))
            {
                message = message.Substring(1);
            }

            if (IsBanned(account.Name))
            {
                connection.SendSysMessage("You are banned from this room.");
                return;
            }

            var userName  = account.Name;
            var userId    = account.Id.ToString("D");
            var userStyle = account.EnabledStyle;
            var line      = new ChatLine(Util.GetCurrentTimestamp(), roomName, "RohBot", userName, userId, userStyle, message, false);

            SendLine(line);
        }
Example #15
0
        public bool AddAndCheck(Connection connection, double cost)
        {
            lock (_delays)
            {
                double delay;
                if (!_delays.TryGetValue(connection.Address, out delay))
                {
                    if (cost > 0)
                        _delays.Add(connection.Address, cost);
                }
                else
                {
                    _delays[connection.Address] += cost;
                }

                var shouldDelay = (delay + cost) >= DelayThreshold;

                if (shouldDelay)
                    connection.SendSysMessage("Too many requests are coming from your location and your request has been canceled. Please wait and try again in a few minutes.");

                return shouldDelay;
            }
        }
Example #16
0
        /// <summary>
        /// Called when somebody sends a message.
        /// </summary>
        public virtual void SendMessage(Connection connection, string message)
        {
            if (connection.Session == null) // should never happen
            {
                return;
            }

            var roomName = RoomInfo.ShortName;
            var account  = connection.Session.Account;

            if (IsBanned(account.Name))
            {
                connection.SendSysMessage("You are banned from this room.");
                return;
            }

            var userName  = account.Name;
            var userId    = account.Id.ToString("D");
            var userStyle = account.EnabledStyle;
            var line      = new ChatLine(Util.GetCurrentTimestamp(), roomName, "RohBot", userName, userId, userStyle, message, false);

            SendLine(line);
        }
        public override void Handle(Connection connection)
        {
            var account      = connection.Session.Account;
            var notification = new Notification();

            notification.UserId      = account.Id;
            notification.Regex       = new Regex(RegexPattern);
            notification.DeviceToken = DeviceToken;

            if (Program.NotificationManager.Exists(DeviceToken))
            {
                notification.Save();
            }
            else
            {
                if (Program.NotificationManager.FindWithId(account.Id).Count() < 5)
                {
                    notification.Insert();
                }
                else
                {
                    connection.SendSysMessage("You may only have 5 devices registered for push notifications.");
                    return;
                }
            }

            Program.NotificationsDirty = true;

            var notificationSubscription = new NotificationSubscription();

            notificationSubscription.DeviceToken  = DeviceToken;
            notificationSubscription.RegexPattern = RegexPattern;
            notificationSubscription.Registered   = true;

            connection.Send(notificationSubscription);
        }
Example #18
0
        /// <summary>
        /// Called when somebody sends a message.
        /// </summary>
        public virtual void SendMessage(Connection connection, string message)
        {
            if (connection.Session == null) // should never happen
                return;

            var roomName = RoomInfo.ShortName;
            var account = connection.Session.Account;

            if (IsBanned(account.Name))
            {
                connection.SendSysMessage("You are banned from this room.");
                return;
            }

            var userName = account.Name;
            var userId = account.Id.ToString("D");
            var userStyle = account.EnabledStyle;
            var line = new ChatLine(Util.GetCurrentTimestamp(), roomName, "RohBot", userName, userId, userStyle, message, false);
            SendLine(line);
        }
Example #19
0
        /// <summary>
        /// Called when somebody sends a message.
        /// </summary>
        public void SendMessage(Connection connection, string message)
        {
            if (connection.Session == null) // should never happen
                return;

            var roomName = RoomInfo.ShortName;
            var account = connection.Session.Account;

            if (!message.StartsWith("//") && Command.Handle(new CommandTarget(connection, roomName), message, "/"))
                return;

            if (!message.StartsWith("~~") && Command.Handle(new CommandTarget(connection, roomName), message, "~"))
                return;

            if (message.StartsWith("//") || message.StartsWith("~~"))
                message = message.Substring(1);

            if (IsBanned(account.Name))
            {
                connection.SendSysMessage("You are banned from this room.");
                return;
            }

            var userName = account.Name;
            var userId = account.Id.ToString("D");
            var userStyle = account.EnabledStyle;
            var line = new ChatLine(Util.GetCurrentTimestamp(), roomName, "RohBot", userName, userId, userStyle, message, false);
            SendLine(line);
        }
Example #20
0
        /// <summary>
        /// Called when somebody joins the room. Should call base.
        /// </summary>
        public virtual void SendHistory(Connection connection)
        {
            if (IsPrivate)
            {
                if (connection.Session == null)
                {
                    ClearScrollbackFor(connection);
                    connection.SendSysMessage("You must login to view this room.");
                    return;
                }

                if (IsBanned(connection.Session.Account.Name))
                {
                    ClearScrollbackFor(connection);
                    connection.SendSysMessage("You are banned from this room.");
                    return;
                }
            }

            var lines = GetHistoryLines(connection);
            var chatHistory = new ChatHistory { ShortName = RoomInfo.ShortName, Requested = false, Lines = lines };
            connection.Send(chatHistory);
        }
Example #21
0
        public override void Handle(Connection connection)
        {
            if (Program.DelayManager.AddAndCheck(connection, DelayManager.Database))
            {
                return;
            }

            if (connection.Session == null)
            {
                connection.SendSysMessage("You need to be logged in to do that.");
                return;
            }

            if (!connection.Session.IsInRoom(Target))
            {
                connection.SendSysMessage("You are not in that room.");
                return;
            }

            var room = Program.RoomManager.Get(Target);

            if (room == null)
            {
                connection.SendSysMessage("Room does not exist.");
                return;
            }

            if (room.IsPrivate && room.IsBanned(connection.Session.Account.Name))
            {
                return;
            }

            List <HistoryLine> lines;

            if (Util.DateTimeFromTimestamp(AfterDate) < (DateTime.UtcNow - Util.MaximumHistoryRequest))
            {
                lines = new List <HistoryLine>();
            }
            else
            {
                var cmd = new SqlCommand("SELECT * FROM rohbot.chathistory WHERE chat=lower(:chat) AND date<:afterdate ORDER BY date DESC LIMIT 100;");
                cmd["chat"]      = Target;
                cmd["afterdate"] = AfterDate;

                lines = cmd.Execute().Select(r => (HistoryLine)HistoryLine.Read(r)).ToList();
                lines.Reverse();
            }

            if (lines.Count == 0)
            {
                lines.Add(new ChatLine(0, Target, "Steam", Program.Settings.PersonaName, "0", "", "No additional history is available.", false));
            }

            var history = new ChatHistory
            {
                ShortName = room.RoomInfo.ShortName,
                Requested = true,
                Lines     = lines
            };

            connection.Send(history);
        }