2020-10-20 23:25:34 +02:00
/ * *
* @ name RemoveNicknames
2021-03-05 13:26:41 +01:00
* @ author DevilBro
2020-10-20 23:25:34 +02:00
* @ authorId 278543574059057154
2022-11-30 10:50:49 +01:00
* @ version 1.4 . 3
2021-03-05 13:26:41 +01:00
* @ description Replaces Nicknames with Accountnames
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/RemoveNicknames/
2021-03-10 09:17:37 +01:00
* @ updateUrl https : //mwittrien.github.io/BetterDiscordAddons/Plugins/RemoveNicknames/RemoveNicknames.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-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 ( ) {
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 ;
}
2021-05-20 16:44:45 +02:00
} : ( ( [ Plugin , BDFDB ] ) => {
2020-10-09 21:09:35 +02:00
return class RemoveNicknames extends Plugin {
2021-01-06 12:38:36 +01:00
onLoad ( ) {
2020-09-19 20:49:33 +02:00
this . defaults = {
2021-05-20 16:44:45 +02:00
general : {
2022-09-29 14:07:26 +02:00
replaceOwn : { value : false , description : "Replaces your own Name" } ,
replaceBots : { value : true , description : "Replaces the Nickname of Bots" } ,
addNickname : { value : false , description : "Adds Nickname as Parentheses" } ,
swapPositions : { value : false , description : "Swaps the Position of Username and Nickname" } ,
2021-05-20 16:44:45 +02:00
} ,
places : {
chat : { value : true , description : "Messages" } ,
mentions : { value : true , description : "Mentions" } ,
voiceChat : { value : true , description : "Voice Channels" } ,
memberList : { value : true , description : "Member List" } ,
typing : { value : true , description : "Typing List" } ,
autocompletes : { value : true , description : "Autocomplete Menu" }
2020-09-19 20:49:33 +02:00
}
} ;
2020-02-04 08:20:40 +01:00
2022-11-29 22:17:34 +01:00
this . modulePatches = {
before : [
"AutocompleteUserResult" ,
"ChannelReply" ,
"MemberListItem" ,
"VoiceUser"
] ,
after : [
"RichUserMention" ,
"TypingUsers" ,
"UserMention"
]
2020-09-19 20:49:33 +02:00
} ;
}
2020-02-04 08:20:40 +01:00
2021-01-06 12:38:36 +01:00
onStart ( ) {
2022-11-29 22:30:49 +01:00
BDFDB . PatchUtils . patch ( this , BDFDB . LibraryModules . UserNameUtils , "getName" , { after : e => {
return this . getNewName ( e . methodArguments [ 2 ] , e . methodArguments [ 0 ] ) ;
} } ) ;
2022-11-29 22:17:34 +01:00
BDFDB . PatchUtils . patch ( this , BDFDB . LibraryModules . MessageAuthorUtils , [ "getAuthor" , "getMessageAuthor" ] , { after : e => {
2021-05-20 20:11:55 +02:00
if ( this . settings . places . chat && e . methodArguments [ 0 ] && e . methodArguments [ 0 ] . author ) {
2022-11-29 22:30:49 +01:00
let newName = this . getNewName ( e . methodArguments [ 0 ] . author , ( BDFDB . LibraryStores . ChannelStore . getChannel ( e . methodArguments [ 0 ] . channel _id ) || { } ) . guild _id ) ;
2021-01-07 14:09:40 +01:00
if ( newName ) e . returnValue . nick = newName ;
}
} } ) ;
2020-09-19 20:49:33 +02:00
this . forceUpdateAll ( ) ;
2018-10-11 10:21:26 +02: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 = { } ) {
2021-05-20 16:44:45 +02:00
let settingsPanel ;
return settingsPanel = BDFDB . PluginUtils . createSettingsPanel ( this , {
collapseStates : collapseStates ,
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 : this . defaults . general [ key ] . description ,
value : this . settings . general [ key ]
} ) ) ) ;
settingsItems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsPanelList , {
title : "Remove Nicknames 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 ]
} ) )
} ) ) ;
return settingsItems ;
}
} ) ;
2020-02-04 08:20:40 +01:00
}
2018-10-11 10:21:26 +02:00
2020-09-19 20:49:33 +02:00
onSettingsClosed ( e ) {
if ( this . SettingsUpdated ) {
delete this . SettingsUpdated ;
this . forceUpdateAll ( ) ;
}
}
2021-01-06 12:38:36 +01:00
forceUpdateAll ( ) {
2022-11-29 22:30:49 +01:00
BDFDB . DiscordUtils . 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
processAutocompleteUserResult ( e ) {
2021-05-20 16:44:45 +02:00
if ( e . instance . props . user && e . instance . props . nick && this . settings . places . autocompletes ) {
2020-09-19 20:49:33 +02:00
let newName = this . getNewName ( e . instance . props . user ) ;
if ( newName ) e . instance . props . nick = newName ;
}
2020-02-04 08:20:40 +01:00
}
2019-01-26 22:45:19 +01:00
2020-09-19 20:49:33 +02:00
processVoiceUser ( e ) {
2021-05-20 16:44:45 +02:00
if ( e . instance . props . user && e . instance . props . nick && this . settings . places . voiceChat ) {
2022-11-29 22:30:49 +01:00
let newName = this . getNewName ( e . instance . props . user , e . instance . props . channel && e . instance . props . channel . guild _id ) ;
2020-09-19 20:49:33 +02:00
if ( newName ) e . instance . props . nick = newName ;
}
2020-02-04 08:20:40 +01:00
}
2019-01-26 22:45:19 +01:00
2020-09-19 20:49:33 +02:00
processTypingUsers ( e ) {
2021-05-20 16:44:45 +02:00
if ( BDFDB . ObjectUtils . is ( e . instance . props . typingUsers ) && Object . keys ( e . instance . props . typingUsers ) . length && this . settings . places . typing ) {
2022-09-27 16:53:10 +02:00
let users = Object . keys ( e . instance . props . typingUsers ) . filter ( id => id != BDFDB . UserUtils . me . id ) . filter ( id => ! BDFDB . LibraryStores . RelationshipStore . isBlocked ( id ) ) . map ( id => BDFDB . LibraryStores . UserStore . getUser ( id ) ) . filter ( user => user ) ;
2020-09-19 20:49:33 +02:00
if ( users . length ) {
let [ children , index ] = BDFDB . ReactUtils . findParent ( e . returnvalue , { props : [ [ "className" , BDFDB . disCN . typingtext ] ] } ) ;
if ( index > - 1 && BDFDB . ArrayUtils . is ( children [ index ] . props . children ) ) for ( let child of children [ index ] . props . children ) if ( child . type == "strong" ) {
let newName = this . getNewName ( users . shift ( ) ) ;
2022-11-30 10:50:49 +01:00
if ( newName ) child . props . children = newName ;
2020-09-19 20:49:33 +02:00
}
2019-03-22 20:49:46 +01:00
}
}
2019-01-02 12:52:40 +01:00
}
2020-10-15 13:08:07 +02:00
2021-02-24 17:32:17 +01:00
processUserMention ( e ) {
2021-05-20 16:44:45 +02:00
if ( e . instance . props . userId && this . settings . places . mentions ) {
2022-11-29 22:30:49 +01:00
let newName = this . getNewName ( BDFDB . LibraryStores . UserStore . getUser ( e . instance . props . userId ) , ( BDFDB . LibraryStores . ChannelStore . getChannel ( e . instance . props . channelId ) || { } ) . guild _id ) ;
2021-05-20 16:44:45 +02:00
if ( ! newName ) return ;
if ( typeof e . returnvalue . props . children == "function" ) {
let renderChildren = e . returnvalue . props . children ;
2021-07-05 16:33:10 +02:00
e . returnvalue . props . children = BDFDB . TimeUtils . suppress ( ( ... args ) => {
2021-05-20 16:44:45 +02:00
let children = renderChildren ( ... args ) ;
this . changeMention ( BDFDB . ReactUtils . findChild ( children , { name : "Mention" } ) , newName ) ;
return children ;
2021-07-05 16:33:10 +02:00
} , "" , this ) ;
2021-05-20 16:44:45 +02:00
}
else this . changeMention ( BDFDB . ReactUtils . findChild ( e . returnvalue , { name : "Mention" } ) , newName ) ;
2020-10-15 13:08:07 +02:00
}
}
2020-12-04 22:16:16 +01:00
2021-02-24 17:32:17 +01:00
processRichUserMention ( e ) {
2021-05-20 16:44:45 +02:00
if ( e . instance . props . id && this . settings . places . mentions && typeof e . returnvalue . props . children == "function" ) {
2022-11-29 22:30:49 +01:00
let newName = this . getNewName ( BDFDB . LibraryStores . UserStore . getUser ( e . instance . props . id ) , e . instance . props . guildId ) ;
2020-12-04 22:16:16 +01:00
if ( newName ) {
let renderChildren = e . returnvalue . props . children ;
2021-07-05 16:33:10 +02:00
e . returnvalue . props . children = BDFDB . TimeUtils . suppress ( ( ... args ) => {
2020-12-04 22:16:16 +01:00
let children = renderChildren ( ... args ) ;
2021-05-20 16:44:45 +02:00
this . changeMention ( children , newName ) ;
2020-12-04 22:16:16 +01:00
return children ;
2021-07-05 16:33:10 +02:00
} , "" , this ) ;
2020-12-04 22:16:16 +01:00
}
}
}
2021-05-20 16:44:45 +02:00
changeMention ( mention , newName ) {
if ( ! mention ) return ;
2022-04-16 19:22:30 +02:00
const changeMentionName = ( child , name ) => {
if ( ! child ) return ;
if ( BDFDB . ArrayUtils . is ( child ) ) for ( let i in child ) {
if ( typeof child [ i ] == "string" && child [ i ] [ 0 ] == "@" ) {
if ( child [ i ] == "@" ) child [ parseInt ( i ) + 1 ] = newName ;
else child [ i ] = "@" + newName ;
}
else changeMentionName ( child [ i ] ) ;
}
else if ( child . props && typeof child . props . children == "string" && child . props . children [ 0 ] == "@" ) child . props . children = "@" + newName ;
else if ( child . props && child . props . children ) changeMentionName ( child . props . children ) ;
} ;
changeMentionName ( mention ) ;
2021-05-20 16:44:45 +02:00
}
2019-01-26 22:45:19 +01:00
2020-12-15 09:56:43 +01:00
processChannelReply ( e ) {
2021-05-20 16:44:45 +02:00
if ( e . instance . props . reply && e . instance . props . reply . message && this . settings . places . chat ) {
2022-11-29 22:30:49 +01:00
let newName = this . getNewName ( e . instance . props . reply . message . author , e . instance . props . reply . channel && e . instance . props . reply . channel . guild _id ) ;
2020-12-15 09:56:43 +01:00
if ( newName ) e . instance . props . reply . message = new BDFDB . DiscordObjects . Message ( Object . assign ( { } , e . instance . props . reply . message , { nick : newName } ) ) ;
}
}
processMemberListItem ( e ) {
2021-05-20 16:44:45 +02:00
if ( e . instance . props . user && e . instance . props . nick && this . settings . places . memberList ) {
2022-11-29 22:30:49 +01:00
let newName = this . getNewName ( e . instance . props . user , e . instance . props . channel . guild _id ) ;
2020-12-15 09:56:43 +01:00
if ( newName ) e . instance . props . nick = newName ;
}
}
2022-11-29 22:30:49 +01:00
getNewName ( user , guildId = BDFDB . LibraryStores . SelectedGuildStore . getGuildId ( ) ) {
2020-09-19 20:49:33 +02:00
if ( ! user ) return null ;
2022-11-29 22:30:49 +01:00
let member = BDFDB . LibraryStores . GuildMemberStore . getMember ( guildId , user . id ) || { } ;
2022-09-27 16:53:10 +02:00
let origUser = BDFDB . LibraryStores . UserStore . getUser ( user . id ) || { } ;
2020-12-04 20:10:40 +01:00
let EditUsers = BDFDB . BDUtils . getPlugin ( "EditUsers" , true ) ;
let username = EditUsers && EditUsers . getUserData ( user , true , false , origUser ) . username || user . username ;
2022-11-29 22:30:49 +01:00
if ( ! member ) return username ;
2021-05-20 16:44:45 +02:00
if ( ! member . nick || user . id == BDFDB . UserUtils . me . id && ! this . settings . general . replaceOwn || user . bot && ! this . settings . general . replaceBots ) return username != origUser . username ? username : ( member . nick || username ) ;
return this . settings . general . addNickname ? ( this . settings . general . swapPositions ? ( member . nick + " (" + username + ")" ) : ( username + " (" + member . nick + ")" ) ) : username ;
2020-09-19 20:49:33 +02:00
}
} ;
2022-09-01 14:40:11 +02:00
} ) ( window . BDFDB _Global . PluginUtils . buildPlugin ( changeLog ) ) ;
2021-02-24 20:39:14 +01:00
} ) ( ) ;