2021-01-09 20:54:44 +01:00
/ * *
* @ name CustomStatusPresets
2021-03-05 13:26:41 +01:00
* @ author DevilBro
2021-01-09 20:54:44 +01:00
* @ authorId 278543574059057154
2024-07-31 18:45:08 +02:00
* @ version 1.1 . 9
2021-03-05 13:26:41 +01:00
* @ description Allows you to save Custom Statuses as Quick Select
2021-01-09 20:54:44 +01:00
* @ invite Jx3TjNS
* @ 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/CustomStatusPresets/
2021-03-10 09:17:37 +01:00
* @ updateUrl https : //mwittrien.github.io/BetterDiscordAddons/Plugins/CustomStatusPresets/CustomStatusPresets.plugin.js
2021-01-09 20:54:44 +01:00
* /
module . exports = ( _ => {
2022-09-01 14:40:11 +02:00
const changeLog = {
2024-07-31 18:45:08 +02:00
fixed : {
"New Style" : "If Discord updated for you and you no longer got the old Custom Status Entry in the UserPopup, then you'll need to right click the Custom Status Bubble next to your avatar to pick a preset Custom Status"
}
2021-01-09 20:54: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 ( ) {
2023-11-18 18:31:04 +01:00
BdApi . Net . fetch ( "https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js" ) . then ( r => {
if ( ! r || r . status != 200 ) throw new Error ( ) ;
else return r . text ( ) ;
} ) . then ( b => {
if ( ! b ) throw new Error ( ) ;
else return require ( "fs" ) . writeFile ( require ( "path" ) . join ( BdApi . Plugins . folder , "0BDFDB.plugin.js" ) , b , _ => BdApi . showToast ( "Finished downloading BDFDB Library" , { type : "success" } ) ) ;
} ) . catch ( error => {
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
} ) ;
}
2021-01-09 20:54:44 +01:00
load ( ) {
if ( ! window . BDFDB _Global || ! Array . isArray ( window . BDFDB _Global . pluginQueue ) ) window . BDFDB _Global = Object . assign ( { } , window . BDFDB _Global , { pluginQueue : [ ] } ) ;
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. ` , {
2021-01-09 20:54:44 +01:00
confirmText : "Download Now" ,
cancelText : "Cancel" ,
onCancel : _ => { delete window . BDFDB _Global . downloadModal ; } ,
onConfirm : _ => {
delete window . BDFDB _Global . downloadModal ;
2021-02-01 17:13:13 +01:00
this . downloadLibrary ( ) ;
2021-01-09 20:54:44 +01:00
}
} ) ;
}
2022-09-01 14:55:22 +02:00
if ( ! window . BDFDB _Global . pluginQueue . includes ( this . name ) ) window . BDFDB _Global . pluginQueue . push ( this . name ) ;
2021-01-09 20:54:44 +01:00
}
start ( ) { this . load ( ) ; }
stop ( ) { }
getSettingsPanel ( ) {
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 ) ;
2021-01-09 20:54:44 +01:00
return template . content . firstElementChild ;
}
} : ( ( [ Plugin , BDFDB ] ) => {
2021-01-20 17:42:56 +01:00
var _this ;
2021-01-09 20:54:44 +01:00
var presets = { } ;
2022-01-11 14:13:16 +01:00
const ClearAfterValues = {
2022-01-11 14:13:52 +01:00
HOURS _1 : 3600000 ,
HOURS _4 : 14400000 ,
MINUTES _30 : 1800000 ,
2022-01-11 14:13:16 +01:00
TODAY : "TODAY"
} ;
2021-04-03 17:25:09 +02:00
const CustomStatusInputComponent = class CustomStatusInput extends BdApi . React . Component {
2021-01-20 17:42:56 +01:00
handleChange ( ) {
this . props . onChange ( this . props ) ;
}
render ( ) {
return BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . emojiinputcontainer ,
children : [
BDFDB . ReactUtils . createElement ( "div" , {
key : "EMOJIINPUT" ,
className : BDFDB . disCN . emojiinputbuttoncontainer ,
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . EmojiPickerButton , {
emoji : this . props . emoji ,
onSelect : this . handleChange . bind ( this )
} )
} ) ,
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . TextInput , {
key : "TEXTINPUT" ,
inputClassName : BDFDB . disCN . emojiinput ,
maxLength : 128 ,
value : this . props . text ,
placeholder : this . props . text ,
onChange : this . handleChange . bind ( this )
} ) ,
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Button , {
size : BDFDB . LibraryComponents . Button . Sizes . NONE ,
look : BDFDB . LibraryComponents . Button . Looks . BLANK ,
className : BDFDB . disCN . emojiinputclearbutton ,
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SvgIcon , {
className : BDFDB . disCN . emojiinputclearicon ,
name : BDFDB . LibraryComponents . SvgIcon . Names . CLOSE _CIRCLE
} ) ,
onClick : ( e , instance ) => {
this . props . text = "" ;
delete this . props . text ;
this . handleChange ( ) ;
BDFDB . ReactUtils . forceUpdate ( this ) ;
}
} )
]
} ) ;
}
} ;
2021-04-03 17:25:09 +02:00
const SortableListComponent = class SortableList extends BdApi . React . Component {
2021-01-20 17:42:56 +01:00
createDragPreview ( div , event ) {
if ( ! Node . prototype . isPrototypeOf ( div ) ) return ;
let dragPreview = div . cloneNode ( true ) ;
BDFDB . DOMUtils . addClass ( dragPreview , BDFDB . disCN . _customstatuspresetsdragpreview ) ;
BDFDB . DOMUtils . hide ( dragPreview ) ;
dragPreview . style . setProperty ( "pointer-events" , "none" , "important" ) ;
dragPreview . style . setProperty ( "left" , event . clientX - 25 + "px" , "important" ) ;
dragPreview . style . setProperty ( "top" , event . clientY - 25 + "px" , "important" ) ;
document . querySelector ( BDFDB . dotCN . appmount ) . appendChild ( dragPreview ) ;
this . props . dragPreview = dragPreview ;
}
updateDragPreview ( event ) {
if ( ! Node . prototype . isPrototypeOf ( this . props . dragPreview ) ) return ;
BDFDB . DOMUtils . show ( this . props . dragPreview ) ;
this . props . dragPreview . style . setProperty ( "left" , event . clientX - 25 + "px" , "important" ) ;
this . props . dragPreview . style . setProperty ( "top" , event . clientY - 25 + "px" , "important" ) ;
}
render ( ) {
2021-04-03 17:31:51 +02:00
return ! Object . keys ( this . props . entries ) . length ? BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . TextElement , {
2021-04-03 17:25:09 +02:00
children : "You haven't added any Custom Status Presets. You can add some via the Custom Status Modal, where you usually configure your Custom Status."
} ) : Object . keys ( BDFDB . ObjectUtils . sort ( this . props . entries , this . props . sortKey ) ) . map ( id => [
2021-01-20 17:42:56 +01:00
this . props . hovered == id && BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . _customstatuspresetssortdivider
} ) ,
this . props . dragged != id && BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . _customstatuspresetssortablecard ,
cardId : id ,
onMouseDown : event => {
event = event . nativeEvent || event ;
let target = BDFDB . DOMUtils . containsClass ( event . target , BDFDB . disCN . hovercard ) ? event . target . parentElement : event . target ;
if ( ! BDFDB . DOMUtils . containsClass ( target , BDFDB . disCN . _customstatuspresetssortablecard ) ) return ;
let mouseMove = event2 => {
if ( Math . sqrt ( ( event . pageX - event2 . pageX ) * * 2 ) > 20 || Math . sqrt ( ( event . pageY - event2 . pageY ) * * 2 ) > 20 ) {
BDFDB . ListenerUtils . stopEvent ( event ) ;
this . createDragPreview ( target , event2 ) ;
this . props . dragged = id ;
BDFDB . ReactUtils . forceUpdate ( this ) ;
document . removeEventListener ( "mousemove" , mouseMove ) ;
document . removeEventListener ( "mouseup" , mouseUp ) ;
let dragging = event3 => {
this . updateDragPreview ( event3 ) ;
2021-02-07 22:36:14 +01:00
let hoveredId = BDFDB . DOMUtils . getParent ( BDFDB . dotCN . _customstatuspresetssortablecard , event3 . target ) ;
hoveredId = hoveredId && hoveredId . getAttribute ( "cardId" ) ;
2021-01-20 17:42:56 +01:00
let update = hoveredId != this . props . hovered ;
this . props . hovered = hoveredId ;
if ( update ) BDFDB . ReactUtils . forceUpdate ( this ) ;
} ;
let releasing = event3 => {
BDFDB . ListenerUtils . stopEvent ( event3 ) ;
BDFDB . DOMUtils . remove ( this . props . dragPreview ) ;
if ( this . props . hovered ) {
presets [ id ] [ this . props . sortKey ] = presets [ this . props . hovered ] [ this . props . sortKey ] - 0.5 ;
let pos = 0 , sortedPresets = BDFDB . ObjectUtils . sort ( presets , this . props . sortKey ) ;
for ( let sortId in sortedPresets ) presets [ sortId ] [ this . props . sortKey ] = pos ++ ;
this . props . entries = presets ;
BDFDB . DataUtils . save ( presets , _this , "presets" ) ;
}
delete this . props . dragged ;
delete this . props . hovered ;
BDFDB . ReactUtils . forceUpdate ( this ) ;
document . removeEventListener ( "mousemove" , dragging ) ;
document . removeEventListener ( "mouseup" , releasing ) ;
} ;
document . addEventListener ( "mousemove" , dragging ) ;
document . addEventListener ( "mouseup" , releasing ) ;
}
} ;
let mouseUp = _ => {
document . removeEventListener ( "mousemove" , mouseMove ) ;
document . removeEventListener ( "mouseup" , mouseUp ) ;
} ;
document . addEventListener ( "mousemove" , mouseMove ) ;
document . addEventListener ( "mouseup" , mouseUp ) ;
} ,
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Card , {
horizontal : true ,
children : [
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Flex . Child , {
wrap : true ,
2021-04-03 17:25:09 +02:00
children : BDFDB . ReactUtils . createElement ( CustomStatusInputComponent , {
2021-01-20 17:42:56 +01:00
text : presets [ id ] . text ,
emoji : presets [ id ] . emojiInfo ,
onChange : value => {
presets [ id ] . text = value . text ;
presets [ id ] . emojiInfo = value . emoji ;
BDFDB . DataUtils . save ( presets , _this , "presets" ) ;
}
} )
} ) ,
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Flex . Child , {
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Switch , {
value : ! presets [ id ] . disabled ,
onChange : value => {
presets [ id ] . disabled = ! value ;
BDFDB . DataUtils . save ( presets , _this , "presets" ) ;
}
} )
} )
] ,
onRemove : _ => {
delete presets [ id ] ;
BDFDB . DataUtils . save ( presets , _this , "presets" ) ;
this . props . entries = presets ;
BDFDB . ReactUtils . forceUpdate ( this ) ;
}
} )
} )
] ) . flat ( ) . filter ( n => n ) ;
}
} ;
2021-01-09 20:54:44 +01:00
return class CustomStatusPresets extends Plugin {
onLoad ( ) {
2021-01-20 17:42:56 +01:00
_this = this ;
2022-10-20 12:01:17 +02:00
this . modulePatches = {
before : [
"Menu"
] ,
after : [
2024-07-31 18:45:08 +02:00
"CustomStatusModal" ,
"UserPopoutCustomStatusPicker"
2022-10-20 12:01:17 +02:00
]
2021-01-09 20:54:44 +01:00
} ;
this . css = `
$ { BDFDB . dotCN . customstatusmodal } {
min - width : 440 px ;
width : unset ;
}
$ { BDFDB . dotCN . animationcontainerscale + BDFDB . dotCN . animationcontainerrender } {
transform : unset ! important ;
}
2022-05-07 18:05:37 +02:00
$ { BDFDB . dotCN . menu } # account - edit - custom - status $ { BDFDB . dotCN . menuhintcontainer } {
margin - right : 8 px ;
margin - left : 0 ;
order : - 1 ;
}
2021-01-09 20:54:44 +01:00
# status - picker$ { BDFDB . dotCN . menu } # status - picker - custom - status$ { BDFDB . dotCN . menulabelcontainer } {
2022-04-08 11:20:49 +02:00
padding - left : 0 ;
2021-01-09 20:54:44 +01:00
}
# status - picker$ { BDFDB . dotCN . menu } # status - picker - custom - status $ { BDFDB . dotCN . menulabel } {
overflow : visible ;
white - space : unset ;
}
$ { BDFDB . dotCN . _customstatuspresetscustomstatusitem } {
display : flex ;
align - items : center ;
}
$ { BDFDB . dotCN . _customstatuspresetsdeletebutton } {
display : flex ;
margin - right : 6 px ;
}
2021-04-13 16:30:51 +02:00
$ { BDFDB . dotCN . _customstatuspresetsstatus } {
margin - right : 6 px ;
2021-07-08 16:59:41 +02:00
flex : 0 0 auto ;
2021-04-13 16:30:51 +02:00
}
2021-01-20 17:42:56 +01:00
$ { BDFDB . dotCN . _customstatuspresetssortdivider } {
2023-02-22 15:34:45 +01:00
background : $ { BDFDB . DiscordConstants . Colors . GREEN } ;
2021-01-20 17:42:56 +01:00
height : 2 px ;
margin : 0 26 px 8 px 0 ;
}
$ { BDFDB . dotCN . _customstatuspresetsdragpreview } {
pointer - events : none ! important ;
position : absolute ! important ;
opacity : 0.5 ! important ;
z - index : 10000 ! important ;
}
2021-01-09 20:54:44 +01:00
` ;
}
onStart ( ) {
this . forceUpdateAll ( ) ;
}
onStop ( ) {
this . forceUpdateAll ( ) ;
}
2021-01-20 17:42:56 +01:00
getSettingsPanel ( collapseStates = { } ) {
let settingsPanel , settingsItems = [ ] ;
settingsItems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsPanelList , {
title : "Custom Status Presets:" ,
dividerTop : true ,
2021-04-03 17:25:09 +02:00
children : BDFDB . ReactUtils . createElement ( SortableListComponent , {
2021-01-20 17:42:56 +01:00
entries : presets ,
sortKey : "pos"
} )
} ) ) ;
return settingsPanel = BDFDB . PluginUtils . createSettingsPanel ( this , settingsItems ) ;
}
2021-01-09 20:54:44 +01:00
forceUpdateAll ( ) {
presets = BDFDB . DataUtils . load ( this , "presets" ) ;
BDFDB . PatchUtils . forceAllUpdates ( this ) ;
}
2024-07-31 18:45:08 +02:00
processUserPopoutCustomStatusPicker ( e ) {
if ( e . instance . props . profileType != "BITE_SIZE" ) return ;
let container = BDFDB . ReactUtils . findChild ( e . returnvalue , { props : [ [ "className" , BDFDB . disCN . userpopoutcustomstatuspickervisiblecontainer ] ] } ) ;
if ( ! container ) return ;
let onContextMenu = container . props . onContextMenu ;
container . props . onContextMenu = BDFDB . TimeUtils . suppress ( event => {
onContextMenu && onContextMenu ( event ) ;
let enabledPresets = BDFDB . ObjectUtils . filter ( presets , id => ! presets [ id ] . disabled , true ) ;
if ( ! Object . keys ( enabledPresets ) . length ) return ;
BDFDB . ContextMenuUtils . open ( this , event , BDFDB . ContextMenuUtils . createItem ( BDFDB . LibraryComponents . MenuItems . MenuGroup , {
children : Object . keys ( BDFDB . ObjectUtils . sort ( enabledPresets , "pos" ) ) . map ( id => BDFDB . ContextMenuUtils . createItem ( BDFDB . LibraryComponents . MenuItems . MenuItem , {
id : BDFDB . ContextMenuUtils . createItemId ( this . name , "custom-status-preset" , id ) ,
label : BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . _customstatuspresetscustomstatusitem ,
children : [
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . TooltipContainer , {
text : BDFDB . LanguageUtils . LanguageStrings . CUSTOM _STATUS _CLEAR _CUSTOM _STATUS ,
tooltipConfig : {
zIndex : 2001
} ,
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Clickable , {
className : BDFDB . disCN . _customstatuspresetsdeletebutton ,
onClick : _ => {
delete presets [ id ] ;
let pos = 0 , sortedPresets = BDFDB . ObjectUtils . sort ( presets , "pos" ) ;
for ( let id in sortedPresets ) presets [ id ] . pos = pos ++ ;
BDFDB . DataUtils . save ( presets , this , "presets" ) ;
} ,
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SvgIcon , {
className : BDFDB . disCN . _customstatuspresetsdeleteicon ,
name : BDFDB . LibraryComponents . SvgIcon . Names . CLOSE _CIRCLE ,
width : 14 ,
height : 14
} )
} )
} ) ,
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . StatusComponents . Status , {
className : BDFDB . disCN . _customstatuspresetsstatus ,
status : presets [ id ] . status || BDFDB . LibraryComponents . StatusComponents . Types . ONLINE
} ) ,
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . TextScroller , {
children : presets [ id ] . text
} )
]
} ) ,
imageUrl : presets [ id ] . emojiInfo && ( presets [ id ] . emojiInfo . id ? BDFDB . LibraryModules . IconUtils . getEmojiURL ( presets [ id ] . emojiInfo ) : BDFDB . LibraryModules . EmojiStateUtils . getURL ( presets [ id ] . emojiInfo . name ) ) ,
hint : ! presets [ id ] . clearAfter ? BDFDB . LanguageUtils . LanguageStrings . DISPLAY _OPTION _NEVER : presets [ id ] . clearAfter == ClearAfterValues . TODAY ? BDFDB . LanguageUtils . LanguageStrings . CUSTOM _STATUS _TODAY : BDFDB . LanguageUtils . LanguageStringsFormat ( "CUSTOM_STATUS_HOURS" , presets [ id ] . clearAfter / 3600000 ) ,
action : _ => {
if ( ! presets [ id ] ) return ;
let expiresAt = presets [ id ] . clearAfter ? presets [ id ] . clearAfter : null ;
if ( presets [ id ] . clearAfter === ClearAfterValues . TODAY ) {
let date = new Date ;
expiresAt = new Date ( date . getFullYear ( ) , date . getMonth ( ) , date . getDate ( ) + 1 ) . getTime ( ) - date . getTime ( ) ;
}
if ( presets [ id ] . status ) BDFDB . DiscordUtils . setSetting ( "status" , "status" , presets [ id ] . status ) ;
BDFDB . DiscordUtils . setSetting ( "status" , "customStatus" , {
text : presets [ id ] . text && presets [ id ] . text . length > 0 ? presets [ id ] . text : "" ,
expiresAtMs : expiresAt ? BDFDB . DiscordObjects . Timestamp ( ) . add ( expiresAt , "ms" ) . toDate ( ) . getTime ( ) . toString ( ) : "0" ,
emojiId : presets [ id ] . emojiInfo ? presets [ id ] . emojiInfo . id : "0" ,
emojiName : presets [ id ] . emojiInfo ? presets [ id ] . emojiInfo . name : ""
} ) ;
}
} ) )
} ) ) ;
} , "" , this ) ;
}
2021-01-09 20:54:44 +01:00
processMenu ( e ) {
2024-06-23 20:15:57 +02:00
if ( e . instance . props . navId != "account" && e . instance . props . navId != "status" ) return ;
2021-01-20 17:42:56 +01:00
let enabledPresets = BDFDB . ObjectUtils . filter ( presets , id => ! presets [ id ] . disabled , true ) ;
2022-04-08 11:20:49 +02:00
if ( ! Object . keys ( enabledPresets ) . length ) return ;
2024-07-05 18:58:16 +02:00
let [ children , index ] = BDFDB . ContextMenuUtils . findItem ( e . instance , { id : [ "custom-status" , "set-custom-status" , "edit-custom-status" , "add-custom-status" ] } ) ;
2022-04-08 11:20:49 +02:00
if ( index > - 1 && children [ index ] . props && ! children [ index ] . props . children ) {
let render = children [ index ] . props . render || children [ index ] . props . label ;
delete children [ index ] . props . render ;
delete children [ index ] . props . label ;
2024-07-05 18:58:16 +02:00
children [ index ] . props . icon = children [ index ] . props . hint ;
2024-06-23 20:15:57 +02:00
delete children [ index ] . props . hint ;
2022-04-08 11:20:49 +02:00
children [ index ] = BDFDB . ContextMenuUtils . createItem ( BDFDB . LibraryComponents . MenuItems . MenuItem , Object . assign ( { } , children [ index ] . props , {
2022-05-07 18:05:37 +02:00
label : typeof render == "function" ? render ( ) : render ,
2022-04-08 11:20:49 +02:00
children : Object . keys ( BDFDB . ObjectUtils . sort ( enabledPresets , "pos" ) ) . map ( id => BDFDB . ContextMenuUtils . createItem ( BDFDB . LibraryComponents . MenuItems . MenuItem , {
id : BDFDB . ContextMenuUtils . createItemId ( this . name , "custom-status-preset" , id ) ,
label : BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . _customstatuspresetscustomstatusitem ,
children : [
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . TooltipContainer , {
text : BDFDB . LanguageUtils . LanguageStrings . CUSTOM _STATUS _CLEAR _CUSTOM _STATUS ,
tooltipConfig : {
zIndex : 2001
} ,
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Clickable , {
className : BDFDB . disCN . _customstatuspresetsdeletebutton ,
onClick : _ => {
delete presets [ id ] ;
let pos = 0 , sortedPresets = BDFDB . ObjectUtils . sort ( presets , "pos" ) ;
for ( let id in sortedPresets ) presets [ id ] . pos = pos ++ ;
BDFDB . DataUtils . save ( presets , this , "presets" ) ;
2021-01-09 20:54:44 +01:00
} ,
2022-04-08 11:20:49 +02:00
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SvgIcon , {
className : BDFDB . disCN . _customstatuspresetsdeleteicon ,
name : BDFDB . LibraryComponents . SvgIcon . Names . CLOSE _CIRCLE ,
width : 14 ,
height : 14
2021-01-09 20:54:44 +01:00
} )
2021-07-08 16:59:41 +02:00
} )
2022-04-08 11:20:49 +02:00
} ) ,
2022-10-02 17:12:02 +02:00
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . StatusComponents . Status , {
2022-04-08 11:20:49 +02:00
className : BDFDB . disCN . _customstatuspresetsstatus ,
2022-10-02 17:12:02 +02:00
status : presets [ id ] . status || BDFDB . LibraryComponents . StatusComponents . Types . ONLINE
2022-04-08 11:20:49 +02:00
} ) ,
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . TextScroller , {
children : presets [ id ] . text
} )
]
} ) ,
imageUrl : presets [ id ] . emojiInfo && ( presets [ id ] . emojiInfo . id ? BDFDB . LibraryModules . IconUtils . getEmojiURL ( presets [ id ] . emojiInfo ) : BDFDB . LibraryModules . EmojiStateUtils . getURL ( presets [ id ] . emojiInfo . name ) ) ,
hint : ! presets [ id ] . clearAfter ? BDFDB . LanguageUtils . LanguageStrings . DISPLAY _OPTION _NEVER : presets [ id ] . clearAfter == ClearAfterValues . TODAY ? BDFDB . LanguageUtils . LanguageStrings . CUSTOM _STATUS _TODAY : BDFDB . LanguageUtils . LanguageStringsFormat ( "CUSTOM_STATUS_HOURS" , presets [ id ] . clearAfter / 3600000 ) ,
action : _ => {
if ( ! presets [ id ] ) return ;
let expiresAt = presets [ id ] . clearAfter ? presets [ id ] . clearAfter : null ;
if ( presets [ id ] . clearAfter === ClearAfterValues . TODAY ) {
let date = new Date ;
expiresAt = new Date ( date . getFullYear ( ) , date . getMonth ( ) , date . getDate ( ) + 1 ) . getTime ( ) - date . getTime ( ) ;
2021-01-09 20:54:44 +01:00
}
2022-09-29 18:58:49 +02:00
if ( presets [ id ] . status ) BDFDB . DiscordUtils . setSetting ( "status" , "status" , presets [ id ] . status ) ;
BDFDB . DiscordUtils . setSetting ( "status" , "customStatus" , {
2022-08-08 14:14:00 +02:00
text : presets [ id ] . text && presets [ id ] . text . length > 0 ? presets [ id ] . text : "" ,
expiresAtMs : expiresAt ? BDFDB . DiscordObjects . Timestamp ( ) . add ( expiresAt , "ms" ) . toDate ( ) . getTime ( ) . toString ( ) : "0" ,
emojiId : presets [ id ] . emojiInfo ? presets [ id ] . emojiInfo . id : "0" ,
emojiName : presets [ id ] . emojiInfo ? presets [ id ] . emojiInfo . name : ""
2022-04-08 11:20:49 +02:00
} ) ;
}
} ) )
} ) ) ;
2021-01-09 20:54:44 +01:00
}
}
processCustomStatusModal ( e ) {
2022-10-20 12:01:17 +02:00
let footer = BDFDB . ReactUtils . findChild ( e . returnvalue , { name : "ModalFooter" } ) ;
if ( ! footer ) return ;
2021-01-09 20:54:44 +01:00
let id = BDFDB . NumberUtils . generateId ( Object . keys ( presets ) ) ;
2022-10-20 12:01:17 +02:00
footer . props . children . splice ( 1 , 0 , BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Button , {
2021-01-09 20:54:44 +01:00
color : BDFDB . disCN . modalcancelbutton ,
look : BDFDB . LibraryComponents . Button . Looks . LINK ,
onClick : event => {
2021-04-13 16:30:51 +02:00
presets [ id ] = Object . assign ( { pos : Object . keys ( presets ) . length } , BDFDB . ObjectUtils . extract ( e . instance . state , "clearAfter" , "emojiInfo" , "status" , "text" ) ) ;
2021-01-09 20:54:44 +01:00
BDFDB . DataUtils . save ( presets , this , "presets" ) ;
if ( ! event . shiftKey ) e . instance . props . onClose ( ) ;
else id = BDFDB . NumberUtils . generateId ( Object . keys ( presets ) ) ;
} ,
children : this . labels . modal _savepreset
} ) ) ;
}
setLabelsByLanguage ( ) {
switch ( BDFDB . LanguageUtils . getLanguage ( ) . id ) {
case "bg" : // Bulgarian
return {
modal _savepreset : "Запазване като бърз избор"
} ;
case "da" : // Danish
return {
modal _savepreset : "Gem som hurtigvalg"
} ;
case "de" : // German
return {
modal _savepreset : "Als Schnellauswahl speichern"
} ;
case "el" : // Greek
return {
modal _savepreset : "Αποθήκευση ως γρήγορη επιλογή"
} ;
case "es" : // Spanish
return {
modal _savepreset : "Guardar como selección rápida"
} ;
case "fi" : // Finnish
return {
modal _savepreset : "Tallenna pikavalintana"
} ;
case "fr" : // French
return {
modal _savepreset : "Enregistrer en tant que sélection rapide"
} ;
case "hr" : // Croatian
return {
modal _savepreset : "Spremi kao brzi odabir"
} ;
case "hu" : // Hungarian
return {
modal _savepreset : "Mentés gyorsválasztásként"
} ;
case "it" : // Italian
return {
modal _savepreset : "Salva come selezione rapida"
} ;
case "ja" : // Japanese
return {
modal _savepreset : "クイック選択として保存"
} ;
case "ko" : // Korean
return {
modal _savepreset : "빠른 선택으로 저장"
} ;
case "lt" : // Lithuanian
return {
modal _savepreset : "Išsaugoti kaip greitą pasirinkimą"
} ;
case "nl" : // Dutch
return {
modal _savepreset : "Opslaan als snel selecteren"
} ;
case "no" : // Norwegian
return {
modal _savepreset : "Lagre som hurtigvalg"
} ;
case "pl" : // Polish
return {
modal _savepreset : "Zapisz jako Szybki wybór"
} ;
case "pt-BR" : // Portuguese (Brazil)
return {
modal _savepreset : "Salvar como seleção rápida"
} ;
case "ro" : // Romanian
return {
modal _savepreset : "Salvați ca selecție rapidă"
} ;
case "ru" : // Russian
return {
modal _savepreset : "Сохранить как быстрый выбор"
} ;
case "sv" : // Swedish
return {
modal _savepreset : "Spara som snabbval"
} ;
case "th" : // Thai
return {
modal _savepreset : "บันทึกเป็น เลือกด่วน"
} ;
case "tr" : // Turkish
return {
modal _savepreset : "Hı zlı Seçim olarak kaydet"
} ;
case "uk" : // Ukrainian
return {
modal _savepreset : "Зберегти як швидкий вибір"
} ;
case "vi" : // Vietnamese
return {
modal _savepreset : "Lưu dưới dạng Chọn nhanh"
} ;
2021-01-15 17:54:22 +01:00
case "zh-CN" : // Chinese (China)
2021-01-09 20:54:44 +01:00
return {
modal _savepreset : "另存为快速选择"
} ;
2021-01-15 17:54:22 +01:00
case "zh-TW" : // Chinese (Taiwan)
2021-01-09 20:54:44 +01:00
return {
modal _savepreset : "另存為快速選擇"
} ;
default : // English
return {
modal _savepreset : "Save as Quick Select"
} ;
}
}
} ;
2022-09-01 14:40:11 +02:00
} ) ( window . BDFDB _Global . PluginUtils . buildPlugin ( changeLog ) ) ;
2021-02-07 22:36:14 +01:00
} ) ( ) ;