This repository has been archived by the owner on Apr 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIRC.as
74 lines (63 loc) · 1.72 KB
/
IRC.as
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
namespace IRC
{
class Prefix
{
string m_origin;
string m_user;
string m_host;
Prefix(const string &in prefix)
{
auto match = Regex::Match(prefix, """:([^!@]+)(![^@]+)?(@.+)?""");
m_origin = match[1];
m_user = match[2].SubStr(1);
m_host = match[3].SubStr(1);
}
}
class Message
{
dictionary m_tags;
Prefix@ m_prefix;
string m_command;
array<string> m_params;
Message(string line)
{
auto matchTags = Regex::Search(line, """^(@[^ ]+) """);
if (matchTags.Length != 0) {
auto matchAllTags = Regex::SearchAll(matchTags[1], """([a-zA-Z0-9\-]+)=?([^;]*)""");
for (uint i = 0; i < matchAllTags.Length; i++) {
auto matchTag = matchAllTags[i];
m_tags.Set(matchTag[1], matchTag[2]);
}
line = LineSub(line, matchTags[0]);
}
auto matchPrefix = Regex::Search(line, """^(:[^ ]+) """);
if (matchPrefix.Length != 0) {
@m_prefix = Prefix(matchPrefix[1]);
line = LineSub(line, matchPrefix[0]);
}
auto matchCommand = Regex::Search(line, """^([^ $]+|[0-9]{3}) ?""");
m_command = matchCommand[1];
line = LineSub(line, matchCommand[0]);
while (line.Length > 0) {
if (line.StartsWith(":")) {
m_params.InsertLast(line.SubStr(1));
break;
}
int spaceIndex = line.IndexOf(" ");
if (spaceIndex == -1) {
m_params.InsertLast(line);
break;
}
m_params.InsertLast(line.SubStr(0, spaceIndex));
line = line.SubStr(spaceIndex + 1);
}
}
string LineSub(const string &in line, const string &in match)
{
//TODO: There is some bug that doesn't let us do this:
// line = line.SubStr(matchTags[0].Length);
// Because .Length seems to be called on an invalid object?
return line.SubStr(match.Length);
}
}
}