|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- 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;
- }
- }
- }
|