-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
91 lines (85 loc) · 1.71 KB
/
index.js
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
const { clipboard } = require('electron');
module.exports = function paste(mod) {
const command = mod.command;
let enabled = true;
command.add(['paste', '!paste'], {
$none() {
enabled = !enabled;
command.message('Paste mod '+(enabled ? 'Enabled' : 'Disabled') + '.');
},
$default() {
command.message('Invalid command! see README for the list of valid commands')
},
test() {
if(enabled) {
command.message(clipboard.readText());
}
},
p() {
if(enabled) {
sendMessage(clipboard.readText(),1);
}
},
s() {
if(enabled) {
sendMessage(clipboard.readText(),0);
}
},
pn() {
if(enabled) {
sendMessage(clipboard.readText(),21);
}
},
c() {
if(enabled) {
sendMessage(clipboard.readText(),27);
}
},
i() {
if(enabled) {
sendMessage(clipboard.readText(),32);
}
},
in() {
if(enabled) {
sendMessage(clipboard.readText(),25);
}
},
w(arg) {
if(enabled && arg) {
sendWhisper(clipboard.readText(),arg);
}
},
g() {
if(enabled) {
sendMessage(clipboard.readText(),2);
}
}
});
/* say = 0, party = 1, guild = 2, area = 3, trade = 4, greet = 9,
* private = 11-18, p-notice = 21, emote = 26, global = 27, r-notice = 25,
* raid = 32, megaphone = 213, guild-adv = 214 */
function sendMessage(msg, chan)
{
if(msg !== ''){
mod.toServer('C_CHAT', 1, {
channel: chan,
message: msg
});
}
}
function sendWhisper(msg, target)
{
if(isValidName(msg)){
mod.toServer('C_WHISPER', 1, {
target: target,
message: msg
});
}
}
//incomplete test, but better than nothing
function isValidName(string) {
var test = new RegExp('[a-z]+[.]?[a-z]+', 'i');
return test.test(string);
}
}