2020-10-20 23:25:34 +02:00
/ * *
* @ name NotificationSounds
2021-03-05 13:26:41 +01:00
* @ author DevilBro
2020-10-20 23:25:34 +02:00
* @ authorId 278543574059057154
2024-02-01 18:27:18 +01:00
* @ version 3.9 . 2
2022-03-21 22:38:32 +01:00
* @ description Allows you to replace the native Sounds with custom Sounds
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/NotificationSounds/
2021-03-10 09:17:37 +01:00
* @ updateUrl https : //mwittrien.github.io/BetterDiscordAddons/Plugins/NotificationSounds/NotificationSounds.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 = {
2024-01-25 10:50:38 +01:00
"added" : {
"Current Channel" : "Added Option to change the sound for the current channel notification, (note: Discord added an option in the THEIR notification settings to play a different sound when a message is sent in the current channel, you need to have this enabled in order to be able to change the sound in the plugin settings"
2024-01-25 10:51:23 +01:00
} ,
"fixed" : {
2024-01-31 11:21:16 +01:00
"Current Channel" : "No longer plays notification sounds for current channels, if the option is disabled"
2024-01-25 10:50:38 +01: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-07-07 21:03:57 +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
} ) ;
2020-03-10 15:58:09 +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 ) ;
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-10-06 11:30:21 +02:00
var audios , choices , firedEvents ;
2020-11-11 00:36:02 +01:00
var volumes = { } ;
2020-10-06 11:30:21 +02:00
2020-09-19 20:49:33 +02:00
const removeAllKey = "REMOVE_ALL_BDFDB_DEVILBRO_DO_NOT_COPY" ;
2020-10-06 11:30:21 +02:00
const defaultDevice = "default" ;
2022-10-21 11:30:49 +02:00
var currentDevice = defaultDevice , createdAudios = { } ;
2020-09-19 20:49:33 +02:00
2021-07-02 23:29:38 +02:00
let types = { } ;
2021-06-09 17:52:32 +02:00
2021-07-02 23:29:38 +02:00
const message1Types = {
2024-01-25 10:50:38 +01:00
dm : { src : "./message3.mp3" , name : "Message (Direct Message)" } ,
groupdm : { src : "./message3.mp3" , name : "Message (Group Message)" } ,
mentioned : { src : "./message2.mp3" , name : "Message Mentioned" } ,
reply : { src : "./message2.mp3" , name : "Message Mentioned (reply)" } ,
role : { src : "./mention1.mp3" , name : "Message Mentioned (role)" } ,
everyone : { src : "./mention2.mp3" , name : "Message Mentioned (@everyone)" } ,
here : { src : "./mention3.mp3" , name : "Message Mentioned (@here)" }
2020-09-19 20:49:33 +02:00
} ;
2021-07-02 23:29:38 +02:00
2023-07-11 08:59:43 +02:00
const namePrefixes = {
"user_join" : "Voice Channel" ,
"user_leave" : "Voice Channel" ,
"user_moved" : "Voice Channel"
} ;
const nameSynonymes = {
2024-01-25 10:50:38 +01:00
"message3" : "Message (Current Channel)" ,
2023-07-11 08:59:43 +02:00
"reconnect" : "Invited To Speak"
} ;
2020-09-19 20:49:33 +02:00
const defaultAudios = {
"---" : {
2021-07-02 23:29:38 +02:00
"---" : null
2020-09-19 20:49:33 +02:00
} ,
"Discord" : { }
} ;
2020-10-06 11:30:21 +02:00
const WebAudioSound = class WebAudioSound {
constructor ( type ) {
2022-12-08 19:09:01 +01:00
this . name = type ;
2023-03-09 15:37:05 +01:00
this . _src = choices [ type ] && audios [ choices [ type ] . category ] [ choices [ type ] . sound ] || types [ type ] && types [ type ] . src || BDFDB . LibraryModules . SoundParser ( ` ./ ${ type } .mp3 ` ) ;
this . _volume = ( choices [ type ] ? choices [ type ] . volume : 100 ) / 100 ;
2020-10-06 11:30:21 +02:00
}
2021-01-06 12:38:36 +01:00
loop ( ) {
2020-10-06 11:30:21 +02:00
this . _ensureAudio ( ) . then ( audio => {
audio . loop = true ;
audio . play ( ) ;
} ) ;
}
2021-01-06 12:38:36 +01:00
play ( ) {
2020-10-06 11:30:21 +02:00
this . _ensureAudio ( ) . then ( audio => {
audio . loop = false ;
audio . play ( ) ;
} ) ;
}
2023-07-14 09:41:57 +02:00
playWithListener ( duration ) {
return new Promise ( ( callback , errorCallback ) => {
this . _ensureAudio ( ) . then ( audio => {
if ( ! duration && duration !== 0 ) errorCallback ( new Error ( "sound has no duration" ) ) ;
audio . loop = false ;
audio . play ( ) ;
setTimeout ( _ => callback ( true ) , duration ) ;
} ) ;
} ) ;
}
2021-01-06 12:38:36 +01:00
pause ( ) {
2020-10-06 11:30:21 +02:00
this . _audio . then ( audio => {
audio . pause ( ) ;
} ) ;
}
2021-01-06 12:38:36 +01:00
stop ( ) {
2020-10-06 11:30:21 +02:00
this . _destroyAudio ( ) ;
}
setTime ( time ) {
this . _audio . then ( audio => {
audio . currentTime = time ;
} ) ;
}
setLoop ( loop ) {
this . _audio . then ( audio => {
audio . loop = loop ;
} ) ;
}
2021-01-06 12:38:36 +01:00
_destroyAudio ( ) {
2020-10-06 11:30:21 +02:00
if ( this . _audio ) {
this . _audio . then ( audio => {
audio . pause ( ) ;
audio . src = "" ;
} ) ;
this . _audio = null ;
}
}
2021-01-06 12:38:36 +01:00
_ensureAudio ( ) {
2020-10-06 11:30:21 +02:00
return this . _audio = this . _audio || new Promise ( ( callback , errorCallback ) => {
let audio = new Audio ;
2020-11-22 15:12:40 +01:00
audio . src = this . _src && this . _src . startsWith ( "data" ) ? this . _src . replace ( / /g , "" ) : this . _src ;
2020-10-06 11:30:21 +02:00
audio . onloadeddata = _ => {
2022-12-08 19:09:01 +01:00
audio . volume = Math . min ( ( BDFDB . LibraryStores . MediaEngineStore . getOutputVolume ( ) / 100 ) * this . _volume * ( volumes . globalVolume / 100 ) , 1 ) ;
2022-09-29 15:10:16 +02:00
BDFDB . DiscordUtils . isPlaformEmbedded ( ) && audio . setSinkId ( currentDevice || defaultDevice ) ;
2020-10-06 11:30:21 +02:00
callback ( audio ) ;
} ;
2021-08-27 13:07:03 +02:00
audio . onerror = _ => errorCallback ( new Error ( "could not play audio" ) ) ;
audio . onended = _ => this . _destroyAudio ( ) ;
2020-10-06 11:30:21 +02:00
audio . load ( ) ;
} ) , this . _audio ;
}
} ;
2020-09-19 20:49:33 +02:00
2020-10-09 21:09:35 +02:00
return class NotificationSounds extends Plugin {
2021-01-06 12:38:36 +01:00
onLoad ( ) {
2020-09-19 20:49:33 +02:00
audios = { } ;
choices = { } ;
firedEvents = { } ;
2020-03-10 15:58:09 +01:00
2020-11-11 00:36:02 +01:00
this . defaults = {
volumes : {
2024-01-25 10:50:38 +01:00
globalVolume : { value : 100 , description : "Global Notification Sounds Volume" }
2020-11-11 00:36:02 +01:00
}
} ;
2021-04-09 18:13:38 +02:00
this . patchPriority = 9 ;
2022-12-01 22:00:48 +01:00
}
onStart ( ) {
2021-07-02 23:29:38 +02:00
const soundKeys = BDFDB . LibraryModules . SoundParser . keys ( ) ;
for ( let key of soundKeys ) {
const id = key . replace ( "./" , "" ) . replace ( ".mp3" , "" ) ;
2023-07-11 08:59:43 +02:00
const name = [ namePrefixes [ id ] , ( nameSynonymes [ id ] || id ) . replace ( "ddr-" , "HotKeys_" ) . replace ( "ptt_" , "Push2Talk_" ) . split ( /[_-]/ ) ] . flat ( 10 ) . filter ( n => n ) . map ( BDFDB . StringUtils . upperCaseFirstChar ) . join ( " " ) . replace ( /1$/g , "" ) ;
2021-07-02 23:29:38 +02:00
const src = BDFDB . LibraryModules . SoundParser ( key ) ;
let soundPackName = id . split ( "_" ) [ 0 ] ;
if ( soundPackName != id && soundKeys . filter ( n => n . indexOf ( ` ./ ${ soundPackName } ` ) > - 1 ) . length > 10 ) {
2022-09-27 11:53:04 +02:00
soundPackName = BDFDB . StringUtils . upperCaseFirstChar ( soundPackName ) ;
2021-07-02 23:29:38 +02:00
if ( ! defaultAudios [ soundPackName ] ) defaultAudios [ soundPackName ] = { } ;
defaultAudios [ soundPackName ] [ name . replace ( new RegExp ( ` ${ soundPackName } ` , "i" ) , "" ) . replace ( /bootup/i , "Discodo" ) ] = src ;
}
else {
defaultAudios . Discord [ name ] = src ;
if ( this . isSoundUsedAnywhere ( id ) ) types [ id ] = {
name : name ,
src : src ,
mute : id . startsWith ( "call_" ) ? null : false ,
2023-03-16 15:43:29 +01:00
streamMute : false ,
2024-01-25 10:50:38 +01:00
invisibleMute : false
2021-07-02 23:29:38 +02:00
} ;
if ( id == "message1" ) {
types [ id ] . mute = true ;
2023-03-16 15:43:29 +01:00
types [ id ] . streamMute = false ;
2023-04-21 09:05:58 +02:00
types [ id ] . invisibleMute = false ;
2021-07-02 23:29:38 +02:00
for ( let subType in message1Types ) types [ subType ] = {
name : message1Types [ subType ] . name ,
src : BDFDB . LibraryModules . SoundParser ( message1Types [ subType ] . src ) ,
mute : true ,
2023-03-16 15:43:29 +01:00
streamMute : false ,
2024-01-25 10:50:38 +01:00
invisibleMute : false
2021-07-02 23:29:38 +02:00
}
}
}
types = BDFDB . ObjectUtils . sort ( types , "name" ) ;
}
for ( let pack in defaultAudios ) defaultAudios [ pack ] = BDFDB . ObjectUtils . sort ( defaultAudios [ pack ] ) ;
2022-12-01 22:00:48 +01:00
2022-09-29 15:10:16 +02:00
if ( BDFDB . DiscordUtils . isPlaformEmbedded ( ) ) {
2020-10-06 11:30:21 +02:00
let change = _ => {
if ( window . navigator . mediaDevices && window . navigator . mediaDevices . enumerateDevices ) {
window . navigator . mediaDevices . enumerateDevices ( ) . then ( enumeratedDevices => {
2022-09-27 16:53:10 +02:00
let id = BDFDB . LibraryStores . MediaEngineStore . getOutputDeviceId ( ) ;
let allDevices = BDFDB . LibraryStores . MediaEngineStore . getOutputDevices ( ) ;
2020-10-06 11:30:21 +02:00
let filteredDevices = enumeratedDevices . filter ( d => d . kind == "audiooutput" && d . deviceId != "communications" ) ;
let deviceIndex = BDFDB . LibraryModules . ArrayUtils ( allDevices ) . sortBy ( d => d . index ) . findIndex ( d => d . id == id ) ;
let deviceViaId = allDevices [ id ] ;
let deviceViaIndex = filteredDevices [ deviceIndex ] ;
if ( deviceViaId && deviceViaIndex && deviceViaIndex . label != deviceViaId . name ) deviceViaIndex = filteredDevices . find ( d => d . label == deviceViaId . name ) ;
currentDevice = deviceViaIndex ? deviceViaIndex . deviceId : defaultDevice ;
} ) . catch ( _ => {
currentDevice = defaultDevice ;
} ) ;
}
} ;
2022-09-27 16:53:10 +02:00
BDFDB . StoreChangeUtils . add ( this , BDFDB . LibraryStores . MediaEngineStore , change ) ;
2020-10-06 11:30:21 +02:00
change ( ) ;
}
2022-08-04 16:35:10 +02:00
BDFDB . PatchUtils . patch ( this , BDFDB . LibraryModules . DispatchApiUtils , "dispatch" , { before : e => {
2022-08-01 22:55:52 +02:00
if ( BDFDB . ObjectUtils . is ( e . methodArguments [ 0 ] ) && e . methodArguments [ 0 ] . type == "MESSAGE_CREATE" && e . methodArguments [ 0 ] . message ) {
2021-08-27 13:07:03 +02:00
const message = e . methodArguments [ 0 ] . message ;
const guildId = message . guild _id || null ;
2024-01-31 11:21:16 +01:00
if ( message . author . id != BDFDB . UserUtils . me . id && ! BDFDB . LibraryStores . RelationshipStore . isBlocked ( message . author . id ) ) {
const isCurrent = BDFDB . LibraryStores . SelectedChannelStore . getChannelId ( ) == message . channel _id ;
2022-09-27 14:48:10 +02:00
const channel = BDFDB . LibraryStores . ChannelStore . getChannel ( message . channel _id ) ;
2022-02-12 20:49:00 +01:00
const isGroupDM = channel . isGroupDM ( ) ;
2024-01-25 21:28:17 +01:00
const isThread = BDFDB . ChannelUtils . isThread ( channel ) ;
if ( isThread && BDFDB . LibraryStores . JoinedThreadsStore . isMuted ( channel . id ) || ! isThread && BDFDB . LibraryStores . UserGuildSettingsStore . isGuildOrCategoryOrChannelMuted ( guildId , channel . id ) ) return ;
2024-01-25 10:50:38 +01:00
if ( ! guildId ) {
2022-02-12 20:49:00 +01:00
this . fireEvent ( isGroupDM ? "groupdm" : "dm" ) ;
2024-02-01 18:27:18 +01:00
! BDFDB . LibraryStores . NotificationSettingsStore . getNotifyMessagesInSelectedChannel ( ) && ! document . hasFocus ( ) && this . playAudio ( isGroupDM ? "groupdm" : "dm" ) ;
2020-03-24 12:15:03 +01:00
return ;
2020-01-16 17:33:59 +01:00
}
2022-03-09 09:39:03 +01:00
else if ( guildId ) {
2022-04-10 09:07:00 +02:00
if ( BDFDB . LibraryModules . MentionUtils . isRawMessageMentioned ( { rawMessage : message , userId : BDFDB . UserUtils . me . id } ) ) {
2022-04-08 11:32:42 +02:00
if ( message . mentions . length && ! this . isSuppressMentionsEnabled ( guildId , channel . id ) ) for ( const mention of message . mentions ) if ( mention . id == BDFDB . UserUtils . me . id ) {
2024-01-25 10:50:38 +01:00
if ( message . message _reference && ! message . interaction ) {
2022-03-09 09:39:03 +01:00
this . fireEvent ( "reply" ) ;
2024-01-31 11:21:16 +01:00
! isCurrent && this . playAudio ( "reply" ) ;
2022-03-09 09:39:03 +01:00
return ;
}
2024-01-25 10:50:38 +01:00
if ( ! message . message _reference ) {
2022-03-09 09:39:03 +01:00
this . fireEvent ( "mentioned" ) ;
2024-01-31 11:21:16 +01:00
! isCurrent && this . playAudio ( "mentioned" ) ;
2022-03-09 09:39:03 +01:00
return ;
}
2021-08-27 13:07:03 +02:00
}
2024-01-25 10:50:38 +01:00
if ( message . mention _roles . length && ! BDFDB . LibraryStores . UserGuildSettingsStore . isSuppressRolesEnabled ( guildId , channel . id ) ) {
2022-09-27 16:53:10 +02:00
const member = BDFDB . LibraryStores . GuildMemberStore . getMember ( guildId , BDFDB . UserUtils . me . id ) ;
2022-03-09 09:39:03 +01:00
if ( member && member . roles . length ) for ( const roleId of message . mention _roles ) if ( member . roles . includes ( roleId ) ) {
this . fireEvent ( "role" ) ;
2024-01-31 11:21:16 +01:00
! isCurrent && this . playAudio ( "role" ) ;
2022-03-09 09:39:03 +01:00
return ;
}
2021-08-27 13:07:03 +02:00
}
2022-09-27 16:53:10 +02:00
if ( message . mention _everyone && ! BDFDB . LibraryStores . UserGuildSettingsStore . isSuppressEveryoneEnabled ( guildId , channel . id ) ) {
2024-01-25 10:50:38 +01:00
if ( message . content . indexOf ( "@everyone" ) > - 1 ) {
2022-03-09 09:39:03 +01:00
this . fireEvent ( "everyone" ) ;
2024-01-31 11:21:16 +01:00
! isCurrent && this . playAudio ( "everyone" ) ;
2022-03-09 09:39:03 +01:00
return ;
}
2024-01-25 10:50:38 +01:00
if ( message . content . indexOf ( "@here" ) > - 1 ) {
2022-03-09 09:39:03 +01:00
this . fireEvent ( "here" ) ;
2024-01-31 11:21:16 +01:00
! isCurrent && this . playAudio ( "here" ) ;
2022-03-09 09:39:03 +01:00
return ;
}
2020-03-24 13:52:51 +01:00
}
2020-03-10 15:58:09 +01:00
}
2024-01-25 21:28:17 +01:00
if ( BDFDB . LibraryStores . UserGuildSettingsStore . allowAllMessages ( channel ) && ! ( isThread && ! BDFDB . LibraryStores . JoinedThreadsStore . hasJoined ( channel . id ) ) ) {
2022-03-09 09:39:03 +01:00
this . fireEvent ( "message1" ) ;
2024-01-31 11:21:16 +01:00
! isCurrent && this . playAudio ( "message1" ) ;
2022-03-09 09:39:03 +01:00
return ;
2020-03-10 15:58:09 +01:00
}
2020-01-16 17:33:59 +01:00
}
2018-10-11 10:21:26 +02:00
}
}
2020-03-10 15:58:09 +01:00
} } ) ;
2022-02-12 20:49:00 +01:00
2022-02-12 23:28:36 +01:00
BDFDB . PatchUtils . patch ( this , BDFDB . LibraryModules . DesktopNotificationUtils , "showNotification" , { before : e => {
2022-03-17 16:00:06 +01:00
let soundObjIndex = Array . from ( e . methodArguments ) . findIndex ( n => n && n . sound ) ;
if ( soundObjIndex && e . methodArguments [ soundObjIndex ] . sound . includes ( "message" ) ) e . methodArguments [ soundObjIndex ] . sound = null ;
2022-02-12 23:28:36 +01:00
} } ) ;
2022-12-08 19:09:01 +01:00
if ( BDFDB . LibraryModules . SoundUtils && BDFDB . LibraryModules . SoundUtils . createSound ) {
let cancel = BDFDB . PatchUtils . patch ( this , BDFDB . LibraryModules . SoundUtils , "createSound" , { after : e => {
if ( e . returnValue && e . returnValue . constructor && e . returnValue . constructor . prototype && typeof e . returnValue . constructor . prototype . play == "function" ) {
cancel ( ) ;
2023-07-14 09:41:57 +02:00
BDFDB . PatchUtils . patch ( this , e . returnValue . constructor . prototype , [ "play" , "loop" , "playWithListener" ] , { instead : e2 => {
2022-12-08 19:09:01 +01:00
let type = e2 . instance && e2 . instance . name ;
if ( type && choices [ type ] ) {
e2 . stopOriginalMethodCall ( ) ;
2023-07-14 09:41:57 +02:00
if ( type == "message1" ) BDFDB . TimeUtils . timeout ( _ => {
let called = false ;
for ( let subType of [ type ] . concat ( Object . keys ( message1Types ) ) ) if ( firedEvents [ subType ] ) {
delete firedEvents [ subType ] ;
called = true ;
break ;
2022-12-08 19:09:01 +01:00
}
2023-07-14 09:41:57 +02:00
if ( ! called ) return this . playAudio ( type , e2 . originalMethodName , e2 . instance . duration ) ;
2022-12-08 19:09:01 +01:00
} ) ;
2023-07-14 09:41:57 +02:00
else return this . playAudio ( type , e2 . originalMethodName , e2 . instance . duration ) ;
2021-06-09 17:52:32 +02:00
}
2023-07-14 09:41:57 +02:00
else return this . playAudio ( type , e2 . originalMethodName , e2 . instance . duration ) ;
2022-12-08 19:09:01 +01:00
} } ) ;
BDFDB . PatchUtils . patch ( this , e . returnValue . constructor . prototype , "stop" , { after : e2 => {
let type = e2 . instance && e2 . instance . name ;
if ( type && createdAudios [ type ] ) createdAudios [ type ] . stop ( ) ;
} } ) ;
}
} } , { noCache : true } ) ;
BDFDB . LibraryModules . SoundUtils . createSound ( "call_calling" ) ;
}
2020-03-10 15:58:09 +01:00
this . loadAudios ( ) ;
this . loadChoices ( ) ;
2020-05-07 18:23:19 +02:00
2020-05-08 19:59:59 +02:00
this . forceUpdateAll ( ) ;
2020-03-10 15:58:09 +01:00
}
2020-09-19 20:49:33 +02:00
2021-01-06 12:38:36 +01:00
onStop ( ) {
2020-10-06 11:30:21 +02:00
for ( let type in createdAudios ) if ( createdAudios [ type ] ) createdAudios [ type ] . stop ( ) ;
2020-03-10 15:58:09 +01:00
}
2018-10-11 10:21:26 +02:00
2021-08-27 13:07:03 +02:00
getSettingsPanel ( collapseStates = { } ) {
2020-09-19 20:49:33 +02:00
let successSavedAudio = data => {
2020-11-19 16:51:14 +01:00
BDFDB . NotificationUtils . toast ( ` Sound ${ data . sound } was added to category ${ data . category } . ` , { type : "success" } ) ;
2020-09-19 20:49:33 +02:00
if ( ! audios [ data . category ] ) audios [ data . category ] = { } ;
2020-10-06 23:53:08 +02:00
audios [ data . category ] [ data . sound ] = data . source ;
2020-09-19 20:49:33 +02:00
BDFDB . DataUtils . save ( audios , this , "audios" ) ;
BDFDB . PluginUtils . refreshSettingsPanel ( this , settingsPanel , collapseStates ) ;
} ;
2020-05-08 19:59:59 +02:00
2020-11-23 20:56:13 +01:00
let settingsPanel ;
return settingsPanel = BDFDB . PluginUtils . createSettingsPanel ( this , {
2020-09-19 20:49:33 +02:00
collapseStates : collapseStates ,
2020-11-23 20:56:13 +01:00
children : _ => {
let settingsItems = [ ] ;
settingsItems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . CollapseContainer , {
title : "Settings" ,
collapseStates : collapseStates ,
children : Object . keys ( volumes ) . map ( key => BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsSaveItem , {
type : "Slider" ,
plugin : this ,
keys : [ "volumes" , key ] ,
basis : "50%" ,
label : this . defaults . volumes [ key ] . description ,
value : volumes [ key ]
} ) )
} ) ) ;
settingsItems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . CollapseContainer , {
title : "Add new Sound" ,
collapseStates : collapseStates ,
2020-09-19 20:49:33 +02:00
children : [
2020-11-23 20:56:13 +01:00
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Flex , {
className : BDFDB . disCN . margintop4 ,
children : [
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Flex . Child , {
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . FormComponents . FormItem , {
title : "Categoryname" ,
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . TextInput , {
className : "input-newsound input-category" ,
value : "" ,
placeholder : "Categoryname"
} )
} )
} ) ,
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Flex . Child , {
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . FormComponents . FormItem , {
title : "Soundname" ,
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . TextInput , {
className : "input-newsound input-sound" ,
value : "" ,
placeholder : "Soundname"
} )
} )
2020-09-19 20:49:33 +02:00
} )
2020-11-23 20:56:13 +01:00
]
2020-09-19 20:49:33 +02:00
} ) ,
2020-11-23 20:56:13 +01:00
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Flex , {
className : BDFDB . disCN . margintop4 ,
align : BDFDB . LibraryComponents . Flex . Align . END ,
children : [
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Flex . Child , {
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . FormComponents . FormItem , {
title : "Source" ,
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . TextInput , {
className : "input-newsound input-source" ,
type : "file" ,
filter : [ "audio" , "video" ] ,
useFilePath : true ,
value : "" ,
placeholder : "Source"
} )
} )
} ) ,
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Button , {
style : { marginBottom : 1 } ,
onClick : _ => {
2023-10-21 13:22:27 +02:00
for ( let input of settingsPanel . props . _node . querySelectorAll ( ".input-newsound " + BDFDB . dotCN . input ) ) if ( ! input . value || input . value . length == 0 || input . value . trim ( ) . length == 0 ) return BDFDB . NotificationUtils . toast ( "Fill out all Fields to add a new Sound" , { type : "danger" } ) ;
2020-11-23 20:56:13 +01:00
let category = settingsPanel . props . _node . querySelector ( ".input-category " + BDFDB . dotCN . input ) . value . trim ( ) ;
let sound = settingsPanel . props . _node . querySelector ( ".input-sound " + BDFDB . dotCN . input ) . value . trim ( ) ;
let source = settingsPanel . props . _node . querySelector ( ".input-source " + BDFDB . dotCN . input ) . value . trim ( ) ;
if ( source . indexOf ( "http" ) == 0 ) BDFDB . LibraryRequires . request ( source , ( error , response , result ) => {
if ( response ) {
let type = response . headers [ "content-type" ] ;
if ( type && ( type . indexOf ( "octet-stream" ) > - 1 || type . indexOf ( "audio" ) > - 1 || type . indexOf ( "video" ) > - 1 ) ) return successSavedAudio ( { category , sound , source } ) ;
}
BDFDB . NotificationUtils . toast ( "Use a valid direct link to a video or audio source, they usually end on something like .mp3, .mp4 or .wav" , { type : "danger" } ) ;
} ) ;
2023-11-06 10:00:44 +01:00
else BDFDB . LibraryRequires . fs . readFile ( source , "base64" , ( error , body ) => {
2023-10-21 13:22:27 +02:00
if ( error ) BDFDB . NotificationUtils . toast ( "Could not fetch file. Please make sure the file exists." , { type : "danger" } ) ;
2023-11-06 10:00:44 +01:00
else return successSavedAudio ( { category , sound , source : ` data:audio/mpeg;base64, ${ body } ` } ) ;
2020-11-23 20:56:13 +01:00
} ) ;
} ,
children : BDFDB . LanguageUtils . LanguageStrings . SAVE
2020-09-19 20:49:33 +02:00
} )
2020-11-23 20:56:13 +01:00
]
2020-09-19 20:49:33 +02:00
} )
]
2020-11-23 20:56:13 +01:00
} ) ) ;
settingsItems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . CollapseContainer , {
2021-05-12 19:59:57 +02:00
title : "Sound Configuration" ,
2020-11-23 20:56:13 +01:00
collapseStates : collapseStates ,
2024-01-25 10:50:38 +01:00
children : Object . keys ( types ) . map ( type => type == "message3" && ! BDFDB . LibraryStores . NotificationSettingsStore . getNotifyMessagesInSelectedChannel ( ) ? null : [
2021-08-27 13:07:03 +02:00
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Flex , {
className : BDFDB . disCN . marginbottom8 ,
align : BDFDB . LibraryComponents . Flex . Align . CENTER ,
direction : BDFDB . LibraryComponents . Flex . Direction . HORIZONTAL ,
children : [
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsLabel , {
label : types [ type ] . name
} ) ,
2024-01-25 10:50:38 +01:00
[ "mute" , "streamMute" , "invisibleMute" ] . some ( n => types [ type ] [ n ] !== null ) && BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Clickable , {
2023-03-16 15:43:29 +01:00
onClick : event => BDFDB . ContextMenuUtils . open ( this , event , BDFDB . ContextMenuUtils . createItem ( BDFDB . LibraryComponents . MenuItems . MenuGroup , {
children : [
{ key : "mute" , label : [ "Mute in" , BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . StatusComponents . Status , { style : { marginLeft : 6 } , size : 12 , status : BDFDB . LibraryComponents . StatusComponents . Types . DND } ) ] } ,
2023-04-21 09:05:58 +02:00
{ key : "invisibleMute" , label : [ "Mute in" , BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . StatusComponents . Status , { style : { marginLeft : 6 } , size : 12 , status : BDFDB . LibraryComponents . StatusComponents . Types . INVISIBLE } ) ] } ,
{ key : "streamMute" , label : [ "Mute while" , BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . StatusComponents . Status , { style : { marginLeft : 6 } , size : 12 , status : BDFDB . LibraryComponents . StatusComponents . Types . STREAMING } ) ] }
2023-03-16 15:43:29 +01:00
] . map ( n => types [ type ] [ n . key ] !== null && BDFDB . ContextMenuUtils . createItem ( BDFDB . LibraryComponents . MenuItems . MenuCheckboxItem , {
label : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Flex , {
2023-03-28 16:51:56 +02:00
align : BDFDB . LibraryComponents . Flex . Align . CENTER ,
2023-03-16 15:43:29 +01:00
children : n . label
} ) ,
hint : n . hint ,
id : BDFDB . ContextMenuUtils . createItemId ( this . name , type , n . key ) ,
2023-03-28 16:51:56 +02:00
checked : choices [ type ] [ n . key ] ,
2023-03-16 15:43:29 +01:00
action : state => {
choices [ type ] [ n . key ] = state ;
this . saveChoice ( type , false ) ;
}
} ) ) . filter ( n => n )
} ) ) ,
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SvgIcon , {
width : 20 ,
height : 20 ,
name : BDFDB . LibraryComponents . SvgIcon . Names . COG
} )
2021-08-27 13:07:03 +02:00
} )
] . filter ( n => n )
} ) ,
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Flex , {
className : BDFDB . disCN . marginbottom8 ,
children : [
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Flex . Child , {
grow : 0 ,
shrink : 0 ,
basis : "31%" ,
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . FormComponents . FormItem , {
title : "Category" ,
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Select , {
value : choices [ type ] . category ,
options : Object . keys ( audios ) . map ( name => ( { value : name , label : name } ) ) ,
searchable : true ,
onChange : value => {
const categorySounds = audios [ value ] || { } ;
choices [ type ] . category = value ;
choices [ type ] . sound = categorySounds [ types [ type ] . name ] ? types [ type ] . name : Object . keys ( categorySounds ) [ 0 ] ;
this . saveChoice ( type , true ) ;
BDFDB . PluginUtils . refreshSettingsPanel ( this , settingsPanel , collapseStates ) ;
}
} )
} )
} ) ,
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Flex . Child , {
grow : 0 ,
shrink : 0 ,
basis : "31%" ,
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . FormComponents . FormItem , {
title : "Sound" ,
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Select , {
value : choices [ type ] . sound ,
options : Object . keys ( audios [ choices [ type ] . category ] || { } ) . map ( name => ( { value : name , label : name } ) ) ,
searchable : true ,
onChange : value => {
choices [ type ] . sound = value ;
this . saveChoice ( type , true ) ;
BDFDB . PluginUtils . refreshSettingsPanel ( this , settingsPanel , collapseStates ) ;
}
} )
} )
} ) ,
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Flex . Child , {
grow : 0 ,
shrink : 0 ,
basis : "31%" ,
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . FormComponents . FormItem , {
title : "Volume" ,
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Slider , {
defaultValue : choices [ type ] . volume ,
digits : 1 ,
onValueRender : value => {
return value + "%" ;
} ,
onValueChange : value => {
choices [ type ] . volume = value ;
this . saveChoice ( type , true ) ;
}
} )
} )
} )
]
} ) ,
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . FormComponents . FormDivider , {
className : BDFDB . disCN . marginbottom8
} )
] ) . flat ( 10 ) . filter ( n => n )
2020-11-23 20:56:13 +01:00
} ) ) ;
let removeableCategories = [ { value : removeAllKey , label : BDFDB . LanguageUtils . LanguageStrings . FORM _LABEL _ALL } ] . concat ( Object . keys ( audios ) . filter ( category => ! ( defaultAudios [ category ] && ! Object . keys ( audios [ category ] || { } ) . filter ( sound => defaultAudios [ category ] [ sound ] === undefined ) . length ) ) . map ( name => ( { value : name , label : name } ) ) ) ;
let removeableSounds = { } ;
for ( let category of removeableCategories ) removeableSounds [ category . value ] = [ { value : removeAllKey , label : BDFDB . LanguageUtils . LanguageStrings . FORM _LABEL _ALL } ] . concat ( Object . keys ( audios [ category . value ] || { } ) . filter ( sound => ! ( defaultAudios [ category . value ] && defaultAudios [ category . value ] [ sound ] !== undefined ) ) . map ( name => ( { value : name , label : name } ) ) ) ;
settingsItems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . CollapseContainer , {
title : "Remove Sounds" ,
collapseStates : collapseStates ,
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Flex , {
className : BDFDB . disCN . margintop4 ,
align : BDFDB . LibraryComponents . Flex . Align . END ,
children : [
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Flex . Child , {
grow : 0 ,
shrink : 0 ,
basis : "35%" ,
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . FormComponents . FormItem , {
title : "Category" ,
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Select , {
key : "REMOVE_CATEGORY" ,
value : removeAllKey ,
options : removeableCategories ,
searchable : true ,
onChange : ( category , instance ) => {
let soundSelectIns = BDFDB . ReactUtils . findOwner ( BDFDB . ReactUtils . findOwner ( instance , { name : [ "BDFDB_Modal" , "BDFDB_SettingsPanel" ] , up : true } ) , { key : "REMOVE_SOUND" } ) ;
if ( soundSelectIns && removeableSounds [ category . value ] ) {
soundSelectIns . props . options = removeableSounds [ category . value ] ;
soundSelectIns . props . value = removeAllKey ;
BDFDB . ReactUtils . forceUpdate ( soundSelectIns ) ;
}
}
} )
2020-09-19 20:49:33 +02:00
} )
2020-11-23 20:56:13 +01:00
} ) ,
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Flex . Child , {
grow : 0 ,
shrink : 0 ,
basis : "35%" ,
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . FormComponents . FormItem , {
title : "Sound" ,
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Select , {
key : "REMOVE_SOUND" ,
value : removeAllKey ,
options : removeableSounds [ removeAllKey ] ,
searchable : true
} )
} )
} ) ,
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Flex . Child , {
grow : 0 ,
shrink : 1 ,
basis : "25%" ,
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Button , {
style : { marginBottom : 1 } ,
color : BDFDB . LibraryComponents . Button . Colors . RED ,
onClick : ( event , instance ) => {
let wrapperIns = BDFDB . ReactUtils . findOwner ( instance , { name : [ "BDFDB_Modal" , "BDFDB_SettingsPanel" ] , up : true } ) ;
let categorySelectIns = BDFDB . ReactUtils . findOwner ( wrapperIns , { key : "REMOVE_CATEGORY" } ) ;
let soundSelectIns = BDFDB . ReactUtils . findOwner ( wrapperIns , { key : "REMOVE_SOUND" } ) ;
if ( categorySelectIns && soundSelectIns ) {
let soundAmount = 0 ;
let catAll = categorySelectIns . props . value == removeAllKey ;
let soundAll = soundSelectIns . props . value == removeAllKey ;
if ( catAll ) soundAmount = BDFDB . ArrayUtils . sum ( Object . keys ( audios ) . map ( category => Object . keys ( audios [ category ] || { } ) . filter ( sound => ! ( defaultAudios [ category ] && defaultAudios [ category ] [ sound ] !== undefined ) ) . length ) ) ;
else if ( soundAll ) soundAmount = Object . keys ( audios [ categorySelectIns . props . value ] || { } ) . filter ( sound => ! ( defaultAudios [ categorySelectIns . props . value ] && defaultAudios [ categorySelectIns . props . value ] [ sound ] !== undefined ) ) . length ;
else if ( audios [ categorySelectIns . props . value ] [ soundSelectIns . props . value ] ) soundAmount = 1 ;
2021-05-12 19:59:57 +02:00
if ( soundAmount ) BDFDB . ModalUtils . confirm ( this , ` Are you sure you want to delete ${ soundAmount } added Sound ${ soundAmount == 1 ? "" : "s" } ? ` , _ => {
2020-11-23 20:56:13 +01:00
if ( catAll ) BDFDB . DataUtils . remove ( this , "audios" ) ;
else if ( soundAll ) BDFDB . DataUtils . remove ( this , "audios" , categorySelectIns . props . value ) ;
else {
delete audios [ categorySelectIns . props . value ] [ soundSelectIns . props . value ] ;
if ( BDFDB . ObjectUtils . isEmpty ( audios [ categorySelectIns . props . value ] ) ) delete audios [ categorySelectIns . props . value ] ;
BDFDB . DataUtils . save ( audios , this , "audios" ) ;
}
this . loadAudios ( ) ;
this . loadChoices ( ) ;
BDFDB . PluginUtils . refreshSettingsPanel ( this , settingsPanel , collapseStates ) ;
} ) ;
2021-05-12 19:59:57 +02:00
else BDFDB . NotificationUtils . toast ( "No Sounds to delete" , { type : "danger" } ) ;
2020-09-19 20:49:33 +02:00
}
2020-11-23 20:56:13 +01:00
} ,
children : BDFDB . LanguageUtils . LanguageStrings . DELETE
} )
} )
]
2020-09-19 20:49:33 +02:00
} )
2020-11-23 20:56:13 +01:00
} ) ) ;
return settingsItems ;
}
} ) ;
2020-09-19 20:49:33 +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 ;
2020-10-06 11:30:21 +02:00
for ( let type in createdAudios ) if ( createdAudios [ type ] ) createdAudios [ type ] . stop ( ) ;
createdAudios = { } ;
2020-09-19 20:49:33 +02:00
this . forceUpdateAll ( ) ;
}
2020-05-08 19:59:59 +02:00
}
2020-08-03 18:26:59 +02:00
2021-01-06 12:38:36 +01:00
forceUpdateAll ( ) {
2020-11-11 00:36:02 +01:00
volumes = BDFDB . DataUtils . get ( this , "volumes" ) ;
2022-12-08 19:09:01 +01:00
2020-09-19 20:49:33 +02:00
BDFDB . PatchUtils . forceAllUpdates ( this ) ;
2021-02-04 15:24:56 +01:00
BDFDB . DiscordUtils . rerenderAll ( ) ;
2020-03-10 15:58:09 +01:00
}
2020-05-30 20:03:50 +02:00
2021-01-06 12:38:36 +01:00
loadAudios ( ) {
2020-11-12 17:48:14 +01:00
audios = Object . assign ( { } , BDFDB . DataUtils . load ( this , "audios" ) , defaultAudios ) ;
BDFDB . DataUtils . save ( BDFDB . ObjectUtils . exclude ( audios , Object . keys ( defaultAudios ) ) , this , "audios" ) ;
2020-09-19 20:49:33 +02:00
}
2019-01-26 22:45:19 +01:00
2021-01-06 12:38:36 +01:00
loadChoices ( ) {
2020-09-19 20:49:33 +02:00
let loadedChoices = BDFDB . DataUtils . load ( this , "choices" ) ;
for ( let type in types ) {
2020-10-06 23:53:08 +02:00
let choice = loadedChoices [ type ] || { } , soundFound = false ;
for ( let category in audios ) if ( choice . category == category ) for ( let sound in audios [ category ] ) if ( choice . sound == sound ) {
soundFound = true ;
2020-09-19 20:49:33 +02:00
break ;
}
2020-10-06 23:53:08 +02:00
if ( ! soundFound ) choice = {
2020-09-19 20:49:33 +02:00
category : "---" ,
2020-10-06 23:53:08 +02:00
sound : "---" ,
2020-09-19 20:49:33 +02:00
volume : 100 ,
mute : types [ type ] . mute ,
2023-03-16 15:43:29 +01:00
streamMute : types [ type ] . streamMute ,
2024-01-25 10:50:38 +01:00
invisibleMute : types [ type ] . invisibleMute
2020-09-19 20:49:33 +02:00
} ;
choices [ type ] = choice ;
this . saveChoice ( type , false ) ;
2020-03-10 15:58:09 +01:00
}
2018-10-11 10:21:26 +02:00
}
2019-01-26 22:45:19 +01:00
2020-09-19 20:49:33 +02:00
saveChoice ( type , play ) {
if ( ! choices [ type ] ) return ;
BDFDB . DataUtils . save ( choices [ type ] , this , "choices" , type ) ;
if ( play ) {
this . SettingsUpdated = true ;
2020-10-06 11:30:21 +02:00
this . playAudio ( type ) ;
2020-09-19 20:49:33 +02:00
}
2020-03-10 15:58:09 +01:00
}
2019-01-26 22:45:19 +01:00
2023-07-14 09:41:57 +02:00
playAudio ( type , functionCall = "play" , duration = 0 ) {
2022-09-27 14:54:19 +02:00
if ( this . dontPlayAudio ( type ) || BDFDB . LibraryStores . StreamerModeStore . disableSounds ) return ;
2020-10-06 11:30:21 +02:00
if ( createdAudios [ type ] ) createdAudios [ type ] . stop ( ) ;
createdAudios [ type ] = new WebAudioSound ( type ) ;
2023-07-14 09:41:57 +02:00
return createdAudios [ type ] [ typeof createdAudios [ type ] [ functionCall ] == "function" ? functionCall : "play" ] ( duration ) ;
2020-03-10 15:58:09 +01:00
}
2022-04-08 11:32:42 +02:00
2022-03-09 09:39:03 +01:00
isSuppressMentionsEnabled ( guildId , channelId ) {
2022-09-27 16:53:10 +02:00
let channelSettings = BDFDB . LibraryStores . UserGuildSettingsStore . getChannelMessageNotifications ( guildId , channelId ) ;
return channelSettings && ( channelSettings == BDFDB . DiscordConstants . UserNotificationSettings . NO _MESSAGES || channelSettings == BDFDB . DiscordConstants . UserNotificationSettings . NULL && BDFDB . LibraryStores . UserGuildSettingsStore . getMessageNotifications ( guildId ) == BDFDB . DiscordConstants . UserNotificationSettings . NO _MESSAGES ) ;
2020-09-19 20:49:33 +02:00
}
2019-01-26 22:45:19 +01:00
2020-09-19 20:49:33 +02:00
dontPlayAudio ( type ) {
let status = BDFDB . UserUtils . getStatus ( ) ;
2023-04-21 09:05:58 +02:00
return choices [ type ] && ( choices [ type ] . mute && status == "dnd" || choices [ type ] . streamMute && status == "streaming" || choices [ type ] . invisibleMute && ( status == "offline" || status == "invisible" ) ) ;
2020-09-19 20:49:33 +02:00
}
2020-07-26 17:02:25 +02:00
2020-09-19 20:49:33 +02:00
fireEvent ( type ) {
firedEvents [ type ] = true ;
2021-06-09 17:52:32 +02:00
BDFDB . TimeUtils . timeout ( _ => delete firedEvents [ type ] , 3000 ) ;
2020-09-19 20:49:33 +02:00
}
2021-07-02 23:29:38 +02:00
isSoundUsedAnywhere ( type ) {
2024-01-25 10:50:38 +01:00
return type && type . indexOf ( "poggermode_" ) != 0 && type != "human_man" && type != "robot_man" && type != "discodo" && type != "overlayunlock" && type != "call_ringing_beat" && ! ( type != "message1" && type != "message3" && /\d$/ . test ( type ) ) ;
2021-07-02 23:29:38 +02:00
}
2020-09-19 20:49:33 +02:00
} ;
2022-09-01 14:40:11 +02:00
} ) ( window . BDFDB _Global . PluginUtils . buildPlugin ( changeLog ) ) ;
2020-11-14 02:10:14 +01:00
} ) ( ) ;