BetterDiscordAddons/Plugins/FriendNotifications/FriendNotifications.plugin.js

1180 lines
50 KiB
JavaScript
Raw Normal View History

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
2024-10-09 18:35:46 +02:00
* @version 2.0.3
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
* @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 = (_ => {
2022-09-01 14:40:11 +02:00
const changeLog = {
2023-03-18 12:22:28 +01:00
2020-02-20 23:12:40 +01: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-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;
2022-09-01 14:55:22 +02:00
BdApi.showConfirmationModal("Library Missing", `The Library Plugin needed for ${this.name} is missing. Please click "Download Now" to install it.`, {
2020-09-19 20:49:33 +02:00
confirmText: "Download Now",
cancelText: "Cancel",
onCancel: _ => {delete window.BDFDB_Global.downloadModal;},
2020-09-20 08:15:13 +02:00
onConfirm: _ => {
delete window.BDFDB_Global.downloadModal;
2021-02-01 17:13:13 +01:00
this.downloadLibrary();
2020-09-20 08:15:13 +02:00
}
2020-09-19 20:49:33 +02:00
});
}
2022-09-01 14:55:22 +02:00
if (!window.BDFDB_Global.pluginQueue.includes(this.name)) window.BDFDB_Global.pluginQueue.push(this.name);
2020-10-09 21:09:35 +02:00
}
2021-01-06 12:38:36 +01:00
start () {this.load();}
stop () {}
getSettingsPanel () {
2020-11-28 23:12:09 +01:00
let template = document.createElement("template");
2022-09-01 14:55:22 +02:00
template.innerHTML = `<div style="color: var(--header-primary); font-size: 16px; font-weight: 300; white-space: pre; line-height: 22px;">The Library Plugin needed for ${this.name} is missing.\nPlease 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;
2021-04-24 12:50:06 +02:00
var userStatusStore, timeLog, lastTimes, checkInterval;
2020-12-22 18:45:40 +01:00
var friendCounter, timeLogList;
2021-06-30 15:38:41 +02:00
var defaultSettings = {};
2021-04-24 12:50:06 +02:00
var observedUsers = {};
var paginationOffset = {};
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
},
2022-09-07 15:51:27 +02:00
screensharing: {
value: false,
sound: true
},
2021-01-15 21:21:24 +01:00
offline: {
value: true,
name: "STATUS_OFFLINE",
sound: true
},
2021-08-12 18:52:55 +02:00
login: {
value: false
},
2021-01-15 21:21:24 +01:00
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,
2022-12-11 17:45:46 +01:00
color: "var(--status-positive)"
2021-01-02 12:51:18 +01:00
}
};
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-04-24 15:13:50 +02:00
children: BDFDB.LibraryComponents.DateInput.format(_this.settings.dates.logDate, log.timestamp)
2020-12-22 18:45:40 +01:00
}),
2022-09-30 16:50:38 +02:00
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Avatars.Avatar, {
2020-12-22 18:45:40 +01:00
className: BDFDB.disCN._friendnotificationslogavatar,
src: log.avatar,
2024-03-28 19:13:48 +01:00
size: BDFDB.LibraryComponents.AvatarConstants.AvatarSizes.SIZE_40
2020-12-22 18:45:40 +01:00
}),
2021-04-14 16:44:59 +02:00
_this.createStatusDot(log.status, log.mobile, {marginRight: 6}),
2021-05-19 17:18:28 +02:00
BDFDB.ReactUtils.createElement("div", {
2020-12-22 18:45:40 +01:00
className: BDFDB.disCN._friendnotificationslogcontent,
2021-05-19 17:18:28 +02:00
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextElement, {
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextScroller, {
speed: 1,
2021-04-13 18:25:20 +02:00
children: BDFDB.ReactUtils.elementToReact(BDFDB.DOMUtils.create(log.string))
})
2020-12-22 18:45:40 +01:00
})
2021-04-14 16:28:46 +02:00
})
2020-12-22 18:45:40 +01:00
]
})
]
2023-11-24 11:11:40 +01:00
}) : BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.EmptyStateImage, {});
2020-12-22 18:45:40 +01:00
}
};
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;
2022-04-10 09:43:05 +02:00
this.neverSyncData = true;
2019-09-04 12:34:02 +02:00
2020-09-19 20:49:33 +02:00
this.defaults = {
2021-04-24 12:50:06 +02:00
general: {
2024-07-07 10:10:49 +02:00
addOnlineCount: {value: true, description: "Adds an Online Friend Counter to the Server List (Click to open Time Log)"},
showDiscriminator: {value: false, description: "Adds the User Discriminator"},
showTimestamp: {value: false, description: "Adds the Timestamp"},
muteOnDND: {value: false, description: "Does not notify you when you are in DnD Status"},
openOnClick: {value: false, description: "Opens the DM when you click a Notification"}
},
choices: {
toastPosition: {value: "right", description: "Position of Toast Notifications", items: "ToastPositions"}
2020-07-06 13:34:43 +02:00
},
2021-04-24 12:50:06 +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'"},
2023-11-18 18:31:04 +01:00
screensharing: {value: "$user started screensharing"},
2021-01-15 21:21:24 +01:00
offline: {value: "$user changed status to '$status'"},
2021-08-12 18:52:55 +02:00
login: {value: "$user just logged in '$status'"},
2021-01-15 21:21:24 +01:00
custom: {value: "$user changed status to '$custom'"}
2020-02-09 14:51:48 +01:00
},
2021-04-24 12:50:06 +02:00
notificationSounds: {},
2021-03-16 15:16:36 +01:00
dates: {
2023-11-18 18:31:04 +01:00
logDate: {value: {}, description: "Log Timestamp"},
2021-03-16 15:16:36 +01:00
},
2020-09-19 20:49:33 +02:00
amounts: {
2023-11-18 18:31:04 +01:00
toastTime: {value: 5, min: 1, description: "Amount of Seconds a Toast Notification stays on Screen: "},
checkInterval: {value: 10, min: 5, description: "Checks 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
2022-10-11 09:35:15 +02:00
this.modulePatches = {
after: [
"GuildsBar"
]
2020-09-19 20:49:33 +02:00
};
this.css = `
${BDFDB.dotCN._friendnotificationslogtime} {
2021-03-16 15:16:36 +01:00
flex: 0 1 auto;
min-width: 160px;
2020-09-19 20:49:33 +02:00
}
${BDFDB.dotCN._friendnotificationslogavatar} {
margin: 0 10px;
}
${BDFDB.dotCN._friendnotificationslogcontent} {
max-width: 600px;
2021-04-13 18:25:20 +02:00
overflow: hidden;
2020-09-19 20:49:33 +02:00
}
${BDFDB.dotCN._friendnotificationstypelabel} {
border-radius: 3px;
padding: 0 3px;
margin: 0 6px;
}
${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) {
2021-04-24 12:50:06 +02:00
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
}
}
2022-04-10 09:43:05 +02:00
onStart () {
2020-09-19 20:49:33 +02:00
this.startInterval();
2021-06-30 15:38:41 +02:00
this.forceUpdateAll();
2020-09-19 20:49:33 +02:00
}
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);
2021-06-30 15:38:41 +02:00
this.forceUpdateAll();
}
forceUpdateAll () {
2021-08-12 18:52:55 +02:00
defaultSettings = Object.assign(BDFDB.ObjectUtils.map(statuses, status => notificationTypes[status.value ? "TOAST" : "DISABLED"].value), {timelog: true}, BDFDB.DataUtils.load(this, "defaultSettings"));
2021-10-08 11:14:54 +02:00
2022-10-10 15:53:50 +02:00
BDFDB.DiscordUtils.rerenderAll();
2020-09-19 20:49:33 +02:00
}
2020-11-23 20:56:13 +01:00
getSettingsPanel (collapseStates = {}) {
2021-01-02 12:51:18 +01:00
let changeAllConfigs = (type, config, notificationType) => {
2021-04-24 12:50:06 +02:00
let observed = this.getObservedData();
let specificObserved = observed[type] || {};
2021-01-02 12:51:18 +01:00
if (config == "all") {
config = "disabled";
2021-08-12 18:52:55 +02:00
const value = notificationTypes[notificationType].button == 0 ? false : true;
for (let id in specificObserved) specificObserved[id][config] = value;
}
else if (config == "timelog") {
const value = notificationType == "TOAST" ? notificationTypes.TOAST.value : notificationTypes.DISABLED.value;
for (let id in specificObserved) specificObserved[id][config] = value;
2021-01-02 12:51:18 +01:00
}
else {
2021-04-24 12:50:06 +02:00
let disabled = BDFDB.ObjectUtils.toArray(specificObserved).every(d => !d.disabled && d[config] == notificationTypes[notificationType].value);
for (let id in specificObserved) specificObserved[id][config] = notificationTypes[disabled ? "DISABLED" : notificationType].value;
2020-09-19 20:49:33 +02:00
}
2021-04-24 12:50:06 +02:00
observed[type] = specificObserved
2022-04-10 09:43:05 +02:00
BDFDB.DataUtils.save(observed, this, "observed");
2020-09-19 20:49:33 +02:00
this.SettingsUpdated = true;
BDFDB.PluginUtils.refreshSettingsPanel(this, settingsPanel, collapseStates);
};
2024-10-04 15:16:09 +02:00
let successSavedAudio = (type, parsedData) => {
if (parsedData) BDFDB.NotificationUtils.toast(`Sound was saved successfully.`, {type: "success"});
2021-04-24 12:50:06 +02:00
this.settings.notificationSounds[type].song = parsedData;
BDFDB.DataUtils.save(this.settings.notificationSounds, this, "notificationSounds");
2020-09-19 20:49:33 +02:00
this.SettingsUpdated = true;
};
let createUserList = (users, type, title) => {
let items = [];
items.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex, {
2024-07-04 19:07:16 +02:00
className: BDFDB.disCNS.settingsrowtitle + 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"
}),
2021-05-26 14:09:31 +02: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, {
2024-07-04 19:07:16 +02:00
className: BDFDB.disCNS.settingsrowtitle + 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,
2022-12-11 17:49:16 +01:00
style: {backgroundColor: "var(--status-positive)"},
2020-09-19 20:49:33 +02:00
children: "Desktop"
2020-02-09 14:51:48 +01:00
}),
2021-05-26 14:09:31 +02:00
"Notifications for that User"
]
}));
items.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex, {
2024-07-04 19:07:16 +02:00
className: BDFDB.disCNS.settingsrowtitle + BDFDB.disCN.cursordefault,
2021-05-26 14:09:31 +02:00
style: {marginTop: 6},
children: [
"Click on an Option Header to toggle",
BDFDB.ReactUtils.createElement("span", {
className: BDFDB.disCN._friendnotificationstypelabel,
style: {backgroundColor: "var(--bdfdb-blurple)"},
children: "Toast"
}),
"Notifications for all Users"
]
}));
if ("Notification" in window) items.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex, {
2024-07-04 19:07:16 +02:00
className: BDFDB.disCNS.settingsrowtitle + BDFDB.disCN.cursordefault,
2021-05-26 14:09:31 +02:00
children: [
"Right-Click on an Option Header to toggle",
BDFDB.ReactUtils.createElement("span", {
className: BDFDB.disCN._friendnotificationstypelabel,
2022-12-11 17:49:16 +01:00
style: {backgroundColor: "var(--status-positive)"},
2021-05-26 14:09:31 +02:00
children: "Desktop"
}),
"Notifications for all Users"
]
}));
items.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex, {
2024-07-04 19:07:16 +02:00
className: BDFDB.disCNS.settingsrowtitle + BDFDB.disCN.cursordefault,
2021-05-26 14:09:31 +02:00
style: {marginTop: 6},
children: "Click on an Avatar to toggle between enabled/disabled"
}));
if ("Notification" in window) items.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex, {
2024-07-04 19:07:16 +02:00
className: BDFDB.disCNS.settingsrowtitle + BDFDB.disCN.cursordefault,
2021-05-26 14:09:31 +02:00
children: [
"Right-Click on an Avatar to toggle all Options between",
BDFDB.ReactUtils.createElement("span", {
className: BDFDB.disCN._friendnotificationstypelabel,
style: {backgroundColor: "var(--bdfdb-blurple)"},
children: "Toast"
}),
"/",
BDFDB.ReactUtils.createElement("span", {
className: BDFDB.disCN._friendnotificationstypelabel,
2022-12-11 17:49:16 +01:00
style: {backgroundColor: "var(--status-positive)"},
2021-05-26 14:09:31 +02:00
children: "Desktop"
})
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-08-12 18:52:55 +02:00
settings: Object.keys(statuses).concat("timelog"),
2020-09-19 20:49:33 +02:00
data: users,
pagination: {
alphabetKey: "username",
amount: 50,
offset: paginationOffset[title] || 0,
2021-08-12 18:52:55 +02:00
onJump: offset => paginationOffset[title] = offset
2020-09-19 20:49:33 +02:00
},
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;
},
2021-08-12 18:52:55 +02:00
getCheckboxValue: (value, event, instance) => {
if (instance && instance.props.settingId == "timelog") {
return value == notificationTypes.DISABLED.value ? notificationTypes.TOAST.value : notificationTypes.DISABLED.value;
}
else {
let eventValue = (BDFDB.ObjectUtils.toArray(notificationTypes).find(n => n.button == event.button) || {}).value;
return eventValue == value ? 0 : eventValue;
}
2021-01-02 12:51:18 +01:00
},
2021-04-24 12:50:06 +02:00
renderLabel: cardData => [
2022-09-30 16:50:38 +02:00
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Avatars.Avatar, {
2021-04-24 12:50:06 +02:00
className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN.listavatar, cardData.disabled && BDFDB.disCN.avatardisabled),
src: BDFDB.UserUtils.getAvatar(cardData.id),
status: BDFDB.UserUtils.getStatus(cardData.id),
2024-03-28 19:13:48 +01:00
size: BDFDB.LibraryComponents.AvatarConstants.AvatarSizes.SIZE_40,
2021-04-24 12:50:06 +02:00
onClick: _ => {
let observed = this.getObservedData();
2021-06-30 15:38:41 +02:00
let data = observed[type][cardData.id] || Object.assign({}, defaultSettings);
2021-04-24 12:50:06 +02:00
data.disabled = !data.disabled;
observed[type][data.id] = data;
2022-04-10 09:43:05 +02:00
BDFDB.DataUtils.save(observed, this, "observed");
2021-01-02 12:51:18 +01:00
this.SettingsUpdated = true;
2021-05-26 14:09:31 +02:00
BDFDB.PluginUtils.refreshSettingsPanel(this, settingsPanel, collapseStates);
},
onContextMenu: _ => {
let observed = this.getObservedData();
2021-06-30 15:38:41 +02:00
let data = observed[type][cardData.id] || Object.assign({}, defaultSettings);
2021-05-26 14:09:31 +02:00
let batchType;
for (let config in statuses) {
if (data[config] == notificationTypes.TOAST.value) batchType = notificationTypes.DESKTOP.value;
else if (data[config] == notificationTypes.DESKTOP.value) batchType = notificationTypes.TOAST.value;
if (batchType != undefined) break;
}
for (let config in statuses) if (data[config] != notificationTypes.DISABLED.value) data[config] = batchType;
observed[type][data.id] = data;
2022-04-10 09:43:05 +02:00
BDFDB.DataUtils.save(observed, this, "observed");
2021-05-26 14:09:31 +02:00
this.SettingsUpdated = true;
2021-01-02 12:51:18 +01:00
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, {
2023-06-20 08:44:41 +02:00
children: cardData.globalName || cardData.username
2020-02-09 14:51:48 +01:00
})
2020-09-19 20:49:33 +02:00
],
2021-04-24 12:50:06 +02:00
onHeaderClick: config => {
2021-01-02 12:51:18 +01:00
changeAllConfigs(type, config, "TOAST");
2020-09-19 20:49:33 +02:00
},
2021-04-24 12:50:06 +02:00
onHeaderContextMenu: config => {
2021-01-02 12:51:18 +01:00
changeAllConfigs(type, config, "DESKTOP");
2020-09-19 20:49:33 +02:00
},
onCheckboxChange: (value, instance) => {
2021-04-24 12:50:06 +02:00
let observed = this.getObservedData();
2021-06-30 15:38:41 +02:00
let data = observed[type][instance.props.cardId] || Object.assign({}, defaultSettings);
2020-09-19 20:49:33 +02:00
data[instance.props.settingId] = value;
2021-04-24 12:50:06 +02:00
observed[type][instance.props.cardId] = data;
2022-04-10 09:43:05 +02:00
BDFDB.DataUtils.save(observed, this, "observed");
2020-09-19 20:49:33 +02:00
this.SettingsUpdated = true;
},
noRemove: type == "friends",
onRemove: (e, instance) => {
2021-04-24 12:50:06 +02:00
let observed = this.getObservedData();
delete observed[type][instance.props.cardId];
2022-04-10 09:43:05 +02:00
BDFDB.DataUtils.save(observed, this, "observed");
2020-09-19 20:49:33 +02:00
BDFDB.PluginUtils.refreshSettingsPanel(this, settingsPanel, collapseStates);
this.SettingsUpdated = true;
}
2024-03-28 19:13:48 +01:00
}, true));
2020-09-19 20:49:33 +02:00
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: _ => {
2021-04-24 12:50:06 +02:00
let settingsItems = [];
2020-11-23 20:56:13 +01:00
2021-04-24 12:50:06 +02:00
let observed = this.getObservedData();
2022-09-27 16:53:10 +02:00
let friendIds = BDFDB.LibraryStores.RelationshipStore.getFriendIDs();
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,
2021-04-24 12:50:06 +02:00
children: [
Object.keys(this.defaults.general).map(key => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
type: "Switch",
plugin: this,
keys: ["general", key],
label: this.defaults.general[key].description,
value: this.settings.general[key]
})),
2024-07-07 10:10:49 +02:00
Object.keys(this.defaults.choices).map(key => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
type: "Select",
plugin: this,
keys: ["choices", key],
label: this.defaults.choices[key].description,
basis: "50%",
value: this.settings.choices[key],
options: Object.keys(BDFDB.DiscordConstants[this.defaults.choices[key].items] || {}).map(p => ({
value: p,
label: BDFDB.LanguageUtils.LibraryStrings[p] || p
})),
searchable: true
})),
2021-04-24 12:50:06 +02:00
Object.keys(this.defaults.dates).map(key => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.DateInput, {
...(this.settings.dates[key] || {}),
label: this.defaults.dates[key].description,
onChange: valueObj => {
this.SettingsUpdated = true;
this.settings.dates[key] = valueObj;
BDFDB.DataUtils.save(this.settings.dates, this, "dates");
}
})),
Object.keys(this.defaults.amounts).map(key => (key.indexOf("desktop") == -1 || "Notification" in window) && 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: this.settings.amounts[key]
}))
]
2020-11-23 20:56:13 +01:00
}));
2021-06-30 15:38:41 +02:00
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, {
title: "Default Settings for new Users",
collapseStates: collapseStates,
children: ["disabled"].concat(Object.keys(defaultSettings)).map(key => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, {
type: "Switch",
2022-09-27 11:53:04 +02:00
label: BDFDB.StringUtils.upperCaseFirstChar(key),
2021-06-30 15:38:41 +02:00
value: !!defaultSettings[key],
onChange: value => {
defaultSettings[key] = !!statuses[key] ? notificationTypes[value ? "TOAST" : "DISABLED"].value : value;
BDFDB.DataUtils.save(defaultSettings, this, "defaultSettings");
}
}))
}));
2022-09-27 16:53:10 +02:00
let friendCards = Object.keys(observed.friends).map(BDFDB.LibraryStores.UserStore.getUser).filter(n => n);
let strangerCards = Object.keys(observed.strangers).map(BDFDB.LibraryStores.UserStore.getUser).filter(n => n);
2021-04-24 12:50:06 +02:00
if (friendCards.length) settingsItems.push(createUserList(friendCards.map(user => Object.assign({}, user, observed.friends[user.id], {
key: user.id,
className: observed.friends[user.id].disabled ? BDFDB.disCN.hovercarddisabled : ""
})), "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, {
2023-06-30 11:20:53 +02:00
placeholder: "user (id, accountname 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();
2023-06-30 11:20:53 +02:00
if (userId == BDFDB.UserUtils.me.id) BDFDB.NotificationUtils.toast("Are you seriously trying to observe yourself?", {type: "danger"});
2021-04-24 12:50:06 +02:00
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"});
else if (observed.strangers[userId]) BDFDB.NotificationUtils.toast("User is already being observed as a 'Stranger'", {type: "danger"});
2020-11-23 20:56:13 +01:00
else {
2023-06-30 11:20:53 +02:00
let user = /.+#[0-9]{4}/.test(userId) ? BDFDB.LibraryStores.UserStore.findByTag(userId.split("#").slice(0, -1).join("#"), userId.split("#").pop()) : (BDFDB.LibraryStores.UserStore.findByTag(userId) || BDFDB.LibraryStores.UserStore.getUser(userId));
2020-11-23 20:56:13 +01:00
if (user) {
2023-06-30 11:20:53 +02:00
if (user.id == BDFDB.UserUtils.me.id) BDFDB.NotificationUtils.toast("Are you seriously trying to observe yourself?", {type: "danger"});
else {
observed.strangers[user.id || userId] = Object.assign({}, defaultSettings);
BDFDB.DataUtils.save(observed, this, "observed");
BDFDB.PluginUtils.refreshSettingsPanel(this, settingsPanel, collapseStates);
this.SettingsUpdated = true;
}
2020-11-23 20:56:13 +01:00
}
2023-06-30 11:20:53 +02:00
else BDFDB.NotificationUtils.toast("Please enter a valid ID or Accountname 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-04-24 12:50:06 +02:00
if (strangerCards.length) settingsItems.push(createUserList(strangerCards.map(user => Object.assign({}, user, observed.strangers[user.id], {
key: user.id,
className: observed.strangers[user.id].disabled ? BDFDB.disCN.hovercarddisabled : ""
})), "strangers", "Stranger-List"));
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", {
2024-07-04 19:07:16 +02:00
className: BDFDB.disCNS.settingsrowtitle + BDFDB.disCN.cursordefault,
2020-11-23 20:56:13 +01:00
children: [
2023-01-10 10:03:38 +01:00
"Allows you to configure your own Message Strings for the different Statuses.",
[
["$user", " is the Placeholder for the Username"],
2023-01-10 10:24:19 +01:00
["$nick", " for the Friend Nickname (fallback to $user if unused)"],
2023-01-10 10:03:38 +01:00
["$status", " for the Status Name"],
["$statusOld", " for the previous Status Name"],
["$custom", " for the Custom Status"],
["$game", " for the Game Name"],
["$song", " for the Song Name"],
["$artist", " for the Song Artist"]
].map(n => BDFDB.ReactUtils.createElement("div", {children: [
BDFDB.ReactUtils.createElement("strong", {children: n[0]}),
n[1]
]}))
2020-11-23 20:56:13 +01:00
]
2020-09-19 20:49:33 +02:00
})
2021-04-24 12:50:06 +02:00
})].concat(Object.keys(this.defaults.notificationStrings).map(key => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
2020-11-23 20:56:13 +01:00
type: "TextInput",
plugin: this,
2021-04-24 12:50:06 +02:00
keys: ["notificationStrings", key],
placeholder: this.defaults.notificationStrings[key].value,
2022-09-27 11:53:04 +02:00
label: BDFDB.StringUtils.upperCaseFirstChar(key),
2021-01-15 21:21:24 +01:00
basis: "80%",
2021-04-24 12:50:06 +02:00
value: this.settings.notificationStrings[key]
2020-11-23 20:56:13 +01:00
})))
}));
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,
2021-04-24 12:50:06 +02:00
children: Object.keys(this.defaults.notificationSounds).map((key, i) => (key.indexOf("desktop") == -1 || "Notification" in window) && [
2020-11-23 20:56:13 +01:00
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, {
2022-09-27 11:53:04 +02:00
label: `${key.split(/(desktop)|(toast)/).filter(n => n).map(n => BDFDB.StringUtils.upperCaseFirstChar(n)).join("-")} Notification Sound`,
2020-11-23 20:56:13 +01:00
}),
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, {
type: "Switch",
mini: true,
grow: 0,
label: "Mute:",
2021-04-24 12:50:06 +02:00
value: this.settings.notificationSounds[key].mute,
2020-11-23 20:56:13 +01:00
onChange: value => {
2021-04-24 12:50:06 +02:00
this.settings.notificationSounds[key].mute = value;
BDFDB.DataUtils.save(this.settings.notificationSounds, this, "notificationSounds");
2020-11-23 20:56:13 +01:00
}
})
].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"],
2024-10-04 15:16:09 +02:00
placeholder: "Url or File",
value: this.settings.notificationSounds[key].data
2020-11-23 20:56:13 +01:00
})
}),
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Button, {
onClick: _ => {
2024-10-09 18:35:46 +02:00
let source = settingsPanel.props._node.querySelector(`.input-${key}src ` + BDFDB.dotCN.input);
let value = source && (source.getAttribute("file") || source.value).trim()
2020-11-23 20:56:13 +01:00
if (!source.length) {
2021-04-24 12:50:06 +02: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)) {
2024-10-04 15:16:09 +02:00
successSavedAudio(key, source);
2020-11-23 20:56:13 +01:00
return;
}
}
2021-04-24 12:50:06 +02:00
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"});
2020-11-23 20:56:13 +01:00
});
2024-10-04 15:16:09 +02:00
else if (source.indexOf("data:") == 0) return successSavedAudio(key, source);
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
]).flat(10).filter(n => n)
}));
2021-04-24 12:50:06 +02: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",
2021-08-12 18:52:55 +02:00
onClick: _ => this.showTimeLog(),
2021-04-24 12:50:06 +02:00
children: "Timelog"
})
}));
2020-11-23 20:56:13 +01:00
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();
2021-06-30 15:38:41 +02:00
this.forceUpdateAll();
2020-09-19 20:49:33 +02:00
}
2020-02-09 14:51:48 +01:00
}
2021-04-13 18:25:20 +02:00
2022-10-11 09:35:15 +02:00
processGuildsBar (e) {
2021-10-08 14:15:40 +02:00
if (!this.settings.general.addOnlineCount) return;
2024-09-05 14:25:29 +02:00
const process = returnValue => {
let [children, index] = BDFDB.ReactUtils.findParent(returnValue, {name: "UnreadDMs"});
if (index > -1) children.splice(index, 0, BDFDB.ReactUtils.createElement(FriendOnlineCounterComponent, {
amount: this.getOnlineCount()
}));
};
let themeWrapper = BDFDB.ReactUtils.findChild(e.returnvalue, {filter: n => n && n.props && typeof n.props.children == "function"});
if (themeWrapper) {
let childrenRender = themeWrapper.props.children;
themeWrapper.props.children = BDFDB.TimeUtils.suppress((...args) => {
let children = childrenRender(...args);
process(children);
return children;
}, "Error in Children Render of Theme Wrapper!", this);
}
else process(e.returnvalue);
2020-10-30 16:15:43 +01:00
}
2021-03-16 15:16:36 +01:00
2021-04-24 12:50:06 +02:00
getObservedData () {
2022-04-10 09:43:05 +02:00
let observed = Object.assign({friends: {}, strangers: {}}, BDFDB.DataUtils.load(this, "observed"));
2022-09-27 16:53:10 +02:00
let friendIds = BDFDB.LibraryStores.RelationshipStore.getFriendIDs();
2021-03-16 15:16:36 +01:00
for (let id of friendIds) {
2022-09-27 16:53:10 +02:00
let user = BDFDB.LibraryStores.UserStore.getUser(id);
2021-03-16 15:16:36 +01:00
if (user) {
2021-08-12 18:52:55 +02:00
observed.friends[id] = Object.assign({}, defaultSettings, observed.friends[id] || observed.strangers[id]);
2021-04-24 12:50:06 +02:00
delete observed.strangers[id];
2021-03-16 15:16:36 +01:00
}
}
2021-04-24 12:50:06 +02:00
for (let id in observed.friends) if (!friendIds.includes(id)) {
observed.strangers[id] = Object.assign({}, observed.friends[id]);
delete observed.friends[id];
2021-03-16 15:16:36 +01:00
}
2021-04-24 12:50:06 +02:00
delete observed.friends[BDFDB.UserUtils.me.id];
delete observed.strangers[BDFDB.UserUtils.me.id];
2022-04-10 09:43:05 +02:00
BDFDB.DataUtils.save(observed, this, "observed");
2021-04-24 12:50:06 +02:00
return observed;
2021-03-16 15:16:36 +01:00
}
2019-09-04 12:34:02 +02:00
2021-04-13 18:25:20 +02:00
getStatusWithMobileAndActivity (id, config, clientStatuses) {
2023-06-06 08:48:41 +02:00
let voiceState = BDFDB.LibraryStores.SortedGuildStore.getFlattenedGuildIds().map(BDFDB.LibraryStores.SortedVoiceStateStore.getVoiceStates).map(BDFDB.ObjectUtils.toArray).flat(10).map(n => n.voiceState || n).find(n => n.selfStream & n.userId == id && BDFDB.LibraryStores.ChannelStore.getChannel(n.channelId) && BDFDB.UserUtils.can("VIEW_CHANNEL", BDFDB.UserUtils.me.id, n.channelId));
2021-04-15 14:30:17 +02:00
let status = {
name: BDFDB.UserUtils.getStatus(id),
activity: null,
custom: false,
2022-09-07 15:51:27 +02:00
screensharing: voiceState ? voiceState.channelId : null,
2021-04-15 14:30:17 +02:00
mobile: clientStatuses && clientStatuses[id] && Object.keys(clientStatuses[id]).length == 1 && !!clientStatuses[id].mobile
};
2021-01-15 21:21:24 +01:00
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]) {
2022-09-07 15:51:27 +02:00
Object.assign(status, {name: isCustom ? status.name : activityName, activity: Object.assign({}, activity), custom: isCustom, screensharing: false});
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();
2021-02-09 18:36:43 +01:00
return statusName;
2021-02-09 17:03:52 +01:00
}
2021-04-14 14:37:19 +02:00
activityIsSame (id, status) {
2021-01-20 14:50:09 +01:00
return BDFDB.equals(BDFDB.ObjectUtils.extract(userStatusStore[id].activity, "name", "details", "state", "emoji"), status && BDFDB.ObjectUtils.extract(status.activity, "name", "details", "state", "emoji"));
}
2021-08-02 21:07:53 +02:00
getOnlineCount () {
2022-10-02 17:12:02 +02:00
return Object.entries(BDFDB.LibraryStores.RelationshipStore.getRelationships()).filter(n => n[1] == BDFDB.DiscordConstants.RelationshipTypes.FRIEND && BDFDB.LibraryStores.PresenceStore.getStatus(n[0]) != BDFDB.LibraryComponents.StatusComponents.Types.OFFLINE).length;
2021-08-02 21:07:53 +02:00
}
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);
2021-04-24 12:50:06 +02:00
let data = this.getObservedData();
observedUsers = Object.assign({}, data.strangers, data.friends);
2021-03-05 14:15:25 +01:00
delete observedUsers[BDFDB.UserUtils.me.id];
2020-09-19 20:49:33 +02:00
2022-09-27 16:53:10 +02:00
let clientStatuses = BDFDB.LibraryStores.PresenceStore.getState().clientStatuses;
2021-04-13 18:25:20 +02:00
for (let id in observedUsers) userStatusStore[id] = this.getStatusWithMobileAndActivity(id, observedUsers[id], clientStatuses);
2020-09-19 20:49:33 +02:00
checkInterval = BDFDB.TimeUtils.interval(_ => {
2021-08-02 21:07:53 +02:00
let amount = this.getOnlineCount();
2020-09-19 20:49:33 +02:00
if (friendCounter && friendCounter.props.amount != amount) {
friendCounter.props.amount = amount;
BDFDB.ReactUtils.forceUpdate(friendCounter);
}
2022-09-27 16:53:10 +02:00
clientStatuses = BDFDB.LibraryStores.PresenceStore.getState().clientStatuses;
2020-09-19 20:49:33 +02:00
for (let id in observedUsers) if (!observedUsers[id].disabled) {
2022-09-27 16:53:10 +02:00
let user = BDFDB.LibraryStores.UserStore.getUser(id);
2021-04-13 18:25:20 +02:00
let status = this.getStatusWithMobileAndActivity(id, observedUsers[id], clientStatuses);
2022-09-07 15:51:27 +02:00
let transitionChannelId = null;
let customChanged = false, loginNotice = false, screensharingNotice = false;
2022-10-02 17:12:02 +02:00
if (user && (!observedUsers[id][status.name] && observedUsers[id].login && status.name != BDFDB.LibraryComponents.StatusComponents.Types.OFFLINE && userStatusStore[id].name == BDFDB.LibraryComponents.StatusComponents.Types.OFFLINE && (loginNotice = true) || observedUsers[id][status.name] && (
2021-01-15 21:21:24 +01:00
observedUsers[id].custom && (
2021-04-14 14:37:19 +02:00
userStatusStore[id].custom != status.custom && ((customChanged = status.custom) || true) ||
(customChanged = status.custom && !this.activityIsSame(id, status))
2021-01-15 21:21:24 +01:00
) ||
2022-09-07 15:51:27 +02:00
observedUsers[id].screensharing && status.screensharing && userStatusStore[id].screensharing != status.screensharing && (screensharingNotice = true) ||
2021-04-14 14:37:19 +02:00
observedUsers[id].mobile && userStatusStore[id].mobile != status.mobile ||
statuses[status.name].checkActivity && !this.activityIsSame(id, status) ||
userStatusStore[id].name != status.name
2021-08-12 18:52:55 +02:00
))) {
2020-09-19 20:49:33 +02:00
let EUdata = BDFDB.BDUtils.isPluginEnabled("EditUsers") && BDFDB.DataUtils.load("EditUsers", "users", user.id) || {};
2023-06-20 08:44:41 +02:00
let name = EUdata.name || user.globalName || user.username;
2023-01-10 10:24:19 +01:00
let nickname = EUdata.name || BDFDB.LibraryStores.RelationshipStore.getNickname(user.id);
2020-09-19 20:49:33 +02:00
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
2022-09-07 15:51:27 +02:00
let string = this.settings.notificationStrings[screensharingNotice ? "screensharing" : customChanged ? "custom" : loginNotice ? "login" : status.name] || "'$user' changed status to '$status'";
2023-01-10 10:24:19 +01:00
let hasUserPlaceholder = string.indexOf("$user") > -1;
let toastString = BDFDB.StringUtils.htmlEscape(string)
2023-06-30 10:55:35 +02:00
.replace(/'{0,1}\$user'{0,1}/g, `<strong>${BDFDB.StringUtils.htmlEscape(name)}</strong>${this.settings.general.showDiscriminator && !user.isPomelo() ? ("#" + user.discriminator) : ""}`)
.replace(/'{0,1}\$nick'{0,1}/g, nickname ? `<strong>${BDFDB.StringUtils.htmlEscape(nickname)}</strong>${!hasUserPlaceholder && this.settings.general.showDiscriminator && !user.isPomelo() ? ("#" + user.discriminator) : ""}` : !hasUserPlaceholder ? `<strong>${BDFDB.StringUtils.htmlEscape(name)}</strong>${this.settings.general.showDiscriminator && user.discriminator && user.discriminator != "0" ? ("#" + user.discriminator) : ""}` : "")
2023-01-10 10:24:19 +01:00
.replace(/'{0,1}\$statusOld'{0,1}/g, `<strong>${oldStatusName}</strong>`)
.replace(/'{0,1}\$status'{0,1}/g, `<strong>${statusName}</strong>`);
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
2021-04-13 18:25:20 +02:00
let statusType = BDFDB.UserUtils.getStatus(user.id);
2021-08-12 18:52:55 +02:00
if (observedUsers[id].timelog == undefined || observedUsers[id].timelog) timeLog.unshift({
2020-09-19 20:49:33 +02:00
string: toastString,
avatar: avatar,
2022-04-10 09:43:05 +02:00
id: id,
2020-09-19 20:49:33 +02:00
name: name,
2021-04-13 18:25:20 +02:00
status: statusType,
mobile: status.mobile,
2021-03-16 15:16:36 +01:00
timestamp: timestamp
2020-09-19 20:49:33 +02:00
});
2022-10-02 17:12:02 +02:00
if (!(this.settings.general.muteOnDND && BDFDB.UserUtils.getStatus() == BDFDB.LibraryComponents.StatusComponents.Types.DND) && (!lastTimes[user.id] || lastTimes[user.id] != timestamp)) {
2021-03-16 15:16:36 +01:00
lastTimes[user.id] = timestamp;
2020-09-19 20:49:33 +02:00
let openChannel = _ => {
2021-04-24 12:50:06 +02:00
if (this.settings.general.openOnClick) {
2022-09-07 15:51:27 +02:00
if (status.screensharing) {
BDFDB.LibraryModules.ChannelUtils.selectVoiceChannel(status.screensharing);
BDFDB.LibraryModules.WindowUtils.focus();
}
else {
2022-09-27 14:48:10 +02:00
let DMid = BDFDB.LibraryStores.ChannelStore.getDMFromUserId(user.id)
2022-09-07 15:51:27 +02:00
if (DMid) BDFDB.LibraryModules.ChannelUtils.selectPrivateChannel(DMid);
2022-09-27 16:53:10 +02:00
else BDFDB.LibraryModules.PrivateChannelUtils.openPrivateChannel(user.id);
2022-09-07 15:51:27 +02:00
BDFDB.LibraryModules.WindowUtils.focus();
}
2020-09-19 20:49:33 +02:00
}
};
2021-08-26 11:45:11 +02:00
if ((loginNotice ? observedUsers[id].login : observedUsers[id][status.name]) == notificationTypes.DESKTOP.value) {
2021-06-30 23:30:58 +02:00
let desktopString = string.replace(/\$user/g, `${name}${this.settings.general.showDiscriminator ? ("#" + user.discriminator) : ""}`).replace(/\$statusOld/g, oldStatusName).replace(/\$status/g, statusName);
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-04-13 18:25:20 +02:00
if (status.mobile) desktopString += " (mobile)";
2021-04-24 12:50:06 +02:00
let notificationSound = this.settings.notificationSounds["desktop" + status.name] || {};
2022-09-07 15:51:27 +02:00
BDFDB.NotificationUtils.desktop([desktopString, this.settings.general.showTimeLog && BDFDB.LibraryComponents.DateInput.format(this.settings.dates.logDate, timestamp)].filter(n => n).join("\n\n"), {
2021-01-25 14:10:20 +01:00
icon: avatar,
silent: notificationSound.mute,
sound: notificationSound.song,
onClick: openChannel
});
2020-09-19 20:49:33 +02:00
}
2022-09-07 15:51:27 +02:00
else BDFDB.NotificationUtils.toast(BDFDB.ReactUtils.createElement("div", {
2021-04-13 18:25:20 +02:00
children: [
2022-09-07 15:51:27 +02:00
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex, {
align: BDFDB.LibraryComponents.Flex.Align.CENTER,
children: [
BDFDB.ReactUtils.elementToReact(BDFDB.DOMUtils.create(toastString)),
this.createStatusDot(statusType, status.mobile, {marginLeft: 6})
]
}),
this.settings.general.showTimestamp && BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextElement, {
className: BDFDB.disCN.margintop4,
size: BDFDB.LibraryComponents.TextElement.Sizes.SIZE_12,
2023-11-01 11:23:33 +01:00
color: BDFDB.LibraryComponents.TextElement.Colors.MUTED,
2022-09-07 15:51:27 +02:00
children: BDFDB.LibraryComponents.DateInput.format(this.settings.dates.logDate, timestamp)
})
2021-04-13 18:25:20 +02:00
]
}), {
2021-04-24 12:50:06 +02:00
timeout: this.settings.amounts.toastTime * 1000,
2021-02-12 17:07:48 +01:00
avatar: avatar,
barColor: BDFDB.UserUtils.getStatusColor(status.name, true),
2024-07-07 10:10:49 +02:00
position: this.settings.choices.toastPosition,
2021-02-12 17:07:48 +01:00
onClick: openChannel,
onShow: _ => {
2021-04-24 12:50:06 +02:00
let notificationSound = this.settings.notificationSounds["toast" + status.name] || {};
2021-02-12 17:07:48 +01:00
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
}
2021-04-24 12:50:06 +02:00
}, this.settings.amounts.checkInterval * 1000);
2021-04-13 18:25:20 +02:00
}
2021-04-14 16:44:59 +02:00
createStatusDot (status, isMobile, style = {}) {
2022-10-02 17:12:02 +02:00
return BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.StatusComponents.Status, {
2021-04-14 16:44:59 +02:00
style: Object.assign({}, style),
2021-04-13 18:25:20 +02:00
size: 12,
color: isMobile ? BDFDB.UserUtils.getStatusColor(status, true) : null,
isMobile: isMobile,
2022-10-02 17:12:02 +02:00
status: isMobile ? BDFDB.LibraryComponents.StatusComponents.Types.ONLINE : status
2021-04-13 18:25:20 +02:00
});
}
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,
2021-04-15 14:30:17 +02:00
titleChildren: [
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Button, {
color: BDFDB.LibraryComponents.Button.Colors.RED,
size: BDFDB.LibraryComponents.Button.Sizes.TINY,
2021-05-27 15:59:45 +02:00
look: BDFDB.LibraryComponents.Button.Looks.OUTLINE,
2021-04-15 14:30:17 +02:00
style: {marginLeft: 6, marginRight: 12},
children: BDFDB.LanguageUtils.LanguageStrings.BUILD_OVERRIDE_CLEAR,
onClick: _ => BDFDB.ModalUtils.confirm(this, this.labels.clear_log, _ => {
timeLog = [];
timeLogList.props.entries = timeLog;
2020-12-22 18:45:40 +01:00
BDFDB.ReactUtils.forceUpdate(timeLogList);
2021-04-15 14:30:17 +02:00
})
}),
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SearchBar, {
autoFocus: true,
query: "",
2022-04-10 09:43:05 +02:00
onChange: value => {
2021-04-15 14:30:17 +02:00
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);
},
2022-04-10 09:43:05 +02:00
onClear: _ => {
2021-04-15 14:30:17 +02:00
timeLogList.props.entries = timeLog;
BDFDB.ReactUtils.forceUpdate(timeLogList);
}
})
],
2020-12-22 18:45:40 +01:00
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 {
2024-09-05 14:25:29 +02:00
clear_log: "Наистина ли искате да изчистите дневника на времето?",
2021-01-15 21:21:24 +01:00
status_listening: "Слушане",
status_playing: "Играе"
};
case "da": // Danish
return {
2024-09-05 14:25:29 +02:00
clear_log: "Er du sikker på, at du vil rydde tidsloggen?",
2021-01-15 21:21:24 +01:00
status_listening: "Hører efter",
status_playing: "Spiller"
};
case "de": // German
return {
2024-09-05 14:25:29 +02:00
clear_log: "Möchtest du das Zeitprotokoll wirklich löschen?",
2021-01-15 21:21:24 +01:00
status_listening: "Hören",
status_playing: "Spielen"
};
case "el": // Greek
return {
2024-09-05 14:25:29 +02:00
clear_log: "Είστε βέβαιοι ότι θέλετε να διαγράψετε το ημερολόγιο ώρας;",
2021-01-15 21:21:24 +01:00
status_listening: "Ακούγοντας",
status_playing: "Παιχνίδι"
};
case "es": // Spanish
return {
2024-09-05 14:25:29 +02:00
clear_log: "¿Está seguro de que desea borrar el registro de tiempo?",
2021-01-15 21:21:24 +01:00
status_listening: "Escuchando",
status_playing: "Jugando"
};
case "fi": // Finnish
return {
2024-09-05 14:25:29 +02:00
clear_log: "Haluatko varmasti tyhjentää aikalokin?",
2021-01-15 21:21:24 +01:00
status_listening: "Kuunteleminen",
status_playing: "Pelataan"
};
case "fr": // French
return {
2024-09-05 14:25:29 +02:00
clear_log: "Voulez-vous vraiment effacer le journal de temps?",
2021-01-15 21:21:24 +01:00
status_listening: "Écoute",
status_playing: "En jouant"
};
case "hr": // Croatian
return {
2024-09-05 14:25:29 +02:00
clear_log: "Jeste li sigurni da želite očistiti vremenski zapisnik?",
2021-01-15 21:21:24 +01:00
status_listening: "Slušanje",
status_playing: "Sviranje"
};
case "hu": // Hungarian
return {
2024-09-05 14:25:29 +02:00
clear_log: "Biztosan törli az időnaplót?",
2021-01-15 21:21:24 +01:00
status_listening: "Hallgatás",
status_playing: "Játék"
};
case "it": // Italian
return {
2024-09-05 14:25:29 +02:00
clear_log: "Sei sicuro di voler cancellare il registro del tempo?",
2021-01-15 21:21:24 +01:00
status_listening: "Ascoltando",
status_playing: "Giocando"
};
case "ja": // Japanese
return {
2024-09-05 14:25:29 +02:00
clear_log: "タイムログをクリアしてもよろしいですか?",
2021-01-15 21:21:24 +01:00
status_listening: "聞いている",
status_playing: "遊ぶ"
};
case "ko": // Korean
return {
2024-09-05 14:25:29 +02:00
clear_log: "시간 로그를 지우시겠습니까?",
2021-01-15 21:21:24 +01:00
status_listening: "청취",
status_playing: "놀이"
};
case "lt": // Lithuanian
return {
2024-09-05 14:25:29 +02:00
clear_log: "Ar tikrai norite išvalyti laiko žurnalą?",
2021-01-15 21:21:24 +01:00
status_listening: "Klausymas",
status_playing: "Žaidžia"
};
case "nl": // Dutch
return {
2024-09-05 14:25:29 +02:00
clear_log: "Weet u zeker dat u het tijdlogboek wilt wissen?",
2021-01-15 21:21:24 +01:00
status_listening: "Luisteren",
status_playing: "Spelen"
};
case "no": // Norwegian
return {
2024-09-05 14:25:29 +02:00
clear_log: "Er du sikker på at du vil slette tidsloggen?",
2021-01-15 21:21:24 +01:00
status_listening: "Lytte",
status_playing: "Spiller"
};
case "pl": // Polish
return {
2024-09-05 14:25:29 +02:00
clear_log: "Czy na pewno chcesz wyczyścić dziennik czasu?",
2021-01-15 21:21:24 +01:00
status_listening: "Słuchający",
status_playing: "Gra"
};
case "pt-BR": // Portuguese (Brazil)
return {
2024-09-05 14:25:29 +02:00
clear_log: "Tem certeza de que deseja limpar o registro de horas?",
2021-01-15 21:21:24 +01:00
status_listening: "Ouvindo",
status_playing: "Jogando"
};
case "ro": // Romanian
return {
2024-09-05 14:25:29 +02:00
clear_log: "Sigur doriți să ștergeți jurnalul de timp?",
2021-01-15 21:21:24 +01:00
status_listening: "Ascultare",
status_playing: "Joc"
};
case "ru": // Russian
return {
2024-09-05 14:25:29 +02:00
clear_log: "Вы уверены, что хотите очистить журнал времени?",
2021-01-15 21:21:24 +01:00
status_listening: "Прослушивание",
status_playing: "Играет"
};
case "sv": // Swedish
return {
2024-09-05 14:25:29 +02:00
clear_log: "Är du säker på att du vill rensa tidsloggen?",
2021-01-15 21:21:24 +01:00
status_listening: "Lyssnande",
status_playing: "Spelar"
};
case "th": // Thai
return {
2024-09-05 14:25:29 +02:00
clear_log: "แน่ใจไหมว่าต้องการล้างบันทึกเวลา",
2021-01-15 21:21:24 +01:00
status_listening: "การฟัง",
status_playing: "กำลังเล่น"
};
case "tr": // Turkish
return {
2024-09-05 14:25:29 +02:00
clear_log: "Zaman kaydını temizlemek istediğinizden emin misiniz?",
2021-01-15 21:21:24 +01:00
status_listening: "Dinleme",
status_playing: "Çalma"
};
case "uk": // Ukrainian
return {
2024-09-05 14:25:29 +02:00
clear_log: "Ви впевнені, що хочете очистити журнал часу?",
2021-01-15 21:21:24 +01:00
status_listening: "Слухання",
status_playing: "Гра"
};
case "vi": // Vietnamese
return {
2024-09-05 14:25:29 +02:00
clear_log: "Bạn có chắc chắn muốn xóa nhật ký thời gian không?",
2021-01-15 21:21:24 +01:00
status_listening: "Lắng nghe",
status_playing: "Đang chơi"
};
case "zh-CN": // Chinese (China)
return {
2024-09-05 14:25:29 +02:00
clear_log: "您确定要清除时间记录吗?",
2021-12-15 21:44:54 +01:00
status_listening: "聆听中",
status_playing: "游戏中"
2021-01-15 21:21:24 +01:00
};
case "zh-TW": // Chinese (Taiwan)
return {
2024-09-05 14:25:29 +02:00
clear_log: "您確定要清除時間記錄嗎?",
2021-12-15 21:44:54 +01:00
status_listening: "聆聽中",
status_playing: "遊戲中"
2021-01-15 21:21:24 +01:00
};
default: // English
return {
2024-09-05 14:25:29 +02:00
clear_log: "Are you sure you want to clear the timelog?",
2021-01-15 21:21:24 +01:00
status_listening: "Listening",
status_playing: "Playing"
};
}
}
2020-09-19 20:49:33 +02:00
};
2022-09-01 14:40:11 +02:00
})(window.BDFDB_Global.PluginUtils.buildPlugin(changeLog));
2022-12-11 17:45:46 +01:00
})();