2020-10-20 23:25:34 +02:00
/ * *
* @ name CustomQuoter
* @ authorId 278543574059057154
* @ invite Jx3TjNS
2020-11-19 16:45:36 +01:00
* @ donate https : //www.paypal.me/MircoWittrien
* @ patreon https : //www.patreon.com/MircoWittrien
* @ website https : //github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/CustomQuoter
* @ source https : //raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/CustomQuoter/CustomQuoter.plugin.js
* @ updateUrl https : //raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/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 = ( _ => {
2020-10-09 21:09:35 +02:00
const config = {
2020-09-19 20:49:33 +02:00
"info" : {
"name" : "CustomQuoter" ,
"author" : "DevilBro" ,
2020-12-01 20:18:55 +01:00
"version" : "1.2.3" ,
2020-10-16 10:25:30 +02:00
"description" : "Customize the output of the native quote feature of Discord"
2020-10-23 19:13:48 +02:00
} ,
"changeLog" : {
2020-11-19 18:31:53 +01:00
"fixed" : {
2020-12-01 21:20:41 +01:00
"DMs" : "No longer always copies quote to clipboard in DMs"
2020-10-23 19:13:48 +02:00
}
2020-02-23 19:40:36 +01:00
}
} ;
2020-11-13 19:47:44 +01:00
2020-10-09 21:09:35 +02:00
return ! window . BDFDB _Global || ( ! window . BDFDB _Global . loaded && ! window . BDFDB _Global . started ) ? class {
2021-01-06 12:38:36 +01:00
getName ( ) { return config . info . name ; }
getAuthor ( ) { return config . info . author ; }
getVersion ( ) { return config . info . version ; }
2021-01-14 16:14:44 +01:00
getDescription ( ) { return ` The Library Plugin needed for ${ config . info . name } is missing. Open the Plugin Settings to download it. \n \n ${ config . info . description } ` ; }
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 ;
2021-01-14 16:14:44 +01:00
BdApi . showConfirmationModal ( "Library Missing" , ` The Library Plugin needed for ${ config . info . 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 ;
2020-11-19 16:45:36 +01:00
require ( "request" ) . get ( "https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js" , ( e , r , b ) => {
2020-10-20 23:25:34 +02:00
if ( ! e && b && b . indexOf ( ` * @name BDFDB ` ) > - 1 ) require ( "fs" ) . writeFile ( require ( "path" ) . join ( BdApi . Plugins . folder , "0BDFDB.plugin.js" ) , b , _ => { } ) ;
2021-01-14 16:14:44 +01:00
else BdApi . alert ( "Error" , "Could not download BDFDB Library Plugin, try again later or download it manually from GitHub: https://github.com/mwittrien/BetterDiscordAddons/tree/master/Library/" ) ;
2020-09-20 08:15:13 +02:00
} ) ;
}
2020-09-19 20:49:33 +02:00
} ) ;
}
if ( ! window . BDFDB _Global . pluginQueue . includes ( config . info . name ) ) window . BDFDB _Global . pluginQueue . push ( config . info . 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" ) ;
2021-01-14 16:14:44 +01: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 ${ config . info . name } is missing. \n Please click <a style="font-weight: 500;">Download Now</a> to install it.</div> ` ;
2020-11-28 23:12:09 +01:00
template . content . firstElementChild . querySelector ( "a" ) . addEventListener ( "click" , _ => {
require ( "request" ) . get ( "https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js" , ( e , r , b ) => {
if ( ! e && b && b . indexOf ( ` * @name BDFDB ` ) > - 1 ) require ( "fs" ) . writeFile ( require ( "path" ) . join ( BdApi . Plugins . folder , "0BDFDB.plugin.js" ) , b , _ => { } ) ;
2021-01-14 16:14:44 +01:00
else BdApi . alert ( "Error" , "Could not download BDFDB Library Plugin, try again later or download it manually from GitHub: https://github.com/mwittrien/BetterDiscordAddons/tree/master/Library/" ) ;
2020-11-28 23:12:09 +01:00
} ) ;
} ) ;
return template . content . firstElementChild ;
}
2020-10-09 21:09:35 +02:00
} : ( ( [ Plugin , BDFDB ] ) => {
2020-09-19 20:49:33 +02:00
var _this ;
var settings = { } , formats = { } , format = null ;
const PreviewMessageComponent = class PreviewMessage extends BdApi . React . Component {
2021-01-06 12:38:36 +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
2020-09-19 20:49:33 +02:00
this . defaults = {
settings : {
2020-11-19 16:51:14 +01:00
quoteOnlySelected : { value : true , description : "Only insert selected text in a quoted message" } ,
alwaysCopy : { value : false , description : "Always copy quote to clipboard without holding shift" } ,
ignoreMentionInDM : { value : true , description : "Do not add a mention in DM channels" } ,
forceZeros : { value : false , description : "Force leading Zeros" }
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 ,
children : Object . keys ( settings ) . map ( key => BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsSaveItem , {
type : "Switch" ,
plugin : this ,
keys : [ "settings" , key ] ,
label : this . defaults . settings [ key ] . description ,
value : settings [ key ] ,
onChange : ( value , instance ) => {
settings [ key ] = value ;
}
} ) )
} ) ) ;
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 ) ;
} ,
2020-11-24 18:06:40 +01:00
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 ;
2020-11-26 09:53:49 +01:00
BDFDB . ReactUtils . forceUpdate ( BDFDB . ReactUtils . findOwner ( BDFDB . ObjectUtils . get ( instance , ` ${ BDFDB . ReactUtils . instanceKey } .return ` ) , { key : "PREVIEW_MESSAGE_" + key . replace ( /\s/g , "_" ) } ) ) ;
2020-11-24 18:06:40 +01:00
}
} ) ,
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 : [
2020-11-22 18:52:32 +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 (ignored for DMs)" ,
"$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" ,
"$hour will be replaced with the quote hour" ,
"$minute will be replaced with the quote minutes" ,
"$second will be replaced with the quote seconds" ,
"$msecond will be replaced with the quote milliseconds" ,
"$timemode will change $hour to a 12h format and will be replaced with AM/PM" ,
"$year will be replaced with the quote year" ,
"$month will be replaced with the quote month" ,
"$day will be replaced with the quote day" ,
"$monthnameL will be replaced with the monthname in long format based on the Discord Language" ,
"$monthnameS will be replaced with the monthname in short format based on the Discord Language" ,
"$weekdayL will be replaced with the weekday in long format based on the Discord Language" ,
"$weekdayS will be replaced with the weekday in short format based on the Discord Language"
] . map ( string => BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . FormComponents . FormText , {
type : BDFDB . LibraryComponents . FormComponents . FormTextTypes . DESCRIPTION ,
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
settings = BDFDB . DataUtils . get ( this , "settings" ) ;
formats = Object . assign ( { "Standard" : "$quote $mention" } , BDFDB . DataUtils . load ( this , "formats" ) ) ;
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 ] ;
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 {
let hint = BDFDB . BDUtils . isPluginEnabled ( "MessageUtilities" ) ? BDFDB . BDUtils . getPlugin ( "MessageUtilities" ) . getActiveShortcutString ( "__Quote_Message" ) : null ;
if ( hint ) item . props . hint = _ => {
return BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . MenuItems . MenuHint , {
hint : hint
} ) ;
} ;
}
2020-07-01 16:37:43 +02:00
}
}
2020-11-19 18:31:53 +01:00
onMessageOptionContextMenu ( e ) {
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" ) ,
icon : _ => {
return BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SvgIcon , {
className : BDFDB . disCN . menuicon ,
name : BDFDB . LibraryComponents . SvgIcon . Names . QUOTE
} ) ;
} ,
action : event => {
this . quote ( e . instance . props . channel , e . instance . props . message , event . shiftKey ) ;
}
} ) ) ;
}
}
}
onMessageOptionToolbar ( e ) {
if ( e . instance . props . expanded && e . instance . props . message && e . instance . props . channel ) {
let quoteButton = BDFDB . ReactUtils . findChild ( e . returnvalue , { key : "quote" } ) ;
2020-11-19 19:55:06 +01:00
if ( ! quoteButton ) {
2020-11-19 18:31:53 +01:00
let [ children , index ] = BDFDB . ReactUtils . findParent ( e . returnvalue , { key : "mark-unread" } ) ;
children . splice ( index > - 1 ? index : 0 , 0 , BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . TooltipContainer , {
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
} )
} )
} ) ) ;
}
}
}
quote ( channel , message , shift ) {
2020-11-25 09:02:58 +01:00
let text = this . parseQuote ( message , channel ) ;
if ( text && text . length ) {
2020-12-01 20:18:55 +01:00
if ( shift && ! settings . alwaysCopy || ! shift && settings . alwaysCopy || ! ( BDFDB . DMUtils . isDMChannel ( channel ) || BDFDB . UserUtils . can ( "SEND_MESSAGES" ) ) ) {
2020-11-25 09:02:58 +01:00
BDFDB . LibraryRequires . electron . clipboard . write ( { text : 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
}
else {
BDFDB . LibraryModules . DispatchUtils . ComponentDispatch . dispatchToLastSubscribed ( BDFDB . DiscordConstants . ComponentActions . INSERT _TEXT , { content : text } ) ;
}
2020-11-19 18:31:53 +01:00
}
}
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 || "" ;
let guild = channel . guild _id ? ( BDFDB . LibraryModules . GuildStore . getGuild ( channel . guild _id ) || { id : channel . guild _id , name : "Test Server" } ) : { id : BDFDB . DiscordConstants . ME , name : BDFDB . LanguageUtils . LanguageStrings . DIRECT _MESSAGES } ;
let member = guild && BDFDB . LibraryModules . MemberStore . getMember ( guild . id , message . author . id ) ;
let timestamp = new Date ( message . editedTimestamp || message . timestamp ) ;
let hour = timestamp . getHours ( ) , minute = timestamp . getMinutes ( ) , second = timestamp . getSeconds ( ) , msecond = timestamp . getMilliseconds ( ) , day = timestamp . getDate ( ) , month = timestamp . getMonth ( ) + 1 , timemode = "" ;
if ( quoteFormat . indexOf ( "$timemode" ) > - 1 ) {
timemode = hour >= 12 ? "PM" : "AM" ;
hour = hour % 12 ;
hour = hour ? hour : 12 ;
}
let content = message . content ;
let selectedText = settings . quoteOnlySelected && document . getSelection ( ) . toString ( ) . trim ( ) ;
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 ) => {
let user = BDFDB . LibraryModules . UserStore . getUser ( match ) ;
if ( user ) {
let userMember = channel . guild _id && BDFDB . LibraryModules . MemberStore . 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 )
. replace ( "$mention" , settings . ignoreMentionInDM && 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 || "" )
. replace ( "$hour" , settings . forceZeros && hour < 10 ? "0" + hour : hour )
. replace ( "$minute" , minute < 10 ? "0" + minute : minute )
. replace ( "$second" , second < 10 ? "0" + second : second )
. replace ( "$msecond" , settings . forceZeros ? ( msecond < 10 ? "00" + msecond : ( msecond < 100 ? "0" + msecond : msecond ) ) : msecond )
. replace ( "$timemode" , timemode )
. replace ( "$weekdayL" , timestamp . toLocaleDateString ( languageId , { weekday : "long" } ) )
. replace ( "$weekdayS" , timestamp . toLocaleDateString ( languageId , { weekday : "short" } ) )
. replace ( "$monthnameL" , timestamp . toLocaleDateString ( languageId , { month : "long" } ) )
. replace ( "$monthnameS" , timestamp . toLocaleDateString ( languageId , { month : "short" } ) )
. replace ( "$day" , settings . forceZeros && day < 10 ? "0" + day : day )
. replace ( "$month" , settings . forceZeros && month < 10 ? "0" + month : month )
. replace ( "$year" , timestamp . getFullYear ( ) )
. 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
2020-09-19 20:49:33 +02:00
addLeadingZeros ( timestring ) {
let charArray = timestring . split ( "" ) ;
let numreg = /[0-9]/ ;
for ( let i = 0 ; i < charArray . length ; i ++ ) if ( ! numreg . test ( charArray [ i - 1 ] ) && numreg . test ( charArray [ i ] ) && ! numreg . test ( charArray [ i + 1 ] ) ) charArray [ i ] = "0" + charArray [ i ] ;
2020-02-23 18:55:20 +01:00
2020-09-19 20:49:33 +02:00
return charArray . join ( "" ) ;
}
2020-12-24 12:59:02 +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"
} ;
case "zh" : // Chinese
return {
toast _quotecopied : "报价已复制到剪贴板"
} ;
case "zh-TW" : // Chinese (Traditional)
return {
toast _quotecopied : "報價已復製到剪貼板"
} ;
default : // English
return {
toast _quotecopied : "Quote has been copied to clipboard"
} ;
}
}
2020-09-19 20:49:33 +02:00
} ;
2020-10-09 21:09:35 +02:00
} ) ( window . BDFDB _Global . PluginUtils . buildPlugin ( config ) ) ;
2020-11-19 19:55:06 +01:00
} ) ( ) ;