2020-10-20 23:25:34 +02:00
/ * *
* @ name FriendNotifications
2021-03-05 14:15:25 +01:00
* @ author DevilBro
2020-10-20 23:25:34 +02:00
* @ authorId 278543574059057154
2021-03-21 11:14:57 +01:00
* @ version 1.6 . 5
2021-03-05 14:15:25 +01:00
* @ description Shows a Notification when a Friend or a User , you choose to observe , changes their Status
2020-10-20 23:25:34 +02:00
* @ invite Jx3TjNS
2020-11-19 16:45:36 +01:00
* @ 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/FriendNotifications/
2021-03-10 09:17:37 +01:00
* @ updateUrl https : //mwittrien.github.io/BetterDiscordAddons/Plugins/FriendNotifications/FriendNotifications.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 = ( _ => {
2020-10-09 21:09:35 +02:00
const config = {
2020-09-19 20:49:33 +02:00
"info" : {
"name" : "FriendNotifications" ,
"author" : "DevilBro" ,
2021-03-21 11:14:57 +01:00
"version" : "1.6.5" ,
2021-03-04 12:15:46 +01:00
"description" : "Shows a Notification when a Friend or a User, you choose to observe, changes their Status"
2020-10-30 16:16:10 +01:00
} ,
2020-10-30 16:15:43 +01:00
"changeLog" : {
2021-03-21 11:14:57 +01:00
"fixed" : {
"Add Stranger" : "Works again"
} ,
2021-03-16 15:16:36 +01:00
"improved" : {
"Time Log Timestamp Format" : "Added Option to allow Users to customize the Timestamp Format in the Time Log"
2020-10-30 16:15:43 +01:00
}
}
2020-02-20 23:12:40 +01:00
} ;
2020-11-13 19:47:44 +01:00
2020-10-09 21:09:35 +02:00
return ! window . BDFDB _Global || ( ! window . BDFDB _Global . loaded && ! window . BDFDB _Global . started ) ? class {
2021-01-06 12:38:36 +01:00
getName ( ) { return config . info . name ; }
getAuthor ( ) { return config . info . author ; }
getVersion ( ) { return config . info . version ; }
2021-02-01 17:13:13 +01:00
getDescription ( ) { return ` The Library Plugin needed for ${ config . info . name } is missing. Open the Plugin Settings to download it. \n \n ${ config . info . description } ` ; }
downloadLibrary ( ) {
require ( "request" ) . get ( "https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js" , ( e , r , b ) => {
2021-03-05 14:15:25 +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-02-09 14:51:48 +01: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 ;
2021-01-14 16:14:44 +01:00
BdApi . showConfirmationModal ( "Library Missing" , ` The Library Plugin needed for ${ config . info . 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
} ) ;
}
if ( ! window . BDFDB _Global . pluginQueue . includes ( config . info . name ) ) window . BDFDB _Global . pluginQueue . push ( config . info . 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" ) ;
2021-01-14 16:14:44 +01: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 ${ config . info . 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
var _this ;
2020-12-22 18:45:40 +01:00
var userStatusStore , timeLog , lastTimes , checkInterval , paginationOffset = { } ;
var friendCounter , timeLogList ;
2021-03-16 15:16:36 +01:00
var settings = { } , dates = { } , amounts = { } , notificationStrings = { } , notificationSounds = { } , observedUsers = { } ;
2020-01-22 13:54:03 +01:00
2021-01-15 21:21:24 +01:00
const statuses = {
online : {
value : true ,
name : "STATUS_ONLINE" ,
sound : true
} ,
idle : {
value : false ,
name : "STATUS_IDLE" ,
sound : true
} ,
dnd : {
value : false ,
name : "STATUS_DND" ,
sound : true
} ,
playing : {
value : false ,
2021-01-20 14:50:09 +01:00
checkActivity : true ,
2021-01-15 21:21:24 +01:00
sound : true
} ,
listening : {
value : false ,
2021-01-20 14:50:09 +01:00
checkActivity : true ,
2021-01-15 21:21:24 +01:00
sound : true
} ,
streaming : {
value : false ,
2021-01-20 14:50:09 +01:00
checkActivity : true ,
2021-01-15 21:21:24 +01:00
sound : true
} ,
offline : {
value : true ,
name : "STATUS_OFFLINE" ,
sound : true
} ,
mobile : {
value : false
} ,
custom : {
value : false
}
} ;
2021-01-02 12:51:18 +01:00
const notificationTypes = {
DISABLED : {
button : null ,
value : 0 ,
color : ""
} ,
TOAST : {
button : 0 ,
value : 1 ,
color : "var(--bdfdb-blurple)"
} ,
DESKTOP : {
button : 2 ,
value : 2 ,
color : "STATUS_GREEN"
}
} ;
2020-09-19 20:49:33 +02:00
const FriendOnlineCounterComponent = class FriendOnlineCounter extends BdApi . React . Component {
2021-01-20 16:00:29 +01:00
componentDidMount ( ) {
2020-09-19 20:49:33 +02:00
friendCounter = this ;
2019-12-17 11:15:02 +01:00
}
2021-01-20 16:00:29 +01:00
render ( ) {
2020-09-19 20:49:33 +02:00
return BDFDB . ReactUtils . createElement ( "div" , {
2021-03-30 11:18:14 +02:00
className : BDFDB . disCNS . guildouter + BDFDB . disCN . _friendnotificationsfriendsonlinewrap ,
2020-09-19 20:49:33 +02:00
children : BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCNS . guildslabel + BDFDB . disCN . _friendnotificationsfriendsonline ,
children : BDFDB . LanguageUtils . LanguageStringsFormat ( "FRIENDS_ONLINE_HEADER" , this . props . amount ) ,
2021-03-16 15:16:36 +01:00
onClick : _ => _this . showTimeLog ( )
2020-09-19 20:49:33 +02:00
} )
} ) ;
}
} ;
2020-12-22 18:45:40 +01:00
const TimeLogComponent = class TimeLog extends BdApi . React . Component {
2021-01-20 16:00:29 +01:00
componentDidMount ( ) {
2020-12-22 18:45:40 +01:00
timeLogList = this ;
}
2021-01-20 16:00:29 +01:00
render ( ) {
2020-12-22 18:45:40 +01:00
return this . props . entries . length ? BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . PaginatedList , {
items : this . props . entries ,
2021-03-17 09:36:59 +01:00
amount : 50 ,
2020-12-22 18:45:40 +01:00
copyToBottom : true ,
renderItem : ( log , i ) => [
i > 0 ? BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . FormComponents . FormDivider , {
className : BDFDB . disCNS . margintop8 + BDFDB . disCN . marginbottom8
} ) : null ,
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Flex , {
align : BDFDB . LibraryComponents . Flex . Align . CENTER ,
children : [
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . TextElement , {
className : BDFDB . disCN . _friendnotificationslogtime ,
2021-03-16 15:16:36 +01:00
children : BDFDB . LibraryComponents . DateInput . format ( dates . logDate , log . timestamp )
2020-12-22 18:45:40 +01:00
} ) ,
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . AvatarComponents . default , {
className : BDFDB . disCN . _friendnotificationslogavatar ,
src : log . avatar ,
status : log . status ,
size : BDFDB . LibraryComponents . AvatarComponents . Sizes . SIZE _40
} ) ,
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . TextScroller , {
className : BDFDB . disCN . _friendnotificationslogcontent ,
speed : 1 ,
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . TextElement , {
children : BDFDB . ReactUtils . elementToReact ( BDFDB . DOMUtils . create ( log . string ) )
} )
} )
]
} )
]
} ) : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . MessagesPopoutComponents . EmptyStateBottom , {
msg : BDFDB . LanguageUtils . LanguageStrings . AUTOCOMPLETE _NO _RESULTS _HEADER ,
image : BDFDB . DiscordUtils . getTheme ( ) == BDFDB . disCN . themelight ? "/assets/9b0d90147f7fab54f00dd193fe7f85cd.svg" : "/assets/308e587f3a68412f137f7317206e92c2.svg"
} )
}
} ;
2020-09-19 20:49:33 +02:00
2020-10-09 21:09:35 +02:00
return class FriendNotifications extends Plugin {
2021-01-06 12:38:36 +01:00
onLoad ( ) {
2020-09-19 20:49:33 +02:00
_this = this ;
userStatusStore = { } ;
timeLog = [ ] ;
lastTimes = { } ;
friendCounter = null ;
2019-09-04 12:34:02 +02:00
2020-09-19 20:49:33 +02:00
this . defaults = {
settings : {
2021-01-02 12:51:18 +01:00
addOnlineCount : { value : true , description : "Add an Online friend Counter to the Server List (click to open logs)" } ,
showDiscriminator : { value : false , description : "Add the User Discriminator" } ,
2020-11-19 16:51:14 +01:00
disableForNew : { value : false , description : "Disable Notifications for newly added Friends: " } ,
2021-01-02 12:51:18 +01:00
muteOnDND : { value : false , description : "Do not notify me when I am in DnD" } ,
2020-11-19 16:51:14 +01:00
openOnClick : { value : false , description : "Open the DM when you click a Notification" }
2020-07-06 13:34:43 +02:00
} ,
2020-09-19 20:49:33 +02:00
notificationstrings : {
2021-01-15 21:21:24 +01:00
online : { value : "$user changed status to '$status'" } ,
idle : { value : "$user changed status to '$status'" } ,
dnd : { value : "$user changed status to '$status'" } ,
playing : { value : "$user started playing '$game'" } ,
listening : { value : "$user started listening to '$song'" } ,
streaming : { value : "$user started streaming '$game'" } ,
offline : { value : "$user changed status to '$status'" } ,
custom : { value : "$user changed status to '$custom'" }
2020-02-09 14:51:48 +01:00
} ,
2020-09-19 20:49:33 +02:00
notificationsounds : { } ,
2021-03-16 15:16:36 +01:00
dates : {
logDate : { value : { } , description : "Log Timestamp" } ,
} ,
2020-09-19 20:49:33 +02:00
amounts : {
2021-01-02 12:51:18 +01:00
toastTime : { value : 5 , min : 1 , description : "Amount of Seconds a Toast Notification stays on Screen: " } ,
checkInterval : { value : 10 , min : 5 , description : "Check Users every X Seconds: " }
2020-02-09 14:51:48 +01:00
}
2020-09-19 20:49:33 +02:00
} ;
2020-02-09 14:51:48 +01:00
2020-09-19 20:49:33 +02:00
this . patchedModules = {
after : {
Guilds : "render"
}
} ;
this . css = `
$ { BDFDB . dotCN . _friendnotificationslogtime } {
2021-03-16 15:16:36 +01:00
flex : 0 1 auto ;
min - width : 160 px ;
2020-09-19 20:49:33 +02:00
}
$ { BDFDB . dotCN . _friendnotificationslogavatar } {
margin : 0 10 px ;
}
$ { BDFDB . dotCN . _friendnotificationslogcontent } {
max - width : 600 px ;
}
$ { BDFDB . dotCN . _friendnotificationstypelabel } {
border - radius : 3 px ;
padding : 0 3 px ;
margin : 0 6 px ;
}
$ { BDFDB . dotCN . _friendnotificationsfriendsonline } {
cursor : pointer ;
2020-02-09 14:51:48 +01:00
}
2020-12-22 18:45:40 +01:00
$ { BDFDB . dotCNS . _friendnotificationstimelogmodal + BDFDB . dotCN . messagespopoutemptyplaceholder } {
position : absolute ;
bottom : 0 ;
width : 100 % ;
}
2020-09-19 20:49:33 +02:00
` ;
2021-01-15 21:21:24 +01:00
for ( let type in statuses ) if ( statuses [ type ] . sound ) {
this . defaults . notificationsounds [ "toast" + type ] = { value : { url : null , song : null , mute : false } } ;
this . defaults . notificationsounds [ "desktop" + type ] = { value : { url : null , song : null , mute : false } } ;
2020-02-09 14:51:48 +01:00
}
}
2021-01-06 12:38:36 +01:00
onStart ( ) {
2020-09-19 20:49:33 +02:00
this . startInterval ( ) ;
BDFDB . PatchUtils . forceAllUpdates ( this ) ;
}
2020-02-09 14:51:48 +01:00
2021-01-06 12:38:36 +01:00
onStop ( ) {
2020-09-19 20:49:33 +02:00
BDFDB . TimeUtils . clear ( checkInterval ) ;
BDFDB . PatchUtils . forceAllUpdates ( this ) ;
}
2020-11-23 20:56:13 +01:00
getSettingsPanel ( collapseStates = { } ) {
2021-01-02 12:51:18 +01:00
let changeAllConfigs = ( type , config , notificationType ) => {
2020-09-19 20:49:33 +02:00
let allData = BDFDB . DataUtils . load ( this , type ) ;
2021-01-02 12:51:18 +01:00
if ( config == "all" ) {
config = "disabled" ;
for ( let id in allData ) allData [ id ] [ config ] = notificationTypes [ notificationType ] . button == 0 ? false : true ;
}
else {
let disabled = BDFDB . ObjectUtils . toArray ( allData ) . every ( d => ! d . disabled && d [ config ] == notificationTypes [ notificationType ] . value ) ;
for ( let id in allData ) allData [ id ] [ config ] = notificationTypes [ disabled ? "DISABLED" : notificationType ] . value ;
2020-09-19 20:49:33 +02:00
}
BDFDB . DataUtils . save ( allData , this , type ) ;
this . SettingsUpdated = true ;
BDFDB . PluginUtils . refreshSettingsPanel ( this , settingsPanel , collapseStates ) ;
} ;
let successSavedAudio = ( type , parsedUrl , parsedData ) => {
2020-11-19 16:51:14 +01:00
if ( parsedUrl && parsedData ) BDFDB . NotificationUtils . toast ( ` Sound was saved successfully. ` , { type : "success" } ) ;
2020-09-19 20:49:33 +02:00
notificationSounds [ type ] . url = parsedUrl ;
notificationSounds [ type ] . song = parsedData ;
BDFDB . DataUtils . save ( notificationSounds [ type ] , this , "notificationsounds" , type ) ;
this . SettingsUpdated = true ;
} ;
let createUserList = ( users , type , title ) => {
let items = [ ] ;
items . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Flex , {
2020-11-25 17:37:22 +01:00
className : BDFDB . disCNS . settingsrowtitle + BDFDB . disCNS . settingsrowtitledefault + BDFDB . disCN . cursordefault ,
2020-02-09 14:51:48 +01:00
children : [
2021-01-02 12:51:18 +01:00
"Click on an Option to toggle" ,
2020-09-19 20:49:33 +02:00
BDFDB . ReactUtils . createElement ( "span" , {
className : BDFDB . disCN . _friendnotificationstypelabel ,
2020-12-16 16:35:56 +01:00
style : { backgroundColor : "var(--bdfdb-blurple)" } ,
2020-09-19 20:49:33 +02:00
children : "Toast"
} ) ,
2020-11-19 16:51:14 +01:00
"Notifications for that User: "
2020-02-09 14:51:48 +01:00
]
2020-09-19 20:49:33 +02:00
} ) ) ;
if ( "Notification" in window ) items . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Flex , {
2020-11-25 17:37:22 +01:00
className : BDFDB . disCNS . settingsrowtitle + BDFDB . disCNS . settingsrowtitledefault + BDFDB . disCN . cursordefault ,
2020-02-09 14:51:48 +01:00
children : [
2021-01-02 12:51:18 +01:00
"Right-Click on an Option to toggle" ,
2020-09-19 20:49:33 +02:00
BDFDB . ReactUtils . createElement ( "span" , {
className : BDFDB . disCN . _friendnotificationstypelabel ,
style : { backgroundColor : BDFDB . DiscordConstants . Colors . STATUS _GREEN } ,
children : "Desktop"
2020-02-09 14:51:48 +01:00
} ) ,
2020-11-19 16:51:14 +01:00
"Notifications for that User: "
2020-09-19 20:49:33 +02:00
]
} ) ) ;
items . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsList , {
className : BDFDB . disCN . margintop20 ,
2021-01-02 12:51:18 +01:00
title : "all" ,
2021-01-15 21:21:24 +01:00
settings : Object . keys ( statuses ) ,
2020-09-19 20:49:33 +02:00
data : users ,
pagination : {
alphabetKey : "username" ,
amount : 50 ,
offset : paginationOffset [ title ] || 0 ,
onJump : offset => { paginationOffset [ title ] = offset ; }
} ,
2021-01-02 12:51:18 +01:00
getCheckboxColor : value => {
let color = ( BDFDB . ObjectUtils . toArray ( notificationTypes ) . find ( n => n . value == value ) || { } ) . color ;
return BDFDB . DiscordConstants . Colors [ color ] || color ;
} ,
getCheckboxValue : ( value , event ) => {
let eventValue = ( BDFDB . ObjectUtils . toArray ( notificationTypes ) . find ( n => n . button == event . button ) || { } ) . value ;
return eventValue == value ? 0 : eventValue ;
} ,
2020-09-19 20:49:33 +02:00
renderLabel : data => [
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . AvatarComponents . default , {
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . listavatar , data . disabled && BDFDB . disCN . avatardisabled ) ,
src : BDFDB . UserUtils . getAvatar ( data . id ) ,
status : BDFDB . UserUtils . getStatus ( data . id ) ,
size : BDFDB . LibraryComponents . AvatarComponents . Sizes . SIZE _40 ,
onClick : ( e , instance ) => {
2021-01-02 12:51:18 +01:00
let saveData = BDFDB . DataUtils . load ( this , type , data . id ) || this . createDefaultConfig ( ) ;
saveData . disabled = ! saveData . disabled ;
BDFDB . DataUtils . save ( saveData , this , type , data . id ) ;
this . SettingsUpdated = true ;
BDFDB . PluginUtils . refreshSettingsPanel ( this , settingsPanel , collapseStates ) ;
2020-02-09 14:51:48 +01:00
}
2020-09-19 20:49:33 +02:00
} ) ,
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . TextScroller , {
children : data . username
2020-02-09 14:51:48 +01:00
} )
2020-09-19 20:49:33 +02:00
] ,
onHeaderClick : ( config , instance ) => {
2021-01-02 12:51:18 +01:00
changeAllConfigs ( type , config , "TOAST" ) ;
2020-09-19 20:49:33 +02:00
} ,
onHeaderContextMenu : ( config , instance ) => {
2021-01-02 12:51:18 +01:00
changeAllConfigs ( type , config , "DESKTOP" ) ;
2020-09-19 20:49:33 +02:00
} ,
onCheckboxChange : ( value , instance ) => {
let data = BDFDB . DataUtils . load ( this , type , instance . props . cardId ) || this . createDefaultConfig ( ) ;
data [ instance . props . settingId ] = value ;
BDFDB . DataUtils . save ( data , this , type , instance . props . cardId ) ;
this . SettingsUpdated = true ;
} ,
noRemove : type == "friends" ,
onRemove : ( e , instance ) => {
BDFDB . DataUtils . remove ( this , type , instance . props . cardId ) ;
BDFDB . PluginUtils . refreshSettingsPanel ( this , settingsPanel , collapseStates ) ;
this . SettingsUpdated = true ;
}
} ) ) ;
return BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . CollapseContainer , {
title : title ,
collapseStates : collapseStates ,
2020-10-30 16:15:43 +01:00
dividerTop : true ,
2020-09-19 20:49:33 +02:00
children : items
} ) ;
} ;
2020-11-23 20:56:13 +01:00
let settingsPanel ;
return settingsPanel = BDFDB . PluginUtils . createSettingsPanel ( this , {
collapseStates : collapseStates ,
children : _ => {
2020-11-23 20:58:41 +01:00
let settingsItems = [ ] , innerItems = [ ] ;
2020-11-23 20:56:13 +01:00
let settings = BDFDB . DataUtils . get ( this , "settings" ) ;
let amounts = BDFDB . DataUtils . get ( this , "amounts" ) ;
2021-03-16 15:16:36 +01:00
let dates = BDFDB . DataUtils . get ( this , "dates" ) ;
2020-11-23 20:56:13 +01:00
let notificationStrings = BDFDB . DataUtils . get ( this , "notificationstrings" ) ;
let notificationSounds = BDFDB . DataUtils . get ( this , "notificationsounds" ) ;
2021-03-21 11:14:57 +01:00
let { friendIds , cards } = this . getObserverData ( ) ;
2020-11-23 20:56:13 +01:00
for ( let key in settings ) innerItems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsSaveItem , {
type : "Switch" ,
plugin : this ,
keys : [ "settings" , key ] ,
label : this . defaults . settings [ key ] . description ,
value : settings [ key ]
} ) ) ;
2020-11-23 20:58:41 +01:00
2021-03-16 15:16:36 +01:00
for ( let key in dates ) innerItems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . DateInput , Object . assign ( { } , dates [ key ] , {
label : this . defaults . dates [ key ] . description ,
onChange : valueObj => {
this . SettingsUpdated = true ;
dates [ key ] = valueObj ;
BDFDB . DataUtils . save ( dates , this , "dates" ) ;
}
} ) ) ) ;
2020-11-23 20:56:13 +01:00
for ( let key in amounts ) if ( key . indexOf ( "desktop" ) == - 1 || "Notification" in window ) innerItems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsSaveItem , {
type : "TextInput" ,
childProps : {
type : "number"
} ,
plugin : this ,
keys : [ "amounts" , key ] ,
label : this . defaults . amounts [ key ] . description ,
basis : "20%" ,
min : this . defaults . amounts [ key ] . min ,
max : this . defaults . amounts [ key ] . max ,
value : amounts [ key ]
} ) ) ;
2020-11-23 20:58:41 +01:00
2020-11-23 20:56:13 +01:00
settingsItems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . CollapseContainer , {
title : "Settings" ,
collapseStates : collapseStates ,
children : innerItems
} ) ) ;
2021-03-16 15:16:36 +01:00
if ( cards . friends . length ) settingsItems . push ( createUserList ( cards . friends , "friends" , "Friend-List" ) ) ;
2020-11-23 20:58:41 +01:00
2021-02-15 15:28:41 +01:00
let strangerId = "" ;
2020-11-23 20:56:13 +01:00
settingsItems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . CollapseContainer , {
title : "Add new Stranger" ,
collapseStates : collapseStates ,
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Flex , {
className : BDFDB . disCN . margintop8 ,
align : BDFDB . LibraryComponents . Flex . Align . CENTER ,
children : [
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Flex . Child , {
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . TextInput , {
className : ` input-newstranger ` ,
placeholder : "user (id or name#discriminator)" ,
2021-02-15 15:28:41 +01:00
value : "" ,
onChange : value => strangerId = value
2020-11-23 20:56:13 +01:00
} )
} ) ,
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Button , {
onClick : _ => {
2021-02-15 15:28:41 +01:00
let userId = strangerId . trim ( ) ;
2021-01-24 13:27:39 +01:00
if ( userId == BDFDB . UserUtils . me . id ) BDFDB . NotificationUtils . toast ( "Are you seriously trying to stalk yourself?" , { type : "danger" } ) ;
else if ( friendIds . includes ( userId ) ) BDFDB . NotificationUtils . toast ( "User is already a friend of yours, please use the 'Friend-List' area to configure them" , { type : "danger" } ) ;
2021-03-16 15:16:36 +01:00
else if ( Object . keys ( cards . nonFriends ) . includes ( userId ) ) BDFDB . NotificationUtils . toast ( "User is already being observed as a 'Stranger'" , { type : "danger" } ) ;
2020-11-23 20:56:13 +01:00
else {
let user = /.+#[0-9]{4}/ . test ( userId ) ? BDFDB . LibraryModules . UserStore . findByTag ( userId . split ( "#" ) . slice ( 0 , - 1 ) . join ( "#" ) , userId . split ( "#" ) . pop ( ) ) : BDFDB . LibraryModules . UserStore . getUser ( userId ) ;
if ( user ) {
2021-02-15 15:28:41 +01:00
BDFDB . DataUtils . save ( this . createDefaultConfig ( ) , this , "nonfriends" , user . id || userId ) ;
2020-11-23 20:56:13 +01:00
BDFDB . PluginUtils . refreshSettingsPanel ( this , settingsPanel , collapseStates ) ;
this . SettingsUpdated = true ;
}
2021-01-24 13:27:39 +01:00
else BDFDB . NotificationUtils . toast ( "Please enter a valid UserID of a user that has been loaded in your client" , { type : "danger" } ) ;
2020-11-23 20:56:13 +01:00
}
} ,
children : BDFDB . LanguageUtils . LanguageStrings . ADD
} )
]
2020-02-09 14:51:48 +01:00
} )
2020-11-23 20:56:13 +01:00
} ) ) ;
2020-11-23 20:58:41 +01:00
2021-03-16 15:16:36 +01:00
if ( cards . nonFriends . length ) settingsItems . push ( createUserList ( cards . nonFriends , "nonfriends" , "Stranger-List" ) ) ;
2020-11-23 20:56:13 +01:00
settingsItems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . CollapseContainer , {
title : "LogIn/-Out Timelog" ,
collapseStates : collapseStates ,
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsItem , {
type : "Button" ,
label : "Overview of LogIns/-Outs of current Session" ,
onClick : _ => { this . showTimeLog ( ) } ,
children : "Timelog"
} )
} ) ) ;
2020-11-23 20:58:41 +01:00
2020-11-23 20:56:13 +01:00
settingsItems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . CollapseContainer , {
title : "Notification Messages" ,
collapseStates : collapseStates ,
children : [ BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Flex , {
className : BDFDB . disCN . marginbottom8 ,
children : BDFDB . ReactUtils . createElement ( "div" , {
2020-12-22 18:45:40 +01:00
className : BDFDB . disCNS . settingsrowtitle + BDFDB . disCNS . settingsrowtitle + BDFDB . disCNS . settingsrowtitledefault + BDFDB . disCN . cursordefault ,
2020-11-23 20:56:13 +01:00
children : [
2021-02-09 17:03:52 +01:00
"Allows you to configure your own Message Strings for the different Statuses. " ,
2020-11-23 20:56:13 +01:00
BDFDB . ReactUtils . createElement ( "strong" , { children : "$user" } ) ,
2021-02-09 17:03:52 +01:00
" is the Placeholder for the User Name, " ,
2020-11-23 20:56:13 +01:00
BDFDB . ReactUtils . createElement ( "strong" , { children : "$status" } ) ,
2021-02-09 17:03:52 +01:00
" for the Status Name, " ,
BDFDB . ReactUtils . createElement ( "strong" , { children : "$statusOld" } ) ,
" for the previous Status Name, " ,
2021-01-15 21:21:24 +01:00
BDFDB . ReactUtils . createElement ( "strong" , { children : "$custom" } ) ,
2021-02-09 17:03:52 +01:00
" for the Custom Status, " ,
2020-11-23 20:56:13 +01:00
BDFDB . ReactUtils . createElement ( "strong" , { children : "$game" } ) ,
2021-02-09 17:03:52 +01:00
" for the Game Name, " ,
2020-11-23 20:56:13 +01:00
BDFDB . ReactUtils . createElement ( "strong" , { children : "$song" } ) ,
2021-02-09 17:03:52 +01:00
" for the Song Name and " ,
2020-11-23 20:56:13 +01:00
BDFDB . ReactUtils . createElement ( "strong" , { children : "$artist" } ) ,
2021-02-09 17:03:52 +01:00
" for the Song Artist."
2020-11-23 20:56:13 +01:00
]
2020-09-19 20:49:33 +02:00
} )
2020-11-23 20:56:13 +01:00
} ) ] . concat ( Object . keys ( notificationStrings ) . map ( key => BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsSaveItem , {
type : "TextInput" ,
plugin : this ,
keys : [ "notificationstrings" , key ] ,
placeholder : this . defaults . notificationstrings [ key ] . value ,
2021-01-15 21:21:24 +01:00
label : ` ${ BDFDB . LibraryModules . StringUtils . upperCaseFirstChar ( key ) } : ` ,
basis : "80%" ,
2020-11-23 20:56:13 +01:00
value : notificationStrings [ key ]
} ) ) )
} ) ) ;
2020-11-23 20:58:41 +01:00
2020-11-23 20:56:13 +01:00
settingsItems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . CollapseContainer , {
title : "Notification Sounds" ,
collapseStates : collapseStates ,
children : Object . keys ( notificationSounds ) . map ( ( key , i ) => ( key . indexOf ( "desktop" ) == - 1 || "Notification" in window ) && [
i != 0 && key . indexOf ( "toast" ) == 0 && BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . FormComponents . FormDivider , {
className : BDFDB . disCN . marginbottom8
} ) ,
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 : ` ${ key . split ( /(desktop)|(toast)/ ) . filter ( n => n ) . map ( n => BDFDB . LibraryModules . StringUtils . upperCaseFirstChar ( n ) ) . join ( "-" ) } Notification Sound: ` ,
} ) ,
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsItem , {
type : "Switch" ,
mini : true ,
grow : 0 ,
label : "Mute:" ,
value : notificationSounds [ key ] . mute ,
onChange : value => {
notificationSounds [ key ] . mute = value ;
BDFDB . DataUtils . save ( notificationSounds , this , "notificationsounds" ) ;
}
} )
] . filter ( n => n )
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 . marginbottom8 ,
align : BDFDB . LibraryComponents . Flex . Align . CENTER ,
children : [
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Flex . Child , {
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . TextInput , {
className : ` input- ${ key } src ` ,
type : "file" ,
filter : [ "audio" , "video" ] ,
useFilePath : true ,
placeholder : "Url or Filepath" ,
value : notificationSounds [ key ] . url
} )
} ) ,
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Button , {
onClick : _ => {
let source = settingsPanel . props . _node . querySelector ( ` .input- ${ key } src ` + BDFDB . dotCN . input ) . value . trim ( ) ;
if ( ! source . length ) {
2021-01-24 12:57:02 +01:00
BDFDB . NotificationUtils . toast ( ` Sound file was removed. ` , { type : "warning" } ) ;
2020-09-19 20:49:33 +02:00
successSavedAudio ( key , source , source ) ;
}
2020-11-23 20:56:13 +01:00
else 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 ) ) {
successSavedAudio ( key , source , source ) ;
return ;
}
}
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" } ) ;
} ) ;
else BDFDB . LibraryRequires . fs . readFile ( source , ( error , response ) => {
if ( error ) BDFDB . NotificationUtils . toast ( "Could not fetch file, please make sure the file exists" , { type : "danger" } ) ;
else successSavedAudio ( key , source , ` data:audio/mpeg;base64, ${ response . toString ( "base64" ) } ` ) ;
} ) ;
} ,
children : BDFDB . LanguageUtils . LanguageStrings . SAVE
} )
]
2020-09-19 20:49:33 +02:00
} )
2020-11-23 20:56:13 +01:00
] ) . flat ( 10 ) . filter ( n => n )
} ) ) ;
return settingsItems ;
}
} ) ;
2020-02-09 14:51:48 +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 . startInterval ( ) ;
BDFDB . PatchUtils . forceAllUpdates ( this ) ;
}
2020-02-09 14:51:48 +01:00
}
2020-02-20 23:12:40 +01:00
2020-09-19 20:49:33 +02:00
processGuilds ( e ) {
if ( settings . addOnlineCount ) {
2020-10-30 16:15:43 +01:00
if ( typeof e . returnvalue . props . children == "function" ) {
let childrenRender = e . returnvalue . props . children ;
e . returnvalue . props . children = ( ... args ) => {
let children = childrenRender ( ... args ) ;
2020-11-16 10:00:48 +01:00
this . checkTree ( children ) ;
2020-10-30 16:15:43 +01:00
return children ;
} ;
}
2020-11-16 10:00:48 +01:00
else this . checkTree ( e . returnvalue ) ;
2020-09-19 20:49:33 +02:00
}
2020-02-20 23:12:40 +01:00
}
2020-11-16 10:00:48 +01:00
checkTree ( returnvalue ) {
let tree = BDFDB . ReactUtils . findChild ( returnvalue , { filter : n => n && n . props && typeof n . props . children == "function" } ) ;
if ( tree ) {
let childrenRender = tree . props . children ;
tree . props . children = ( ... args ) => {
let children = childrenRender ( ... args ) ;
this . injectCounter ( children ) ;
return children ;
} ;
}
else this . injectCounter ( returnvalue ) ;
}
2020-10-30 16:15:43 +01:00
injectCounter ( returnvalue ) {
let [ children , index ] = BDFDB . ReactUtils . findParent ( returnvalue , { name : "ConnectedUnreadDMs" } ) ;
if ( index > - 1 ) children . splice ( index , 0 , BDFDB . ReactUtils . createElement ( FriendOnlineCounterComponent , {
amount : BDFDB . LibraryModules . StatusMetaUtils . getOnlineFriendCount ( )
} ) ) ;
}
2021-03-16 15:16:36 +01:00
getObserverData ( ) {
let friendIds = BDFDB . LibraryModules . RelationshipStore . getFriendIDs ( ) ;
let friendDatas = BDFDB . DataUtils . load ( this , "friends" ) , nonFriendDatas = BDFDB . DataUtils . load ( this , "nonfriends" ) ;
let friendCards = [ ] , nonFriendCards = [ ] ;
for ( let id of friendIds ) {
let user = BDFDB . LibraryModules . UserStore . getUser ( id ) ;
if ( user ) {
friendDatas [ id ] = Object . assign ( { } , friendDatas [ id ] || nonFriendDatas [ id ] || this . createDefaultConfig ( ) ) ;
delete nonFriendDatas [ id ] ;
}
}
for ( let id in friendDatas ) {
let user = BDFDB . LibraryModules . UserStore . getUser ( id ) ;
if ( user ) {
if ( ! friendIds . includes ( id ) ) {
nonFriendDatas [ id ] = Object . assign ( { } , friendDatas [ id ] ) ;
delete friendDatas [ id ] ;
}
else if ( id != BDFDB . UserUtils . me . id ) friendCards . push ( Object . assign ( { } , user , friendDatas [ id ] , {
key : id ,
className : friendDatas [ id ] . disabled ? BDFDB . disCN . hovercarddisabled : ""
} ) ) ;
}
}
for ( let id in nonFriendDatas ) {
let user = BDFDB . LibraryModules . UserStore . getUser ( id ) ;
if ( user && id != BDFDB . UserUtils . me . id ) nonFriendCards . push ( Object . assign ( { } , user , nonFriendDatas [ id ] , {
key : id ,
className : nonFriendDatas [ id ] . disabled ? BDFDB . disCN . hovercarddisabled : ""
} ) ) ;
}
BDFDB . DataUtils . save ( friendDatas , this , "friends" ) ;
BDFDB . DataUtils . save ( nonFriendDatas , this , "nonfriends" ) ;
2021-03-21 11:14:57 +01:00
return { friendIds , data : { friends : friendDatas , nonFriends : nonFriendDatas } , cards : { friends : friendCards , nonFriends : nonFriendCards } } ;
2021-03-16 15:16:36 +01:00
}
2019-09-04 12:34:02 +02:00
2021-01-06 12:38:36 +01:00
createDefaultConfig ( ) {
2020-09-19 20:49:33 +02:00
return Object . assign ( {
disabled : settings . disableForNew
2021-01-15 21:21:24 +01:00
} , BDFDB . ObjectUtils . map ( statuses , init => notificationTypes [ init ? "TOAST" : "DISABLED" ] . value ) ) ;
2020-09-19 20:49:33 +02:00
}
2020-01-22 13:54:03 +01:00
2020-09-19 20:49:33 +02:00
getStatusWithMobileAndActivity ( id , config ) {
2021-01-15 21:21:24 +01:00
let status = { name : BDFDB . UserUtils . getStatus ( id ) , activity : null , custom : false , mobile : BDFDB . LibraryModules . StatusMetaUtils . isMobileOnline ( id ) } ;
let activity = BDFDB . UserUtils . getActivity ( id ) || BDFDB . UserUtils . getCustomStatus ( id ) ;
2020-09-19 20:49:33 +02:00
if ( activity && BDFDB . DiscordConstants . ActivityTypes [ activity . type ] ) {
2021-01-15 21:21:24 +01:00
let isCustom = activity . type == BDFDB . DiscordConstants . ActivityTypes . CUSTOM _STATUS ;
let activityName = isCustom ? "custom" : BDFDB . DiscordConstants . ActivityTypes [ activity . type ] . toLowerCase ( ) ;
if ( statuses [ activityName ] && config [ activityName ] ) {
Object . assign ( status , { name : isCustom ? status . name : activityName , activity : Object . assign ( { } , activity ) , custom : isCustom } ) ;
2021-01-21 13:49:31 +01:00
if ( activity . type == BDFDB . DiscordConstants . ActivityTypes . STREAMING || activity . type == BDFDB . DiscordConstants . ActivityTypes . LISTENING ) delete status . activity . name ;
else if ( activity . type == BDFDB . DiscordConstants . ActivityTypes . PLAYING ) {
delete status . activity . details ;
delete status . activity . state ;
}
2020-09-19 20:49:33 +02:00
}
2020-02-09 14:51:48 +01:00
}
2020-09-19 20:49:33 +02:00
return status ;
2019-09-19 16:02:12 +02:00
}
2021-01-20 14:50:09 +01:00
2021-02-09 17:03:52 +01:00
getStatusName ( id , status ) {
if ( ! status ) return "" ;
let statusName = ( BDFDB . LanguageUtils . LanguageStringsCheck [ statuses [ status . name ] . name ] && BDFDB . LanguageUtils . LanguageStrings [ statuses [ status . name ] . name ] || this . labels [ "status_" + status . name ] || statuses [ status . name ] . name || "" ) . toLowerCase ( ) ;
if ( status . mobile && observedUsers [ id ] . mobile ) statusName += ` ( ${ BDFDB . LanguageUtils . LanguageStrings . ACTIVE _ON _MOBILE } ) ` ;
2021-02-09 18:36:43 +01:00
return statusName ;
2021-02-09 17:03:52 +01:00
}
2021-01-20 14:50:09 +01:00
compareActivity ( id , status ) {
return BDFDB . equals ( BDFDB . ObjectUtils . extract ( userStatusStore [ id ] . activity , "name" , "details" , "state" , "emoji" ) , status && BDFDB . ObjectUtils . extract ( status . activity , "name" , "details" , "state" , "emoji" ) ) ;
}
2019-01-26 22:45:19 +01:00
2021-01-06 12:38:36 +01:00
startInterval ( ) {
2020-09-19 20:49:33 +02:00
BDFDB . TimeUtils . clear ( checkInterval ) ;
settings = BDFDB . DataUtils . get ( this , "settings" ) ;
amounts = BDFDB . DataUtils . get ( this , "amounts" ) ;
2021-03-16 15:16:36 +01:00
dates = BDFDB . DataUtils . get ( this , "dates" ) ;
2020-09-19 20:49:33 +02:00
notificationStrings = BDFDB . DataUtils . get ( this , "notificationstrings" ) ;
notificationSounds = BDFDB . DataUtils . get ( this , "notificationsounds" ) ;
2021-03-16 15:16:36 +01:00
let { data } = this . getObserverData ( ) ;
observedUsers = Object . assign ( { } , data . nonFriends , data . friends ) ;
2021-03-05 14:15:25 +01:00
delete observedUsers [ BDFDB . UserUtils . me . id ] ;
2020-09-19 20:49:33 +02:00
2021-01-15 21:21:24 +01:00
for ( let id in observedUsers ) userStatusStore [ id ] = this . getStatusWithMobileAndActivity ( id , observedUsers [ id ] ) ;
2020-09-19 20:49:33 +02:00
checkInterval = BDFDB . TimeUtils . interval ( _ => {
let amount = BDFDB . LibraryModules . StatusMetaUtils . getOnlineFriendCount ( ) ;
if ( friendCounter && friendCounter . props . amount != amount ) {
friendCounter . props . amount = amount ;
BDFDB . ReactUtils . forceUpdate ( friendCounter ) ;
}
for ( let id in observedUsers ) if ( ! observedUsers [ id ] . disabled ) {
let user = BDFDB . LibraryModules . UserStore . getUser ( id ) ;
let status = this . getStatusWithMobileAndActivity ( id , observedUsers [ id ] ) ;
2021-01-15 21:21:24 +01:00
let customChanged = false ;
if ( user && observedUsers [ id ] [ status . name ] && (
userStatusStore [ id ] . name != status . name ||
observedUsers [ id ] . mobile && userStatusStore [ id ] . mobile != status . mobile ||
observedUsers [ id ] . custom && (
userStatusStore [ id ] . custom != status . custom ||
2021-01-20 14:50:09 +01:00
( customChanged = status . custom && ! this . compareActivity ( id , status ) )
2021-01-15 21:21:24 +01:00
) ||
2021-01-20 14:50:09 +01:00
statuses [ status . name ] . checkActivity && ! this . compareActivity ( id , status )
2021-01-15 21:21:24 +01:00
) ) {
2020-09-19 20:49:33 +02:00
let EUdata = BDFDB . BDUtils . isPluginEnabled ( "EditUsers" ) && BDFDB . DataUtils . load ( "EditUsers" , "users" , user . id ) || { } ;
let name = EUdata . name || user . username ;
let avatar = EUdata . removeIcon ? "" : ( EUdata . url || BDFDB . UserUtils . getAvatar ( user . id ) ) ;
2021-03-16 15:16:36 +01:00
let timestamp = new Date ( ) . getTime ( ) ;
2020-04-13 19:58:49 +02:00
2021-02-09 17:03:52 +01:00
let statusName = this . getStatusName ( id , status ) ;
let oldStatusName = this . getStatusName ( id , userStatusStore [ id ] ) ;
2021-01-15 21:21:24 +01:00
let string = notificationStrings [ customChanged ? "custom" : status . name ] || "'$user' changed status to '$status'" ;
2021-02-09 17:03:52 +01:00
let toastString = BDFDB . StringUtils . htmlEscape ( string ) . replace ( /'{0,1}\$user'{0,1}/g , ` <strong> ${ BDFDB . StringUtils . htmlEscape ( name ) } </strong> ${ settings . showDiscriminator ? ( "#" + user . discriminator ) : "" } ` ) . replace ( /'{0,1}\$statusOld'{0,1}/g , ` <strong> ${ oldStatusName } </strong> ` ) . replace ( /'{0,1}\$status'{0,1}/g , ` <strong> ${ statusName } </strong> ` ) ;
2021-01-20 14:50:09 +01:00
if ( status . activity ) toastString = toastString . replace ( /'{0,1}\$song'{0,1}|'{0,1}\$game'{0,1}/g , ` <strong> ${ status . activity . name || status . activity . details || "" } </strong> ` ) . replace ( /'{0,1}\$artist'{0,1}|'{0,1}\$custom'{0,1}/g , ` <strong> ${ [ status . activity . emoji && status . activity . emoji . name , status . activity . state ] . filter ( n => n ) . join ( " " ) || "" } </strong> ` ) ;
2020-09-19 20:49:33 +02:00
timeLog . unshift ( {
string : toastString ,
avatar : avatar ,
name : name ,
status : BDFDB . UserUtils . getStatus ( user . id ) ,
2021-03-16 15:16:36 +01:00
timestamp : timestamp
2020-09-19 20:49:33 +02:00
} ) ;
2021-03-16 15:16:36 +01:00
if ( ! ( settings . muteOnDND && BDFDB . UserUtils . getStatus ( ) == BDFDB . DiscordConstants . StatusTypes . DND ) && ( ! lastTimes [ user . id ] || lastTimes [ user . id ] != timestamp ) ) {
lastTimes [ user . id ] = timestamp ;
2020-09-19 20:49:33 +02:00
let openChannel = _ => {
if ( settings . openOnClick ) {
let DMid = BDFDB . LibraryModules . ChannelStore . getDMFromUserId ( user . id )
2021-03-05 17:43:06 +01:00
if ( DMid ) BDFDB . LibraryModules . ChannelUtils . selectPrivateChannel ( DMid ) ;
2020-09-19 20:49:33 +02:00
else BDFDB . LibraryModules . DirectMessageUtils . openPrivateChannel ( BDFDB . UserUtils . me . id , user . id ) ;
2021-02-02 12:45:38 +01:00
BDFDB . LibraryModules . WindowUtils . focus ( ) ;
2020-09-19 20:49:33 +02:00
}
} ;
2021-01-15 21:21:24 +01:00
if ( observedUsers [ id ] [ status . name ] == notificationTypes . DESKTOP . value ) {
2021-02-09 17:03:52 +01:00
let desktopString = string . replace ( /\$user/g , ` ${ name } ${ settings . showDiscriminator ? ( "#" + user . discriminator ) : "" } ` ) . replace ( /\$status/g , statusName ) . replace ( /\$statusOld/g , oldStatusName ) ;
2021-01-20 14:50:09 +01:00
if ( status . activity ) desktopString = desktopString . replace ( /\$song|\$game/g , status . activity . name || status . activity . details || "" ) . replace ( /\$artist|\$custom/g , [ status . activity . emoji && status . activity . emoji . name , status . activity . state ] . filter ( n => n ) . join ( " " ) || "" ) ;
2021-01-24 14:05:34 +01:00
let notificationSound = notificationSounds [ "desktop" + status . name ] || { } ;
2021-01-25 14:10:20 +01:00
BDFDB . NotificationUtils . desktop ( desktopString , {
icon : avatar ,
silent : notificationSound . mute ,
sound : notificationSound . song ,
onClick : openChannel
} ) ;
2020-09-19 20:49:33 +02:00
}
2021-02-12 17:07:48 +01:00
else BDFDB . NotificationUtils . toast ( BDFDB . ReactUtils . elementToReact ( BDFDB . DOMUtils . create ( toastString ) ) , {
timeout : amounts . toastTime * 1000 ,
avatar : avatar ,
barColor : BDFDB . UserUtils . getStatusColor ( status . name , true ) ,
onClick : openChannel ,
onShow : _ => {
let notificationSound = notificationSounds [ "toast" + status . name ] || { } ;
if ( ! notificationSound . mute && notificationSound . song ) {
let audio = new Audio ( ) ;
audio . src = notificationSound . song ;
audio . play ( ) ;
2021-01-26 21:14:48 +01:00
}
2021-02-12 17:07:48 +01:00
}
} ) ;
2020-02-09 14:51:48 +01:00
}
2019-08-22 16:17:21 +02:00
}
2021-01-15 21:21:24 +01:00
userStatusStore [ id ] = status ;
2019-08-22 16:17:21 +02:00
}
2020-09-19 20:49:33 +02:00
} , amounts . checkInterval * 1000 ) ;
}
2019-05-01 21:02:25 +02:00
2021-01-06 12:38:36 +01:00
showTimeLog ( ) {
2020-12-22 18:45:40 +01:00
let searchTimeout ;
BDFDB . ModalUtils . open ( this , {
2020-09-19 20:49:33 +02:00
size : "MEDIUM" ,
header : "LogIn/-Out Timelog" ,
2021-01-23 18:50:24 +01:00
subHeader : "" ,
2020-12-22 18:45:40 +01:00
className : BDFDB . disCN . _friendnotificationstimelogmodal ,
titleChildren : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SearchBar , {
autoFocus : true ,
query : "" ,
onChange : ( value , instance ) => {
BDFDB . TimeUtils . clear ( searchTimeout ) ;
searchTimeout = BDFDB . TimeUtils . timeout ( _ => {
let searchString = value . toUpperCase ( ) ;
timeLogList . props . entries = timeLog . filter ( n => n && n . name && n . name . toUpperCase ( ) . indexOf ( searchString ) > - 1 ) ;
BDFDB . ReactUtils . forceUpdate ( timeLogList ) ;
} , 1000 ) ;
} ,
onClear : instance => {
timeLogList . props . entries = timeLog ;
BDFDB . ReactUtils . forceUpdate ( timeLogList ) ;
}
} ) ,
children : BDFDB . ReactUtils . createElement ( TimeLogComponent , {
entries : timeLog
2020-09-19 20:49:33 +02:00
} )
} ) ;
}
2021-01-15 21:21:24 +01:00
setLabelsByLanguage ( ) {
switch ( BDFDB . LanguageUtils . getLanguage ( ) . id ) {
case "bg" : // Bulgarian
return {
status _listening : "Слушане" ,
status _playing : "Играе"
} ;
case "da" : // Danish
return {
status _listening : "Hører efter" ,
status _playing : "Spiller"
} ;
case "de" : // German
return {
status _listening : "Hören" ,
status _playing : "Spielen"
} ;
case "el" : // Greek
return {
status _listening : "Ακούγοντας" ,
status _playing : "Παιχνίδι"
} ;
case "es" : // Spanish
return {
status _listening : "Escuchando" ,
status _playing : "Jugando"
} ;
case "fi" : // Finnish
return {
status _listening : "Kuunteleminen" ,
status _playing : "Pelataan"
} ;
case "fr" : // French
return {
status _listening : "Écoute" ,
status _playing : "En jouant"
} ;
case "hr" : // Croatian
return {
status _listening : "Slušanje" ,
status _playing : "Sviranje"
} ;
case "hu" : // Hungarian
return {
status _listening : "Hallgatás" ,
status _playing : "Játék"
} ;
case "it" : // Italian
return {
status _listening : "Ascoltando" ,
status _playing : "Giocando"
} ;
case "ja" : // Japanese
return {
status _listening : "聞いている" ,
status _playing : "遊ぶ"
} ;
case "ko" : // Korean
return {
status _listening : "청취" ,
status _playing : "놀이"
} ;
case "lt" : // Lithuanian
return {
status _listening : "Klausymas" ,
status _playing : "Žaidžia"
} ;
case "nl" : // Dutch
return {
status _listening : "Luisteren" ,
status _playing : "Spelen"
} ;
case "no" : // Norwegian
return {
status _listening : "Lytte" ,
status _playing : "Spiller"
} ;
case "pl" : // Polish
return {
status _listening : "Słuchający" ,
status _playing : "Gra"
} ;
case "pt-BR" : // Portuguese (Brazil)
return {
status _listening : "Ouvindo" ,
status _playing : "Jogando"
} ;
case "ro" : // Romanian
return {
status _listening : "Ascultare" ,
status _playing : "Joc"
} ;
case "ru" : // Russian
return {
status _listening : "Прослушивание" ,
status _playing : "Играет"
} ;
case "sv" : // Swedish
return {
status _listening : "Lyssnande" ,
status _playing : "Spelar"
} ;
case "th" : // Thai
return {
status _listening : "การฟัง" ,
status _playing : "กำลังเล่น"
} ;
case "tr" : // Turkish
return {
status _listening : "Dinleme" ,
status _playing : "Çalma"
} ;
case "uk" : // Ukrainian
return {
status _listening : "Слухання" ,
status _playing : "Гра"
} ;
case "vi" : // Vietnamese
return {
status _listening : "Lắng nghe" ,
status _playing : "Đang chơi"
} ;
case "zh-CN" : // Chinese (China)
return {
status _listening : "倾听" ,
status _playing : "玩"
} ;
case "zh-TW" : // Chinese (Taiwan)
return {
status _listening : "傾聽" ,
status _playing : "玩"
} ;
default : // English
return {
status _listening : "Listening" ,
status _playing : "Playing"
} ;
}
}
2020-09-19 20:49:33 +02:00
} ;
2020-10-09 21:09:35 +02:00
} ) ( window . BDFDB _Global . PluginUtils . buildPlugin ( config ) ) ;
2021-03-30 11:18:14 +02:00
} ) ( ) ;