forked from lofi-nomi/BD-Tone-Indicators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ToneIndicator.plugin.js
311 lines (292 loc) · 14.6 KB
/
ToneIndicator.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
/**
* @name ToneIndicators
* @originalauthor NomadNaomie, Zuri
* @author Daedreus, Merith-TK
* @description Displays the messages tone indicators or by highlighting a tone tag will give you the defintion
* @version 1.4.0
* @source https://github.com/drakosoldier298/BD-Tone-Indicators-extra
* @updateUrl https://raw.githubusercontent.com/drakosoldier298/BD-Tone-Indicators-extra/main/ToneIndicator.plugin.js
*/
module.exports = (_ => {
const toneMap = [
{ tag: ["/j", "joking"], colors: ['#BFFCC6', '#0d7a1a'] },
{ tag: ["/hj", "half joking"], colors: ['#D8FFD6', '#0d7a1a'] },
{ tag: ["/srs", "serious"], colors: ['#6EB5FF', '#29629e'] },
{ tag: ["/nsrs", "not serious"], colors: ['#F6A6FF', '#a639b3'] },
{ tag: ["/lh", "light hearted"], colors: ['#ACE6FF', '#217ca3'] },
{ tag: ["/ij", "inside joke"], colors: ['#E7FFAC', '#6d9114'] },
{ tag: ["/ref", "reference"], colors: ['#AFCBFF', '#144091'] },
{ tag: ["/t", "teasing"], colors: ['#FFFFD1', '##c7c710'] },
{ tag: ["/nm", "not mad"], colors: ['#DCD3FF', '#3d1bc2'] },
{ tag: ["/lu", "a little upset"], colors: ['#FFF5BA', '#8f7c0b'] },
{ tag: ["/nf", "not forced"], colors: ['#DEFDE0', '#089611'] },
{ tag: ["/nbh", "nobody here"], colors: ['#FCF7DE', '#7a6600'] },
{ tag: ["/nsb", "not subtweeting"], colors: ['#DEF3FD', '#00405e'] },
{ tag: ["/nay", "not at you"], colors: ['#F0DEFD', '#7a02d1'] },
{ tag: ["/nav", "not a vent"], colors: ['#00cc99', '#0aAB31'] },
{ tag: ["/ay", "at you"], colors: ['#FDDFDF', '#8c0707'] },
{ tag: ["/nbr", "not being rude"], colors: ['#9ADBB3', '#048a38'] },
{ tag: ["/ot", "off-topic"], colors: ['#E7FFAC', '#476108'] },
{ tag: ["/th", "threat"], colors: ['#FFABAB', '#b50e0e'] },
{ tag: ["/cb", "clickbait"], colors: ['#F3FFE3', '#569106'] },
{ tag: ["/f", "fake"], colors: ['#85E3FF', '#066480'] },
{ tag: ["/c", "copypasta"], colors: ['#DBFFD6', '#1f8c0f'] },
{ tag: ["/m", "metaphor / metaphorically"], colors: ['#FBE4FF', '#750987'] },
{ tag: ["/li", "literal / literally"], colors: ['#BED2FE', '#0a328a'] },
{ tag: ["/hyp", "hyperbole"], colors: ['#F6F9FF', '#2a3c5e'] },
{ tag: ["/p", "platonic"], colors: ['#B5CCFE', '#2260e6'] },
{ tag: ["/r", "romantic"], colors: ['#FFCCF9', '#bf19ac'] },
{ tag: ["/a", "alterous"], colors: ['#C7D9FE', '#1458e3'] },
{ tag: ["/neu", "neutral / neutral connotation"], colors: ['#E3ECFF', '#315ab0'] },
{ tag: ["/g", "/gen", "/genq", "genuine / genuine question"], colors: ['#AFF8D8', '#089c5b'] },
{ tag: ["/s", "/sarc", "sarcastic / sarcasm"], colors: ['#FFCBC1', '#cf3d21'] },
{ tag: ["/l", "/ly", "lyrics"], colors: ['#97A2FF', '#0e1873'] },
{ tag: ["/rt", "/rh", "rhetorical question"], colors: ['#A79AFF', '#1c099c'] },
{ tag: ["/sx", "/x", "sexual intent"], colors: ['#FF9CEE', '#780b65'] },
{ tag: ["/nsx", "/ns", "/nx", "non-sexual intent"], colors: ['#FFBEBC', '#7a201d'] },
{ tag: ["/pc", "/pos", "positive connotation"], colors: ['#84D3B2', '#0e9e62'] },
{ tag: ["/nc", "/neg", "negative connotation"], colors: ['#FFCCBB', '#87452f'] },
{ tag: ["/npa", "/npa", "not passive agressive"], colors: ['#C8A2C8', '#C8A2C8'] },
{ tag: ["/nmay", "/nmay", "not mad at you"], colors: ['#EBA937', '#EBA937'] },
{ tag: ["/v", "vague"], colors: ['#ADD8E6', '#ADD8E6'] },
{ tag: ["/ssx", "slightly sexual intent"], colors: ['#FF9CEE', '#780b65'] },
{ tag: ["/dom", "dominant"], colors: ['#FF9CEE', '#780b65'] },
{ tag: ["/sub", "submissive"], colors: ['#FF9CEE', '#780b65'] },
{ tag: ["/inn", "innuendo"], colors: ['#FFBEBC', '#7a201d'] },
].map(v => { let desc = v.tag.pop(); return [v.tag, desc, v.colors] })
const findResults = (s, furtherSearch, directMatch) => {
if (directMatch) return toneMap.filter(v => v[0].find(x => x === s))[0];
let firstSearch = toneMap.filter(v => v[0].find(x => x.startsWith(s)));
if (firstSearch.length > 0) return firstSearch;
if (furtherSearch) {
let secondSearch = toneMap.filter(v => v[1].includes(s.slice(1)));
if (secondSearch) return secondSearch;
}
return null;
}
const config = {
info: {
name: 'ToneIndicators',
authors: [
{ name: 'Merith', discord_id: '210878074495959040', github_username: 'Merith-TK', website: 'https://merith.xyz'},
{ name: 'Daedreus', discord_id: '188496964030038017', github_username: 'drakosoldier298'},
{ name: 'NomadNaomie', discord_id: '188323207793606656', github_username: 'NomadNaomie', twitter_username: 'NomadNaomie' },
{ name: 'Zuri', discord_id: '746871249791221880', github_username: 'Zuriix', website: "https://zuriix.github.io/" }
],
version: '1.4.0',
description: 'Displays the messages tone indicators or by highlighting a tone tag will give you the defintion',
github_raw: 'https://raw.githubusercontent.com/drakosoldier298/BD-Tone-Indicators-extra/main/ToneIndicator.plugin.js',
github: 'https://github.com/drakosoldier298/BD-Tone-Indicators-extra'
},
changelog: [
{
title: "1.4.0-TK - Fork and add more tones",
type: "fixed",
items: ["just forked the repo and added our own tone indicators, and ran the code through an formatter"]
},
{
title: "1.3.5 - Fixed Another Whitespace Issue",
type: "fixed",
items: ["Fixed an issue where space between slashes and non-tone indicators would be removed."]
},
{
title: "1.3.4 - Fixed autocomplete overriding",
type: "fixed",
items: ["Fixed an issue where autocomplete would override the tone indicator text in instances of multiple indicators per tone."]
},
{
title: "1.3.3 - Fixed Whitespace Issue",
type: "fixed",
items: ["Fixed an issue where tone indicators would not be detected with a space between the slash and indicator"]
},
{
title: "1.3.2 - Fixed Autocomplete",
type: "fixed",
items: ["Fixed Autocomplete not working correctly"]
},
],
defaultConfig: [
/* Corner settings */
{
type: 'category',
id: 'corners',
name: 'Corner settings',
collapsible: true,
shown: false,
settings: [
{ type: "switch", id: "disabled", name: "Remove Corners", default: false },
{ type: "slider", id: "radius", name: "Radius", note: "Changes the corner radius", value: 6 }
]
},
/* Background settings */
{
type: 'category',
id: 'background',
name: 'Background settings',
collapsible: true,
shown: false,
settings: [
{ type: "switch", id: "disabled", name: "Remove Background Color", note: "Removes the background color from indicators in messages.", value: false },
{ type: "slider", id: "transparency", name: "Background Transparency", note: "Changes the transparency of the indicators background color.", value: 10 }
]
},
/* Tooltip settings */
{
type: 'category',
id: 'tooltip',
name: 'Tooltip settings',
collapsible: true,
shown: false,
settings: [
{ type: "switch", id: "bottom", name: "Display tooltip under message", note: "Displays tooltip under the message instead of above it.", value: true }
]
},
/* Indicator settings */
{
type: 'category',
id: 'tonecolor',
name: 'Tone colour settings',
collapsible: true,
shown: false,
settings: [
{ type: "switch", id: "lightmode", name: "Light Mode", note: "Changes the tone indicators to use a light color scheme.", value: false },
{ type: "switch", id: "autochange", name: "Automatic Mode", note: "Changes the tone indicators depending on the current color scheme.", value: true }
]
},
/* Auto Complete Settings */
{
type: 'category',
id: 'autocomplete',
name: 'Auto complete settings',
collapsible: true,
shown: false,
settings: [
{ type: "switch", id: "toneautocomplete", name: "Autocomplete Tones", note: "Suggests tones to use when typing a slash", value: true },
{ type: "slider", id: "tonelistlimit", name: "Suggestion Limit", note: "How many tone suggestions should be given", min: 1, max: 36, value: 6, units: " tones" }
]
},
]
};
if (!global.ZeresPluginLibrary) {
return class { load() { BdApi.showConfirmationModal("Zere's Library Missing", "Either Click Download Now to install it or manually install it. ", { confirmText: "Automatically Install", cancelText: "Cancel", onConfirm: () => { require("request").get("https://rauenzi.github.io/BDPluginLibrary/release/0PluginLibrary.plugin.js", async (error, result, body) => { !error && result.statusCode == 200 && body ? require("fs").writeFile(require("path").join(BdApi.Plugins.folder, "0PluginLibrary.plugin.js"), body, _ => BdApi.showToast("Finished downloading Zere's Plugin Library", { type: "success" })) : BdApi.showToast("Failed to download Zere's Plugin Library", { type: "error" }) }) } }) } };
} else {
return (([Plugin, Zlib]) => {
const { WebpackModules, ContextMenu, Patcher, showToast, React, clearCSS, injectCSS } = { ...Zlib, ...BdApi };
return class ToneIndicators extends Plugin {
generateBackgroundColor(r, e) { let n = "0x" + r.substring(1); return "rgba(" + [n >> 16 & 255, n >> 8 & 255, 255 & n].join(",") + `,${e})` }
getSettingsPanel() { const panel = this.buildSettingsPanel(); return panel.getElement(); }
onStop() {
Patcher.unpatchAll("ToneIndicator");
clearCSS("ToneIndicator");
}
onStart() {
this.onStop(); // Unpatch all and clearCSS, just in case -3-
injectCSS("ToneIndicator", `
.tone-tag {
display: inline-block;
color: var(--tone-color);
background: var(--tone-background);
border-radius: var(--tone-corners);
}`); // Inject CSS
this.injectAutocomplete(); // Inject autocomplete
this.patchContextMenu(); // Patch context menu
this.patchMessageContent(); // Patch message content
}
injectAutocomplete() {
if (!this.settings.autocomplete.toneautocomplete) return;
const Autocomplete = WebpackModules.getByDisplayName('Autocomplete');
WebpackModules.getByProps('AUTOCOMPLETE_OPTIONS').AUTOCOMPLETE_PRIORITY = ["TONES", ...WebpackModules.getByProps('AUTOCOMPLETE_OPTIONS').AUTOCOMPLETE_PRIORITY.filter(v => v != "TONES")];
WebpackModules.getByProps('AUTOCOMPLETE_OPTIONS').AUTOCOMPLETE_OPTIONS.TONES = {
autoSelect: true,
matches: (channel, guild, content) => {
if (!this.settings.autocomplete.toneautocomplete) return false;
if (document.getElementsByClassName(ZLibrary.DiscordClasses.Textarea.textArea)[0].innerText.split(' ').length < 2) return false
if (content.startsWith('/')) return true;
return false;
},
queryResults: (channel, guild, content) => {
if (!content) return;
let res = findResults(content, true).slice(0, Math.floor(this.settings.autocomplete.tonelistlimit));
if (!res) return;
return { results: { ret: res.map(x => { return { name: x[1], desc: x[0], color: x[2][false ? 1 : 0], content: content } }) } };
},
renderResults: data => {
return [React.createElement(Autocomplete.Title, { title: ["Tone Indicator"] }),
data.results.ret.map((tag, i) => React.createElement(Autocomplete.Generic, {
index: i,
text: React.createElement('span', { style: { color: tag.color }, children: tag.name }),
description: React.createElement('span', { style: { color: tag.color }, children: tag.desc.join(' ') }),
tag: tag,
onClick: data.onClick,
onHover: data.onHover,
selected: data.selectedIndex === i,
}))
]
},
onSelect: data => { let index = data.results.ret[data.index].desc.findIndex(t => t.startsWith(data.results.ret[data.index].content)); return data.options.insertText(data.results.ret[data.index].desc[index == -1 ? 0 : index]) }
};
}
patchContextMenu() {
ContextMenu.getDiscordMenu("MessageContextMenu").then(menu => {
Patcher.after("ToneIndicator", menu, "default", (_, [props], ret) => {
let textSelection = document.getSelection().toString().replaceAll("/ ", "/").trim();
if (textSelection) {
textSelection = textSelection.match("/") ? textSelection : "/" + textSelection;
let textTag = findResults(textSelection.toLowerCase())[0];
"object" === typeof textTag && ret.props.children.push(ContextMenu.buildMenuItem({
type: "separator"
}), ContextMenu.buildMenuItem({
label: "Tone Indicator",
action: () => showToast(`${textTag[0]} - ${textTag[1]}`)
}))
}
})
})
}
patchMessageContent() {
const MessageContent = WebpackModules.find(e => e.type && "MessageContent" === e.type.displayName);
Patcher.after("ToneIndicator", MessageContent, "type", (_, [props], ret) => {
if (props.message.content && props.message.content.includes("/")) {
let finishedProps = [],
modifiedTags = 0;
ret.props.children[0].forEach(x => typeof x === "string" ? x.split(/(\n)/g).map(y => y.split(/( )/g)).forEach((z) => { z.forEach((e, i) => { e === "/" && z.length > i + 2 && findResults("/" + z[i + 2], false, true) && (z.splice(i, 3, `/${z[i + 2]}`)) }); z.forEach(a => findResults(a, false, true) ? (finishedProps.push(this.createTone(a) || a) && modifiedTags++) : finishedProps.push(a)) }) : finishedProps.push(x));
if (!finishedProps || !modifiedTags) return;
ret.props.children[0] = finishedProps;
}
})
}
createTone(content) {
let result = findResults(content, false, true);
this.settings.tonecolor.autochange && (this.settings.tonecolor.lightmode = !document.getElementsByClassName("theme-dark").length > 0)
if (result) return React.createElement("span", {
class: "tone-tag",
style: {
padding: this.settings.background.disabled ? '1px 1px' : '0px 4px,',
"--tone-color": this.settings.tonecolor.lightmode ? result[2][1] : result[2][0],
"--tone-background": this.settings.background.disabled ? '' : this.generateBackgroundColor(result[2][0], this.settings.background.transparency / 100 || .1),
"--tone-corners": this.settings.corners.disabled ? '' : this.settings.corners.radius + "px",
},
children: React.createElement(WebpackModules.getByProps("TooltipContainer").TooltipContainer, {
position: this.settings.tooltip.bottom ? "bottom" : "top",
class: "tone-tooltip",
text: `${result[1]} (${result[0].join(" or ")})`,
}, content)
})
}
}
})(global.ZeresPluginLibrary.buildPlugin(config));
}
})();
/*
":"
___:____ |"\/"|
,' `. \ /
| O \___/ |
~^~^~^~^~^~^~^~^~^~^~^~^~
_____ _ ___ _ _
|_ _| | | / (_) | |
| | ___ __ _ _ __ ___ | |/ / _| | | ___ _ __
| |/ _ \/ _` | '_ ` _ \| \| | | |/ _ \ '__|
| | __/ (_| | | | | | | |\ \ | | | __/ |
\_/\___|\__,_|_| |_| |_\_| \_/_|_|_|\___|_|
*/