public override void SendLine(HistoryLine line) { try { var chatLine = line as ChatLine; if (chatLine != null && Chat != null && chatLine.UserType == "RohBot") { Chat.Send($"[{WebUtility.HtmlDecode(chatLine.Sender)}] {WebUtility.HtmlDecode(chatLine.Content)}"); } var stateLine = line as StateLine; if (EchoWebStates && stateLine != null && Chat != null && stateLine.ForType == "RohBot" && stateLine.State != "Action") { Chat.Send("> " + WebUtility.HtmlDecode(stateLine.Content)); } if (stateLine != null && Chat != null && stateLine.State == "Action") { Chat.Send(WebUtility.HtmlDecode(stateLine.Content)); } } catch (Exception e) { Program.Logger.Error("Failed to forward message to Steam", e); } base.SendLine(line); }
public override void SendLine(HistoryLine line) { var chatLine = line as ChatLine; if (chatLine != null && Chat != null && chatLine.UserType == "RohBot") { Chat.Send(string.Format("[{0}] {1}", WebUtility.HtmlDecode(chatLine.Sender), WebUtility.HtmlDecode(chatLine.Content))); } base.SendLine(line); }
public void should_add_one_history_line() { List <HistoryLine> historyLines = new List <HistoryLine>(); IHistory history = new History(historyLines); decimal amountOfMoney = new decimal(1000); Balance balance = new Balance(1000); DateTime movementDate = new DateTime(2012, 1, 10); HistoryLine historyLine = new HistoryLine(movementDate, amountOfMoney, anyAccountId, balance); history.AddLine(amountOfMoney, anyAccountId, balance, movementDate); historyLines[historyLines.Count - 1].Should().Be(historyLine); }
public override void SendLine(HistoryLine line) { if (_script != null) { bool cont = true; SafeInvoke(() => cont = _script.OnSendLine(line)); if (!cont) { return; } } base.SendLine(line); }
/// <summary> /// Called when a message is being sent to the room. Should call base. /// </summary> public virtual void SendLine(HistoryLine line) { line = Util.EmoticonReplace(line); var chatLine = line as ChatLine; if (chatLine != null && _showLinkTitles && chatLine.SenderId != "0") { Action checkTitles = async() => { var titles = await LinkTitles.Lookup(chatLine.Content); if (!string.IsNullOrWhiteSpace(titles)) { Send(titles); } }; checkTitles(); } var message = new Message(); message.Line = line; Func <Session, bool> filter = session => { if (session.Account == null) { return(false); } if (IsPrivate && IsBanned(session.Account.Name)) { return(false); } return(session.IsInRoom(RoomInfo.ShortName)); }; var sessions = Program.SessionManager.List.Where(filter); sessions = SendLineFilter(line, sessions); Program.SessionManager.Send(message, sessions); Program.NotificationManager.HandleMessage(this, message); AddHistory(line); }
private void AddHistory(HistoryLine line) { lock (_history) { if (_history.Count >= 100) { _history.RemoveFirst(); } _history.AddLast(line); } if (IsLogging) { line.Insert(); } }
public void should_josey_history_lines_when_we_ask_it() { HistoryLine josey = new HistoryLine(new DateTime(2000, 1, 1), 2000, new Id("josey"), null); HistoryLine marie = new HistoryLine(new DateTime(2000, 1, 1), 1000, new Id("marie"), null); List <HistoryLine> expectedHistorylines = new List <HistoryLine> { marie, josey }; IHistory history = new History(expectedHistorylines); List <HistoryLine> historyLine = history.Get(new Id("josey")); historyLine.Should().Equal(new List <HistoryLine> { josey }); }
void WriteLine(IChatLine line) { if (PassesFilter(line)) { if (highlightActive && !DeHighlighted(line.Text)) { line = new HistoryLine(line.Text); } var splitText = line.Text.Replace("\r\n", "\n").Replace("\\n", "\n").Split('\n'); AppendText(splitText[0]); string padding = (line is TopicLine) ? "" : " "; //padding to avoid player spoofing different player using multi-line & color & formating for (int i = 1; i < splitText.Length; i++) { AppendText(padding + splitText[i]); } } }
public MainWindow() { InitializeComponent(); InitializeGui(); InitializeGlobals(); for (var i = 0; i < 20; ++i) { var node = new HistoryLine { Title = $"Test {i}" }; Model.History.Add(node); } HistoryControl.ItemsSource = Model.History; DataContext = new ActorViewModel(); }
public override void SendLine(HistoryLine line) { var chatLine = line as ChatLine; if (chatLine != null && Chat != null && chatLine.UserType == "RohBot") { Chat.Send(string.Format("[{0}] {1}", WebUtility.HtmlDecode(chatLine.Sender), WebUtility.HtmlDecode(chatLine.Content))); } var stateLine = line as StateLine; if (EchoWebStates && stateLine != null && Chat != null && stateLine.ForType == "RohBot") { string fmt; switch (stateLine.State) { case "Enter": fmt = "<{0}> entered chat."; break; case "Left": fmt = "<{0}> left chat."; break; case "Disconnected": fmt = "<{0}> disconnected."; break; default: fmt = null; break; } if (fmt != null) { Chat.Send(string.Format(fmt, WebUtility.HtmlDecode(stateLine.For))); } } if (stateLine != null && Chat != null && stateLine.State == "Action") { Chat.Send(WebUtility.HtmlDecode(stateLine.Content)); } base.SendLine(line); }
public override void SendLine(HistoryLine line) { var chatLine = line as ChatLine; if (chatLine != null && Chat != null && chatLine.UserType == "RohBot") { Chat.Send(string.Format("[{0}] {1}", WebUtility.HtmlDecode(chatLine.Sender), WebUtility.HtmlDecode(chatLine.Content))); } var stateLine = line as StateLine; if (EchoWebStates && stateLine != null && Chat != null && stateLine.ForType == "RohBot" && stateLine.State != "Action") { Chat.Send("> " + WebUtility.HtmlDecode(stateLine.Content)); } if (stateLine != null && Chat != null && stateLine.State == "Action") { Chat.Send(WebUtility.HtmlDecode(stateLine.Content)); } base.SendLine(line); }
public override void SendLine(HistoryLine line) { var chatLine = line as ChatLine; if (chatLine != null && Chat != null && chatLine.UserType == "RohBot") { Chat.Send($"[{WebUtility.HtmlDecode(chatLine.Sender)}] {WebUtility.HtmlDecode(chatLine.Content)}"); } var stateLine = line as StateLine; if (EchoWebStates && stateLine != null && Chat != null && stateLine.ForType == "RohBot" && stateLine.State != "Action") { Chat.Send("> " + WebUtility.HtmlDecode(stateLine.Content)); } if (stateLine != null && Chat != null && stateLine.State == "Action") { Chat.Send(WebUtility.HtmlDecode(stateLine.Content)); } base.SendLine(line); }
public Room(RoomInfo roomInfo) { RoomInfo = roomInfo; IsActive = true; _settings = RoomSettings.Get(RoomInfo.ShortName); if (_settings == null) { _settings = new RoomSettings { Room = RoomInfo.ShortName, Bans = new HashSet <string>(), Mods = new HashSet <string>() }; _settings.Insert(); } _history = new LinkedList <HistoryLine>(); var cmd = new SqlCommand("SELECT * FROM rohbot.chathistory WHERE chat=lower(:chat) ORDER BY date DESC LIMIT 100;"); cmd["chat"] = RoomInfo.ShortName; foreach (var line in cmd.Execute().Reverse().Select(r => HistoryLine.Read(r))) { _history.AddLast(line); } _showLinkTitles = (RoomInfo["LinkTitles"] ?? "").ToLower() == "true"; IsWhitelisted = (RoomInfo["Whitelist"] ?? "").ToLower() == "true"; IsHidden = (RoomInfo["Hidden"] ?? "").ToLower() == "true"; IsPrivate = (RoomInfo["Private"] ?? "").ToLower() == "true"; IsLogging = (RoomInfo["Logging"] ?? "true").ToLower() == "true"; ShowWebStates = (RoomInfo["WebStates"] ?? "true").ToLower() == "true"; DisableBanning = (RoomInfo["DisableBanning"] ?? "").ToLower() == "true"; }
public void SendLine(HistoryLine line) { _room.SendLine(line); }
public Message(JsonObject obj) { Line = new HistoryLine(obj.GetNamedObject("Line")); }
private void AddHistory(HistoryLine line) { lock (_history) { if (_history.Count >= 100) _history.RemoveFirst(); _history.AddLast(line); } if (IsLogging) line.Insert(); }
public bool OnSendLine(HistoryLine line) { return(true); }
/// <summary> /// Called when a message is being sent to the room. Should call base. /// </summary> public virtual void SendLine(HistoryLine line) { var chatLine = line as ChatLine; if (chatLine != null && _showLinkTitles && chatLine.SenderId != "0") { ThreadPool.QueueUserWorkItem(a => { var titles = LinkTitles.Lookup(chatLine.Content); if (!string.IsNullOrWhiteSpace(titles)) Send(titles); }); } var message = new Message(); message.Line = line; Func<Session, bool> filter = session => { if (IsPrivate) { if (session.Account == null || IsBanned(session.Account.Name)) return false; } return session.Room == RoomInfo.ShortName; }; Program.SessionManager.Broadcast(message, filter); AddHistory(line); }
/// <summary> /// Filter sessions which receive lines from SendLine. /// </summary> public virtual IEnumerable <Session> SendLineFilter(HistoryLine line, IEnumerable <Session> sessions) { return(sessions); }
public override void SendLine(HistoryLine line) { if (_script != null) { bool cont = true; SafeInvoke(() => cont = _script.OnSendLine(line)); if (!cont) return; } base.SendLine(line); }
/// <summary> /// Called when a message is being sent to the room. Should call base. /// </summary> public virtual void SendLine(HistoryLine line) { line = Util.EmoticonReplace(line); var chatLine = line as ChatLine; if (chatLine != null && _showLinkTitles && chatLine.SenderId != "0") { Action checkTitles = async () => { var titles = await LinkTitles.Lookup(chatLine.Content); if (!string.IsNullOrWhiteSpace(titles)) Send(titles); }; checkTitles(); } var message = new Message(); message.Line = line; Func<Session, bool> filter = session => { if (session.Account == null) return false; if (IsPrivate && IsBanned(session.Account.Name)) return false; return session.IsInRoom(RoomInfo.ShortName); }; var sessions = Program.SessionManager.List.Where(filter); sessions = SendLineFilter(line, sessions); Program.SessionManager.Send(message, sessions); AddHistory(line); }
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); }
/// <summary> /// Filter sessions which receive lines from SendLine. /// </summary> public virtual IEnumerable<Session> SendLineFilter(HistoryLine line, IEnumerable<Session> sessions) { return sessions; }