-
Notifications
You must be signed in to change notification settings - Fork 0
/
OwOcord.plugin.js
325 lines (304 loc) · 11.2 KB
/
OwOcord.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
/**
* @name OwOcord
* @author PrinceBunBun981
* @authorId 644298972420374528
* @description Changes various things on your client to be *perfect*. (ノ◕ヮ◕)ノ*:・゚✧
* @version 1.1.2
* @source https://github.com/PrinceBunBun981/BetterDiscordPlugins
* @updateUrl https://raw.githubusercontent.com/PrinceBunBun981/BetterDiscordPlugins/main/OwOcord.plugin.js
*/
/*@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@*/
/*
* Vanilla Discord Client script by Ben - https://gist.github.com/Benricheson101/6a16ff2c1f1c208ac1e17e3f9571e66d#file-discord-owo-js (255834596766253057)
* Modified to work with BetterDiscord and allow for specific options:
* - Enable/Disable String Translations
* - Enable/Disable Guild Name Translations
* - Enable/Disable Channel Name Translations
*/
const FACE_CHANCE = 40;
const faces = [
'(o´∀`o)',
'(#`ε´)',
'(๑•̀ㅁ•́๑)✧',
'(*≧m≦*)',
'(・`ω´・)',
'UwU',
'OwO',
'>w<',
'。゚( ゚^∀^゚)゚。',
'ヾ(`ε´)ノ',
'(´• ω •`)',
'o(>ω<)o',
'(ノ◕ヮ◕)ノ*:・゚✧',
'(⁀ᗢ⁀)',
'( ̄ε ̄@)',
'( 〃▽〃)',
'(o^ ^o)',
"ヾ(*'▽'*)",
];
/**
* OwOify a string.
* @param {String} str The string to OwOify.
* @returns The OwOified string.
*/
function transform(str) {
let out = '';
let level = 0;
const chars = str.split('');
for (let i = 0; i < chars.length; i++) {
switch (chars[i]) {
case '(':
case '{':
out += chars[i];
level++;
break;
case ')':
case '}':
out += chars[i];
level--;
break;
case '!': {
out += chars[i];
if (
level !== 0 ||
!(
chars[i - 1] !== '}' &&
chars[i - 2] !== '}' &&
chars[i + 1] !== '{' &&
chars[i + 2] !== '{'
) ||
chars[i + 1] === '!'
) {
break;
}
const face = faces[Math.floor(Math.random() * faces.length)];
out += ' ' + face + ' ';
continue;
}
default: {
if (level == 0) {
out += chars[i].replace(/[rl]/g, 'w').replace(/[RL]/g, 'W');
} else {
out += chars[i];
}
break;
}
}
if (i === chars.length - 1) {
if (Math.floor(Math.random() * 100) < FACE_CHANCE) {
const face = faces[Math.floor(Math.random() * faces.length)];
out += ' ' + face;
}
}
}
return out.trim();
};
const config = {
"main": "index.js",
"info": {
"name": "OwOcord",
"authors": [{
"name": "PrinceBunBun981",
"discord_id": "644298972420374528",
"github_username": "PrinceBunBun981",
}],
"version": "1.1.2",
"description": transform("Changes various things on your client to be *perfect*."),
"github": "https://github.com/PrinceBunBun981/BetterDiscordPlugins",
"github_raw": "https://raw.githubusercontent.com/PrinceBunBun981/BetterDiscordPlugins/main/OwOcord.plugin.js"
},
"defaultConfig": [{
"type": "switch",
"id": "transformStrings",
"name": "Discord Strings",
"note": transform("OwOify Discord messages to be perfect."),
"value": true
},
{
"type": "switch",
"id": "transformGuilds",
"name": "Guild Names",
"note": transform("OwOify names for servers you're in to be perfect."),
"value": true
},
{
"type": "switch",
"id": "transformChannels",
"name": "Channel Names",
"note": transform("OwOify channel names in servers to be perfect."),
"value": true
},
{
"type": "switch",
"id": "transformSentMessages",
"name": "Sent Messages",
"note": transform("OwOify messages that you send."),
"value": true
}
]};
let settings = BdApi.loadData(config.info.name, `settings`);
class Dummy {
constructor() {this._config = config;}
start() {}
stop() {}
}
if (!global.ZeresPluginLibrary) {
BdApi.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.app/Download?id=9");
await new Promise(r => require("fs").writeFile(require("path").join(BdApi.Plugins.folder, "0PluginLibrary.plugin.js"), body, r));
});
}
});
}
module.exports = !global.ZeresPluginLibrary ? Dummy : (([Plugin, Api]) => {
const plugin = (Plugin, Library) => {
const {Logger, Patcher, DiscordModules} = Library;
const language = BdApi.findModuleByProps("getLanguages", "Messages");
const provider = language._provider;
const strs = BdApi.findModuleByProps("COMMAND_NICK_SUCCESS");
const defaultStrs = provider._context.defaultMessages;
const GuildStore = BdApi.findModuleByProps("getGuildCount");
const ChannelStore = BdApi.findModuleByProps("getMutableGuildChannelsForGuild");
let newStrs = {...strs};
let newDefaultStrs = {...defaultStrs}
/**
* OwOifies all Discord strings.
*/
function transformStrings() {
newStrs = Object.fromEntries(
Object.entries(newStrs).map(([name, str]) =>
typeof str === 'string' ? [name, transform(str)] : [name, str]
)
);
console.log(newStrs);
provider.refresh({
messages: newStrs,
defaultMessages: newDefaultStrs,
locale: 'en-US',
});
}
/**
* Resets Discord strings to their defaults.
*/
function resetStrings() {
provider.refresh({
messages: strs,
defaultMessages: newDefaultStrs,
locale: 'en-US',
});
}
/**
* OwOifies guild and/or channel names.
* @param {Boolean} transformGuilds OwOify guild names?
* @param {Boolean} transformChannels OwOify channel names?
*/
function transformGuildsAndChannels(transformGuilds, transformChannels) {
Object.values(GuildStore.getGuilds()).forEach(g => {
if (transformGuilds) {
g.oldName = g.name;
g.name = transform(g.name);
}
if (transformChannels) {
var channels = ChannelStore.getMutableGuildChannelsForGuild(g.id);
if (channels) {
Object.values(channels).forEach(c => {
c.oldName = c.name;
c.name = transform(c.name);
});
}
}
});
}
/**
* Resets guild and/or channel names.
* @param {Boolean} transformGuilds Reset guild names?
* @param {Boolean} transformChannels Reset channel names?
*/
function resetGuildsAndChannels(transformGuilds, transformChannels) {
Object.values(GuildStore.getGuilds()).forEach(g => {
if (transformGuilds) {
if (g.oldName && g.name != g.oldName) g.name = g.oldName;
}
if (transformChannels) {
var channels = ChannelStore.getMutableGuildChannelsForGuild(g.id);
if (channels) {
Object.values(channels).forEach(c => {
if (c.oldName && c.name != c.oldName) c.name = c.oldName;
});
}
}
});
}
return class OwO extends Plugin {
onStart() {
Logger.log("Started");
if (settings.transformStrings) setTimeout(() => {transformStrings()}, 5000);
transformGuildsAndChannels(settings.transformGuilds, settings.transformChannels);
Patcher.after(DiscordModules.MessageActions, "sendMessage", (_, [, message]) => {
if (settings.transformSentMessages) message.content = transform(message.content);
});
}
onStop() {
Logger.log("Stopped");
resetStrings();
resetGuildsAndChannels(true, true);
Patcher.unpatchAll();
}
getSettingsPanel() {
const panel = this.buildSettingsPanel();
panel.addListener((id, checked) => {
switch (id) {
case "transformStrings":
if (checked) {
transformStrings();
} else {
resetStrings();
}
break;
case "transformGuilds":
if (checked) {
transformGuildsAndChannels(true, false);
} else {
resetGuildsAndChannels(true, false);
}
break;
case "transformChannels":
if (checked) {
transformGuildsAndChannels(false, true);
} else {
resetGuildsAndChannels(false, true);
}
break;
}
settings = BdApi.loadData(config.info.name, `settings`);
});
return panel.getElement();
}
};
};
return plugin(Plugin, Api);})(global.ZeresPluginLibrary.buildPlugin(config));
/*@end@*/