-
Notifications
You must be signed in to change notification settings - Fork 0
/
Zalgo.plugin.js
351 lines (284 loc) · 17.9 KB
/
Zalgo.plugin.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
/**
* @name Zalgo
* @authorLink https://github.com/lol219
* @source https://raw.githubusercontent.com/lol219/Zalgo/main/Zalgo.plugin.js
* @invite TCuGtFNhpq
*/
/*@cc_on
@if (@_jscript)
// Offer to self-install for clueless users that try to run this directly.
var shell = WScript.CreateObject("WScript.Shell");
var fs = new ActiveXObject("Scripting.FileSystemObject");
var pathPlugins = shell.ExpandEnvironmentStrings("%APPDATA%\BetterDiscord\plugins");
var pathSelf = WScript.ScriptFullName;
// Put the user at ease by addressing them in the first person
shell.Popup("It looks like you've mistakenly tried to run me directly. \n(Don't do that!)", 0, "I'm a plugin for BetterDiscord", 0x30);
if (fs.GetParentFolderName(pathSelf) === fs.GetAbsolutePathName(pathPlugins)) {
shell.Popup("I'm in the correct folder already.", 0, "I'm already installed", 0x40);
} else if (!fs.FolderExists(pathPlugins)) {
shell.Popup("I can't find the BetterDiscord plugins folder.\nAre you sure it's even installed?", 0, "Can't install myself", 0x10);
} else if (shell.Popup("Should I copy myself to BetterDiscord's plugins folder for you?", 0, "Do you need some help?", 0x34) === 6) {
fs.CopyFile(pathSelf, fs.BuildPath(pathPlugins, fs.GetFileName(pathSelf)), true);
// Show the user where to put plugins in the future
shell.Exec("explorer " + pathPlugins);
shell.Popup("I'm installed!", 0, "Successfully installed", 0x40);
}
WScript.Quit();
@else@*/
var Zalgo = (() => {
//module.exports = (() => {
const config = {
"info": {
"name":"Zalgo",
"authors": [
{
"name":"Alexandro",
"discord_id":"820767057959321641",
"github_username":"lol219"
}
],
"version":"0.2.0",
"description":
"A plugin that makes your text to zalgo if you used this : {{0.01:text_goes_here}} (you can change 0:01 to another thing)",
"github":"https://github.com/lol219/Zalgo",
"github_raw":"https://raw.githubusercontent.com/lol219/Zalgo/main/Zalgo.plugin.js"
},
"changelog":[
{"title": "Added", "items": ["Code Cleanup and patched some issues after the last discord update"]},
{"title": "On-going", "type": "progress", "items": [
"**Threads**: Making it support threads too"]}
],
"main":"index.js"
};
class Zalgo{
getName() {return "Zalgo";}
getDescription() {return "A plugin that makes your text to zalgo if you used this : {{0.01:text_goes_here}} (you can change 0:01 to another thing)";}
getVersion() {return "0.2.0";}
getAuthor() {return "Alexandro";}
start() {
if (!global.ZeresPluginLibrary) return window.BdApi.alert("Library Missing",`The library plugin needed for ${this.getName()} is missing.<br /><br /> <a href="https://betterdiscord.net/ghdl?url=https://raw.githubusercontent.com/rauenzi/BDPluginLibrary/master/release/0PluginLibrary.plugin.js" target="_blank">Click here to download the library!</a>`);
ZLibrary.PluginUpdater.checkForUpdate(this.getName(), this.getVersion(), "https://raw.githubusercontent.com/lol219/Zalgo/main/Zalgo.plugin.js");
}
stop() {
}
}
//var Zalgo = (() => {
//const config = {"info":{"name":"Zalgo","authors":[{"name":"Chami","discord_id":"165709167095578625","github_username":"planetarian","twitter_username":"pir0zhki"}],"version":"0.4.0","description":"Zalgo text generation plugin -- write something {{like this}} to corrupt it l̕i̸̶͜ḱ͟e͏̶͢ ̨̛t̢̛҉̧ḩ͘i͘̕͏́͟ş̸̢͘͏\r\nYou can configure the amount of corruption in settings, or prefix it with a corruption amount:\r\n{{0.01:just a little corrupt}} -> j̨ųs͏t̨ ̷a͘ ̸l̶i̷t̀t҉l͡e҉ ̴c̡o͏r҉ŕu̡p̢t̕\r\nYou can also ramp the corruption amount gradually:\r\n{{r:start at zero and get more corrupted}} -> st̶a̷r̸t͜ ҉a̴t̡ ͘z̢e̵r̵o͡ ͝a̡ńd̡ ̛g͝e͞t͏̷ ͜m͟ó̡r̕͠e̸̴ ҉̨͟c̨̀͢͠ơ̕̕͝͞r̸̵̡͢ŕ̛͞u̧p̨͟͝t̴̶͝e̷̡d͏̴́͡","github":"https://github.com/planetarian/BetterDiscordPlugins","github_raw":"https://raw.githubusercontent.com/planetarian/BetterDiscordPlugins/master/Zalgo.plugin.js"},"changelog":[{"title":"0.4.0","items":["Fixed breakage caused by discord update","Switched from element manipulation to method patching"]},{"title":"0.3.0","items":["Fixed breakage caused by discord update","Switched from locally-tracked classes to use DiscordSelectors"]},{"title":"Plugin revamp","items":["Switched to new plugin format","Switched to new ZeresLib"]}],"main":"index.js"};
return !global.ZeresPluginLibrary ? class {
constructor() {this._config = config;}
getName() {return config.info.name;}
getAuthor() {return config.info.authors.map(a => a.name).join(", ");}
getDescription() {return config.info.description;}
getVersion() {return config.info.version;}
load() {
dApi.showConfirmationModal("Library Missing", `The library plugin needed for ${config.info.name} is missing. Please click Download Now to install it.`, {
confirmText: "Download Now",
cancelText: "Cancel",
onConfirm: () => {
require("request").get("https://rauenzi.github.io/BDPluginLibrary/release/0PluginLibrary.plugin.js", async (error, response, body) => {
if (error) return require("electron").shell.openExternal("https://betterdiscord.net/ghdl?url=https://raw.githubusercontent.com/rauenzi/BDPluginLibrary/master/release/0PluginLibrary.plugin.js");
await new Promise(r => require("fs").writeFile(require("path").join(BdApi.Plugins.folder, "0PluginLibrary.plugin.js"), body, r));
});
}
});
}
start() {}
stop() {}
} : (([Plugin, Api]) => {
const plugin = (Plugin, Library) => {
const { Logger, DiscordModules, Patcher, Settings } = Library;
if(!BdApi.Plugins.get("AlexLib") && !BdApi.getData(config.info.name)){
BdApi.saveData(config.info.name);
BdApi.showConfirmationModal("Missing Library",
[`Do you want to download a Alexandro plugin library ? it needs it `],
{
confirmText: "Download",
cancelText: "Cancel",
onConfirm: () => {
require("request").get("https://raw.githubusercontent.com/lol219/AlexLib/main/AlexLib.plugin.js", (error, response, body) => {
if (error) return require("electron").shell.openExternal("https://betterdiscord.net/ghdl?url=https://raw.githubusercontent.com/lol219/AlexLib/main/AlexLib.plugin.js");
else require("fs").writeFile(require("path").join(BdApi.Plugins.folder, "AlexLib.plugin.js"), body, ()=>{
window.setTimeout(()=>BdApi.Plugins.enable("AlexLib"), 1000);
});
});
}
}
);
}
return class Zalgo extends Plugin {
constructor() {
super();
this.zalgoUp = [
'\u030d', /* ̍ */ '\u030e', /* ̎ */ '\u0304', /* ̄ */ '\u0305', /* ̅ */
'\u033f', /* ̿ */ '\u0311', /* ̑ */ '\u0306', /* ̆ */ '\u0310', /* ̐ */
'\u0352', /* ͒ */ '\u0357', /* ͗ */ '\u0351', /* ͑ */ '\u0307', /* ̇ */
'\u0308', /* ̈ */ '\u030a', /* ̊ */ '\u0342', /* ͂ */ '\u0343', /* ̓ */
'\u0344', /* ̈́ */ '\u034a', /* ͊ */ '\u034b', /* ͋ */ '\u034c', /* ͌ */
'\u0303', /* ̃ */ '\u0302', /* ̂ */ '\u030c', /* ̌ */ '\u0350', /* ͐ */
'\u0300', /* ̀ */ '\u0301', /* ́ */ '\u030b', /* ̋ */ '\u030f', /* ̏ */
'\u0312', /* ̒ */ '\u0313', /* ̓ */ '\u0314', /* ̔ */ '\u033d', /* ̽ */
'\u0309', /* ̉ */ '\u0363', /* ͣ */ '\u0364', /* ͤ */ '\u0365', /* ͥ */
'\u0366', /* ͦ */ '\u0367', /* ͧ */ '\u0368', /* ͨ */ '\u0369', /* ͩ */
'\u036a', /* ͪ */ '\u036b', /* ͫ */ '\u036c', /* ͬ */ '\u036d', /* ͭ */
'\u036e', /* ͮ */ '\u036f', /* ͯ */ '\u033e', /* ̾ */ '\u035b', /* ͛ */
'\u0346', /* ͆ */ '\u031a' /* ̚ */
];
this.zalgoMid = [
'\u0315', /* ̕ */ '\u031b', /* ̛ */ '\u0340', /* ̀ */ '\u0341', /* ́ */
'\u0358', /* ͘ */ '\u0321', /* ̡ */ '\u0322', /* ̢ */ '\u0327', /* ̧ */
'\u0328', /* ̨ */ '\u0334', /* ̴ */ '\u0335', /* ̵ */ '\u0336', /* ̶ */
'\u034f', /* ͏ */ '\u035c', /* ͜ */ '\u035d', /* ͝ */ '\u035e', /* ͞ */
'\u035f', /* ͟ */ '\u0360', /* ͠ */ '\u0362', /* ͢ */ '\u0338', /* ̸ */
'\u0337', /* ̷ */ '\u0361', /* ͡ */ '\u0489' /* ҉_ */
];
this.zalgoDown = [
'\u0316', /* ̖ */ '\u0317', /* ̗ */ '\u0318', /* ̘ */ '\u0319', /* ̙ */
'\u031c', /* ̜ */ '\u031d', /* ̝ */ '\u031e', /* ̞ */ '\u031f', /* ̟ */
'\u0320', /* ̠ */ '\u0324', /* ̤ */ '\u0325', /* ̥ */ '\u0326', /* ̦ */
'\u0329', /* ̩ */ '\u032a', /* ̪ */ '\u032b', /* ̫ */ '\u032c', /* ̬ */
'\u032d', /* ̭ */ '\u032e', /* ̮ */ '\u032f', /* ̯ */ '\u0330', /* ̰ */
'\u0331', /* ̱ */ '\u0332', /* ̲ */ '\u0333', /* ̳ */ '\u0339', /* ̹ */
'\u033a', /* ̺ */ '\u033b', /* ̻ */ '\u033c', /* ̼ */ '\u0345', /* ͅ */
'\u0347', /* ͇ */ '\u0348', /* ͈ */ '\u0349', /* ͉ */ '\u034d', /* ͍ */
'\u034e', /* ͎ */ '\u0353', /* ͓ */ '\u0354', /* ͔ */ '\u0355', /* ͕ */
'\u0356', /* ͖ */ '\u0359', /* ͙ */ '\u035a', /* ͚ */ '\u0323' /* ̣ */
];
this.defaultSettings = {
corruptionAmount: 1.0,
rampEnd: 0.7,
corruptUp: false,
corruptMid: true,
corruptDown: false
};
}
onStart() {
Logger.log("Started");
Patcher.before(DiscordModules.MessageActions, "sendMessage", (t,a) => {
let content = a[1].content;
let regex = /\{\{(?:(?:(?:(o|b))?,?)?(?:(r)(\d+(?:\.\d+)?)?,?)?(?:(\d+(?:\.\d+)?)-)?(\d+(?:\.\d+)?)?\:)?((?:(?!{{).)*?)\}\}/g;
if (regex.test(content)) {
content = content.replace(regex, this.doZalgo.bind(this));
if (content.length > 2000) {
PluginUtilities.showToast("This message would exceed the 2000-character limit.\nReduce corruption amount or shorten text.\n\nLength including corruption: " + value.length, {type: 'error'});
e.preventDefault();
return;
}
a[1].content = content;
}
});
this.update();
}
onStop() {
Patcher.unpatchAll();
Logger.log("Stopped");
}
getSettingsPanel() {
return Settings.SettingPanel.build(this.saveSettings.bind(this),
new Settings.SettingGroup("Zalgo Settings", {collapsible: false, shown: true}).append(
new Settings.Slider("Corruption amount", "Adjusts how corrupted your text becomes",
0.05, 3.0, this.settings.corruptionAmount, (e) => { this.settings.corruptionAmount = e; }),
new Settings.Slider("Ramp end position", "Adjusts the endpoint of the ramp-in when using the `r` prefix",
0.05, 1.0, this.settings.rampEnd, e => { this.settings.rampEnd = e; }),
new Settings.Switch("Obscure text", "Determines whether zalgo characters are placed over the text or beneath it (use the `o` or `b` prefixes to set this in-line)",
this.settings.corruptMid, e => { this.settings.corruptMid = e; })
)
);
}
observer({ addedNodes, removedNodes }) {
}
update() {
this.initialized = true;
}
getChatTextArea() {
return $(".slateTextArea-1bp44y");
}
doZalgo(match, midMode, ramp, rampEnd, startAmt, endAmt, contents, offset, string) {
const maxAmt = 10;
let hasStart = startAmt >= 0 && startAmt <= maxAmt;
let hasEnd = endAmt >= 0 && endAmt <= maxAmt;
let hasRampEnd = rampEnd >= 0 && rampEnd <= 1;
let corruptMid = midMode == "o" || (midMode != "b" && this.settings.corruptMid);
let doRamp = ramp == "r" || hasStart;
if (!hasRampEnd) rampEnd = this.settings.rampEnd;
// use default end amount if not provided
if (!hasEnd) endAmt = this.settings.corruptionAmount;
// set end/start amounts to equal if we're not ramping anyway
if (!doRamp) startAmt = endAmt;
// otherwise, start at 0 if we are ramping but no start provided
else if (!hasStart) startAmt = 0;
return this.getZalgo(contents, corruptMid, parseFloat(rampEnd), parseFloat(startAmt), parseFloat(endAmt));
}
getZalgo(txt, corruptMid, rampEnd, startAmt, endAmt) {
// Get saved options for corruption directions
let config = this.settings;
let optUp = config.corruptUp;
let optMid = corruptMid;
let optDown = config.corruptDown || (!optUp && !optMid);
let newTxt = "";
let len = txt.length;
if (len == 0) return "";
// Figure out at what index the ramp ends
let rampEndIndex = len * rampEnd;
for (var i = 0; i < len; i++) {
if (this.isZalgoChar(txt.substr(i, 1)))
continue;
// Add the normal character
newTxt += txt.substr(i, 1);
// Normalized value (0-1.0) representing our current position within the ramp
let rampX = rampEndIndex == 0 ? 1 : Math.min(1, i / rampEndIndex);
// Square the ramp value to ease it in
rampX = Math.pow(rampX, 4);
// To determine the final corruption amount at this position
let rampDiff = rampX * (endAmt - startAmt);
let amt = startAmt + rampDiff;
// Modifier of .07 for up/down corruption accounts for the fact that
// discord only displays a small portion of the characters above/below text
let upDownMod = 0.07;
let numUp = amt * (this.rand(64) / 4 + 3) * upDownMod;
let numMid = amt * (this.rand(16) / 4 + 1);
let numDown = amt * (this.rand(64) / 4 + 3) * upDownMod;
// upward zalgo is disabled in current version except through manual config modification
if (optUp)
for (var j = 0; j < numUp; j++)
newTxt += this.randZalgo(this.zalgoUp);
// middle corruption obscures the text itself
if (optMid)
for (var j = 0; j < numMid; j++)
newTxt += this.randZalgo(this.zalgoMid);
// downward corruption begins at the text baseline
if (optDown)
for (var j = 0; j < numDown; j++)
newTxt += this.randZalgo(this.zalgoDown);
}
// HE COMES
return newTxt;
}
// Gets an int between 0 and max
rand(max) {
return Math.floor(Math.random() * max);
}
// Gets a random char from a zalgo char table
randZalgo(array) {
var ind = Math.floor(Math.random() * array.length);
return array[ind];
}
// Lookup char to know if it's a zalgo char or not
isZalgoChar(c) {
var i;
for (i = 0; i < this.zalgoUp.length; i++)
if (c == this.zalgoUp[i])
return true;
for (i = 0; i < this.zalgoDown.length; i++)
if (c == this.zalgoDown[i])
return true;
for (i = 0; i < this.zalgoMid.length; i++)
if (c == this.zalgoMid[i])
return true;
return false;
}
};
};
return plugin(Plugin, Api);
})(global.ZeresPluginLibrary.buildPlugin(config));
})();
/*@end@*/