forked from amoeba/TownCrier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChatPattern.cs
40 lines (35 loc) · 1.02 KB
/
ChatPattern.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace TownCrier
{
class ChatPattern
{
public string Event { get; }
public Regex Pattern { get; }
public int Color { get; }
public ChatPattern(string evt, string pattern)
{
Event = evt;
Pattern = new Regex(pattern, RegexOptions.Compiled);
Color = -1;
}
public ChatPattern(string evt, string pattern, int color)
{
Event = evt;
Pattern = new Regex(pattern, RegexOptions.Compiled);
Color = color;
}
public bool Match(Decal.Adapter.ChatTextInterceptEventArgs e)
{
// Match the message and the color (but only match color if
// we set a Color to match)
if (Pattern.IsMatch(e.Text) && (Color == -1 ? true : e.Color == Color))
{
return true;
}
return false;
}
}
}