2020-10-20 23:25:34 +02:00
/ * *
2021-04-23 12:01:44 +02:00
* @ name StaffTag
2021-03-05 13:26:41 +01:00
* @ author DevilBro
2020-10-20 23:25:34 +02:00
* @ authorId 278543574059057154
2023-11-01 13:00:43 +01:00
* @ version 1.6 . 0
2021-04-30 16:28:10 +02:00
* @ description Adds a Crown / Tag to Server Owners ( or Admins / Management )
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/
2021-04-23 12:01:44 +02:00
* @ source https : //github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/StaffTag/
* @ updateUrl https : //mwittrien.github.io/BetterDiscordAddons/Plugins/StaffTag/StaffTag.plugin.js
2020-10-20 23:25:34 +02:00
* /
2019-01-09 12:56:24 +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-09-19 20:49:33 +02: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 ( ) {
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
} ) ;
}
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 ] ) => {
2020-09-19 20:49:33 +02:00
const userTypes = {
NONE : 0 ,
MANAGEMENT : 1 ,
ADMIN : 2 ,
2022-09-19 11:03:43 +02:00
FORUM _CREATOR : 3 ,
2021-07-29 22:02:31 +02:00
THREAD _CREATOR : 3 ,
2022-09-19 11:03:43 +02:00
GROUP _OWNER : 5 ,
OWNER : 6
2020-09-19 20:49:33 +02:00
} ;
2022-07-11 11:55:25 +02:00
const labelMap = {
[ userTypes . NONE ] : "" ,
[ userTypes . MANAGEMENT ] : "management" ,
[ userTypes . ADMIN ] : "admin" ,
2022-09-19 11:03:43 +02:00
[ userTypes . FORUM _CREATOR ] : "forumCreator" ,
2022-07-11 11:55:25 +02:00
[ userTypes . THREAD _CREATOR ] : "threadCreator" ,
[ userTypes . GROUP _OWNER ] : "groupOwner" ,
[ userTypes . OWNER ] : "owner"
} ;
const classNameMap = {
[ userTypes . NONE ] : "" ,
[ userTypes . MANAGEMENT ] : "_stafftagmanagementicon" ,
[ userTypes . ADMIN ] : "_stafftagadminicon" ,
2022-09-19 11:03:43 +02:00
[ userTypes . FORUM _CREATOR ] : "_stafftagforumcreatoricon" ,
2022-07-11 11:55:25 +02:00
[ userTypes . THREAD _CREATOR ] : "_stafftagthreadcreatoricon" ,
[ userTypes . GROUP _OWNER ] : "_stafftaggroupownericon" ,
[ userTypes . OWNER ] : "_stafftagownericon"
} ;
2021-04-23 12:01:44 +02:00
return class StaffTag extends Plugin {
2021-01-06 12:38:36 +01:00
onLoad ( ) {
2022-10-21 12:25:34 +02:00
this . modulePatches = {
2022-10-22 11:42:41 +02:00
before : [
2023-11-04 11:55:04 +01:00
"MessageUsername" ,
2023-11-01 13:00:43 +01:00
"NameContainer"
2022-10-22 11:42:41 +02:00
] ,
2022-10-21 12:25:34 +02:00
after : [
2023-11-01 13:00:43 +01:00
"UserProfileUsername" ,
2022-10-21 12:25:34 +02:00
"UsernameSection" ,
"VoiceUser"
]
2020-09-19 20:49:33 +02:00
} ;
this . defaults = {
2021-03-08 16:02:53 +01:00
general : {
2023-11-18 18:31:04 +01:00
useCrown : { value : true , description : "Uses the Crown Icon instead of the Bot Tag Style" } ,
2022-09-19 11:03:43 +02:00
useRoleColor : { value : true , description : "Uses the Role Color instead of the default Blurple" } ,
useBlackFont : { value : false , description : "Uses black Font instead of darkening the Role Color on bright Colors" } ,
2023-11-18 18:31:04 +01:00
ignoreBots : { value : false , description : "Doesn't add the Owner/Admin/Management Tag for Bots" } ,
2022-09-19 11:03:43 +02:00
ignoreMyself : { value : false , description : "Doesn't add the Owner/Admin/Management Tag for yourself" }
2021-03-08 16:02:53 +01:00
} ,
tagTypes : {
2023-11-18 18:31:04 +01:00
owners : { value : true , description : "Server Owner Tag" } ,
2022-07-11 11:55:25 +02:00
groupOwners : { value : true , description : "Group Owner Tag" } ,
threadCreators : { value : true , description : "Thread Creator Tag" } ,
2022-09-19 11:03:43 +02:00
forumCreators : { value : true , description : "Forum Creator Tag" } ,
2023-11-18 18:31:04 +01:00
admins : { value : true , description : "Admin Tag (Admin Permissions)" } ,
2022-07-11 11:55:25 +02:00
managementG : { value : true , description : "Management Tag (Server Management)" } ,
managementC : { value : true , description : "Management Tag (Channel Management)" } ,
managementT : { value : true , description : "Management Tag (Threads Management)" } ,
managementE : { value : true , description : "Management Tag (Events Management)" } ,
managementR : { value : true , description : "Management Tag (Role Management)" } ,
managementU : { value : true , description : "Management Tag (User Management 'Kick/Ban')" } ,
managementV : { value : true , description : "Management Tag (Voice Management 'Mute/Deafen/Move')" } ,
managementM : { value : true , description : "Management Tag (Message Management)" }
2021-03-08 16:02:53 +01:00
} ,
tagPlaces : {
2023-11-18 18:31:04 +01:00
chat : { value : true , description : "Messages" } ,
memberList : { value : true , description : "Member List" } ,
voiceList : { value : true , description : "Voice User List" } ,
userPopout : { value : true , description : "User Popouts" } ,
2022-07-11 11:55:25 +02:00
userProfile : { value : true , description : "User Profile Modal" } ,
2020-09-19 20:49:33 +02:00
} ,
2022-07-11 11:55:25 +02:00
customTitles : {
2023-11-18 18:31:04 +01:00
owner : { value : "" , placeholder : "Owner" , description : "Server Owner Tags" } ,
groupOwner : { value : "" , placeholder : "Group Owner" , description : "Group Owner Tags" } ,
forumCreator : { value : "" , placeholder : "Creator" , description : "Forum Creator Tags" } ,
threadCreator : { value : "" , placeholder : "Creator" , description : "Thread Creator Tags" } ,
admin : { value : "" , placeholder : "Admin" , description : "Admin Tags" } ,
management : { value : "" , placeholder : "Management" , description : "Management Tags" }
2020-09-19 20:49:33 +02:00
}
} ;
2020-02-04 08:20:40 +01:00
2020-09-19 20:49:33 +02:00
this . css = `
2021-04-23 12:01:44 +02:00
$ { BDFDB . dotCN . memberownericon + BDFDB . dotCN . _stafftagadminicon } {
2021-04-15 16:24:21 +02:00
color : # aaa9ad ;
2020-09-19 20:49:33 +02:00
}
2021-04-23 12:01:44 +02:00
$ { BDFDB . dotCN . memberownericon + BDFDB . dotCN . _stafftagmanagementicon } {
2021-04-15 16:24:21 +02:00
color : # 88540 b ;
2020-09-19 20:49:33 +02:00
}
2022-09-19 11:03:43 +02:00
$ { BDFDB . dotCN . memberownericon + BDFDB . dotCN . _stafftagforumcreatoricon } ,
2021-07-29 22:02:31 +02:00
$ { BDFDB . dotCN . memberownericon + BDFDB . dotCN . _stafftagthreadcreatoricon } {
color : var ( -- text - muted ) ;
}
2021-08-02 20:18:26 +02:00
$ { BDFDB . dotCN . memberownericon } {
2021-03-03 14:35:05 +01:00
top : 0 px ;
}
2021-08-02 20:18:26 +02:00
$ { BDFDB . dotCNS . message + BDFDB . dotCN . memberownericon } {
top : 2 px ;
2021-03-03 14:35:05 +01:00
}
2021-07-29 22:02:31 +02:00
$ { BDFDB . dotCNS . messagecompact + BDFDB . dotCN . memberownericon } {
top : 1 px ;
2021-05-14 13:04:07 +02:00
margin - left : 0 ;
margin - right : 4 px ;
}
2021-07-29 22:02:31 +02:00
$ { BDFDB . dotCNS . messagerepliedmessage + BDFDB . dotCN . memberownericon } ,
$ { BDFDB . dotCNS . messagethreadaccessory + BDFDB . dotCN . memberownericon } {
top : 0 px ;
2020-12-07 19:42:24 +01:00
margin - left : 0 ;
margin - right : 4 px ;
}
2022-06-17 19:39:05 +02:00
$ { BDFDB . dotCNS . voiceuser + BDFDB . dotCN . memberownericon } : last - child {
margin - right : 4 px ;
}
2020-09-19 20:49:33 +02:00
` ;
2020-02-04 08:20:40 +01:00
}
2020-09-19 20:49:33 +02:00
2021-01-06 12:38:36 +01:00
onStart ( ) {
2020-02-04 08:20:40 +01:00
this . forceUpdateAll ( ) ;
}
2020-09-19 20:49:33 +02:00
2021-01-06 12:38:36 +01:00
onStop ( ) {
2020-02-04 08:20:40 +01:00
this . forceUpdateAll ( ) ;
}
2019-01-26 22:45:19 +01:00
2020-09-19 20:49:33 +02:00
getSettingsPanel ( collapseStates = { } ) {
2021-03-08 16:02:53 +01:00
let settingsPanel ;
return settingsPanel = BDFDB . PluginUtils . createSettingsPanel ( this , {
2020-09-19 20:49:33 +02:00
collapseStates : collapseStates ,
2021-03-08 16:02:53 +01:00
children : _ => {
let settingsItems = [ ] ;
2020-09-19 20:49:33 +02:00
2021-03-08 16:02:53 +01:00
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 , {
2021-03-08 16:02:53 +01:00
type : "Switch" ,
plugin : this ,
key : key ,
keys : [ "general" , key ] ,
label : this . defaults . general [ key ] . description ,
value : this . settings . general [ key ]
} ) )
} ) ) ;
settingsItems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . CollapseContainer , {
title : "Tag Settings" ,
collapseStates : collapseStates ,
children : [
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsPanelList , {
title : "Add Tags for:" ,
dividerBottom : true ,
2021-03-13 10:45:12 +01:00
children : Object . keys ( this . defaults . tagTypes ) . map ( key => BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsSaveItem , {
2021-03-08 16:02:53 +01:00
type : "Switch" ,
plugin : this ,
keys : [ "tagTypes" , key ] ,
label : this . defaults . tagTypes [ key ] . description ,
value : this . settings . tagTypes [ key ]
} ) )
} ) ,
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsPanelList , {
title : "Add Tags in:" ,
2021-03-13 10:45:12 +01:00
children : Object . keys ( this . defaults . tagPlaces ) . map ( key => BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsSaveItem , {
2021-03-08 16:02:53 +01:00
type : "Switch" ,
plugin : this ,
keys : [ "tagPlaces" , key ] ,
label : this . defaults . tagPlaces [ key ] . description ,
value : this . settings . tagPlaces [ key ]
} ) )
} )
]
} ) ) ;
settingsItems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . CollapseContainer , {
2022-07-11 11:55:25 +02:00
title : "Custom Title Settings" ,
2021-03-08 16:02:53 +01:00
collapseStates : collapseStates ,
2022-07-11 11:55:25 +02:00
children : Object . keys ( this . defaults . customTitles ) . map ( key => BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsSaveItem , {
2021-03-08 16:02:53 +01:00
type : "TextInput" ,
plugin : this ,
2022-07-11 11:55:25 +02:00
keys : [ "customTitles" , key ] ,
label : this . defaults . customTitles [ key ] . description ,
2021-03-08 16:02:53 +01:00
basis : "50%" ,
2022-07-11 11:55:25 +02:00
value : this . settings . customTitles [ key ] ,
placeholder : this . defaults . customTitles [ key ] . placeholder
2021-03-08 16:02:53 +01:00
} ) )
} ) ) ;
return settingsItems ;
}
} ) ;
2020-02-04 08:20:40 +01:00
}
2019-09-04 12:34:02 +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 ;
this . forceUpdateAll ( ) ;
}
}
2021-03-08 16:02:53 +01:00
forceUpdateAll ( ) {
2020-09-19 20:49:33 +02:00
BDFDB . PatchUtils . forceAllUpdates ( this ) ;
BDFDB . MessageUtils . rerenderAll ( ) ;
2020-02-04 08:20:40 +01:00
}
2019-09-04 12:34:02 +02:00
2023-11-01 13:00:43 +01:00
processNameContainer ( e ) {
if ( ! e . instance . props . user ) return ;
2020-09-19 20:49:33 +02:00
let userType = this . getUserType ( e . instance . props . user , e . instance . props . channel && e . instance . props . channel . id ) ;
2021-03-08 16:02:53 +01:00
if ( userType && this . settings . tagPlaces . memberList ) {
2023-11-01 13:00:43 +01:00
this . injectStaffTag ( BDFDB . ObjectUtils . get ( e . instance , "props.decorators.props.children" ) , e . instance . props . user , userType , 1 , {
2021-03-03 14:35:05 +01:00
channelId : e . instance . props . channel && e . instance . props . channel . id ,
2020-09-19 20:49:33 +02:00
tagClass : BDFDB . disCN . bottagmember
2020-04-09 09:29:38 +02:00
} ) ;
2020-02-27 11:53:07 +01:00
}
2020-02-04 08:20:40 +01:00
}
2019-01-26 22:45:19 +01:00
2023-11-04 11:55:04 +01:00
processMessageUsername ( e ) {
2021-06-11 21:57:11 +02:00
if ( ! e . instance . props . message || ! this . settings . tagPlaces . chat ) return ;
const author = e . instance . props . userOverride || e . instance . props . message . author ;
let userType = this . getUserType ( author , e . instance . props . message . channel _id ) ;
2023-11-04 11:36:41 +01:00
if ( ! userType ) return ;
2023-11-04 11:55:04 +01:00
if ( ! BDFDB . ArrayUtils . is ( e . instance . props . decorations [ 0 ] ) ) e . instance . props . decorations [ 0 ] = [ e . instance . props . decorations [ 0 ] ] . filter ( n => n ) ;
this . injectStaffTag ( e . instance . props . decorations [ 0 ] , author , userType , 0 , {
2021-06-11 21:57:11 +02:00
channelId : e . instance . props . message . channel _id ,
tagClass : e . instance . props . compact ? BDFDB . disCN . messagebottagcompact : BDFDB . disCN . messagebottagcozy ,
useRem : true
} ) ;
2020-02-04 08:20:40 +01:00
}
2019-01-26 22:45:19 +01:00
2021-03-03 14:35:05 +01:00
processVoiceUser ( e ) {
2021-03-08 16:02:53 +01:00
if ( e . instance . props . user && this . settings . tagPlaces . voiceList ) {
2021-03-03 14:35:05 +01:00
let userType = this . getUserType ( e . instance . props . user , e . instance . props . channel && e . instance . props . channel . id ) ;
2023-11-01 13:00:43 +01:00
if ( ! userType ) return ;
let content = BDFDB . ReactUtils . findChild ( e . returnvalue , { props : [ [ "className" , BDFDB . disCN . voicecontent ] ] } ) ;
if ( content ) this . injectStaffTag ( content . props . children , e . instance . props . user , userType , 3 , {
channelId : e . instance . props . channel && e . instance . props . channel . id ,
} ) ;
2021-03-03 14:35:05 +01:00
}
}
2020-09-19 20:49:33 +02:00
processNameTag ( e ) {
2023-11-01 13:00:43 +01:00
if ( ! e . instance . props . user || ! e . instance . props . className ) return ;
let userType = this . getUserType ( e . instance . props . user ) ;
if ( ! userType ) return ;
let inject = false , tagClass = "" ;
if ( e . instance . props . className . indexOf ( BDFDB . disCN . userpopoutheadertagwithnickname ) > - 1 ) {
inject = this . settings . tagPlaces . userPopout ;
tagClass = BDFDB . disCNS . userpopoutheaderbottag + BDFDB . disCN . bottagnametag ;
}
else if ( e . instance . props . className . indexOf ( BDFDB . disCN . userprofilenametag ) > - 1 ) {
inject = this . settings . tagPlaces . userProfile ;
tagClass = BDFDB . disCN . bottagnametag ;
2020-02-04 08:20:40 +01:00
}
2023-11-01 13:00:43 +01:00
if ( inject ) this . injectStaffTag ( e . returnvalue . props . children , e . instance . props . user , userType , 2 , {
tagClass : tagClass ,
useRem : e . instance . props . useRemSizes ,
inverted : e . instance . props . invertBotTagColor
} ) ;
2020-02-04 08:20:40 +01:00
}
2021-05-21 17:51:26 +02:00
2022-08-31 12:54:06 +02:00
processUsernameSection ( e ) {
if ( e . instance . props . user && this . settings . tagPlaces . userPopout ) {
let userType = this . getUserType ( e . instance . props . user , e . instance . props . channel && e . instance . props . channel . id ) ;
2023-11-01 13:00:43 +01:00
if ( ! userType ) return ;
let [ children , index ] = BDFDB . ReactUtils . findParent ( e . returnvalue , { props : [ [ "className" , BDFDB . disCN . userpopoutheadernickname ] ] } ) ;
if ( index > - 1 ) {
if ( ! BDFDB . ArrayUtils . is ( children [ index ] . props . children ) ) children [ index ] . props . children = [ children [ index ] . props . children ] . flat ( 10 ) ;
this . injectStaffTag ( children [ index ] . props . children , e . instance . props . user , userType , 2 , {
tagClass : BDFDB . disCNS . userpopoutheaderbottag + BDFDB . disCN . bottagnametag ,
inverted : typeof e . instance . getMode == "function" && e . instance . getMode ( ) !== "Normal"
} ) ;
2020-09-19 20:49:33 +02:00
}
2020-08-29 19:52:21 +02:00
}
2020-02-04 08:20:40 +01:00
}
2023-11-01 13:00:43 +01:00
processUserProfileUsername ( e ) {
if ( e . instance . props . user && this . settings . tagPlaces . userProfile ) {
let userType = this . getUserType ( e . instance . props . user , e . instance . props . channel && e . instance . props . channel . id ) ;
if ( ! userType ) return ;
let username = BDFDB . ReactUtils . findChild ( e . returnvalue , { props : [ "children" , "style" , "variant" ] } ) ;
if ( ! username ) return ;
username . props . children = [ username . props . children ] ;
this . injectStaffTag ( username . props . children , e . instance . props . user , userType , 2 , {
tagClass : BDFDB . disCN . bottagnametag ,
useRem : e . instance . props . useRemSizes ,
inverted : e . instance . props . invertBotTagColor
} ) ;
}
}
2020-09-19 20:49:33 +02:00
2021-04-23 12:01:44 +02:00
injectStaffTag ( children , user , userType , insertIndex , config = { } ) {
2020-09-19 20:49:33 +02:00
if ( ! BDFDB . ArrayUtils . is ( children ) || ! user ) return ;
2021-03-08 16:02:53 +01:00
let [ _ , index ] = BDFDB . ReactUtils . findParent ( children , { props : [ [ "text" , [ BDFDB . LanguageUtils . LanguageStrings . GROUP _OWNER , BDFDB . LanguageUtils . LanguageStrings . GUILD _OWNER ] ] ] } ) ;
if ( index > - 1 ) children [ index ] = null ;
2022-09-27 20:19:49 +02:00
let channel = BDFDB . LibraryStores . ChannelStore . getChannel ( config . channelId || BDFDB . LibraryStores . SelectedChannelStore . getChannelId ( ) ) ;
2022-09-27 16:53:10 +02:00
let member = channel && this . settings . general . useRoleColor ? ( BDFDB . LibraryStores . GuildMemberStore . getMember ( channel . guild _id , user . id ) || { } ) : { } ;
2022-07-11 11:55:25 +02:00
let fallbackLabel = this . settings . general . useCrown && this . getLabelFallback ( userType ) ;
let label = this . getLabel ( userType , fallbackLabel ) ;
2022-09-19 11:03:43 +02:00
let labelExtra = userType == userTypes . FORUM _CREATOR ? BDFDB . LanguageUtils . LanguageStrings . BOT _TAG _FORUM _ORIGINAL _POSTER _TOOLTIP : userType == userTypes . MANAGEMENT && this . getManagementLabel ( user ) ;
2022-07-11 11:55:25 +02:00
2020-09-19 20:49:33 +02:00
let tag = null ;
2022-07-11 11:55:25 +02:00
if ( this . settings . general . useCrown ) tag = BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . TooltipContainer , {
text : labelExtra ? ` ${ label } ( ${ labelExtra } ) ` : label ,
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SvgIcon , {
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . memberownericon , classNameMap [ userType ] && BDFDB . disCN [ classNameMap [ userType ] ] ) ,
name : BDFDB . LibraryComponents . SvgIcon . Names . CROWN ,
"aria-label" : fallbackLabel
} )
} ) ;
2020-09-19 20:49:33 +02:00
else {
let tagColor = BDFDB . ColorUtils . convert ( member . colorString , "RGBA" ) ;
let isBright = BDFDB . ColorUtils . isBright ( tagColor ) ;
2021-03-08 16:02:53 +01:00
tagColor = isBright ? ( this . settings . general . useBlackFont ? tagColor : BDFDB . ColorUtils . change ( tagColor , - 0.3 ) ) : tagColor ;
2020-09-19 20:49:33 +02:00
tag = BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . BotTag , {
className : config . tagClass ,
useRemSizes : config . useRem ,
invertColor : config . inverted ,
style : {
2021-03-08 16:02:53 +01:00
backgroundColor : config . inverted ? ( isBright && this . settings . general . useBlackFont ? "black" : null ) : tagColor ,
color : ! config . inverted ? ( isBright && this . settings . general . useBlackFont ? "black" : null ) : tagColor
2020-09-19 20:49:33 +02:00
} ,
2022-07-11 11:55:25 +02:00
tag : label
2020-09-19 20:49:33 +02:00
} ) ;
2022-07-11 11:55:25 +02:00
if ( labelExtra ) tag = BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . TooltipContainer , {
text : labelExtra ,
2020-09-19 20:49:33 +02:00
children : tag
} ) ;
}
children . splice ( insertIndex , 0 , tag ) ;
2020-02-04 08:20:40 +01:00
}
2020-05-25 17:16:19 +02:00
2022-07-11 11:55:25 +02:00
getLabelFallback ( userType ) {
switch ( userType ) {
case userTypes . OWNER : return BDFDB . LanguageUtils . LanguageStrings . GUILD _OWNER ;
case userTypes . GROUP _OWNER : return BDFDB . LanguageUtils . LanguageStrings . GROUP _OWNER ;
2022-09-19 11:03:43 +02:00
case userTypes . FORUM _CREATOR : return BDFDB . LanguageUtils . LanguageStrings . BOT _TAG _FORUM _ORIGINAL _POSTER ;
2022-07-11 11:55:25 +02:00
case userTypes . THREAD _CREATOR : return this . labels . creator . replace ( "{{var0}}" , BDFDB . LanguageUtils . LanguageStrings . THREAD ) ;
case userTypes . ADMIN : return BDFDB . LanguageUtils . LanguageStrings . ADMINISTRATOR ;
case userTypes . MANAGEMENT : return this . labels . management ;
default : return "" ;
}
}
getLabel ( userType , fallback ) {
let type = labelMap [ userType ] ;
if ( ! type ) return fallback || "" ;
else if ( ! fallback ) return this . settings . customTitles [ type ] || this . defaults . customTitles [ type ] . placeholder ;
else return this . settings . customTitles [ type ] && this . settings . customTitles [ type ] . toLowerCase ( ) != this . defaults . customTitles [ type ] . placeholder . toLowerCase ( ) ? this . settings . customTitles [ type ] : fallback ;
}
2021-03-08 16:02:53 +01:00
getManagementLabel ( user ) {
return [
this . settings . tagTypes . managementG && BDFDB . UserUtils . can ( "MANAGE_GUILD" , user . id ) && BDFDB . LanguageUtils . LibraryStrings . server ,
this . settings . tagTypes . managementC && BDFDB . UserUtils . can ( "MANAGE_CHANNELS" , user . id ) && BDFDB . LanguageUtils . LanguageStrings . CHANNELS ,
2022-04-11 10:02:21 +02:00
this . settings . tagTypes . managementT && BDFDB . UserUtils . can ( "MANAGE_THREADS" , user . id ) && BDFDB . LanguageUtils . LanguageStrings . THREADS ,
this . settings . tagTypes . managementE && BDFDB . UserUtils . can ( "MANAGE_EVENTS" , user . id ) && BDFDB . LanguageUtils . LanguageStrings . GUILD _EVENTS ,
2021-03-08 16:02:53 +01:00
this . settings . tagTypes . managementR && BDFDB . UserUtils . can ( "MANAGE_ROLES" , user . id ) && BDFDB . LanguageUtils . LanguageStrings . ROLES ,
this . settings . tagTypes . managementU && ( BDFDB . UserUtils . can ( "BAN_MEMBERS" , user . id ) || BDFDB . UserUtils . can ( "KICK_MEMBERS" , user . id ) ) && BDFDB . LanguageUtils . LanguageStrings . MEMBERS ,
2022-04-11 10:02:21 +02:00
this . settings . tagTypes . managementV && ( BDFDB . UserUtils . can ( "MUTE_MEMBERS" , user . id ) || BDFDB . UserUtils . can ( "DEAFEN_MEMBERS" , user . id ) || BDFDB . UserUtils . can ( "MOVE_MEMBERS" , user . id ) ) && BDFDB . LanguageUtils . LanguageStrings . VOICE _AND _VIDEO ,
2021-03-08 16:02:53 +01:00
this . settings . tagTypes . managementM && BDFDB . UserUtils . can ( "MANAGE_MESSAGES" , user . id ) && BDFDB . LanguageUtils . LanguageStrings . MESSAGES
] . filter ( n => n ) . join ( ", " ) ;
}
2020-09-19 20:49:33 +02:00
getUserType ( user , channelId ) {
2022-02-11 17:39:10 +01:00
if ( ! user || this . settings . general . ignoreBots && user . bot || this . settings . general . ignoreMyself && user . id == BDFDB . UserUtils . me . id ) return userTypes . NONE ;
2022-09-27 20:19:49 +02:00
const channel = BDFDB . LibraryStores . ChannelStore . getChannel ( channelId || BDFDB . LibraryStores . SelectedChannelStore . getChannelId ( ) ) ;
2020-09-19 20:49:33 +02:00
if ( ! channel ) return userTypes . NONE ;
2022-09-27 14:48:10 +02:00
const guild = BDFDB . LibraryStores . GuildStore . getGuild ( channel . guild _id ) ;
2021-07-29 22:02:31 +02:00
2021-07-30 08:44:34 +02:00
if ( this . settings . tagTypes . owners && guild && guild . ownerId == user . id ) return userTypes . OWNER ;
else if ( this . settings . tagTypes . groupOwners && channel . ownerId == user . id && channel . isGroupDM ( ) ) return userTypes . GROUP _OWNER ;
2022-09-19 11:03:43 +02:00
else if ( this . settings . tagTypes . forumCreators && channel . ownerId == user . id && BDFDB . ChannelUtils . isForumPost ( channel ) ) return userTypes . FORUM _CREATOR ;
else if ( this . settings . tagTypes . threadCreators && channel . ownerId == user . id && BDFDB . ChannelUtils . isThread ( channel ) && ! BDFDB . ChannelUtils . isForumPost ( channel ) ) return userTypes . THREAD _CREATOR ;
2021-03-08 16:02:53 +01:00
else if ( this . settings . tagTypes . admins && BDFDB . UserUtils . can ( "ADMINISTRATOR" , user . id ) ) return userTypes . ADMIN ;
else if ( this . settings . tagTypes . managementG && BDFDB . UserUtils . can ( "MANAGE_GUILD" , user . id ) || this . settings . tagTypes . managementC && BDFDB . UserUtils . can ( "MANAGE_CHANNELS" , user . id ) || this . settings . tagTypes . managementR && BDFDB . UserUtils . can ( "MANAGE_ROLES" , user . id ) || this . settings . tagTypes . managementU && ( BDFDB . UserUtils . can ( "BAN_MEMBERS" , user . id ) || BDFDB . UserUtils . can ( "KICK_MEMBERS" , user . id ) ) || this . settings . tagTypes . managementM && BDFDB . UserUtils . can ( "MANAGE_MESSAGES" , user . id ) ) return userTypes . MANAGEMENT ;
2020-09-19 20:49:33 +02:00
return userTypes . NONE ;
2020-08-31 23:32:22 +02:00
}
2020-07-26 16:39:51 +02: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 {
2021-07-29 22:02:31 +02:00
management : "Управление" ,
2021-09-06 18:33:41 +02:00
creator : "Cъзда те л {{var0}}"
2021-07-29 22:02:31 +02:00
} ;
case "cs" : // Czech
return {
management : "Řízení" ,
creator : "{{var0}} autor"
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 {
2021-07-29 22:02:31 +02:00
management : "Ledelse" ,
creator : "{{var0}} skaber"
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-07-29 22:02:31 +02:00
management : "Verwaltung" ,
creator : "{{var0}}ersteller"
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 {
2021-07-29 22:02:31 +02:00
management : "Διαχείριση" ,
creator : "{{var0}} δημιουργός"
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 {
2021-07-29 22:02:31 +02:00
management : "Administración" ,
creator : "{{var0}} creador"
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 {
2021-07-29 22:02:31 +02:00
management : "Johto" ,
creator : "{{var0}} luoja"
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-07-29 22:02:31 +02:00
management : "La gestion" ,
creator : "{{var0}}créateur"
} ;
case "hi" : // Hindi
return {
management : "प्रबंध" ,
creator : "{{var0}}निर्माता"
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 {
2021-07-29 22:02:31 +02:00
management : "Upravljanje" ,
creator : "{{var0}} kreator"
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 {
2021-07-29 22:02:31 +02:00
management : "Menedzsment" ,
creator : "{{var0}} alkotója"
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 {
2021-07-29 22:02:31 +02:00
management : "Gestione" ,
creator : "{{var0}}creatore"
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 {
2021-07-29 22:02:31 +02:00
management : "管理" ,
creator : "{{var0}}作成者"
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 {
2021-07-29 22:02:31 +02:00
management : "조치" ,
creator : "{{var0}}창조자"
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 {
2021-07-29 22:02:31 +02:00
management : "Valdymas" ,
creator : "{{var0}} kūrėjas"
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 {
2021-07-29 22:02:31 +02:00
management : "Beheer" ,
creator : "{{var0}}maker"
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 {
2021-07-29 22:02:31 +02:00
management : "Ledelse" ,
creator : "{{var0}} skaperen"
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 {
2021-07-29 22:02:31 +02:00
management : "Zarządzanie" ,
creator : "{{var0}}twórca"
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 {
2021-07-29 22:02:31 +02:00
management : "Gestão" ,
creator : "{{var0}} criador"
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 {
2021-07-29 22:02:31 +02:00
management : "Administrare" ,
creator : "{{var0}} creator"
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 {
2021-07-29 22:02:31 +02:00
management : "Управление" ,
2021-09-06 18:33:41 +02:00
creator : "Cо зда те ль {{var0}}"
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 {
2021-07-29 22:02:31 +02:00
management : "Förvaltning" ,
creator : "{{var0}} skapare"
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 {
2021-07-29 22:02:31 +02:00
management : "การจัดการ" ,
creator : "{{var0}}ผู้สร้าง"
2020-12-21 19:56:36 +01:00
} ;
case "tr" : // Turkish
return {
2021-07-29 22:02:31 +02:00
management : "Yönetim" ,
creator : "{{var0}}yaratı cı "
2020-12-21 19:56:36 +01:00
} ;
case "uk" : // Ukrainian
return {
2021-07-29 22:02:31 +02:00
management : "Управління" ,
creator : "{{var0}} творець"
2020-12-21 19:56:36 +01:00
} ;
case "vi" : // Vietnamese
return {
2021-07-29 22:02:31 +02:00
management : "Sự quản lý" ,
creator : "Người tạo {{var0}}"
2020-12-21 19:56:36 +01:00
} ;
2021-01-15 17:54:22 +01:00
case "zh-CN" : // Chinese (China)
2020-12-21 19:56:36 +01:00
return {
2021-07-29 22:02:31 +02:00
management : "管理" ,
2021-12-15 21:44:54 +01:00
creator : "{{var0}} 创建者"
2020-12-21 19:56:36 +01:00
} ;
2021-01-15 17:54:22 +01:00
case "zh-TW" : // Chinese (Taiwan)
2020-12-21 19:56:36 +01:00
return {
2021-07-29 22:02:31 +02:00
management : "管理" ,
2021-12-15 21:44:54 +01:00
creator : "{{var0}} 建立者"
2020-12-21 19:56:36 +01:00
} ;
default : // English
return {
2021-07-29 22:02:31 +02:00
management : "Management" ,
creator : "{{var0}} Creator"
2020-09-19 20:49:33 +02:00
} ;
}
}
} ;
2022-09-01 14:40:11 +02:00
} ) ( window . BDFDB _Global . PluginUtils . buildPlugin ( changeLog ) ) ;
2021-12-15 21:44:54 +01:00
} ) ( ) ;