Skip to content

Commit 7eb7911

Browse files
committed
feat(plugin): Plural kit edit
1 parent 7bb8243 commit 7eb7911

File tree

1 file changed

+54
-46
lines changed

1 file changed

+54
-46
lines changed

src/userplugins/pluralKitEdit/index.tsx

+54-46
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,16 @@
1616
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1717
*/
1818

19-
import { NavContextMenuPatchCallback } from "@api/ContextMenu";
2019
import { addButton, removeButton } from "@api/MessagePopover";
21-
import { definePluginSettings } from "@api/Settings";
22-
import { CodeBlock } from "@components/CodeBlock";
2320
import ErrorBoundary from "@components/ErrorBoundary";
24-
import { Flex } from "@components/Flex";
25-
import { Devs } from "@utils/constants";
26-
import { Margins } from "@utils/margins";
2721
import { copyWithToast } from "@utils/misc";
2822
import { closeModal, ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalRoot, ModalSize, openModal } from "@utils/modal";
29-
import definePlugin, { OptionType } from "@utils/types";
30-
import { Button, ChannelStore, Forms, i18n, Menu, Text } from "@webpack/common";
23+
import definePlugin from "@utils/types";
24+
import { Button, ChannelStore, Forms, Text, Toasts } from "@webpack/common";
3125
import { Message } from "discord-types/general";
32-
import { CopyIcon } from "@components/Icons";
26+
import { insertTextIntoChatInputBox } from "@utils/discord";
27+
import { CheckedTextInput } from "@components/CheckedTextInput";
28+
import { EdgeIcon } from "../../plugins/betterSessions/components/icons";
3329

3430
export default definePlugin({
3531
name: "Plural Kit Edit",
@@ -39,9 +35,14 @@ export default definePlugin({
3935
addButton("EditPluralkit", msg => {
4036
const handleClick = () => {
4137
const pk = msg.author.bot && msg.author.discriminator === "0000";
42-
const pkData = pk ? msg.content : "";
4338
if (pk) {
44-
openViewRawModal(pkData, "PluralKit", msg.content);
39+
openViewRawModal(msg);
40+
} else {
41+
Toasts.show({
42+
message: "This message was not sent by PluralKit",
43+
id: Toasts.genId(),
44+
type: Toasts.Type.FAILURE
45+
});
4546
}
4647
};
4748

@@ -50,14 +51,10 @@ export default definePlugin({
5051
e.stopPropagation();
5152
};
5253

53-
const label = "Edit PluralKit"
54-
5554
return {
56-
label,
57-
icon: (props, context) => {
58-
return <svg viewBox={
59-
"0 0 20 20"
60-
} fill="currentColor" aria-hidden="true" width="18" height="18" {...props}></svg>
55+
label: "Edit PluralKit",
56+
icon: () => {
57+
return <EdgeIcon/>;
6158
},
6259
message: msg,
6360
channel: ChannelStore.getChannel(msg.channel_id),
@@ -71,35 +68,46 @@ export default definePlugin({
7168
},
7269
});
7370

74-
function openViewRawModal(json: string, type: string, msgContent?: string) {
71+
function openViewRawModal(msg?: Message) {
72+
if (!msg) return;
73+
const message = msg;
74+
var result: string = message.content;
7575
const key = openModal(props => (
7676
<ErrorBoundary>
77-
<ModalRoot {...props} size={ModalSize.LARGE}>
78-
<ModalHeader>
79-
<Text variant="heading-lg/semibold" style={{ flexGrow: 1 }}>View Raw</Text>
80-
<ModalCloseButton onClick={() => closeModal(key)} />
81-
</ModalHeader>
82-
<ModalContent>
83-
<div style={{ padding: "16px 0" }}>
84-
{!!msgContent && (
85-
<>
86-
<Forms.FormTitle tag="h5">Content</Forms.FormTitle>
87-
<CodeBlock content={msgContent} lang="" />
88-
<Forms.FormDivider className={Margins.bottom20} />
89-
</>
90-
)}
77+
<ModalRoot {...props} size={ModalSize.MEDIUM}>
78+
<ModalHeader>
79+
<Text variant="heading-lg/semibold" style={{ flexGrow: 1 }}>EDIT MESSAGE</Text>
80+
<ModalCloseButton onClick={() => closeModal(key)}/>
81+
</ModalHeader>
82+
<ModalContent>
83+
<div style={{ padding: "16px 0" }}>
84+
{!!message.content && (
85+
<>
86+
<Forms.FormTitle tag="h5">Content</Forms.FormTitle>
87+
<CheckedTextInput value={message.content} onChange={newValue => result = newValue}
88+
validate={() => true}></CheckedTextInput>
89+
</>
90+
)}
91+
</div>
92+
</ModalContent>
93+
<ModalFooter>
94+
<Button onClick={() => copyWithToast(message.content, `Content copied to clipboard!`)}>
95+
Copy
96+
</Button>
97+
<Button onClick={() => {
98+
closeModal(key)
99+
insertTextIntoChatInputBox("pk;edit " + getMessageLink(message) + " " + result)
100+
}}>
101+
Submit
102+
</Button>
103+
</ModalFooter>
104+
</ModalRoot>
105+
</ErrorBoundary>
106+
));
107+
}
108+
109+
function getMessageLink(msg: Message) {
110+
var guildId = ChannelStore.getChannel(msg.channel_id).getGuildId();
91111

92-
<Forms.FormTitle tag="h5">{type} Data</Forms.FormTitle>
93-
</div>
94-
</ModalContent >
95-
<ModalFooter>
96-
<Flex cellSpacing={10}>
97-
<Button onClick={() => copyWithToast(json, `${type} data copied to clipboard!`)}>
98-
Copy {type} JSON
99-
</Button>
100-
</Flex>
101-
</ModalFooter>
102-
</ModalRoot >
103-
</ErrorBoundary >
104-
));
112+
return `https://discord.com/channels/${guildId}/${msg.channel_id}/${msg.id}`;
105113
}

0 commit comments

Comments
 (0)