2020-10-20 23:25:34 +02:00
/ * *
* @ name CustomQuoter
2021-03-05 13:26:41 +01:00
* @ author DevilBro
2020-10-20 23:25:34 +02:00
* @ authorId 278543574059057154
2022-10-17 22:41:39 +02:00
* @ version 1.3 . 1
2021-03-05 13:26:41 +01:00
* @ description Brings back the Quote Feature and allows you to set your own Quote Formats
2020-10-20 23:25:34 +02:00
* @ invite Jx3TjNS
2020-11-19 16:45:36 +01:00
* @ donate https : //www.paypal.me/MircoWittrien
* @ patreon https : //www.patreon.com/MircoWittrien
2021-03-09 15:10:55 +01:00
* @ website https : //mwittrien.github.io/
* @ source https : //github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/CustomQuoter/
2021-03-10 09:17:37 +01:00
* @ updateUrl https : //mwittrien.github.io/BetterDiscordAddons/Plugins/CustomQuoter/CustomQuoter.plugin.js
2020-10-20 23:25:34 +02:00
* /
2020-02-23 18:55:20 +01:00
2020-09-19 20:49:33 +02:00
module . exports = ( _ => {
2022-09-01 14:40:11 +02:00
const changeLog = {
2022-09-02 12:37:10 +02:00
2020-02-23 19:40:36 +01:00
} ;
2020-11-13 19:47:44 +01:00
2022-02-05 21:14:17 +01:00
return ! window . BDFDB _Global || ( ! window . BDFDB _Global . loaded && ! window . BDFDB _Global . started ) ? class {
2022-09-01 14:55:22 +02:00
constructor ( meta ) { for ( let key in meta ) this [ key ] = meta [ key ] ; }
getName ( ) { return this . name ; }
getAuthor ( ) { return this . author ; }
getVersion ( ) { return this . version ; }
getDescription ( ) { return ` The Library Plugin needed for ${ this . name } is missing. Open the Plugin Settings to download it. \n \n ${ this . description } ` ; }
2021-02-01 17:13:13 +01:00
downloadLibrary ( ) {
require ( "request" ) . get ( "https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js" , ( e , r , b ) => {
2021-03-05 13:14:18 +01:00
if ( ! e && b && r . statusCode == 200 ) require ( "fs" ) . writeFile ( require ( "path" ) . join ( BdApi . Plugins . folder , "0BDFDB.plugin.js" ) , b , _ => BdApi . showToast ( "Finished downloading BDFDB Library" , { type : "success" } ) ) ;
2021-03-06 14:59:48 +01:00
else BdApi . alert ( "Error" , "Could not download BDFDB Library Plugin. Try again later or download it manually from GitHub: https://mwittrien.github.io/downloader/?library" ) ;
2021-02-01 17:13:13 +01:00
} ) ;
}
2020-09-19 20:49:33 +02:00
2021-01-06 12:38:36 +01:00
load ( ) {
2020-11-19 16:51:14 +01:00
if ( ! window . BDFDB _Global || ! Array . isArray ( window . BDFDB _Global . pluginQueue ) ) window . BDFDB _Global = Object . assign ( { } , window . BDFDB _Global , { pluginQueue : [ ] } ) ;
2020-09-19 20:49:33 +02:00
if ( ! window . BDFDB _Global . downloadModal ) {
window . BDFDB _Global . downloadModal = true ;
2022-09-01 14:55:22 +02:00
BdApi . showConfirmationModal ( "Library Missing" , ` The Library Plugin needed for ${ this . name } is missing. Please click "Download Now" to install it. ` , {
2020-09-19 20:49:33 +02:00
confirmText : "Download Now" ,
cancelText : "Cancel" ,
onCancel : _ => { delete window . BDFDB _Global . downloadModal ; } ,
2020-09-20 08:15:13 +02:00
onConfirm : _ => {
delete window . BDFDB _Global . downloadModal ;
2021-02-01 17:13:13 +01:00
this . downloadLibrary ( ) ;
2020-09-20 08:15:13 +02:00
}
2020-09-19 20:49:33 +02:00
} ) ;
}
2022-09-01 14:55:22 +02:00
if ( ! window . BDFDB _Global . pluginQueue . includes ( this . name ) ) window . BDFDB _Global . pluginQueue . push ( this . name ) ;
2020-10-09 21:09:35 +02:00
}
2021-01-06 12:38:36 +01:00
start ( ) { this . load ( ) ; }
stop ( ) { }
getSettingsPanel ( ) {
2020-11-28 23:12:09 +01:00
let template = document . createElement ( "template" ) ;
2022-09-01 14:55:22 +02:00
template . innerHTML = ` <div style="color: var(--header-primary); font-size: 16px; font-weight: 300; white-space: pre; line-height: 22px;">The Library Plugin needed for ${ this . name } is missing. \n Please click <a style="font-weight: 500;">Download Now</a> to install it.</div> ` ;
2021-02-01 17:13:13 +01:00
template . content . firstElementChild . querySelector ( "a" ) . addEventListener ( "click" , this . downloadLibrary ) ;
2020-11-28 23:12:09 +01:00
return template . content . firstElementChild ;
}
2020-10-09 21:09:35 +02:00
} : ( ( [ Plugin , BDFDB ] ) => {
2022-10-17 22:41:39 +02:00
var _this , ChannelTextAreaContainer ;
2021-03-08 17:00:32 +01:00
var formats = { } , format = null ;
2020-09-19 20:49:33 +02:00
const PreviewMessageComponent = class PreviewMessage extends BdApi . React . Component {
2021-01-20 16:00:29 +01:00
render ( ) {
2020-09-19 20:49:33 +02:00
let spoofChannel = new BDFDB . DiscordObjects . Channel ( {
id : "126223823845647771" ,
guild _id : "850725684241078788" ,
"name" : "Test Channel"
} ) ;
let spoofQuotedMessage = new BDFDB . DiscordObjects . Message ( {
id : "562432230424221059" ,
author : new BDFDB . DiscordObjects . User ( {
id : "230422432565221049" ,
username : "Quoted User"
2020-07-01 16:37:43 +02:00
} ) ,
2020-09-19 20:49:33 +02:00
channel _id : spoofChannel . id ,
content : "This is a test message\nto showcase what the quote would look like"
} ) ;
let spoofMessage = new BDFDB . DiscordObjects . Message ( {
author : new BDFDB . DiscordObjects . User ( {
id : "222242304256531049" ,
username : "Test User"
2020-07-01 16:37:43 +02:00
} ) ,
2020-09-19 20:49:33 +02:00
channel _id : spoofChannel . id ,
content : _this . parseQuote ( spoofQuotedMessage , spoofChannel , this . props . format )
} ) ;
2020-12-02 20:04:03 +01:00
return BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . messagepopout ,
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . MessageGroup , {
disableInteraction : true ,
message : spoofMessage ,
channel : spoofChannel
} )
2020-09-19 20:49:33 +02:00
} ) ;
2020-02-23 18:55:20 +01:00
}
2020-09-19 20:49:33 +02:00
} ;
2020-10-09 21:09:35 +02:00
return class CustomQuoter extends Plugin {
2021-01-06 12:38:36 +01:00
onLoad ( ) {
2020-09-19 20:49:33 +02:00
_this = this ;
2020-02-23 18:55:20 +01:00
2022-10-17 22:41:39 +02:00
this . modulePatches = {
before : [
"ChannelTextAreaContainer"
] ,
after : [
"MessageActionsContextMenu" ,
"MessageToolbar"
]
2021-03-08 17:00:32 +01:00
} ;
2020-09-19 20:49:33 +02:00
this . defaults = {
2021-03-08 17:00:32 +01:00
general : {
2021-03-19 22:13:42 +01:00
autoAddNewLine : { value : true , description : "Try to add New Lines before/after Quotes" } ,
holdShiftToolbar : { value : false , description : "Need to hold Shift on a Message to show Quick Quote" } ,
alwaysCopy : { value : false , description : "Always copy Quote to Clipboard without holding Shift" }
} ,
dates : {
quoteDate : { value : { } , description : "Message Timestamp" } ,
2020-09-19 20:49:33 +02:00
}
} ;
}
2021-01-06 12:38:36 +01:00
onStart ( ) {
2020-06-10 19:21:54 +02:00
this . forceUpdateAll ( ) ;
2020-02-23 18:55:20 +01:00
}
2020-09-19 20:49:33 +02:00
2021-01-06 12:38:36 +01:00
onStop ( ) { }
2020-02-23 18:55:20 +01:00
2020-09-19 20:49:33 +02:00
getSettingsPanel ( collapseStates = { } ) {
2020-11-22 18:52:32 +01:00
let settingsPanel ;
return settingsPanel = BDFDB . PluginUtils . createSettingsPanel ( this , {
2020-09-19 20:49:33 +02:00
collapseStates : collapseStates ,
2020-11-22 18:52:32 +01:00
children : _ => {
let settingsItems = [ ] ;
settingsItems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . CollapseContainer , {
title : "Settings" ,
collapseStates : collapseStates ,
2021-03-13 10:45:12 +01:00
children : Object . keys ( this . defaults . general ) . map ( key => BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsSaveItem , {
2020-11-22 18:52:32 +01:00
type : "Switch" ,
plugin : this ,
2021-03-08 17:01:20 +01:00
keys : [ "general" , key ] ,
label : this . defaults . general [ key ] . description ,
value : this . settings . general [ key ]
2021-03-19 22:13:42 +01:00
} ) ) . concat ( Object . keys ( this . defaults . dates ) . map ( key => BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . DateInput , Object . assign ( { } , this . settings . dates [ key ] , {
label : this . defaults . dates [ key ] . description ,
onChange : valueObj => {
this . SettingsUpdated = true ;
this . settings . dates [ key ] = valueObj ;
BDFDB . DataUtils . save ( this . settings . dates , this , "dates" ) ;
}
} ) ) ) )
2020-11-22 18:52:32 +01:00
} ) ) ;
settingsItems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . CollapseContainer , {
title : "Formats" ,
collapseStates : collapseStates ,
2020-09-19 20:49:33 +02:00
children : [
2020-11-22 18:52:32 +01:00
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Flex , {
className : BDFDB . disCN . marginbottom8 ,
align : BDFDB . LibraryComponents . Flex . Align . END ,
children : [
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Flex . Child , {
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . FormComponents . FormItem , {
title : "Name:" ,
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . TextInput , {
className : "input-newquote input-name" ,
value : "" ,
placeholder : "Formatname"
} )
} )
} ) ,
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Flex . Child , {
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . FormComponents . FormItem , {
title : "Quote:" ,
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . TextInput , {
className : "input-newquote input-quote" ,
value : "" ,
placeholder : "Quote"
} )
} )
} ) ,
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Button , {
style : { marginBottom : 1 } ,
onClick : _ => {
for ( let input of settingsPanel . props . _node . querySelectorAll ( ".input-newquote " + BDFDB . dotCN . input ) ) if ( ! input . value || input . value . length == 0 || input . value . trim ( ) . length == 0 ) return BDFDB . NotificationUtils . toast ( "Fill out all fields to add a new quote." , { type : "danger" } ) ;
let key = settingsPanel . props . _node . querySelector ( ".input-name " + BDFDB . dotCN . input ) . value . trim ( ) ;
let quote = settingsPanel . props . _node . querySelector ( ".input-quote " + BDFDB . dotCN . input ) . value . trim ( ) ;
if ( formats [ key ] ) return BDFDB . NotificationUtils . toast ( "A quote with the choosen name already exists, please choose another name" , { type : "danger" } ) ;
else {
formats [ key ] = quote ;
BDFDB . DataUtils . save ( formats , this , "formats" ) ;
BDFDB . PluginUtils . refreshSettingsPanel ( this , settingsPanel , collapseStates ) ;
}
} ,
children : BDFDB . LanguageUtils . LanguageStrings . ADD
2020-09-19 20:49:33 +02:00
} )
2020-11-22 18:52:32 +01:00
]
2020-09-19 20:49:33 +02:00
} ) ,
2020-11-22 18:52:32 +01:00
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . FormComponents . FormDivider , {
className : BDFDB . disCN . marginbottom20
} )
] . concat ( Object . keys ( formats ) . map ( key => BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Card , {
cardId : key ,
noRemove : key == "Standard" ,
onRemove : _ => {
delete formats [ key ] ;
BDFDB . DataUtils . save ( formats , this , "formats" ) ;
BDFDB . PluginUtils . refreshSettingsPanel ( this , settingsPanel , collapseStates ) ;
} ,
2021-03-19 22:13:42 +01:00
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Flex , {
direction : BDFDB . LibraryComponents . Flex . Direction . VERTICAL ,
style : { width : "100%" } ,
children : [
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsSaveItem , {
type : "TextInput" ,
plugin : this ,
keys : [ "formats" , key ] ,
label : key + ":" ,
basis : "70%" ,
value : formats [ key ] ,
onChange : ( value , instance ) => {
formats [ key ] = value ;
BDFDB . ReactUtils . forceUpdate ( BDFDB . ReactUtils . findOwner ( BDFDB . ObjectUtils . get ( instance , ` ${ BDFDB . ReactUtils . instanceKey } .return ` ) , { key : "PREVIEW_MESSAGE_" + key . replace ( /\s/g , "_" ) } ) ) ;
}
} ) ,
BDFDB . ReactUtils . createElement ( PreviewMessageComponent , {
key : "PREVIEW_MESSAGE_" + key . replace ( /\s/g , "_" ) ,
format : key
} )
]
} )
2020-11-22 18:52:32 +01:00
} ) ) )
} ) ) ;
settingsItems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . CollapseContainer , {
title : "Placeholder Guide" ,
collapseStates : collapseStates ,
2020-09-19 20:49:33 +02:00
children : [
2021-03-19 22:13:42 +01:00
"$quote will be replaced with the quoted Message Content" ,
"$rawQuote will be replaced with the raw quoted Message Content" ,
"$mention will be replaced with a Mention of the Message Author" ,
"$link will be replaced with a Discord Direct Link pointing to the Message" ,
"$authorId will be replaced with the ID of the Message Author" ,
"$authorName will be replaced with the Nickname or Username of the Message Author" ,
"$authorAccount will be replaced with the Accountname of the Message Author (username#discriminator)" ,
"$channel will be replaced with a Mention of the Channel" ,
"$channelId will be replaced with the ID of the Channel" ,
"$channelName will be replaced with the Name of the Channel" ,
"$serverId will be replaced with the ID of the Server" ,
"$serverName will be replaced with the Name of the Server" ,
2022-09-11 13:12:02 +02:00
"$timestamp will be replaced with the Formatted Timestamp of the quoted Message" ,
"$unixTimestamp will be replaced with the Unix Timestamp of the quoted Message"
2020-11-22 18:52:32 +01:00
] . map ( string => BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . FormComponents . FormText , {
2022-10-01 15:07:31 +02:00
type : BDFDB . LibraryComponents . FormComponents . FormText . Types . DESCRIPTION ,
2020-11-22 18:52:32 +01:00
children : string
} ) )
} ) ) ;
return settingsItems ;
}
} ) ;
2020-02-23 18:55:20 +01:00
}
2021-01-06 12:38:36 +01:00
onSettingsClosed ( ) {
2020-09-19 20:49:33 +02:00
if ( this . SettingsUpdated ) {
delete this . SettingsUpdated ;
this . forceUpdateAll ( ) ;
}
}
2021-01-06 12:38:36 +01:00
forceUpdateAll ( ) {
2020-09-19 20:49:33 +02:00
formats = Object . assign ( { "Standard" : "$quote $mention" } , BDFDB . DataUtils . load ( this , "formats" ) ) ;
2021-03-08 17:00:32 +01:00
BDFDB . PatchUtils . forceAllUpdates ( this ) ;
2020-02-23 18:55:20 +01:00
}
2020-09-19 20:49:33 +02:00
onMessageContextMenu ( e ) {
if ( e . instance . props . message && e . instance . props . channel ) {
2020-10-23 19:13:48 +02:00
let item = null , action = ( choice , shift ) => {
2020-09-19 20:49:33 +02:00
format = choice ;
2020-11-19 18:31:53 +01:00
this . quote ( e . instance . props . channel , e . instance . props . message , shift ) ;
2020-09-19 20:49:33 +02:00
format = null ;
} ;
let [ children , index ] = BDFDB . ContextMenuUtils . findItem ( e . returnvalue , { id : "quote" } ) ;
if ( index > - 1 ) {
item = children [ index ] ;
2022-02-25 16:12:53 +01:00
item . props . action = event => action ( null , event . shiftKey ) ;
2020-07-01 16:37:43 +02:00
}
2020-09-19 20:49:33 +02:00
else {
item = BDFDB . ContextMenuUtils . createItem ( BDFDB . LibraryComponents . MenuItems . MenuItem , {
label : BDFDB . LanguageUtils . LanguageStrings . QUOTE ,
id : "quote" ,
2020-10-23 19:07:35 +02:00
action : event => { action ( null , event . shiftKey ) ; }
2020-09-19 20:49:33 +02:00
} ) ;
let [ unreadChildren , unreadIndex ] = BDFDB . ContextMenuUtils . findItem ( e . returnvalue , { id : "mark-unread" } ) ;
unreadChildren . splice ( unreadIndex > - 1 ? unreadIndex - 1 : unreadChildren . length , 0 , item ) ;
}
let addedFormats = BDFDB . ObjectUtils . exclude ( formats , "Standard" ) ;
if ( ! BDFDB . ObjectUtils . isEmpty ( addedFormats ) ) item . props . children = BDFDB . ContextMenuUtils . createItem ( BDFDB . LibraryComponents . MenuItems . MenuGroup , {
children : Object . keys ( addedFormats ) . map ( key => BDFDB . ContextMenuUtils . createItem ( BDFDB . LibraryComponents . MenuItems . MenuItem , {
label : key ,
id : BDFDB . ContextMenuUtils . createItemId ( this . name , "added-quote" , key ) ,
action : event => { action ( key , event . shiftKey ) ; }
} ) )
2020-07-01 16:37:43 +02:00
} ) ;
2020-11-24 18:06:40 +01:00
else {
2022-02-25 16:12:53 +01:00
item . props . icon = _ => BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SvgIcon , {
className : BDFDB . disCN . menuicon ,
name : BDFDB . LibraryComponents . SvgIcon . Names . QUOTE
} ) ;
2020-11-24 18:06:40 +01:00
let hint = BDFDB . BDUtils . isPluginEnabled ( "MessageUtilities" ) ? BDFDB . BDUtils . getPlugin ( "MessageUtilities" ) . getActiveShortcutString ( "__Quote_Message" ) : null ;
2022-02-25 16:12:53 +01:00
if ( hint ) item . props . hint = _ => BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . MenuItems . MenuHint , {
hint : hint
} ) ;
2020-11-24 18:06:40 +01:00
}
2020-07-01 16:37:43 +02:00
}
}
2020-11-19 18:31:53 +01:00
2022-10-17 22:41:39 +02:00
processMessageActionsContextMenu ( e ) {
2020-11-19 18:31:53 +01:00
if ( e . instance . props . message && e . instance . props . channel ) {
let [ quoteChildren , quoteIndex ] = BDFDB . ContextMenuUtils . findItem ( e . returnvalue , { id : "quote" } ) ;
if ( quoteIndex == - 1 ) {
let [ children , index ] = BDFDB . ContextMenuUtils . findItem ( e . returnvalue , { id : "mark-unread" } ) ;
children . splice ( index > - 1 ? index : 0 , 0 , BDFDB . ContextMenuUtils . createItem ( BDFDB . LibraryComponents . MenuItems . MenuItem , {
label : BDFDB . LanguageUtils . LanguageStrings . QUOTE ,
id : BDFDB . ContextMenuUtils . createItemId ( this . name , "quote" ) ,
2022-02-25 16:12:53 +01:00
icon : _ => BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SvgIcon , {
className : BDFDB . disCN . menuicon ,
name : BDFDB . LibraryComponents . SvgIcon . Names . QUOTE
} ) ,
2020-11-19 18:31:53 +01:00
action : event => {
this . quote ( e . instance . props . channel , e . instance . props . message , event . shiftKey ) ;
}
} ) ) ;
}
}
}
2022-10-17 22:41:39 +02:00
processMessageToolbar ( e ) {
2021-03-08 17:00:32 +01:00
if ( ( e . instance . props . expanded || ! this . settings . general . holdShiftToolbar ) && e . instance . props . message && e . instance . props . channel ) {
2020-11-19 18:31:53 +01:00
let quoteButton = BDFDB . ReactUtils . findChild ( e . returnvalue , { key : "quote" } ) ;
2020-11-19 19:55:06 +01:00
if ( ! quoteButton ) {
2021-01-16 17:16:12 +01:00
let [ children , index ] = BDFDB . ReactUtils . findParent ( e . returnvalue , { key : [ "reply" , "mark-unread" ] } ) ;
children . splice ( index > - 1 ? index : ( ! e . instance . props . expanded ? 1 : 0 ) , 0 , BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . TooltipContainer , {
2020-11-19 18:31:53 +01:00
key : "quote" ,
text : BDFDB . LanguageUtils . LanguageStrings . QUOTE ,
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Clickable , {
className : BDFDB . disCN . messagetoolbarbutton ,
onClick : _ => {
this . quote ( e . instance . props . channel , e . instance . props . message ) ;
} ,
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SvgIcon , {
className : BDFDB . disCN . messagetoolbaricon ,
name : BDFDB . LibraryComponents . SvgIcon . Names . QUOTE
} )
} )
} ) ) ;
}
}
}
2021-03-08 17:00:32 +01:00
2022-10-17 22:41:39 +02:00
processChannelTextAreaContainer ( e ) {
if ( e . instance . props . type == BDFDB . DiscordConstants . ChannelTextAreaTypes . NORMAL || e . instance . props . type == BDFDB . DiscordConstants . ChannelTextAreaTypes . NORMAL _WITH _ACTIVITY ) ChannelTextAreaContainer = e . instance
2021-03-08 17:00:32 +01:00
}
2020-11-19 18:31:53 +01:00
quote ( channel , message , shift ) {
2020-11-25 09:02:58 +01:00
let text = this . parseQuote ( message , channel ) ;
if ( text && text . length ) {
2021-03-08 17:00:32 +01:00
if ( shift && ! this . settings . general . alwaysCopy || ! shift && this . settings . general . alwaysCopy || ! ( BDFDB . DMUtils . isDMChannel ( channel . id ) || BDFDB . UserUtils . can ( "SEND_MESSAGES" ) ) ) {
2022-10-14 09:01:48 +02:00
BDFDB . LibraryModules . WindowUtils . copy ( text ) ;
2020-12-24 12:59:02 +01:00
BDFDB . NotificationUtils . toast ( this . labels . toast _quotecopied , { type : "success" } ) ;
2020-11-25 09:02:58 +01:00
}
2022-04-06 18:07:40 +02:00
else BDFDB . LibraryModules . DispatchUtils . ComponentDispatch . dispatchToLastSubscribed ( BDFDB . DiscordConstants . ComponentActions . INSERT _TEXT , {
2022-10-17 22:41:39 +02:00
plainText : [ this . settings . general . autoAddNewLine && ChannelTextAreaContainer && ChannelTextAreaContainer . props . textValue && ! this . isNewLine ( ChannelTextAreaContainer . props . textValue , true ) && ! this . isNewLine ( text , false ) && "\n" , text , this . settings . general . autoAddNewLine && ! this . isNewLine ( text , true ) && "\n" ] . filter ( n => n ) . join ( "" )
2022-04-06 18:07:40 +02:00
} ) ;
2020-11-19 18:31:53 +01:00
}
}
2021-03-19 22:13:42 +01:00
isNewLine ( string , end ) {
return string && typeof string == "string" && string . replace ( /[*~_ ]/g , "" ) [ end ? "endsWith" : "startsWith" ] ( "\n" ) ;
}
2020-07-01 16:37:43 +02:00
2020-09-19 20:49:33 +02:00
parseQuote ( message , channel , choice = format ) {
let languageId = BDFDB . LanguageUtils . getLanguage ( ) . id ;
let quoteFormat = formats [ choice ] || formats . Standard || "" ;
2022-09-27 14:48:10 +02:00
let guild = channel . guild _id ? ( BDFDB . LibraryStores . GuildStore . getGuild ( channel . guild _id ) || { id : channel . guild _id , name : "Test Server" } ) : { id : BDFDB . DiscordConstants . ME , name : BDFDB . LanguageUtils . LanguageStrings . DIRECT _MESSAGES } ;
2022-09-27 16:53:10 +02:00
let member = guild && BDFDB . LibraryStores . GuildMemberStore . getMember ( guild . id , message . author . id ) ;
2020-09-19 20:49:33 +02:00
let content = message . content ;
2021-03-09 15:47:58 +01:00
let selectedText = document . getSelection ( ) . toString ( ) . trim ( ) ;
2020-09-19 20:49:33 +02:00
if ( selectedText ) content = BDFDB . StringUtils . extractSelection ( content , selectedText ) ;
if ( content ) {
content = content . replace ( /(@everyone|@here)/g , "`$1`" ) . replace ( /``(@everyone|@here)``/g , "`$1`" ) ;
content = content . replace ( /<@[!&]{0,1}([0-9]{10,})>/g , ( string , match ) => {
2022-09-27 16:53:10 +02:00
let user = BDFDB . LibraryStores . UserStore . getUser ( match ) ;
2020-09-19 20:49:33 +02:00
if ( user ) {
2022-09-27 16:53:10 +02:00
let userMember = channel . guild _id && BDFDB . LibraryStores . GuildMemberStore . getMember ( guild . id , match ) ;
2020-12-24 12:59:02 +01:00
return ` @ ${ userMember && userMember . nick || user . username } ` ;
2020-09-19 20:49:33 +02:00
}
2020-12-24 12:59:02 +01:00
else if ( channel . guild _id && guild . roles [ match ] && guild . roles [ match ] . name ) return ` ${ guild . roles [ match ] . name . indexOf ( "@" ) == 0 ? "" : "@" } ${ guild . roles [ match ] . name } ` ;
2020-09-19 20:49:33 +02:00
return string ;
} ) ;
}
let unquotedLines = content . split ( "\n" ) . filter ( line => ! line . startsWith ( "> " ) ) ;
let quotedLines = unquotedLines . slice ( unquotedLines . findIndex ( line => line . trim ( ) . length > 0 ) ) . map ( line => "> " + line + "\n" ) . join ( "" ) ;
return BDFDB . StringUtils . insertNRST ( quoteFormat )
2021-03-09 15:47:58 +01:00
. replace ( "$mention" , channel . isDM ( ) ? "" : ` <@! ${ message . author . id } > ` )
2020-11-19 16:45:36 +01:00
. replace ( "$link" , ` <https://discordapp.com/channels/ ${ guild . id } / ${ channel . id } / ${ message . id } > ` )
2020-09-19 20:49:33 +02:00
. replace ( "$authorName" , member && member . nick || message . author . username || "" )
. replace ( "$authorAccount" , ` ${ message . author . username } # ${ message . author . discriminator } ` )
. replace ( "$authorId" , message . author . id || "" )
. replace ( "$channelName" , channel . name || "" )
. replace ( "$channelId" , channel . id || "" )
2020-12-24 12:59:02 +01:00
. replace ( "$channel" , channel . isDM ( ) && channel . rawRecipients [ 0 ] ? ` @ ${ channel . rawRecipients [ 0 ] . username } ` : ` <# ${ channel . id } > ` )
2020-09-19 20:49:33 +02:00
. replace ( "$serverId" , guild . id || "" )
. replace ( "$serverName" , guild . name || "" )
2021-03-19 22:13:42 +01:00
. replace ( "$timestamp" , BDFDB . LibraryComponents . DateInput . format ( this . settings . dates . quoteDate , new Date ( message . editedTimestamp || message . timestamp ) ) )
2022-09-11 13:12:02 +02:00
. replace ( "$unixTimestamp" , Math . round ( new Date ( message . editedTimestamp || message . timestamp ) . getTime ( ) / 1000 ) )
2020-09-19 20:49:33 +02:00
. replace ( "$quote" , quotedLines || "" )
2020-12-05 18:39:06 +01:00
. replace ( "$rawQuote" , unquotedLines . join ( "\n" ) || "" ) ;
2020-07-01 16:37:43 +02:00
}
2020-02-23 18:55:20 +01:00
2021-01-06 12:38:36 +01:00
setLabelsByLanguage ( ) {
2020-12-24 12:59:02 +01:00
switch ( BDFDB . LanguageUtils . getLanguage ( ) . id ) {
case "bg" : // Bulgarian
return {
toast _quotecopied : "Цитатът е копиран в клипборда"
} ;
case "da" : // Danish
return {
toast _quotecopied : "Citatet er kopieret til udklipsholderen"
} ;
case "de" : // German
return {
toast _quotecopied : "Zitat wurde in die Zwischenablage kopiert"
} ;
case "el" : // Greek
return {
toast _quotecopied : "Τ ο απόσπασμα έχει αντιγραφεί στο πρόχειρο"
} ;
case "es" : // Spanish
return {
toast _quotecopied : "La cita se copió al portapapeles"
} ;
case "fi" : // Finnish
return {
toast _quotecopied : "Lainaus on kopioitu leikepöydälle"
} ;
case "fr" : // French
return {
toast _quotecopied : "Le devis a été copié dans le presse-papiers"
} ;
case "hr" : // Croatian
return {
toast _quotecopied : "Citat je kopiran u međuspremnik"
} ;
case "hu" : // Hungarian
return {
toast _quotecopied : "Az árajánlatot a vágólapra másolta"
} ;
case "it" : // Italian
return {
toast _quotecopied : "La citazione è stata copiata negli appunti"
} ;
case "ja" : // Japanese
return {
toast _quotecopied : "見積もりがクリップボードにコピーされました"
} ;
case "ko" : // Korean
return {
toast _quotecopied : "견적이 클립 보드에 복사되었습니다."
} ;
case "lt" : // Lithuanian
return {
toast _quotecopied : "Citata nukopijuota į mainų sritį"
} ;
case "nl" : // Dutch
return {
toast _quotecopied : "Citaat is naar het klembord gekopieerd"
} ;
case "no" : // Norwegian
return {
toast _quotecopied : "Tilbudet er kopiert til utklippstavlen"
} ;
case "pl" : // Polish
return {
toast _quotecopied : "Cytat został skopiowany do schowka"
} ;
case "pt-BR" : // Portuguese (Brazil)
return {
toast _quotecopied : "A citação foi copiada para a área de transferência"
} ;
case "ro" : // Romanian
return {
toast _quotecopied : "Citatul a fost copiat în clipboard"
} ;
case "ru" : // Russian
return {
toast _quotecopied : "Цитата скопирована в буфер обмена"
} ;
case "sv" : // Swedish
return {
toast _quotecopied : "Citatet har kopierats till Urklipp"
} ;
case "th" : // Thai
return {
toast _quotecopied : "คัดลอกใบเสนอราคาไปยังคลิปบอร์ดแล้ว"
} ;
case "tr" : // Turkish
return {
toast _quotecopied : "Alı ntı panoya kopyalandı "
} ;
case "uk" : // Ukrainian
return {
toast _quotecopied : "Цитата скопійована в буфер обміну"
} ;
case "vi" : // Vietnamese
return {
toast _quotecopied : "Trích dẫn đã được sao chép vào khay nhớ tạm"
} ;
2021-01-15 17:54:22 +01:00
case "zh-CN" : // Chinese (China)
2020-12-24 12:59:02 +01:00
return {
toast _quotecopied : "报价已复制到剪贴板"
} ;
2021-01-15 17:54:22 +01:00
case "zh-TW" : // Chinese (Taiwan)
2020-12-24 12:59:02 +01:00
return {
toast _quotecopied : "報價已復製到剪貼板"
} ;
default : // English
return {
toast _quotecopied : "Quote has been copied to clipboard"
} ;
}
}
2020-09-19 20:49:33 +02:00
} ;
2022-09-01 14:40:11 +02:00
} ) ( window . BDFDB _Global . PluginUtils . buildPlugin ( changeLog ) ) ;
2020-11-19 19:55:06 +01:00
} ) ( ) ;