2021-03-20 14:31:24 +01:00
/ * *
* @ name GameActivityToggle
* @ author DevilBro
* @ authorId 278543574059057154
2023-03-09 15:37:05 +01:00
* @ version 1.2 . 0
2021-03-20 14:31:24 +01:00
* @ description Adds a Quick - Toggle Game Activity Button
* @ invite Jx3TjNS
* @ donate https : //www.paypal.me/MircoWittrien
* @ patreon https : //www.patreon.com/MircoWittrien
* @ website https : //mwittrien.github.io/
* @ source https : //github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/GameActivityToggle/
* @ updateUrl https : //mwittrien.github.io/BetterDiscordAddons/Plugins/GameActivityToggle/GameActivityToggle.plugin.js
* /
module . exports = ( _ => {
2022-09-01 14:40:11 +02:00
const changeLog = {
2022-09-02 12:37:10 +02:00
2021-03-20 14:31: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-03-20 14:31:24 +01:00
downloadLibrary ( ) {
require ( "request" ) . get ( "https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js" , ( e , r , b ) => {
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" } ) ) ;
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" ) ;
} ) ;
}
load ( ) {
if ( ! window . BDFDB _Global || ! Array . isArray ( window . BDFDB _Global . pluginQueue ) ) window . BDFDB _Global = Object . assign ( { } , window . BDFDB _Global , { pluginQueue : [ ] } ) ;
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. ` , {
2021-03-20 14:31:24 +01:00
confirmText : "Download Now" ,
cancelText : "Cancel" ,
onCancel : _ => { delete window . BDFDB _Global . downloadModal ; } ,
onConfirm : _ => {
delete window . BDFDB _Global . downloadModal ;
this . downloadLibrary ( ) ;
}
} ) ;
}
2022-09-01 14:55:22 +02:00
if ( ! window . BDFDB _Global . pluginQueue . includes ( this . name ) ) window . BDFDB _Global . pluginQueue . push ( this . name ) ;
2021-03-20 14:31:24 +01:00
}
start ( ) { this . load ( ) ; }
stop ( ) { }
getSettingsPanel ( ) {
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-03-20 14:31:24 +01:00
template . content . firstElementChild . querySelector ( "a" ) . addEventListener ( "click" , this . downloadLibrary ) ;
return template . content . firstElementChild ;
}
} : ( ( [ Plugin , BDFDB ] ) => {
var _this ;
var toggleButton ;
const ActivityToggleComponent = class ActivityToggle extends BdApi . React . Component {
componentDidMount ( ) {
toggleButton = this ;
}
render ( ) {
2022-09-29 18:46:11 +02:00
const enabled = this . props . forceState != undefined ? this . props . forceState : BDFDB . DiscordUtils . getSetting ( "status" , "showCurrentGame" ) ;
2021-12-31 14:28:01 +01:00
delete this . props . forceState ;
2021-03-20 14:31:24 +01:00
return BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . PanelButton , Object . assign ( { } , this . props , {
2021-12-22 21:54:02 +01:00
tooltipText : enabled ? _this . labels . disable _activity : _this . labels . enable _activity ,
2021-03-20 14:31:24 +01:00
icon : iconProps => BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SvgIcon , Object . assign ( { } , iconProps , {
nativeClass : true ,
2021-05-18 18:13:18 +02:00
width : 20 ,
height : 20 ,
foreground : BDFDB . disCN . accountinfobuttonstrikethrough ,
2021-12-22 21:54:02 +01:00
name : enabled ? BDFDB . LibraryComponents . SvgIcon . Names . GAMEPAD : BDFDB . LibraryComponents . SvgIcon . Names . GAMEPAD _DISABLED
2021-03-20 14:31:24 +01:00
} ) ) ,
2022-04-20 20:49:39 +02:00
onClick : _ => _this . toggle ( )
2021-03-20 14:31:24 +01:00
} ) ) ;
}
} ;
2022-04-20 20:49:39 +02:00
var sounds = [ ] , keybind ;
2021-03-20 14:31:24 +01:00
return class GameActivityToggle extends Plugin {
onLoad ( ) {
_this = this ;
this . defaults = {
general : {
2022-05-24 14:54:41 +02:00
showButton : { value : true , description : "Show Quick Toggle Button" } ,
showItem : { value : false , description : "Show Quick Toggle Item" } ,
2021-03-20 14:31:24 +01:00
playEnable : { value : true , description : "Play Enable Sound" } ,
playDisable : { value : true , description : "Play Disable Sound" }
} ,
selections : {
enableSound : { value : "stream_started" , description : "Enable Sound" } ,
disableSound : { value : "stream_ended" , description : "Disable Sound" }
}
} ;
2022-10-11 13:08:01 +02:00
this . modulePatches = {
before : [
"Menu"
] ,
after : [
"Account"
]
2021-03-20 14:31:24 +01:00
} ;
2022-04-23 19:48:23 +02:00
this . css = `
2022-04-24 11:05:56 +02:00
$ { BDFDB . dotCNS . _gameactivitytoggleadded + BDFDB . dotCNC . accountinfowithtagasbutton + BDFDB . dotCNS . _gameactivitytoggleadded + BDFDB . dotCN . accountinfowithtagless } {
flex : 1 ;
min - width : 0 ;
2022-04-23 19:48:23 +02:00
}
` ;
2021-03-20 14:31:24 +01:00
}
2021-07-30 13:20:04 +02:00
onStart ( ) {
2022-12-07 11:11:41 +01:00
sounds = [ BDFDB . LibraryModules . SoundParser && BDFDB . LibraryModules . SoundParser . keys ( ) ] . flat ( 10 ) . filter ( n => n ) . map ( s => s . replace ( "./" , "" ) . split ( "." ) [ 0 ] ) . sort ( ) ;
2021-07-30 13:20:04 +02:00
let cachedState = BDFDB . DataUtils . load ( this , "cachedState" ) ;
2022-09-29 18:46:11 +02:00
let state = BDFDB . DiscordUtils . getSetting ( "status" , "showCurrentGame" ) ;
2021-07-30 13:20:04 +02:00
if ( ! cachedState . date || ( new Date ( ) - cachedState . date ) > 1000 * 60 * 60 * 24 * 3 ) {
2021-12-31 14:28:01 +01:00
cachedState . value = state ;
2021-07-30 13:20:04 +02:00
cachedState . date = new Date ( ) ;
BDFDB . DataUtils . save ( cachedState , this , "cachedState" ) ;
}
2022-09-29 18:46:11 +02:00
else if ( cachedState . value != null && cachedState . value != state ) BDFDB . DiscordUtils . setSetting ( "status" , "showCurrentGame" , cachedState . value ) ;
2021-07-30 13:20:04 +02:00
2022-09-29 18:46:11 +02:00
let SettingsStore = BDFDB . DiscordUtils . getSettingsStore ( ) ;
if ( SettingsStore ) BDFDB . PatchUtils . patch ( this , SettingsStore , "updateAsync" , { after : e => {
2022-10-02 08:46:13 +02:00
if ( e . methodArguments [ 0 ] != "status" ) return ;
2022-09-29 18:58:06 +02:00
let newSettings = { value : undefined } ;
2022-09-29 18:46:11 +02:00
e . methodArguments [ 1 ] ( newSettings ) ;
if ( newSettings . showCurrentGame != undefined ) {
if ( toggleButton ) toggleButton . props . forceState = newSettings . showCurrentGame . value ;
BDFDB . ReactUtils . forceUpdate ( toggleButton ) ;
2022-10-12 17:13:05 +02:00
BDFDB . DataUtils . save ( { date : new Date ( ) , value : newSettings . showCurrentGame . value } , this , "cachedState" ) ;
2022-09-29 18:46:11 +02:00
}
2021-07-30 13:20:04 +02:00
} } ) ;
2021-03-20 14:31:24 +01:00
2022-04-20 20:49:39 +02:00
keybind = BDFDB . DataUtils . load ( this , "keybind" ) ;
keybind = BDFDB . ArrayUtils . is ( keybind ) ? keybind : [ ] ;
this . activateKeybind ( ) ;
2022-10-11 13:08:01 +02:00
BDFDB . DiscordUtils . rerenderAll ( ) ;
2021-03-20 14:31:24 +01:00
}
onStop ( ) {
2022-10-11 13:08:01 +02:00
BDFDB . DiscordUtils . rerenderAll ( ) ;
2021-03-20 14:31:24 +01:00
}
getSettingsPanel ( collapseStates = { } ) {
let settingsPanel ;
return settingsPanel = BDFDB . PluginUtils . createSettingsPanel ( this , {
collapseStates : collapseStates ,
children : _ => {
let settingsItems = [ ] ;
for ( let key in this . defaults . general ) settingsItems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsSaveItem , {
type : "Switch" ,
plugin : this ,
keys : [ "general" , key ] ,
label : this . defaults . general [ key ] . description ,
value : this . settings . general [ key ]
} ) ) ;
for ( let key in this . defaults . selections ) settingsItems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsSaveItem , {
type : "Select" ,
plugin : this ,
keys : [ "selections" , key ] ,
label : this . defaults . selections [ key ] . description ,
basis : "50%" ,
2022-09-27 11:53:04 +02:00
options : sounds . map ( o => ( { value : o , label : o . split ( /[-_]/g ) . map ( BDFDB . StringUtils . upperCaseFirstChar ) . join ( " " ) } ) ) ,
2021-03-20 16:11:35 +01:00
value : this . settings . selections [ key ] ,
2023-03-09 15:37:05 +01:00
onChange : value => BDFDB . LibraryModules . SoundUtils . playSound ( value , . 4 )
2021-03-20 14:31:24 +01:00
} ) ) ;
2022-04-20 20:49:39 +02:00
settingsItems . push ( BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . settingsrowcontainer ,
children : BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . settingsrowlabel ,
children : [
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsLabel , {
label : "Global Hotkey"
} ) ,
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Flex . Child , {
className : BDFDB . disCNS . settingsrowcontrol + BDFDB . disCN . flexchild ,
grow : 0 ,
wrap : true ,
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . KeybindRecorder , {
value : ! keybind ? [ ] : keybind ,
reset : true ,
onChange : value => {
keybind = value ;
2022-04-22 18:03:46 +02:00
BDFDB . DataUtils . save ( keybind , this , "keybind" )
2022-04-20 20:49:39 +02:00
this . activateKeybind ( ) ;
}
} )
} )
] . flat ( 10 ) . filter ( n => n )
} )
} ) ) ;
2021-03-20 14:31:24 +01:00
return settingsItems ;
}
} ) ;
}
2022-05-24 14:54:41 +02:00
processMenu ( e ) {
if ( ! this . settings . general . showItem || e . instance . props . navId != "account" ) return ;
let [ _ , oldIndex ] = BDFDB . ContextMenuUtils . findItem ( e . instance , { id : BDFDB . ContextMenuUtils . createItemId ( this . name , "activity-toggle" ) } ) ;
2022-10-11 13:08:01 +02:00
if ( oldIndex > - 1 ) return ;
let [ children , index ] = BDFDB . ContextMenuUtils . findItem ( e . instance , { id : [ "custom-status" , "set-custom-status" , "edit-custom-status" ] } ) ;
if ( index > - 1 ) {
let isChecked = BDFDB . DiscordUtils . getSetting ( "status" , "showCurrentGame" ) ;
children . push ( BDFDB . ContextMenuUtils . createItem ( BDFDB . LibraryComponents . MenuItems . MenuCheckboxItem , {
label : BDFDB . LanguageUtils . LanguageStrings . ACTIVITY _STATUS ,
id : BDFDB . ContextMenuUtils . createItemId ( this . name , "activity-toggle" ) ,
icon : _ => BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . MenuItems . MenuIcon , {
icon : BDFDB . LibraryComponents . SvgIcon . Names . GAMEPAD
} ) ,
showIconFirst : true ,
checked : isChecked ,
action : _ => this . toggle ( )
} ) ) ;
2022-05-24 14:54:41 +02:00
}
}
2021-03-20 14:31:24 +01:00
processAccount ( e ) {
2022-05-24 14:54:41 +02:00
if ( ! this . settings . general . showButton ) return ;
2021-03-20 14:31:24 +01:00
let [ children , index ] = BDFDB . ReactUtils . findParent ( e . returnvalue , { name : "PanelButton" } ) ;
2021-06-18 22:55:21 +02:00
if ( index > - 1 ) {
2021-06-19 11:33:35 +02:00
e . returnvalue . props . className = BDFDB . DOMUtils . formatClassName ( e . returnvalue . props . className , BDFDB . disCN . _gameactivitytoggleadded ) ;
2021-06-18 22:55:21 +02:00
children . unshift ( BDFDB . ReactUtils . createElement ( ActivityToggleComponent , { } ) ) ;
}
2021-03-20 14:31:24 +01:00
}
2022-04-20 20:49:39 +02:00
activateKeybind ( ) {
2022-10-24 09:41:24 +02:00
if ( keybind && keybind . length ) BDFDB . ListenerUtils . addGlobal ( this , "GAMEACTIVITY_TOGGLE" , keybind , _ => this . toggle ( ) ) ;
else BDFDB . ListenerUtils . removeGlobal ( this , "GAMEACTIVITY_TOGGLE" ) ;
2022-04-20 20:49:39 +02:00
}
toggle ( ) {
2022-09-29 18:46:11 +02:00
const shouldEnable = ! BDFDB . DiscordUtils . getSetting ( "status" , "showCurrentGame" ) ;
2023-03-09 15:37:05 +01:00
this . settings . general [ shouldEnable ? "playEnable" : "playDisable" ] && BDFDB . LibraryModules . SoundUtils . playSound ( this . settings . selections [ shouldEnable ? "enableSound" : "disableSound" ] , . 4 ) ;
2022-09-29 18:46:11 +02:00
BDFDB . DiscordUtils . setSetting ( "status" , "showCurrentGame" , shouldEnable ) ;
2022-04-20 20:49:39 +02:00
}
2021-03-20 14:31:24 +01:00
setLabelsByLanguage ( ) {
switch ( BDFDB . LanguageUtils . getLanguage ( ) . id ) {
case "bg" : // Bulgarian
return {
disable _activity : "Деактивирайте активността в играта" ,
enable _activity : "Активирайте Game Activity"
} ;
case "da" : // Danish
return {
disable _activity : "Deaktiver spilaktivitet" ,
enable _activity : "Aktivér spilaktivitet"
} ;
case "de" : // German
return {
disable _activity : "Spieleaktivität deaktivieren" ,
enable _activity : "Spieleaktivität aktivieren"
} ;
case "el" : // Greek
return {
disable _activity : "Απενεργοποίηση δραστηριότητας παιχνιδιού" ,
enable _activity : "Ενεργοποίηση δραστηριότητας παιχνιδιού"
} ;
case "es" : // Spanish
return {
disable _activity : "Deshabilitar la actividad del juego" ,
enable _activity : "Habilitar la actividad del juego"
} ;
case "fi" : // Finnish
return {
disable _activity : "Poista pelitoiminto käytöstä" ,
enable _activity : "Ota pelitoiminta käyttöön"
} ;
case "fr" : // French
return {
disable _activity : "Désactiver l'activité de jeu" ,
enable _activity : "Activer l'activité de jeu"
} ;
case "hr" : // Croatian
return {
disable _activity : "Onemogući aktivnost igre" ,
enable _activity : "Omogući aktivnost u igrama"
} ;
case "hu" : // Hungarian
return {
disable _activity : "Tiltsa le a játéktevékenységet" ,
enable _activity : "Engedélyezze a játéktevékenységet"
} ;
case "it" : // Italian
return {
disable _activity : "Disabilita l'attività di gioco" ,
enable _activity : "Abilita attività di gioco"
} ;
case "ja" : // Japanese
return {
disable _activity : "ゲームアクティビティを無効にする" ,
enable _activity : "ゲームアクティビティを有効にする"
} ;
case "ko" : // Korean
return {
disable _activity : "게임 활동 비활성화" ,
enable _activity : "게임 활동 활성화"
} ;
case "lt" : // Lithuanian
return {
disable _activity : "Išjungti žaidimų veiklą" ,
enable _activity : "Įgalinti žaidimų veiklą"
} ;
case "nl" : // Dutch
return {
disable _activity : "Schakel spelactiviteit uit" ,
enable _activity : "Schakel spelactiviteit in"
} ;
case "no" : // Norwegian
return {
disable _activity : "Deaktiver spillaktivitet" ,
enable _activity : "Aktiver spillaktivitet"
} ;
case "pl" : // Polish
return {
disable _activity : "Wyłącz aktywność w grach" ,
enable _activity : "Włącz aktywność w grach"
} ;
case "pt-BR" : // Portuguese (Brazil)
return {
disable _activity : "Desativar atividade de jogo" ,
enable _activity : "Habilitar atividade de jogo"
} ;
case "ro" : // Romanian
return {
disable _activity : "Dezactivați Activitatea jocului" ,
enable _activity : "Activați Activitatea jocului"
} ;
case "ru" : // Russian
return {
disable _activity : "Отключить игровую активность" ,
enable _activity : "Включить игровую активность"
} ;
case "sv" : // Swedish
return {
disable _activity : "Inaktivera spelaktivitet" ,
enable _activity : "Aktivera spelaktivitet"
} ;
case "th" : // Thai
return {
disable _activity : "ปิดการใช้งานกิจกรรมของเกม" ,
enable _activity : "เปิดใช้งานกิจกรรมเกม"
} ;
case "tr" : // Turkish
return {
disable _activity : "Oyun Etkinliğini Devre Dı şı Bı rak" ,
enable _activity : "Oyun Etkinliğini Etkinleştir"
} ;
case "uk" : // Ukrainian
return {
disable _activity : "Вимкнути ігрову активність" ,
enable _activity : "Увімкнути ігрову активність"
} ;
case "vi" : // Vietnamese
return {
disable _activity : "Tắt hoạt động trò chơi" ,
enable _activity : "Bật hoạt động trò chơi"
} ;
case "zh-CN" : // Chinese (China)
return {
disable _activity : "禁用游戏活动" ,
enable _activity : "启用游戏活动"
} ;
case "zh-TW" : // Chinese (Taiwan)
return {
disable _activity : "禁用遊戲活動" ,
enable _activity : "啟用遊戲活動"
} ;
default : // English
return {
disable _activity : "Disable Game Activity" ,
enable _activity : "Enable Game Activity"
} ;
}
}
} ;
2022-09-01 14:40:11 +02:00
} ) ( window . BDFDB _Global . PluginUtils . buildPlugin ( changeLog ) ) ;
2021-06-18 22:55:21 +02:00
} ) ( ) ;