using System.Reflection; using System.Text.RegularExpressions; namespace CLre_server.Tweaks.Chat { public class Attributes { } [System.AttributeUsage(System.AttributeTargets.Method)] public class ChatCommandAttribute : System.Attribute { public readonly string Name; private readonly Regex _pattern; private readonly Regex _usernamePattern; public ChatCommandAttribute(string name, string pattern, string usernamePattern = null, RegexOptions options = RegexOptions.Compiled | RegexOptions.IgnoreCase) { this.Name = name; this._pattern = new Regex(pattern, options); this._usernamePattern = usernamePattern == null ? null : new Regex(pattern, options); Assembly asm = Assembly.GetCallingAssembly(); if (!ChatConnectionEngine._assembliesToCheck.Contains(asm)) { ChatConnectionEngine._assembliesToCheck.Add(asm); } if (ChatHandler.IsAuthenticationReady && CLre.Config.chat_commands) { // Chat system is already started // TODO } } public Regex GetPattern() { return _pattern; } public Match RegexMatch(string sender, string message) { if (this._usernamePattern != null) { if (this._usernamePattern.IsMatch(sender)) { return _pattern.Match(message); } } else { return _pattern.Match(message); } return System.Text.RegularExpressions.Match.Empty; } } }