2020-10-20 23:25:34 +02:00
/ * *
* @ name SendLargeMessages
* @ authorId 278543574059057154
* @ invite Jx3TjNS
* @ donate https : //www.paypal.me/MircoWittrien
* @ patreon https : //www.patreon.com/MircoWittrien
* @ website https : //github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/SendLargeMessages
* @ source https : //raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/SendLargeMessages/SendLargeMessages.plugin.js
2020-11-12 17:30:48 +01:00
* @ updateUrl https : //raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/SendLargeMessages/SendLargeMessages.plugin.js
2020-10-20 23:25:34 +02:00
* /
2018-10-11 10:21:26 +02: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" : "SendLargeMessages" ,
"author" : "DevilBro" ,
"version" : "1.6.5" ,
2020-10-16 10:25:30 +02:00
"description" : "Split messages into several smaller messages when your message exceeds the limit"
2020-03-28 07:41:31 +01:00
}
2020-09-19 20:49:33 +02: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-02-01 17:13:13 +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 } ` ; }
downloadLibrary ( ) {
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 , _ => { } ) ;
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-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 ;
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
} ) ;
2020-03-28 07:41:31 +01: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> ` ;
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 ] ) => {
2020-09-19 20:49:33 +02:00
const messageDelay = 1000 ; //changing at own risk, might result in bans or mutes
2020-10-09 21:09:35 +02:00
return class SendLargeMessages extends Plugin {
2021-01-06 12:38:36 +01:00
onLoad ( ) {
2020-09-19 20:49:33 +02:00
this . patchedModules = {
before : {
ChannelTextAreaForm : "render" ,
ChannelEditorContainer : "render"
} ,
after : {
ChannelTextAreaContainer : "render" ,
}
} ;
}
2021-01-06 12:38:36 +01:00
onStart ( ) {
2020-09-11 19:31:36 +02:00
BDFDB . PatchUtils . forceAllUpdates ( this ) ;
2020-03-28 07:41:31 +01:00
}
2020-09-19 20:49:33 +02:00
2021-01-06 12:38:36 +01:00
onStop ( ) {
2020-09-11 19:31:36 +02:00
BDFDB . PatchUtils . forceAllUpdates ( this ) ;
2020-03-28 07:41:31 +01:00
}
2018-10-11 10:21:26 +02:00
2020-09-19 20:49:33 +02:00
processChannelTextAreaForm ( e ) {
if ( ! BDFDB . PatchUtils . isPatched ( this , e . instance , "handleSendMessage" ) ) BDFDB . PatchUtils . patch ( this , e . instance , "handleSendMessage" , { instead : e2 => {
if ( e2 . methodArguments [ 0 ] . length > BDFDB . DiscordConstants . MAX _MESSAGE _LENGTH ) {
e2 . stopOriginalMethodCall ( ) ;
let messages = this . formatText ( e2 . methodArguments [ 0 ] ) ;
messages . filter ( n => n ) . forEach ( ( message , i ) => {
BDFDB . TimeUtils . timeout ( _ => {
e2 . originalMethod ( message ) ;
2020-12-21 19:56:36 +01:00
if ( i >= messages . length - 1 ) BDFDB . NotificationUtils . toast ( this . labels . toast _allsent , { type : "success" } ) ;
2020-09-19 20:49:33 +02:00
} , messageDelay * i ) ;
} ) ;
return Promise . resolve ( {
shouldClear : true ,
shouldRefocus : true
} ) ;
}
else return e2 . callOriginalMethodAfterwards ( ) ;
} } , { force : true , noCache : true } ) ;
}
processChannelTextAreaContainer ( e ) {
if ( e . returnvalue . ref && e . returnvalue . ref . current && BDFDB . DOMUtils . getParent ( BDFDB . dotCN . chatform , e . returnvalue . ref . current ) ) {
let [ children , index ] = BDFDB . ReactUtils . findParent ( e . returnvalue , { name : "SlateCharacterCount" } ) ;
if ( index > - 1 ) {
let text = BDFDB . LibraryModules . SlateSelectionUtils . serialize ( children [ index ] . props . document , "raw" ) ;
if ( text . length > BDFDB . DiscordConstants . MAX _MESSAGE _LENGTH ) children [ index ] = BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCNS . textareacharcounter + BDFDB . disCN . textareacharcountererror ,
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . TooltipContainer , {
text : Math . ceil ( text . length / BDFDB . DiscordConstants . MAX _MESSAGE _LENGTH * ( 39 / 40 ) ) + " " + BDFDB . LanguageUtils . LanguageStrings . MESSAGES ,
children : BDFDB . ReactUtils . createElement ( "span" , {
children : BDFDB . DiscordConstants . MAX _MESSAGE _LENGTH - text . length
} )
2020-03-28 07:41:31 +01:00
} )
2020-09-19 20:49:33 +02:00
} ) ;
}
2020-03-28 07:41:31 +01:00
}
2019-12-28 17:39:14 +01:00
}
2019-01-26 22:45:19 +01:00
2020-09-19 20:49:33 +02:00
processChannelEditorContainer ( e ) {
if ( e . instance . props . type && e . instance . props . type == BDFDB . DiscordConstants . TextareaTypes . NORMAL ) e . instance . props . shouldUploadLongMessages = false ;
2018-10-11 10:21:26 +02:00
}
2019-01-26 22:45:19 +01:00
2020-09-19 20:49:33 +02:00
formatText ( text ) {
text = text . replace ( /\t/g , " " ) ;
let longWords = text . match ( new RegExp ( ` [^ ]{ ${ BDFDB . DiscordConstants . MAX _MESSAGE _LENGTH * ( 19 / 20 ) } ,} ` , "gm" ) ) ;
if ( longWords ) for ( let longWord of longWords ) {
let count1 = 0 ;
let shortWords = [ ] ;
longWord . split ( "" ) . forEach ( c => {
if ( shortWords [ count1 ] && ( shortWords [ count1 ] . length >= BDFDB . DiscordConstants . MAX _MESSAGE _LENGTH * ( 19 / 20 ) || ( c == "\n" && shortWords [ count1 ] . length >= BDFDB . DiscordConstants . MAX _MESSAGE _LENGTH * ( 19 / 20 ) - 100 ) ) ) count1 ++ ;
shortWords [ count1 ] = shortWords [ count1 ] ? shortWords [ count1 ] + c : c ;
} ) ;
text = text . replace ( longWord , shortWords . join ( " " ) ) ;
2020-03-28 07:41:31 +01:00
}
2020-09-19 20:49:33 +02:00
let messages = [ ] ;
let count2 = 0 ;
text . split ( " " ) . forEach ( ( word ) => {
if ( messages [ count2 ] && ( messages [ count2 ] + "" + word ) . length > BDFDB . DiscordConstants . MAX _MESSAGE _LENGTH * ( 39 / 40 ) ) count2 ++ ;
messages [ count2 ] = messages [ count2 ] ? messages [ count2 ] + " " + word : word ;
} ) ;
2019-01-26 22:45:19 +01:00
2020-09-19 20:49:33 +02:00
let insertCodeBlock = null , insertCodeLine = null ;
for ( let j = 0 ; j < messages . length ; j ++ ) {
if ( insertCodeBlock ) {
messages [ j ] = insertCodeBlock + messages [ j ] ;
insertCodeBlock = null ;
}
else if ( insertCodeLine ) {
messages [ j ] = insertCodeLine + messages [ j ] ;
insertCodeLine = null ;
}
let codeBlocks = messages [ j ] . match ( /`{3,}[\S]*\n|`{3,}/gm ) ;
let codeLines = messages [ j ] . match ( /[^`]{0,1}`{1,2}[^`]|[^`]`{1,2}[^`]{0,1}/gm ) ;
if ( codeBlocks && codeBlocks . length % 2 == 1 ) {
messages [ j ] = messages [ j ] + "```" ;
insertCodeBlock = codeBlocks [ codeBlocks . length - 1 ] + "\n" ;
}
else if ( codeLines && codeLines . length % 2 == 1 ) {
insertCodeLine = codeLines [ codeLines . length - 1 ] . replace ( /[^`]/g , "" ) ;
messages [ j ] = messages [ j ] + insertCodeLine ;
}
2020-03-28 07:41:31 +01:00
}
2020-09-19 20:49:33 +02:00
return messages ;
2018-10-11 10:21:26 +02:00
}
2019-01-26 22:45:19 +01:00
2021-01-06 12:38:36 +01:00
setLabelsByLanguage ( ) {
2020-09-19 20:49:33 +02:00
switch ( BDFDB . LanguageUtils . getLanguage ( ) . id ) {
2020-12-21 19:56:36 +01:00
case "bg" : // Bulgarian
2020-09-19 20:49:33 +02:00
return {
2020-12-21 19:56:36 +01:00
toast _allsent : "Всички изпратени съобщения"
2020-09-19 20:49:33 +02:00
} ;
2020-12-21 19:56:36 +01:00
case "da" : // Danish
2020-09-19 20:49:33 +02:00
return {
2020-12-21 19:56:36 +01:00
toast _allsent : "Alle beskeder sendt"
2020-09-19 20:49:33 +02:00
} ;
2020-12-21 19:56:36 +01:00
case "de" : // German
2020-09-19 20:49:33 +02:00
return {
2020-12-21 19:56:36 +01:00
toast _allsent : "Alle Nachrichten gesendet"
2020-09-19 20:49:33 +02:00
} ;
2020-12-21 19:56:36 +01:00
case "el" : // Greek
2020-09-19 20:49:33 +02:00
return {
2020-12-21 19:56:36 +01:00
toast _allsent : "Όλα τα μηνύματα εστάλησαν"
2020-09-19 20:49:33 +02:00
} ;
2020-12-21 19:56:36 +01:00
case "es" : // Spanish
2020-09-19 20:49:33 +02:00
return {
2020-12-21 19:56:36 +01:00
toast _allsent : "Todos los mensajes enviados"
2020-09-19 20:49:33 +02:00
} ;
2020-12-21 19:56:36 +01:00
case "fi" : // Finnish
2020-09-19 20:49:33 +02:00
return {
2020-12-21 19:56:36 +01:00
toast _allsent : "Kaikki viestit lähetetty"
2020-09-19 20:49:33 +02:00
} ;
2020-12-21 19:56:36 +01:00
case "fr" : // French
2020-09-19 20:49:33 +02:00
return {
2020-12-21 19:56:36 +01:00
toast _allsent : "Tous les messages envoyés"
2020-09-19 20:49:33 +02:00
} ;
2020-12-21 19:56:36 +01:00
case "hr" : // Croatian
2020-09-19 20:49:33 +02:00
return {
2020-12-21 19:56:36 +01:00
toast _allsent : "Sve poruke poslane"
2020-09-19 20:49:33 +02:00
} ;
2020-12-21 19:56:36 +01:00
case "hu" : // Hungarian
2020-09-19 20:49:33 +02:00
return {
2020-12-21 19:56:36 +01:00
toast _allsent : "Minden üzenet elküldve"
2020-09-19 20:49:33 +02:00
} ;
2020-12-21 19:56:36 +01:00
case "it" : // Italian
2020-09-19 20:49:33 +02:00
return {
2020-12-21 19:56:36 +01:00
toast _allsent : "Tutti i messaggi inviati"
2020-09-19 20:49:33 +02:00
} ;
2020-12-21 19:56:36 +01:00
case "ja" : // Japanese
2020-09-19 20:49:33 +02:00
return {
2020-12-21 19:56:36 +01:00
toast _allsent : "送信されたすべてのメッセージ"
2020-09-19 20:49:33 +02:00
} ;
2020-12-21 19:56:36 +01:00
case "ko" : // Korean
2020-09-19 20:49:33 +02:00
return {
2020-12-21 19:56:36 +01:00
toast _allsent : "보낸 모든 메시지"
2020-09-19 20:49:33 +02:00
} ;
2020-12-21 19:56:36 +01:00
case "lt" : // Lithuanian
2020-09-19 20:49:33 +02:00
return {
2020-12-21 19:56:36 +01:00
toast _allsent : "Visi pranešimai išsiųsti"
2020-09-19 20:49:33 +02:00
} ;
2020-12-21 19:56:36 +01:00
case "nl" : // Dutch
2020-09-19 20:49:33 +02:00
return {
2020-12-21 19:56:36 +01:00
toast _allsent : "Alle berichten zijn verzonden"
2020-09-19 20:49:33 +02:00
} ;
2020-12-21 19:56:36 +01:00
case "no" : // Norwegian
2020-09-19 20:49:33 +02:00
return {
2020-12-21 19:56:36 +01:00
toast _allsent : "Alle meldinger sendt"
2020-09-19 20:49:33 +02:00
} ;
2020-12-21 19:56:36 +01:00
case "pl" : // Polish
2020-09-19 20:49:33 +02:00
return {
2020-12-21 19:56:36 +01:00
toast _allsent : "Wszystkie wiadomości wysłane"
2020-09-19 20:49:33 +02:00
} ;
2020-12-21 19:56:36 +01:00
case "pt-BR" : // Portuguese (Brazil)
2020-09-19 20:49:33 +02:00
return {
2020-12-21 19:56:36 +01:00
toast _allsent : "Todas as mensagens enviadas"
2020-09-19 20:49:33 +02:00
} ;
2020-12-21 19:56:36 +01:00
case "ro" : // Romanian
2020-09-19 20:49:33 +02:00
return {
2020-12-21 19:56:36 +01:00
toast _allsent : "Toate mesajele trimise"
2020-09-19 20:49:33 +02:00
} ;
2020-12-21 19:56:36 +01:00
case "ru" : // Russian
2020-09-19 20:49:33 +02:00
return {
2020-12-21 19:56:36 +01:00
toast _allsent : "В с е сообщения отправлены"
2020-09-19 20:49:33 +02:00
} ;
2020-12-21 19:56:36 +01:00
case "sv" : // Swedish
2020-09-19 20:49:33 +02:00
return {
2020-12-21 19:56:36 +01:00
toast _allsent : "Alla meddelanden skickade"
2020-09-19 20:49:33 +02:00
} ;
2020-12-21 19:56:36 +01:00
case "th" : // Thai
2020-09-19 20:49:33 +02:00
return {
2020-12-21 19:56:36 +01:00
toast _allsent : "ส่งข้อความทั้งหมดแล้ว"
} ;
case "tr" : // Turkish
return {
toast _allsent : "Tüm mesajlar gönderildi"
} ;
case "uk" : // Ukrainian
return {
toast _allsent : "У с і повідомлення надіслано"
} ;
case "vi" : // Vietnamese
return {
toast _allsent : "Tất cả tin nhắn đã gửi"
} ;
2021-01-15 17:54:22 +01:00
case "zh-CN" : // Chinese (China)
2020-12-21 19:56:36 +01:00
return {
toast _allsent : "已发送所有消息"
} ;
2021-01-15 17:54:22 +01:00
case "zh-TW" : // Chinese (Taiwan)
2020-12-21 19:56:36 +01:00
return {
toast _allsent : "已發送所有消息"
} ;
default : // English
return {
toast _allsent : "All messages sent"
2020-09-19 20:49:33 +02:00
} ;
}
2020-03-28 07:41:31 +01:00
}
2020-09-19 20:49:33 +02:00
} ;
2020-10-09 21:09:35 +02:00
} ) ( window . BDFDB _Global . PluginUtils . buildPlugin ( config ) ) ;
2020-09-19 20:49:33 +02:00
} ) ( ) ;