Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
189 lines (170 loc) · 5.46 KB
/
Copy pathindex.js
File metadata and controls
189 lines (170 loc) · 5.46 KB
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
const { Plugin } = require('powercord/entities');
const { React, getModule, constants: { ComponentActions } } = require('powercord/webpack');
// const fs = require('fs');
// const path = require('path');
// const Settings = require('./components/Settings');
// const { openURL } = getModule([ 'openURL' ], false);
// const { ComponentDispatch } = getModule([ 'ComponentDispatch' ], false);
module.exports = class Share extends Plugin {
startPlugin () {
powercord.api.notices.sendAnnouncement("share-plugins-deprecation", {
color: "red",
message: React.createElement(
"div",
null,
"Share Plugins has been deprecated as it has been merged with ",
React.createElement(
"a",
{ href: "https://replugged.dev" },
"replugged core"
),
"."
),
button: {
onClick: () => powercord.pluginManager.disable("share-plugins"),
text: "Disable the plugin"
}
});
return;
powercord.api.settings.registerSettings(this.entityID, {
category: this.entityID,
label: 'Share Plugins',
render: (p) =>
React.createElement(Settings, { ...p })
});
powercord.api.commands.registerCommand({
command: 'share_plugin',
usage: '{c} [plugin name]',
description: 'Share a plugin you have in the chat',
executor: this.sharePlugin.bind(this),
autocomplete: this.autocompletePlugins.bind(this)
});
powercord.api.commands.registerCommand({
command: 'share_theme',
usage: '{c} [theme name]',
description: 'Share a theme you have in the chat',
executor: this.shareTheme.bind(this),
autocomplete: this.autocompleteThemes.bind(this)
});
}
pluginWillUnload () {
return;
powercord.api.settings.unregisterSettings(this.entityID);
powercord.api.commands.unregisterCommand('share_plugin');
powercord.api.commands.unregisterCommand('share_theme');
}
formatUrl (url) {
return url
.replace('.git', '')
.replace('git@github.com:', 'https://github.com/')
.replace('url = ', '');
}
share (data, args) {
data = data.split('\n').map(e => e.trim());
let url = '';
for (let i = 0; i < data.length; i++) {
if (data[i].startsWith('url = ')) {
url = this.formatUrl(data[i]);
break;
}
}
if (url !== '') {
if (args.includes('--open')) {
openURL(url);
return;
}
if ((this.settings.get('repo', false) && !args.includes('--no-repo')) || args.includes('--repo')) {
if ((this.settings.get('linkEmbed', false) || args.includes('--no-embed')) && !args.includes('--embed')) {
url = `<${url}>`;
}
} else {
url = `<https://replugged.dev/install?url=${url}>`;
}
if (args.includes('--no-send')) {
this.appendText(url);
return;
}
return {
send: true,
result: url
};
}
return { result: 'Unable to find a url in the .git config file.' };
}
sharePlugin ([ id, ...args ]) {
if (powercord.pluginManager.plugins.has(id)) {
const plugin = powercord.pluginManager.plugins.get(id);
try {
const data = fs.readFileSync(path.resolve(plugin.entityPath, '.git', 'config'), 'utf8');
return this.share(data, args);
} catch (err) {
console.log(err);
return { result: 'Unable to find the plugin\'s .git folder.' };
}
}
}
shareTheme ([ id, ...args ]) {
if (powercord.styleManager.themes.has(id)) {
const theme = powercord.styleManager.themes.get(id);
try {
const data = fs.readFileSync(path.resolve(theme.entityPath, '.git', 'config'), 'utf8');
return this.share(data, args);
} catch (err) {
console.log(err);
return { result: 'Unable to find the theme\'s .git folder.' };
}
}
}
processName (name) {
return name
.toLowerCase()
.replace(/[\s-_]/g, '');
}
filterMatches (matches, query) {
query = this.processName(query);
return [ ...matches ]
.filter(([ id ]) => this.processName(id).includes(query) && !id.startsWith('pc-'))
.map(([ id ]) => ({ command: id }));
}
autocompleteFlags (args) {
const lastArg = args[args.length - 1].toLowerCase();
if (!lastArg.startsWith('-')) {
return false;
}
const flags = [ '--repo', '--no-repo', '--open', '--no-send', '--embed', '--no-embed' ];
return {
commands: flags.filter(flag => flag.startsWith(lastArg) && !args.includes(flag))
.map(x => ({ command: x })),
header: 'options list'
};
}
autocompletePlugins ([ findId, ...args ]) {
if (args.length) {
return this.autocompleteFlags(args);
}
return {
commands: this.filterMatches(powercord.pluginManager.plugins, findId),
header: 'plugins list'
};
}
autocompleteThemes ([ findId, ...args ]) {
if (args.length) {
return this.autocompleteFlags(args);
}
return {
commands: this.filterMatches(powercord.styleManager.themes, findId),
header: 'themes list'
};
}
appendText (text) {
ComponentDispatch.dispatchToLastSubscribed(
ComponentActions.TEXTAREA_FOCUS
);
setTimeout(() => {
ComponentDispatch.dispatchToLastSubscribed(ComponentActions.INSERT_TEXT, {
plainText: text,
rawText: text
});
}, 0);
}
};