mirror of
https://github.com/Vendicated/Vencord.git
synced 2025-01-10 09:56:24 +00:00
stuff
This commit is contained in:
parent
4f2a87a610
commit
83c0290549
5 changed files with 98 additions and 67 deletions
|
@ -83,7 +83,7 @@ const Components: Record<OptionType, React.ComponentType<ISettingElementProps<an
|
||||||
[OptionType.SELECT]: SettingSelectComponent,
|
[OptionType.SELECT]: SettingSelectComponent,
|
||||||
[OptionType.SLIDER]: SettingSliderComponent,
|
[OptionType.SLIDER]: SettingSliderComponent,
|
||||||
[OptionType.COMPONENT]: SettingCustomComponent,
|
[OptionType.COMPONENT]: SettingCustomComponent,
|
||||||
[OptionType.LIST]: SettingListComponent,
|
[OptionType.ARRAY]: SettingListComponent,
|
||||||
[OptionType.USERS]: SettingListComponent,
|
[OptionType.USERS]: SettingListComponent,
|
||||||
[OptionType.CHANNELS]: SettingListComponent,
|
[OptionType.CHANNELS]: SettingListComponent,
|
||||||
[OptionType.GUILDS]: SettingListComponent
|
[OptionType.GUILDS]: SettingListComponent
|
||||||
|
|
|
@ -22,7 +22,7 @@ import { Margins } from "@utils/margins";
|
||||||
import { wordsFromCamel, wordsToTitle } from "@utils/text";
|
import { wordsFromCamel, wordsToTitle } from "@utils/text";
|
||||||
import { OptionType, PluginOptionList } from "@utils/types";
|
import { OptionType, PluginOptionList } from "@utils/types";
|
||||||
import { findComponentByCodeLazy } from "@webpack";
|
import { findComponentByCodeLazy } from "@webpack";
|
||||||
import { Button,ChannelStore, Forms, GuildStore, React, useState } from "@webpack/common";
|
import { Button, ChannelStore, Forms, GuildStore, React, TextInput, useState } from "@webpack/common";
|
||||||
|
|
||||||
import { ISettingElementProps } from ".";
|
import { ISettingElementProps } from ".";
|
||||||
import { Channel } from "discord-types/general";
|
import { Channel } from "discord-types/general";
|
||||||
|
@ -35,6 +35,13 @@ const CloseIcon = () => {
|
||||||
</svg>;
|
</svg>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const CheckMarkIcon = () => {
|
||||||
|
return <svg width="24" height="24" viewBox="0 0 24 24">
|
||||||
|
<path fill="currentColor" d="M21.7 5.3a1 1 0 0 1 0 1.4l-12 12a1 1 0 0 1-1.4 0l-6-6a1 1 0 1 1 1.4-1.4L9 16.58l11.3-11.3a1 1 0 0 1 1.4 0Z"></path>
|
||||||
|
</svg>;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
interface UserMentionComponentProps {
|
interface UserMentionComponentProps {
|
||||||
id: string;
|
id: string;
|
||||||
channelId: string;
|
channelId: string;
|
||||||
|
@ -52,30 +59,21 @@ export function SettingListComponent({
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
const [items, setItems] = useState<string[]>([]);
|
const [items, setItems] = useState<string[]>([]);
|
||||||
const [newItem, setNewItem] = useState<string>("");
|
|
||||||
|
|
||||||
const addItem = () => {
|
|
||||||
if (newItem.trim() !== "") {
|
|
||||||
setItems([...items, newItem]);
|
|
||||||
setNewItem("");
|
|
||||||
}
|
|
||||||
pluginSettings[id] = items;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (items.length === 0 && pluginSettings[id].length !== 0) {
|
if (items.length === 0 && pluginSettings[id].length !== 0) {
|
||||||
setItems(pluginSettings[id]);
|
setItems(pluginSettings[id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
const removeItem = (index: number) => {
|
const removeItem = (index: number) => {
|
||||||
|
if (items.length === 1) {
|
||||||
|
setItems([]);
|
||||||
|
pluginSettings[id] = [];
|
||||||
|
return;
|
||||||
|
}
|
||||||
setItems(items.filter((_, i) => i !== index));
|
setItems(items.filter((_, i) => i !== index));
|
||||||
pluginSettings[id] = items;
|
pluginSettings[id] = items;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
function handleChange(newValue) {
|
|
||||||
onChange(newValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
function wrapChannel(id: string) {
|
function wrapChannel(id: string) {
|
||||||
const channel = ChannelStore.getChannel(id) as Channel;
|
const channel = ChannelStore.getChannel(id) as Channel;
|
||||||
if (!channel) {
|
if (!channel) {
|
||||||
|
@ -84,14 +82,31 @@ export function SettingListComponent({
|
||||||
return (GuildStore.getGuild(channel.guild_id)?.name ?? "Unknown Guild") + " - " + channel.name;
|
return (GuildStore.getGuild(channel.guild_id)?.name ?? "Unknown Guild") + " - " + channel.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Pseudocode for handling submit */
|
||||||
|
function handleSubmit() {
|
||||||
|
// Handle the submit action for the specific item
|
||||||
|
// This could involve updating the state, making an API call, etc.
|
||||||
|
// Clear the input field after submission
|
||||||
|
const inputElement = document.getElementById(`vc-plugin-modal-input-${option.type === OptionType.CHANNELS ? "channel" : option.type === OptionType.GUILDS ? "guild" : option.type === OptionType.USERS ? "user" : "string"}`);
|
||||||
|
if (!inputElement || inputElement.value === "") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// TODO add searching for users, channels, and guilds lol
|
||||||
|
setItems([...items, inputElement.value]);
|
||||||
|
pluginSettings[id] = items;
|
||||||
|
inputElement.value = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// FIXME make channels and guilds nicer!
|
// FIXME make channels and guilds nicer!
|
||||||
|
// TODO make string type work
|
||||||
return (
|
return (
|
||||||
<Forms.FormSection>
|
<Forms.FormSection>
|
||||||
<Forms.FormTitle>{wordsToTitle(wordsFromCamel(id))}</Forms.FormTitle>
|
<Forms.FormTitle>{wordsToTitle(wordsFromCamel(id))}</Forms.FormTitle>
|
||||||
<Forms.FormText className={Margins.bottom16} type="description">{option.description}</Forms.FormText>
|
<Forms.FormText className={Margins.bottom16} type="description">{option.description}</Forms.FormText>
|
||||||
<ErrorBoundary noop>
|
<ErrorBoundary noop>
|
||||||
|
<React.Fragment>
|
||||||
{items.map((item, index) => (
|
{items.map((item, index) => (
|
||||||
<React.Fragment key={`${item}-${index}`}>
|
|
||||||
<Flex
|
<Flex
|
||||||
flexDirection="row"
|
flexDirection="row"
|
||||||
style={{
|
style={{
|
||||||
|
@ -111,7 +126,7 @@ export function SettingListComponent({
|
||||||
</span>
|
</span>
|
||||||
// TODO add logo to guild and channel?
|
// TODO add logo to guild and channel?
|
||||||
) : (
|
) : (
|
||||||
<span>{item}</span>
|
<span style={{ color: "white" }}>{item}</span>
|
||||||
)}
|
)}
|
||||||
<Button
|
<Button
|
||||||
size={Button.Sizes.MIN}
|
size={Button.Sizes.MIN}
|
||||||
|
@ -123,9 +138,30 @@ export function SettingListComponent({
|
||||||
<CloseIcon/>
|
<CloseIcon/>
|
||||||
</Button>
|
</Button>
|
||||||
</Flex>
|
</Flex>
|
||||||
</React.Fragment>
|
|
||||||
))}
|
))}
|
||||||
|
<Flex
|
||||||
|
flexDirection="row"
|
||||||
|
style={{
|
||||||
|
gap: "5px",
|
||||||
|
marginTop: "10px",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{/* Add a single input field */}
|
||||||
|
<TextInput
|
||||||
|
type="text"
|
||||||
|
placeholder="Add Item"
|
||||||
|
id={`vc-plugin-modal-input-${option.type === OptionType.CHANNELS ? "channel" : option.type === OptionType.GUILDS ? "guild" : option.type === OptionType.USERS ? "user" : "string"}`}
|
||||||
|
/>
|
||||||
|
{/* Add a submit button */}
|
||||||
|
<Button
|
||||||
|
size={Button.Sizes.MIN}
|
||||||
|
onClick={handleSubmit}
|
||||||
|
style={{ background: "none" }}
|
||||||
|
>
|
||||||
|
<CheckMarkIcon/>
|
||||||
|
</Button>
|
||||||
|
</Flex>
|
||||||
|
</React.Fragment>
|
||||||
</ErrorBoundary>
|
</ErrorBoundary>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { definePluginSettings } from "@api/Settings";
|
import { definePluginSettings, migrateSettingsToArrays } from "@api/Settings";
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
import { Logger } from "@utils/Logger";
|
import { Logger } from "@utils/Logger";
|
||||||
import definePlugin, { OptionType } from "@utils/types";
|
import definePlugin, { OptionType } from "@utils/types";
|
||||||
|
@ -25,6 +25,8 @@ import presetQuotesText from "file://quotes.txt";
|
||||||
const presetQuotes = presetQuotesText.split("\n").map(quote => /^\s*[^#\s]/.test(quote) && quote.trim()).filter(Boolean) as string[];
|
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...";
|
const noQuotesQuote = "Did you really disable all loading quotes? What a buffoon you are...";
|
||||||
|
|
||||||
|
migrateSettingsToArrays("LoadingQuotes", ["additionalQuotes"], "|");
|
||||||
|
|
||||||
const settings = definePluginSettings({
|
const settings = definePluginSettings({
|
||||||
replaceEvents: {
|
replaceEvents: {
|
||||||
description: "Should this plugin also apply during events with special event themed quotes? (e.g. Halloween)",
|
description: "Should this plugin also apply during events with special event themed quotes? (e.g. Halloween)",
|
||||||
|
@ -42,14 +44,8 @@ const settings = definePluginSettings({
|
||||||
default: false
|
default: false
|
||||||
},
|
},
|
||||||
additionalQuotes: {
|
additionalQuotes: {
|
||||||
description: "Additional custom quotes to possibly appear, separated by the below delimiter",
|
description: "Additional custom quotes to possibly appear",
|
||||||
type: OptionType.STRING,
|
type: OptionType.ARRAY,
|
||||||
default: "",
|
|
||||||
},
|
|
||||||
additionalQuotesDelimiter: {
|
|
||||||
description: "Delimiter for additional quotes",
|
|
||||||
type: OptionType.STRING,
|
|
||||||
default: "|",
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -79,16 +75,15 @@ export default definePlugin({
|
||||||
|
|
||||||
mutateQuotes(quotes: string[]) {
|
mutateQuotes(quotes: string[]) {
|
||||||
try {
|
try {
|
||||||
const { enableDiscordPresetQuotes, additionalQuotes, additionalQuotesDelimiter, enablePluginPresetQuotes } = settings.store;
|
const { enableDiscordPresetQuotes, additionalQuotes, enablePluginPresetQuotes } = settings.store;
|
||||||
|
|
||||||
if (!enableDiscordPresetQuotes)
|
if (!enableDiscordPresetQuotes)
|
||||||
quotes.length = 0;
|
quotes.length = 0;
|
||||||
|
|
||||||
|
|
||||||
if (enablePluginPresetQuotes)
|
if (enablePluginPresetQuotes)
|
||||||
quotes.push(...presetQuotes);
|
quotes.push(...presetQuotes);
|
||||||
|
|
||||||
quotes.push(...additionalQuotes.split(additionalQuotesDelimiter).filter(Boolean));
|
quotes.push(...additionalQuotes);
|
||||||
|
|
||||||
if (!quotes.length)
|
if (!quotes.length)
|
||||||
quotes.push(noQuotesQuote);
|
quotes.push(noQuotesQuote);
|
||||||
|
|
|
@ -72,12 +72,12 @@ const settings = definePluginSettings({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
stringRules: {
|
stringRules: {
|
||||||
type: OptionType.LIST,
|
type: OptionType.ARRAY,
|
||||||
hidden: true,
|
hidden: true,
|
||||||
description: ""
|
description: ""
|
||||||
},
|
},
|
||||||
regexRules: {
|
regexRules: {
|
||||||
type: OptionType.LIST,
|
type: OptionType.ARRAY,
|
||||||
hidden: true,
|
hidden: true,
|
||||||
description: ""
|
description: ""
|
||||||
},
|
},
|
||||||
|
|
|
@ -167,7 +167,7 @@ export const enum OptionType {
|
||||||
SELECT,
|
SELECT,
|
||||||
SLIDER,
|
SLIDER,
|
||||||
COMPONENT,
|
COMPONENT,
|
||||||
LIST,
|
ARRAY,
|
||||||
USERS, // List of users
|
USERS, // List of users
|
||||||
CHANNELS, // List of channels
|
CHANNELS, // List of channels
|
||||||
GUILDS, // List of guilds
|
GUILDS, // List of guilds
|
||||||
|
@ -265,7 +265,7 @@ export interface PluginSettingSliderDef {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PluginSettingListDef{
|
export interface PluginSettingListDef{
|
||||||
type: OptionType.LIST | OptionType.CHANNELS | OptionType.GUILDS | OptionType.USERS;
|
type: OptionType.ARRAY | OptionType.CHANNELS | OptionType.GUILDS | OptionType.USERS;
|
||||||
popoutText?: string;
|
popoutText?: string;
|
||||||
hidePopout?: boolean;
|
hidePopout?: boolean;
|
||||||
}
|
}
|
||||||
|
@ -305,7 +305,7 @@ type PluginSettingType<O extends PluginSettingDef> = O extends PluginSettingStri
|
||||||
O extends PluginSettingComponentDef ? any :
|
O extends PluginSettingComponentDef ? any :
|
||||||
O extends PluginSettingListDef ? any[] :
|
O extends PluginSettingListDef ? any[] :
|
||||||
never;
|
never;
|
||||||
type PluginSettingDefaultType<O extends PluginSettingDef> = O extends PluginSettingSelectDef ? (
|
type PluginSettingDefaultType<O extends PluginSettingDef> = O extends PluginSettingListDef ? any[] : O extends PluginSettingSelectDef ? (
|
||||||
O["options"] extends { default?: boolean; }[] ? O["options"][number]["value"] : undefined
|
O["options"] extends { default?: boolean; }[] ? O["options"][number]["value"] : undefined
|
||||||
) : O extends { default: infer T; } ? T : undefined;
|
) : O extends { default: infer T; } ? T : undefined;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue