2020-10-20 23:25:34 +02:00
/ * *
* @ name TopRoleEverywhere
2021-03-05 13:26:41 +01:00
* @ author DevilBro
2020-10-20 23:25:34 +02:00
* @ authorId 278543574059057154
2022-11-05 18:26:21 +01:00
* @ version 3.1 . 1
2021-03-05 13:26:41 +01:00
* @ description Adds the highest Role of a User as a Tag
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/TopRoleEverywhere/
2021-03-10 09:17:37 +01:00
* @ updateUrl https : //mwittrien.github.io/BetterDiscordAddons/Plugins/TopRoleEverywhere/TopRoleEverywhere.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 = ( _ => {
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-12-07 19:42:24 +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 ( ) {
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 ;
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 ] ) => {
return class TopRoleEverywhere extends Plugin {
2021-01-06 12:38:36 +01:00
onLoad ( ) {
2020-09-19 20:49:33 +02:00
this . defaults = {
2021-06-11 22:06:02 +02:00
general : {
2021-06-25 16:15:38 +02:00
useOtherStyle : { value : false , description : "Uses BotTag Style instead of the Role Style" } ,
useBlackFont : { value : false , description : "Uses black Font instead of darkening the Color for BotTag Style on bright Colors" } ,
includeColorless : { value : false , description : "Includes colorless Roles" } ,
showOwnerRole : { value : false , description : ` Displays Role Tag of Server Owner as " ${ BDFDB . LanguageUtils . LanguageStrings . GUILD _OWNER } ". ` } ,
disableForBots : { value : false , description : "Disables Role Tag for Bots" } ,
addUserId : { value : false , description : "Adds the User Id as a Tag to the Chat Window" } ,
userIdFirst : { value : false , description : "Places the User Id before the Role Tag" }
2021-06-11 22:06:02 +02:00
} ,
places : {
2021-06-25 16:15:38 +02:00
chat : { value : true , description : "Chat Window" } ,
memberList : { value : true , description : "Member List" } ,
voiceList : { value : true , description : "Voice User List" } ,
2020-09-19 20:49:33 +02:00
}
} ;
2022-10-24 10:12:01 +02:00
this . modulePatches = {
before : [
"MessageHeader"
] ,
after : [
"MemberListItem" ,
"VoiceUser"
]
2020-09-19 20:49:33 +02:00
} ;
2020-12-07 19:42:24 +01:00
this . patchPriority = 4 ;
2020-09-19 20:49:33 +02:00
this . css = `
$ { BDFDB . dotCNS . member + BDFDB . dotCN . namecontainercontent } {
overflow : visible ;
}
$ { BDFDB . dotCN . _toproleseverywheretag } {
2021-03-03 14:35:05 +01:00
display : inline - flex ;
flex : 0 1 auto ;
2020-09-19 20:49:33 +02:00
cursor : pointer ;
overflow : hidden ;
text - overflow : ellipsis ;
white - space : nowrap ;
}
$ { BDFDB . dotCN . _toproleseverywheremembertag } {
max - width : 50 % ;
}
$ { BDFDB . dotCNS . themelight + BDFDB . dotCN . _toproleseverywhererolestyle } {
color : rgba ( 79 , 84 , 92 , 0.8 ) ;
}
$ { BDFDB . dotCNS . themedark + BDFDB . dotCN . _toproleseverywhererolestyle } {
color : hsla ( 0 , 0 % , 100 % , 0.8 ) ;
}
2020-12-07 19:55:57 +01:00
$ { BDFDB . dotCNS . messagerepliedmessage + BDFDB . dotCN . _toproleseverywhererolestyle } ,
$ { BDFDB . dotCNS . messagecompact + BDFDB . dotCN . _toproleseverywhererolestyle } {
2020-09-19 20:49:33 +02:00
margin - right : 0.3 rem ;
2021-06-11 22:06:02 +02:00
margin - left : 0 ;
2020-10-07 10:20:55 +02:00
text - indent : 0 ;
2020-09-19 20:49:33 +02:00
}
$ { BDFDB . dotCN . _toproleseverywhererolestyle } {
display : inline - flex ;
margin : 0 0 0 0.3 rem ;
}
2022-11-22 00:32:47 +01:00
$ { BDFDB . dotCNS . _toproleseverywhererolestyle + BDFDB . dotCN . userrolecircle } {
2020-09-19 20:49:33 +02:00
flex : 0 0 auto ;
}
` ;
}
2020-02-04 08:20:40 +01:00
2021-01-06 12:38:36 +01:00
onStart ( ) {
2020-09-19 20:49:33 +02:00
this . forceUpdateAll ( ) ;
2020-02-04 08:20:40 +01:00
}
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 ( ) ;
}
2018-10-11 10:21:26 +02:00
2020-09-19 20:49:33 +02:00
getSettingsPanel ( collapseStates = { } ) {
let settingsPanel , settingsItems = [ ] ;
2020-02-04 08:20:40 +01:00
2021-06-11 22:06:02 +02:00
for ( let key in this . defaults . general ) settingsItems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsSaveItem , {
2020-09-19 20:49:33 +02:00
type : "Switch" ,
plugin : this ,
2021-06-11 22:06:02 +02:00
keys : [ "general" , key ] ,
label : this . defaults . general [ key ] . description ,
value : this . settings . general [ key ]
2020-09-19 20:49:33 +02:00
} ) ) ;
2020-12-15 10:35:30 +01:00
settingsItems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsPanelList , {
2020-09-19 20:49:33 +02:00
title : "Add Role Tags in:" ,
2021-06-11 22:06:02 +02:00
children : Object . keys ( this . defaults . places ) . map ( key => BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsSaveItem , {
2020-09-19 20:49:33 +02:00
type : "Switch" ,
plugin : this ,
2021-06-11 22:06:02 +02:00
keys : [ "places" , key ] ,
label : this . defaults . places [ key ] . description ,
value : this . settings . places [ key ]
2020-09-19 20:49:33 +02:00
} ) )
} ) ) ;
return settingsPanel = BDFDB . PluginUtils . createSettingsPanel ( this , settingsItems ) ;
2020-02-04 08:20:40 +01:00
}
2019-01-26 22:45:19 +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 ( ) ;
}
2020-02-04 08:20:40 +01:00
}
2020-09-19 20:49:33 +02:00
2021-01-06 12:38:36 +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-01-26 22:45:19 +01:00
2020-09-19 20:49:33 +02:00
processMemberListItem ( e ) {
2021-06-11 22:06:02 +02:00
if ( e . instance . props . user && this . settings . places . memberList ) this . injectRoleTag ( BDFDB . ObjectUtils . get ( e . returnvalue , "props.decorators.props.children" ) , e . instance . props . user , "member" , 2 , {
tagClass : BDFDB . disCN . bottagmember
} ) ;
2020-02-04 08:20:40 +01:00
}
2019-01-26 22:45:19 +01:00
2022-10-24 10:12:01 +02:00
processMessageHeader ( e ) {
2021-06-11 22:06:02 +02:00
if ( ! e . instance . props . message ) return ;
2022-10-24 10:12:01 +02:00
let [ children , index ] = BDFDB . ReactUtils . findParent ( e . instance . props . username , { filter : n => n && n . props && typeof n . props . renderPopout == "function" } ) ;
2022-05-26 15:01:24 +02:00
if ( index == - 1 ) return ;
2021-06-11 22:06:02 +02:00
const author = e . instance . props . userOverride || e . instance . props . message . author ;
2022-06-15 20:47:03 +02:00
if ( this . settings . places . chat ) this . injectRoleTag ( children , author , "chat" , e . instance . props . compact ? index : ( index + 2 ) , {
2021-06-11 22:06:02 +02:00
tagClass : e . instance . props . compact ? BDFDB . disCN . messagebottagcompact : BDFDB . disCN . messagebottagcozy ,
useRem : true
} ) ;
2022-11-05 18:26:21 +01:00
if ( this . settings . general . addUserId ) this . injectIdTag ( children , author , "chat" , ( e . instance . props . compact ? index : ( index + 2 ) ) + ( this . settings . general . userIdFirst ? 0 : 1 ) , {
2021-06-11 22:06:02 +02:00
tagClass : e . instance . props . compact ? BDFDB . disCN . messagebottagcompact : BDFDB . disCN . messagebottagcozy ,
useRem : true
} ) ;
2019-11-28 12:26:23 +01:00
}
2020-06-06 10:49:00 +02:00
2021-03-03 14:35:05 +01:00
processVoiceUser ( e ) {
2021-06-11 22:06:02 +02:00
if ( e . instance . props . user && this . settings . places . voiceList ) {
2021-03-03 14:35:05 +01:00
let content = BDFDB . ReactUtils . findChild ( e . returnvalue , { props : [ [ "className" , BDFDB . disCN . voicecontent ] ] } ) ;
if ( content ) this . injectRoleTag ( content . props . children , e . instance . props . user , "voice" , 3 ) ;
}
}
2020-12-07 19:42:24 +01:00
injectRoleTag ( children , user , type , insertIndex , config = { } ) {
2020-09-19 20:49:33 +02:00
if ( ! BDFDB . ArrayUtils . is ( children ) || ! user ) return ;
2022-09-27 16:53:10 +02:00
let guild = BDFDB . LibraryStores . GuildStore . getGuild ( BDFDB . LibraryStores . SelectedGuildStore . getGuildId ( ) ) ;
2021-06-11 22:06:02 +02:00
if ( ! guild || user . bot && this . settings . general . disableForBots ) return ;
2020-09-19 20:49:33 +02:00
let role = BDFDB . LibraryModules . PermissionRoleUtils . getHighestRole ( guild , user . id ) ;
2021-06-11 22:06:02 +02:00
if ( this . settings . general . showOwnerRole && user . id == guild . ownerId ) role = Object . assign ( { } , role , { name : BDFDB . LanguageUtils . LanguageStrings . GUILD _OWNER , ownerRole : true } ) ;
if ( role && ! role . colorString && ! this . settings . general . includeColorless && ! role . ownerRole ) {
2022-09-27 16:53:10 +02:00
let member = BDFDB . LibraryStores . GuildMemberStore . getMember ( guild . id , user . id ) ;
2020-09-19 20:49:33 +02:00
if ( member ) for ( let sortedRole of BDFDB . ArrayUtils . keySort ( member . roles . map ( roleId => guild . getRole ( roleId ) ) , "position" ) . reverse ( ) ) if ( sortedRole . colorString ) {
role = sortedRole ;
break ;
}
}
2021-06-11 22:06:02 +02:00
if ( role && ( role . colorString || role . ownerRole || this . settings . general . includeColorless ) ) children . splice ( insertIndex , 0 , this . createTag ( role , type , config ) ) ;
2020-09-19 20:49:33 +02:00
}
2020-12-07 19:42:24 +01:00
injectIdTag ( children , user , type , insertIndex , config = { } ) {
2020-09-19 20:49:33 +02:00
if ( ! BDFDB . ArrayUtils . is ( children ) || ! user ) return ;
2020-12-07 19:42:24 +01:00
children . splice ( insertIndex , 0 , this . createTag ( {
2020-09-19 20:49:33 +02:00
name : user . id
} , type , config ) ) ;
}
createTag ( role , type , config = { } ) {
2021-06-11 22:06:02 +02:00
if ( this . settings . general . useOtherStyle ) {
2020-09-19 20:49:33 +02:00
let tagColor = BDFDB . ColorUtils . convert ( role . colorString || BDFDB . DiscordConstants . Colors . PRIMARY _DARK _500 , "RGB" )
let isBright = role . colorString && BDFDB . ColorUtils . isBright ( tagColor ) ;
2021-06-11 22:06:02 +02:00
tagColor = isBright ? ( this . settings . general . useBlackFont ? tagColor : BDFDB . ColorUtils . change ( tagColor , - 0.3 ) ) : tagColor ;
2020-09-19 20:49:33 +02:00
return BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . BotTag , {
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . _toproleseverywheretag , BDFDB . disCN [ ` _toproleseverywhere ${ type } tag ` ] , BDFDB . disCN . _toproleseverywherebadgestyle , config . tagClass ) ,
useRemSizes : config . useRem ,
invertColor : config . inverted ,
style : {
backgroundColor : tagColor ,
2021-06-11 22:06:02 +02:00
color : isBright && this . settings . general . useBlackFont ? "black" : null
2020-09-19 20:49:33 +02:00
} ,
tag : role . name ,
2022-09-27 20:56:31 +02:00
onContextMenu : role . id ? event => this . openRoleContextMenu ( event , role ) : null
2020-09-19 20:49:33 +02:00
} ) ;
}
else return BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . MemberRole , {
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . _toproleseverywheretag , BDFDB . disCN [ ` _toproleseverywhere ${ type } tag ` ] , BDFDB . disCN . _toproleseverywhererolestyle ) ,
role : role ,
2022-09-27 20:56:31 +02:00
onContextMenu : role . id ? event => this . openRoleContextMenu ( event , role ) : null
2020-02-04 08:20:40 +01:00
} ) ;
}
2020-06-06 10:49:00 +02:00
2022-09-27 20:56:31 +02:00
openRoleContextMenu ( event , role ) {
BDFDB . LibraryModules . ContextMenuUtils . openContextMenu ( event , function ( e ) {
2020-09-19 20:49:33 +02:00
return BDFDB . ReactUtils . createElement ( BDFDB . ModuleUtils . findByName ( "DeveloperContextMenu" ) , Object . assign ( { } , e , { id : role . id } ) ) ;
} ) ;
}
} ;
2022-09-01 14:40:11 +02:00
} ) ( window . BDFDB _Global . PluginUtils . buildPlugin ( changeLog ) ) ;
2022-11-05 18:26:21 +01:00
} ) ( ) ;