Update FriendNotifications.plugin.js

This commit is contained in:
Mirco Wittrien 2023-01-10 10:24:19 +01:00
parent 1de133c73f
commit 5b514d5bfc
1 changed files with 17 additions and 4 deletions

View File

@ -2,7 +2,7 @@
* @name FriendNotifications
* @author DevilBro
* @authorId 278543574059057154
* @version 1.8.7
* @version 1.8.8
* @description Shows a Notification when a Friend or a User, you choose to observe, changes their Status
* @invite Jx3TjNS
* @donate https://www.paypal.me/MircoWittrien
@ -14,7 +14,9 @@
module.exports = (_ => {
const changeLog = {
"added": {
"$nick": "New placeholder for friend nicknames"
}
};
return !window.BDFDB_Global || (!window.BDFDB_Global.loaded && !window.BDFDB_Global.started) ? class {
@ -604,6 +606,7 @@ module.exports = (_ => {
"Allows you to configure your own Message Strings for the different Statuses.",
[
["$user", " is the Placeholder for the Username"],
["$nick", " for the Friend Nickname (fallback to $user if unused)"],
["$status", " for the Status Name"],
["$statusOld", " for the previous Status Name"],
["$custom", " for the Custom Status"],
@ -827,6 +830,7 @@ module.exports = (_ => {
))) {
let EUdata = BDFDB.BDUtils.isPluginEnabled("EditUsers") && BDFDB.DataUtils.load("EditUsers", "users", user.id) || {};
let name = EUdata.name || user.username;
let nickname = EUdata.name || BDFDB.LibraryStores.RelationshipStore.getNickname(user.id);
let avatar = EUdata.removeIcon ? "" : (EUdata.url || BDFDB.UserUtils.getAvatar(user.id));
let timestamp = new Date().getTime();
@ -834,8 +838,17 @@ module.exports = (_ => {
let oldStatusName = this.getStatusName(id, userStatusStore[id]);
let string = this.settings.notificationStrings[screensharingNotice ? "screensharing" : customChanged ? "custom" : loginNotice ? "login" : status.name] || "'$user' changed status to '$status'";
let toastString = BDFDB.StringUtils.htmlEscape(string).replace(/'{0,1}\$user'{0,1}/g, `<strong>${BDFDB.StringUtils.htmlEscape(name)}</strong>${this.settings.general.showDiscriminator ? ("#" + user.discriminator) : ""}`).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>`);
let hasUserPlaceholder = string.indexOf("$user") > -1;
let toastString = BDFDB.StringUtils.htmlEscape(string)
.replace(/'{0,1}\$user'{0,1}/g, `<strong>${BDFDB.StringUtils.htmlEscape(name)}</strong>${this.settings.general.showDiscriminator ? ("#" + user.discriminator) : ""}`)
.replace(/'{0,1}\$nick'{0,1}/g, nickname ? `<strong>${BDFDB.StringUtils.htmlEscape(nickname)}</strong>${!hasUserPlaceholder && this.settings.general.showDiscriminator ? ("#" + user.discriminator) : ""}` : !hasUserPlaceholder ? `<strong>${BDFDB.StringUtils.htmlEscape(name)}</strong>${this.settings.general.showDiscriminator ? ("#" + user.discriminator) : ""}` : "")
.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>`);
}
let statusType = BDFDB.UserUtils.getStatus(user.id);
if (observedUsers[id].timelog == undefined || observedUsers[id].timelog) timeLog.unshift({