forked from discord-modifications/better-discord-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTemplate.plugin.js
142 lines (119 loc) · 5.27 KB
/
Template.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
/**
* @name ReplacePluginName
* @source https://github.com/eternal404/better-discord-plugins/blob/master/ReplacePluginName/ReplacePluginName.plugin.js
* @updateUrl https://raw.githubusercontent.com/eternal404/better-discord-plugins/master/ReplacePluginName/ReplacePluginName.plugin.js
* @website https://github.com/eternal404/better-discord-plugins/tree/master/ReplacePluginName/ReplacePluginName.plugin.js
* @authorId 282595588950982656
* @invite shnvz5ryAt
* @donate https://paypal.me/eternal404
*/
/*@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@*/
module.exports = (() => {
const config = {
info: {
name: 'ReplacePluginName',
authors: [
{
name: 'eternal',
discord_id: '282595588950982656',
github_username: 'eternal404'
}
],
version: '1.0.0',
description: 'Description here.',
github: 'https://github.com/eternal404',
github_raw: 'https://raw.githubusercontent.com/eternal404/better-discord-plugins/master/ReplacePluginName/ReplacePluginName.plugin.js'
},
};
return !global.ZeresPluginLibrary ? class {
constructor() {
this.start = this.load = this.handleMissingLib;
}
getName() {
return config.info.name.replace(/\s+/g, '');
}
getAuthor() {
return config.info.authors.map(a => a.name).join(', ');
}
getVersion() {
return config.info.version;
}
getDescription() {
return config.info.description + ' You are missing libraries for this plugin, please enable the plugin and click Download Now.';
}
start() { }
stop() { }
async handleMissingLib() {
const request = require('request');
const path = require('path');
const fs = require('fs');
const dependencies = [
{
global: 'ZeresPluginLibrary',
filename: '0PluginLibrary.plugin.js',
external: 'https://betterdiscord.net/ghdl?url=https://raw.githubusercontent.com/rauenzi/BDPluginLibrary/master/release/0PluginLibrary.plugin.js',
url: 'https://rauenzi.github.io/BDPluginLibrary/release/0PluginLibrary.plugin.js'
}
];
if (!dependencies.map(d => window.hasOwnProperty(d.global)).includes(false)) return;
if (global.eternalModal) {
while (global.eternalModal && dependencies.map(d => window.hasOwnProperty(d.global)).includes(false)) await new Promise(f => setTimeout(f, 1000));
if (!dependencies.map(d => window.hasOwnProperty(d.global)).includes(false)) return BdApi.Plugins.reload(this.getName());
};
global.eternalModal = true;
BdApi.showConfirmationModal(
'Dependencies needed',
`Dependencies needed for ${this.getName()} are missing. Please click download to install the dependecies.`,
{
confirmText: 'Download',
cancelText: 'Cancel',
onCancel: () => delete global.eternalModal,
onConfirm: async () => {
for (const dependency of dependencies) {
if (!window.hasOwnProperty(dependency.global)) {
await new Promise((resolve) => {
request.get(dependency.url, (error, res, body) => {
if (error) return electron.shell.openExternal(dependency.external);
fs.writeFile(path.join(BdApi.Plugins.folder, dependency.filename), body, resolve);
});
});
}
}
delete global.eternalModal;
}
}
);
}
} : (([Plugin, API]) => {
return class extends Plugin {
constructor() {
super();
}
start() {
};
stop() {
};
};
})(ZLibrary.buildPlugin(config));
})();
/*@end@*/