forked from pavben/WebIRC
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmode.js
More file actions
96 lines (79 loc) · 2.02 KB
/
Copy pathmode.js
File metadata and controls
96 lines (79 loc) · 2.02 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
"use strict";
var ModeType = {
NONE: 0,
PLUS_ONLY: 1,
BOTH: 2
};
function parseChannelModes(modes, args) {
var modesWithParams = {};
modesWithParams['a'] = ModeType.BOTH;
modesWithParams['b'] = ModeType.BOTH;
modesWithParams['e'] = ModeType.BOTH;
modesWithParams['f'] = ModeType.BOTH;
modesWithParams['h'] = ModeType.BOTH;
modesWithParams['I'] = ModeType.BOTH;
modesWithParams['j'] = ModeType.BOTH;
modesWithParams['k'] = ModeType.BOTH;
modesWithParams['l'] = ModeType.PLUS_ONLY;
modesWithParams['L'] = ModeType.BOTH;
modesWithParams['o'] = ModeType.BOTH;
modesWithParams['q'] = ModeType.BOTH;
modesWithParams['v'] = ModeType.BOTH;
return parseModes(modes, args, modesWithParams);
}
function parseUserModes(modes, args) {
return parseModes(modes, args, {});
}
function parseModes(modes, args, modesWithParams) {
var plus = null;
var parsedModes = [];
var argIdx = 0;
for (var i = 0; i < modes.length; i++) {
var c = modes.charAt(i);
if (c === '+') {
plus = true;
} else if (c === '-') {
plus = false;
} else {
// it's a mode
if (plus === null) {
// if we got a mode before a +/-, invalid input
return null;
}
var modeType = ModeType.NONE;
if (c in modesWithParams) {
modeType = modesWithParams[c];
}
// if this mode requires an arg, grab it
var arg = null;
if (modeType === ModeType.BOTH || (modeType === ModeType.PLUS_ONLY && plus)) {
if (argIdx < args.length) {
arg = args[argIdx++];
} else {
return null; // not enough args
}
}
parsedModes.push({mode: c, plus: plus, arg: arg});
}
}
return parsedModes;
}
function getUserlistEntryAttributeByMode(mode) {
switch (mode) {
case 'q':
return 'owner';
case 'a':
return 'admin';
case 'o':
return 'op';
case 'h':
return 'halfop';
case 'v':
return 'voice';
default:
return null;
}
}
module.exports.parseChannelModes = parseChannelModes;
module.exports.parseUserModes = parseUserModes;
module.exports.getUserlistEntryAttributeByMode = getUserlistEntryAttributeByMode;