-
Notifications
You must be signed in to change notification settings - Fork 6
/
volaban.user.js
172 lines (163 loc) · 5.66 KB
/
volaban.user.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// ==UserScript==
// @name VolaBan
// @version 4
// @description Filter annoying users
// @namespace https://volafile.org
// @include https://volafile.org/r/*
// @icon https://volafile.org/favicon.ico
// @author topkuk productions
// @match https://volafile.org/r/*
// @require https://greasemonkey.github.io/gm4-polyfill/gm4-polyfill.js
// @require https://cdn.jsdelivr.net/gh/volafiled/volascripts@a9c0424e5498deea9fd437c15b2137c3bec07c61/dry.min.js
// @grant none
// @run-at document-start
// ==/UserScript==
/* globals dry, GM */
(function() {
"use strict";
const basebans = {
staff: ["News"],
exact: ["DeadPool", "Wade"],
whites: ["real", "dolos"],
logs: ["davidbowie", "pinkb0t"]
};
console.log("running", GM.info.script.name, GM.info.script.version, dry.version);
let bans;
const make = function() {
let base = JSON.parse(JSON.stringify(basebans));
bans = JSON.parse(localStorage.getItem("bans"));
if (!bans) {
bans = base;
}
else {
bans = Object.setPrototypeOf(bans, base);
}
for (let key in basebans) {
bans["r" + key] = key === "whites" || key === "logs" ?
new RegExp(`(?:${bans[key].join("|")})`, "i") :
new RegExp(`^(?:${bans[key].join("|")})$`, "i");
}
console.log(bans);
};
make();
const save = function() {
localStorage.setItem("bans", JSON.stringify(bans));
};
const ignore = (nick, options, message) => {
return (bans.exact.length && bans.rexact.test(nick)) ||
(bans.staff.length && options.staff && bans.rstaff.test(nick)) ||
(bans.logs.length && nick === "Log" && Array.isArray(message) &&
message.length === 1 && bans.rlogs.test(message[0].value)) ||
(bans.whites.length && !(options.staff || options.user) && bans.rwhites.test(nick));
};
dry.once("dom", () => {
// Will get rid of messages but not of notifications
new class extends dry.MessageFilter {
showMessage(orig, nick, message, options) {
if (!ignore(nick, options, message)) {
return;
}
console.error("ignored", nick.toString(), JSON.stringify(message), JSON.stringify(options));
return false;
}
}();
const _ban = (what, type, who) => {
if (!who) {
return false;
}
who = who.trim();
let a = bans[what === "w" ? "whites" : (what === "s" ? "staff" :
(what === "l" ? "logs" : "exact"))];
if (type === "block") {
if (a.indexOf(who) < 0) {
a.push(who);
}
else {
dry.appendMessage("VolaBan", `${who}: Nick already in blocklist.`);
return true;
}
}
else if (type === "unblock") {
let index = a.indexOf(who);
if (index >= 0) {
a.splice(index, 1);
}
else {
dry.appendMessage("VolaBan", `${who}: No such nick in blocklist.`);
return true;
}
}
save();
make();
dry.appendMessage("VolaBan", `modified rules for ${what}:${who}`);
return true;
};
new class extends dry.Commands {
block(e) {
return _ban("e", "block", e);
}
wblock(e) {
return _ban("w", "block", e);
}
sblock(e) {
return _ban("s", "block", e);
}
lblock(e) {
return _ban("l", "block", e);
}
unblock(e) {
return _ban("e", "unblock", e);
}
wunblock(e) {
return _ban("w", "unblock", e);
}
sunblock(e) {
return _ban("s", "unblock", e);
}
lunblock(e) {
return _ban("l", "unblock", e);
}
blockreset() {
localStorage.removeItem("bans");
make();
dry.appendMessage("VolaBan", "bans were reset!");
return true;
}
blocklist() {
let m = new window.Array();
m.push({
"type": "text",
"value": `bans:`
});
m.push({"type": "break" });
for (let i of ["whites", "exact", "staff", "logs"]) {
m.push({
"type": "text",
"value": `${i}: ${JSON.stringify(bans[i])}`
});
m.push({"type": "break" });
}
dry.appendMessage("VolaBan", m);
return true;
}
}();
});
dry.on("load", () => {
// Hook the notifications listener too, which is an
// anonymous function from a closure and hence we
// have to find it within the registered events
dry.exts.connection._events.chatMessage.some(e => {
const onChatMessage = e.fn;
if (!/sage/.test("" + onChatMessage)) {
return false;
}
e.fn = function(...args) {
if (ignore(args[0], args[1], args[2])) {
return false;
}
return onChatMessage.apply(this, args);
};
return true;
});
});
})();