2020-10-20 23:25:34 +02:00
/ * *
* @ name JoinedAtDate
2021-03-05 13:26:41 +01:00
* @ author DevilBro
2020-10-20 23:25:34 +02:00
* @ authorId 278543574059057154
2021-03-15 13:28:17 +01:00
* @ version 1.2 . 6
2021-03-05 13:26:41 +01:00
* @ description Displays the Joined At Date of a Member in the UserPopout and UserModal
2020-10-20 23:25:34 +02: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/JoinedAtDate/
2021-03-10 09:17:37 +01:00
* @ updateUrl https : //mwittrien.github.io/BetterDiscordAddons/Plugins/JoinedAtDate/JoinedAtDate.plugin.js
2020-10-20 23:25:34 +02:00
* /
2018-11-23 16:58:33 +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" : "JoinedAtDate" ,
"author" : "DevilBro" ,
2021-03-15 13:28:17 +01:00
"version" : "1.2.6" ,
2021-03-04 12:15:46 +01:00
"description" : "Displays the Joined At Date of a Member in the UserPopout and UserModal"
2020-10-14 21:21:08 +02:00
} ,
"changeLog" : {
2021-03-15 13:28:17 +01:00
"improved" : {
"New Settings" : "Changed the Settings Panel for the Plugin, Settings got reset sowwy ~w~"
2020-10-14 21:21:08 +02:00
}
2020-05-26 10:13:46 +02: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 ) => {
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 ;
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-05-26 10:13:46 +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> ` ;
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 ] ) => {
2021-03-15 13:28:17 +01:00
var loadedUsers , requestedUsers ;
2020-09-19 20:49:33 +02:00
2020-10-09 21:09:35 +02:00
return class JoinedAtDate extends Plugin {
2021-01-06 12:38:36 +01:00
onLoad ( ) {
2020-09-19 20:49:33 +02:00
loadedUsers = { } ;
requestedUsers = { } ;
2019-01-26 22:45:19 +01:00
2020-09-19 20:49:33 +02:00
this . defaults = {
2021-03-15 13:28:17 +01:00
general : {
displayText : { value : true , description : "Display '{{presuffix}}' in the Date" }
2020-09-19 20:49:33 +02:00
} ,
2021-03-15 13:28:17 +01:00
places : {
userPopout : { value : true , description : "User Popouts" } ,
userProfile : { value : true , description : "User Profile Modal" }
2020-09-19 20:49:33 +02:00
} ,
2021-03-15 13:28:17 +01:00
dates : {
joinedAtDate : { value : { } , description : "Joined at Date" } ,
2020-09-19 20:49:33 +02:00
}
} ;
this . patchedModules = {
after : {
UserPopout : "render" ,
AnalyticsContext : "render"
}
} ;
}
2021-01-06 12:38:36 +01:00
onStart ( ) {
2021-03-15 13:28:17 +01:00
BDFDB . PatchUtils . forceAllUpdates ( this ) ;
2020-05-26 10:13:46 +02:00
}
2020-09-19 20:49:33 +02:00
2021-01-06 12:38:36 +01:00
onStop ( ) {
2021-03-15 13:28:17 +01:00
BDFDB . PatchUtils . forceAllUpdates ( this ) ;
2020-05-26 10:13:46 +02:00
}
2018-11-23 16:58:33 +01:00
2020-09-19 20:49:33 +02:00
getSettingsPanel ( collapseStates = { } ) {
2021-03-15 13:28:17 +01:00
let settingsPanel ;
return settingsPanel = BDFDB . PluginUtils . createSettingsPanel ( this , {
2020-09-19 20:49:33 +02:00
collapseStates : collapseStates ,
2021-03-15 13:28:17 +01:00
children : _ => {
let settingsItems = [ ] ;
settingsItems . push ( Object . keys ( this . defaults . general ) . map ( key => BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsSaveItem , {
type : "Switch" ,
plugin : this ,
keys : [ "general" , key ] ,
label : key == "displayText" ? this . defaults . general [ key ] . description . replace ( "{{presuffix}}" , this . labels . joined _at . replace ( "{{time}}" , "" ) . trim ( ) ) : this . defaults . general [ key ] . description ,
value : this . settings . general [ key ]
} ) ) ) ;
settingsItems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . FormComponents . FormDivider , {
className : BDFDB . disCN . marginbottom8
} ) ) ;
settingsItems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsPanelList , {
title : "Add Date in:" ,
children : Object . keys ( this . defaults . places ) . map ( key => BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsSaveItem , {
type : "Switch" ,
plugin : this ,
keys : [ "places" , key ] ,
label : this . defaults . places [ key ] . description ,
value : this . settings . places [ key ]
} ) )
} ) ) ;
settingsItems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . FormComponents . FormDivider , {
className : BDFDB . disCN . marginbottom8
} ) ) ;
settingsItems . push ( 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 ,
prefix : _ => ( this . settings . general . displayText && this . labels . joined _at . split ( "{{time}}" ) [ 0 ] || "" ) . trim ( ) ,
suffix : _ => ( this . settings . general . displayText && this . labels . joined _at . split ( "{{time}}" ) [ 1 ] || "" ) . trim ( ) ,
onChange : valueObj => {
this . SettingsUpdated = true ;
this . settings . dates [ key ] = valueObj ;
BDFDB . DataUtils . save ( this . settings . dates , this , "dates" ) ;
}
} ) ) ) ) ;
return settingsItems . flat ( 10 ) ;
}
} ) ;
2020-07-11 23:28:30 +02:00
}
2021-01-06 12:38:36 +01:00
onSettingsClosed ( ) {
2020-09-19 20:49:33 +02:00
if ( this . SettingsUpdated ) {
delete this . SettingsUpdated ;
2021-03-15 13:28:17 +01:00
BDFDB . PatchUtils . forceAllUpdates ( this ) ;
2020-09-19 20:49:33 +02:00
}
2020-05-26 10:13:46 +02:00
}
2019-01-26 22:45:19 +01:00
2020-09-19 20:49:33 +02:00
processUserPopout ( e ) {
2021-03-15 13:28:17 +01:00
if ( e . instance . props . user && e . instance . props . guild && this . settings . places . userPopout ) {
2020-09-19 20:49:33 +02:00
let [ children , index ] = BDFDB . ReactUtils . findParent ( e . returnvalue , { name : "CustomStatus" } ) ;
if ( index > - 1 ) this . injectDate ( e . instance , children , 2 , e . instance . props . user , e . instance . props . guild . id ) ;
}
2020-07-19 01:05:21 +02:00
}
2019-01-26 22:45:19 +01:00
2020-09-19 20:49:33 +02:00
processAnalyticsContext ( e ) {
2021-03-15 13:28:17 +01:00
if ( typeof e . returnvalue . props . children == "function" && e . instance . props . section == BDFDB . DiscordConstants . AnalyticsSections . PROFILE _MODAL && this . settings . places . userProfile ) {
2020-09-19 20:49:33 +02:00
let renderChildren = e . returnvalue . props . children ;
e . returnvalue . props . children = ( ... args ) => {
let renderedChildren = renderChildren ( ... args ) ;
let [ children , index ] = BDFDB . ReactUtils . findParent ( renderedChildren , { name : [ "DiscordTag" , "ColoredFluxTag" ] } ) ;
if ( index > - 1 ) this . injectDate ( e . instance , children , 1 , children [ index ] . props . user , BDFDB . ReactUtils . findValue ( e . instance , "guildId" , { up : true } ) ) ;
return renderedChildren ;
} ;
}
2019-02-22 21:39:10 +01:00
}
2020-09-19 20:49:33 +02:00
injectDate ( instance , children , index , user , guildId ) {
if ( ! guildId ) guildId = BDFDB . LibraryModules . LastGuildStore . getGuildId ( ) ;
if ( ! BDFDB . ArrayUtils . is ( children ) || ! user || ! guildId || user . discriminator == "0000" || ! BDFDB . LibraryModules . MemberStore . getMember ( guildId , user . id ) ) return ;
if ( ! loadedUsers [ guildId ] ) loadedUsers [ guildId ] = { } ;
if ( ! requestedUsers [ guildId ] ) requestedUsers [ guildId ] = { } ;
if ( ! BDFDB . ArrayUtils . is ( requestedUsers [ guildId ] [ user . id ] ) ) {
requestedUsers [ guildId ] [ user . id ] = [ instance ] ;
BDFDB . LibraryModules . APIUtils . get ( BDFDB . DiscordConstants . Endpoints . GUILD _MEMBER ( guildId , user . id ) ) . then ( result => {
loadedUsers [ guildId ] [ user . id ] = new Date ( result . body . joined _at ) ;
2021-03-15 13:28:17 +01:00
for ( let queuedInstance of requestedUsers [ guildId ] [ user . id ] ) BDFDB . ReactUtils . forceUpdate ( queuedInstance ) ;
2020-09-19 20:49:33 +02:00
} ) ;
}
else if ( ! loadedUsers [ guildId ] [ user . id ] ) requestedUsers [ guildId ] [ user . id ] . push ( instance ) ;
else {
2021-03-15 13:28:17 +01:00
let timestamp = BDFDB . LibraryComponents . DateInput . format ( this . settings . dates . joinedAtDate , loadedUsers [ guildId ] [ user . id ] ) ;
2020-09-19 20:49:33 +02:00
children . splice ( index , 0 , BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . TextScroller , {
className : BDFDB . disCNS . _joinedatdatedate + BDFDB . disCNS . userinfodate + BDFDB . disCN . textrow ,
2021-03-15 13:28:17 +01:00
children : this . settings . general . displayText ? this . labels . joined _at . replace ( "{{time}}" , timestamp ) : timestamp
2020-09-19 20:49:33 +02:00
} ) ) ;
2020-05-26 10:13:46 +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
joined _at : "Присъединил с е на {{time}}"
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
joined _at : "Deltog den {{time}}"
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 {
2021-03-15 13:28:17 +01:00
joined _at : "Beitritt am {{time}}"
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
joined _at : "Έγινε μέλος στις {{time}}"
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
joined _at : "Se unió el {{time}}"
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
joined _at : "Liittyi {{time}}"
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 {
2021-04-30 12:00:48 +02:00
joined _at : "Rejoint le {{time}}"
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
joined _at : "Pridružio se {{time}}"
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
joined _at : "Csatlakozott: {{time}}"
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
joined _at : "Iscritto il {{time}}"
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
joined _at : "{{time}}に参加しました"
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
joined _at : "{{time}}에 가입했습니다."
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
joined _at : "Prisijungė {{time}}"
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
joined _at : "Aangesloten op {{time}}"
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
joined _at : "Ble med {{time}}"
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
joined _at : "Dołączono {{time}}"
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
joined _at : "Entrou em {{time}}"
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
joined _at : "S-a înscris pe {{time}}"
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
joined _at : "Присоединился {{time}}"
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
joined _at : "Gick med den {{time}}"
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
joined _at : "เข้าร่วมเมื่อ {{time}}"
} ;
case "tr" : // Turkish
return {
joined _at : "{{time}} tarihinde katı ldı "
} ;
case "uk" : // Ukrainian
return {
joined _at : "Приєднався {{time}}"
} ;
case "vi" : // Vietnamese
return {
joined _at : "Đã tham gia vào {{time}}"
} ;
2021-01-15 17:54:22 +01:00
case "zh-CN" : // Chinese (China)
2020-12-21 19:56:36 +01:00
return {
joined _at : "已于{{time}}加入"
} ;
2021-01-15 17:54:22 +01:00
case "zh-TW" : // Chinese (Taiwan)
2020-12-21 19:56:36 +01:00
return {
joined _at : "已於{{time}}加入"
} ;
default : // English
return {
joined _at : "Joined on {{time}}"
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
} ) ( ) ;