//META{"name":"FriendNotifications","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/FriendNotifications","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/FriendNotifications/FriendNotifications.plugin.js"}*//
class FriendNotifications {
getName () {return "FriendNotifications";}
getVersion () {return "1.3.7";}
getAuthor () {return "DevilBro";}
getDescription () {return "Notifies you when a Friend or a User your choose to observe changing his online status, can be configured individually in the settings.";}
constructor () {
this.changelog = {
"fixed":[["Non Friends","Fixed issue where previously configured friends that are no longer in your friend list could not be configured via non-friend list"]]
};
}
initConstructor () {
this.userStatusStore = {};
this.checkInterval = null;
this.timeLog = [];
this.timeLogModalMarkup =
`
Friends LogIn/-Out Timelog
`;
this.logEntryMarkup =
`
`;
this.css = `
.${this.name}-modal .log-time {
width: 110px;
}
.${this.name}-modal .log-avatar {
width: 35px;
height: 35px;
background-size: cover;
background-position: center;
border-radius: 50%;
}
.${this.name}-settings .type-toast, .${this.name}-settings .type-desktop {
border-radius: 3px;
padding: 0 3px;
}
.${this.name}-settings .type-toast {
background-color: #7289DA;
}
.${this.name}-settings .type-desktop {
background-color: #43B581;
}
.${this.name}-settings .settings-avatar.desktop {
border-color: #43B581;
}
.${this.name}-settings .settings-avatar {
margin: 5px;
width: 35px;
height: 35px;
background-size: cover;
background-position: center;
border: 3px solid #7289DA;
border-radius: 50%;
box-sizing: border-box;
cursor: pointer;
}
.${this.name}-settings .settings-avatar.desktop {
border-color: #43B581;
}
.${this.name}-settings .settings-avatar.disabled {
border-color: #36393F;
filter: grayscale(100%) brightness(50%);
}
.${this.name}-settings .settings-avatar.disabled ~ * {
filter: grayscale(100%) brightness(50%);
}`;
this.defaults = {
settings: {
disableForNew: {value:false, description:"Disable Notifications for newly added Friends:"},
muteOnDND: {value:false, description:"Do not notify me when I am DnD:"},
openOnClick: {value:false, description:"Open the DM when you click a Notification:"}
},
notificationstrings: {
online: {value:"$user changed status to '$status'", libstring:"STATUS_ONLINE", init:true},
mobile: {value:"$user changed status to '$status'", libstring:"STATUS_ONLINE_MOBILE", init:true},
idle: {value:"$user changed status to '$status'", libstring:"STATUS_IDLE", init:false},
dnd: {value:"$user changed status to '$status'", libstring:"STATUS_DND", init:false},
playing: {value:"$user started playing '$game'", statusname:"Playing", init:false},
listening: {value:"$user started listening to '$song'", statusname:"Listening", init:false},
streaming: {value:"$user started streaming '$game'", libstring:"STATUS_STREAMING", init:false},
offline: {value:"$user changed status to '$status'", libstring:"STATUS_OFFLINE", init:true}
},
notificationsounds: {},
amounts: {
toastTime: {value:5, min:1, description:"Amount of seconds a toast notification stays on screen:"},
desktopTime: {value:5, min:1, description:"Amount of seconds a desktop notification stays on screen:"},
checkInterval: {value:10, min:5, description:"Check Users every X seconds:"}
}
};
for (let type in this.defaults.notificationstrings) {
this.defaults.notificationsounds["toast" + type] = {value:{url:null,song:null,mute:false}};
this.defaults.notificationsounds["desktop" + type] = {value:{url:null,song:null,mute:false}};
}
this.activityTypes = {};
for (let type in BDFDB.DiscordConstants.ActivityTypes) this.activityTypes[BDFDB.DiscordConstants.ActivityTypes[type]] = type;
}
getSettingsPanel () {
if (!global.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
let settings = BDFDB.DataUtils.get(this, "settings");
let notificationstrings = BDFDB.DataUtils.get(this, "notificationstrings");
let notificationsounds = BDFDB.DataUtils.get(this, "notificationsounds");
let amounts = BDFDB.DataUtils.get(this, "amounts");
let friendIDs = BDFDB.LibraryModules.FriendUtils.getFriendIDs();
let friends = BDFDB.DataUtils.load(this, "friends");
let nonfriends = BDFDB.DataUtils.load(this, "nonfriends");
let settingshtml = `
${this.name}
`;
settingshtml += `
General Settings
`;
for (let key in settings) settingshtml += `
${this.defaults.settings[key].description}
`;
for (let key in amounts) if (key.indexOf("desktop") == -1 || "Notification" in window) settingshtml += `
${this.defaults.amounts[key].description}
`;
settingshtml += `
`;
settingshtml += `
Friend-List
`;
settingshtml += `
Click on an Icon to toggle Notifications for that User:
`;
if ("Notification" in window) settingshtml += `
Rightclick on an Icon to toggle Notifications for that User:
`;
settingshtml += `
Click/Rightclick on the table headers to batch set all Friends
`;
settingshtml += `
TYPE
DISABLE
`;
for (let config in this.defaults.notificationstrings) settingshtml += `
${config.toUpperCase()}
`;
settingshtml += `
`;
for (let id of friendIDs) {
let user = BDFDB.LibraryModules.UserStore.getUser(id);
if (user) {
let friend = null;
if (friends[id]) {}
else if (nonfriends[id]) {
friends[id] = Object.assign({}, nonfriends[id]);
delete nonfriends[id];
}
else friends[id] = this.createDefaultConfig();
settingshtml += this.createHoverCard(user, friends[id], "friends");
}
}
for (let id in friends) if (!friendIDs.includes(id)) {
let user = BDFDB.LibraryModules.UserStore.getUser(id);
if (user) {
nonfriends[id] = Object.assign({}, friends[id]);
delete friends[id];
settingshtml += this.createHoverCard(user, friends[id] || (friends[id] = this.createDefaultConfig()), "friends");
}
}
settingshtml += `
`;
settingshtml += `
`;
settingshtml += `
Non-Friend-List
`;
settingshtml += `
Click on a Icon to toggle Notifications for that User:
`;
if ("Notification" in window) settingshtml += `
Rightclick on a Icon to toggle Notifications for that User:
`;
settingshtml += `
Click/Rightclick on the table headers to batch set all Non-Friends
`;
settingshtml += `
Add Non-Friend:
`;
settingshtml += `
TYPE
DISABLE
`;
for (let config in this.defaults.notificationstrings) settingshtml += `
${config.toUpperCase()}
`;
settingshtml += `
`;
for (let id in nonfriends) if (!friendIDs.includes(id)) {
let user = BDFDB.LibraryModules.UserStore.getUser(id);
if (user) {
delete friends[id];
settingshtml += this.createHoverCard(user, nonfriends[id] || (nonfriends[id] = this.createDefaultConfig()), "nonfriends");
}
}
settingshtml += `
`;
settingshtml += `
`;
settingshtml += `
Timelog
`;
settingshtml += `
Timelog of LogIns/-Outs:
`;
settingshtml += `
`;
settingshtml += `
Notification Message Settings
`;
settingshtml += `
Allows you to configure your own message strings for the different statuses. $user is the placeholder for the username, $status for the statusname, $game for the gamename, $song for the songname and $artist for the songartist.
`;
for (let config in notificationstrings) {
settingshtml += `