haicord/src/plugins/loadingQuotes/index.ts

100 lines
3.5 KiB
TypeScript
Raw Normal View History

2022-10-29 22:53:23 +02:00
/*
* Vencord, a modification for Discord's desktop app
* Copyright (c) 2022 Vendicated and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2023-10-25 19:47:29 +02:00
import { definePluginSettings } from "@api/Settings";
import { Devs } from "@utils/constants";
import { Logger } from "@utils/Logger";
2023-10-25 19:47:29 +02:00
import definePlugin, { OptionType } from "@utils/types";
import presetQuotesText from "file://quotes.txt";
2022-10-29 22:53:23 +02:00
const presetQuotes = presetQuotesText.split("\n").map(quote => /^\s*[^#\s]/.test(quote) && quote.trim()).filter(Boolean) as string[];
const noQuotesQuote = "Did you really disable all loading quotes? What a buffoon you are...";
2022-10-29 22:53:23 +02:00
2023-10-25 19:47:29 +02:00
const settings = definePluginSettings({
replaceEvents: {
description: "Should this plugin also apply during events with special event themed quotes? (e.g. Halloween)",
2023-10-25 19:47:29 +02:00
type: OptionType.BOOLEAN,
default: true
},
enablePluginPresetQuotes: {
description: "Enable the quotes preset by this plugin",
type: OptionType.BOOLEAN,
default: true
},
enableDiscordPresetQuotes: {
description: "Enable Discord's preset quotes (including event quotes, during events)",
type: OptionType.BOOLEAN,
default: false
},
additionalQuotes: {
description: "Additional custom quotes to possibly appear, separated by the below delimiter",
type: OptionType.STRING,
default: "",
},
additionalQuotesDelimiter: {
description: "Delimiter for additional quotes",
type: OptionType.STRING,
default: "|",
},
2023-10-25 19:47:29 +02:00
});
2022-10-29 22:53:23 +02:00
export default definePlugin({
name: "LoadingQuotes",
description: "Replace Discords loading quotes",
authors: [Devs.Ven, Devs.KraXen72, Devs.UlyssesZhan],
2023-10-25 19:47:29 +02:00
settings,
2022-10-29 22:53:23 +02:00
patches: [
{
find: ".LOADING_DID_YOU_KNOW",
2023-10-25 19:47:29 +02:00
replacement: [
{
match: /"_loadingText".+?(?=(\i)\[.{0,10}\.random)/,
replace: "$&$self.mutateQuotes($1),"
2023-10-25 19:47:29 +02:00
},
{
match: /"_eventLoadingText".+?(?=(\i)\[.{0,10}\.random)/,
replace: "$&$self.mutateQuotes($1),",
2023-10-25 19:47:29 +02:00
predicate: () => settings.store.replaceEvents
}
]
2022-10-29 22:53:23 +02:00
},
],
mutateQuotes(quotes: string[]) {
try {
const { enableDiscordPresetQuotes, additionalQuotes, additionalQuotesDelimiter, enablePluginPresetQuotes } = settings.store;
if (!enableDiscordPresetQuotes)
quotes.length = 0;
if (enablePluginPresetQuotes)
quotes.push(...presetQuotes);
quotes.push(...additionalQuotes.split(additionalQuotesDelimiter).filter(Boolean));
2022-10-29 22:53:23 +02:00
if (!quotes.length)
quotes.push(noQuotesQuote);
} catch (e) {
new Logger("LoadingQuotes").error("Failed to mutate quotes", e);
}
2022-10-29 22:53:23 +02:00
}
});