16
16
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17
17
*/
18
18
19
- import { NavContextMenuPatchCallback } from "@api/ContextMenu" ;
20
19
import { addButton , removeButton } from "@api/MessagePopover" ;
21
- import { definePluginSettings } from "@api/Settings" ;
22
- import { CodeBlock } from "@components/CodeBlock" ;
23
20
import ErrorBoundary from "@components/ErrorBoundary" ;
24
- import { Flex } from "@components/Flex" ;
25
- import { Devs } from "@utils/constants" ;
26
- import { Margins } from "@utils/margins" ;
27
21
import { copyWithToast } from "@utils/misc" ;
28
22
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" ;
31
25
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" ;
33
29
34
30
export default definePlugin ( {
35
31
name : "Plural Kit Edit" ,
@@ -39,9 +35,14 @@ export default definePlugin({
39
35
addButton ( "EditPluralkit" , msg => {
40
36
const handleClick = ( ) => {
41
37
const pk = msg . author . bot && msg . author . discriminator === "0000" ;
42
- const pkData = pk ? msg . content : "" ;
43
38
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
+ } ) ;
45
46
}
46
47
} ;
47
48
@@ -50,14 +51,10 @@ export default definePlugin({
50
51
e . stopPropagation ( ) ;
51
52
} ;
52
53
53
- const label = "Edit PluralKit"
54
-
55
54
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 /> ;
61
58
} ,
62
59
message : msg ,
63
60
channel : ChannelStore . getChannel ( msg . channel_id ) ,
@@ -71,35 +68,46 @@ export default definePlugin({
71
68
} ,
72
69
} ) ;
73
70
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 ;
75
75
const key = openModal ( props => (
76
76
< 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 ( ) ;
91
111
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 } ` ;
105
113
}
0 commit comments