public static void Chat(string user, string message, Types.Chat type = Types.Chat.Regular, bool isLeave = false) { string lvlColor = @"\cf" + (int)Rtf.Colors[(Irc.UserInList(user) ? Irc.Userlist[user] : Types.UserLevel.Viewer).ToString()][0]; string typeColor = @"\cf" + (int)Rtf.Colors[type.ToString()][0]; string appendText; if ((type == Types.Chat.Regular && type == Types.Chat.Status || type == Types.Chat.Subscribe)) { if (!isLeave && !Irc.UserInList(user)) Irc.AddUserToList(user); else if(isLeave) Irc.RemoveUserFromList(user); } if (Settings.Default.OptionHideBotMsg && string.Equals(user, Settings.Default.OptionName, StringComparison.OrdinalIgnoreCase)) return; switch (type) { case Types.Chat.Regular: // Handle commands. string[] wordArray = message.Split('"') .Select((element, index) => index % 2 == 0 // If even index ? element.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) // Split the item : new[] { element }) // Keep the entire item .SelectMany(element => element).ToArray(); if (Irc.UserInList(user) && Regex.IsMatch(wordArray[0], @"^(?=^[!][\d]*[A-Z|a-z])|(?=^[!][A-Z|a-z][\d|A-Z|a-z])")) { string[] paramStrings = new string[wordArray.Length-1]; for (int i = 1; i < wordArray.Length; i++) paramStrings[i - 1] = wordArray[i]; Commands.ExecuteCommand(user, Irc.Userlist[user], wordArray[0].Substring(1), paramStrings); } // Regular chat messages. string userString = "{" + lvlColor + "<" + user + ">} "; Dictionary<string, string> emoteList = Irc != null && Irc.Emotelist != null ? Irc.Emotelist : new Dictionary<string, string>(); message = Rtf.EscapeString(message); appendText = typeColor + userString + (emoteList.Aggregate(message, (current, pair) => Regex.IsMatch(message, "(^| )" + pair.Key + "( |$)") ? Regex.Replace(current, "(^| )" + pair.Key + "( |$)", Rtf.GetEmbedImageString(pair.Value.ToString()) ?? pair.Key.ToString()) : current)); break; case Types.Chat.Status: // "Joined" and "Left" messages. if (Settings.Default.OptionHideStatusMsg) return; appendText = typeColor + user + " " + message.Trim(); break; case Types.Chat.Subscribe: // "[USER] just subscribed!" messages. appendText = typeColor + message.Substring(message.IndexOf(":", 1) + 1).Trim(); break; default: // UNKNOWN, report as ERROR event. appendText = null; EventLog("A chat message of an unknown type (type: " + type + ") has been received", Types.Log.Error); break; } // Output to the console (disabled by default due to muchness) // Console.WriteLine(message.Trim()); // Output to the chat RichTextBox MainDialog.UpdateChatTextUI(appendText); }
public void AddUserToViewlist(string nick, Types.UserLevel level) { if (!mdTabChatViewerList.Items.ContainsKey(nick)) { ListViewItem li = new ListViewItem(" " + Types.GetUserLevelLetter(level), level.ToString()); li.SubItems.Add(nick); li.Name = nick; mdTabChatViewerList.Items.Add(li); } }