//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.2.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":[["Canary/PTB","Fixed bugs for complete new look in canary/ptb"]]
};
this.patchModules = {
"StandardSidebarView":"componentWillUnmount"
};
}
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: {
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},
streaming: {value:"$user changed status to '$status'", libstring:"STATUS_STREAMING", init:false},
offline: {value:"$user changed status to '$status'", libstring:"STATUS_OFFLINE", init:true}
},
notificationsounds: {
toastonline: {value:{url:null,song:null,mute:false}},
toastmobile: {value:{url:null,song:null,mute:false}},
toastidle: {value:{url:null,song:null,mute:false}},
toastdnd: {value:{url:null,song:null,mute:false}},
toaststreaming: {value:{url:null,song:null,mute:false}},
toastoffline: {value:{url:null,song:null,mute:false}},
desktoponline: {value:{url:null,song:null,mute:false}},
desktopmobile: {value:{url:null,song:null,mute:false}},
desktopidle: {value:{url:null,song:null,mute:false}},
desktopdnd: {value:{url:null,song:null,mute:false}},
desktopstreaming: {value:{url:null,song:null,mute:false}},
desktopoffline: {value:{url:null,song:null,mute:false}}
},
amounts: {
checkInterval: {value:10, min:5, description:"Check Users every X seconds:"}
}
};
}
getSettingsPanel () {
if (!global.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
let settings = BDFDB.getAllData(this, "settings");
let notificationstrings = BDFDB.getAllData(this, "notificationstrings");
let notificationsounds = BDFDB.getAllData(this, "notificationsounds");
let amounts = BDFDB.getAllData(this, "amounts");
let friendIDs = this.FriendUtils.getFriendIDs();
let friends = BDFDB.loadAllData(this, "friends");
let nonfriends = BDFDB.loadAllData(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) 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 = this.UserUtils.getUser(id);
if (user) {
let friend = friends[id] || (friends[id] = nonfriends[id] || this.createDefaultConfig());
settingshtml += this.createHoverCard(user, friend, "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 = this.UserUtils.getUser(id);
if (user) {
let nonfriend = nonfriends[id] || (nonfriends[id] = this.createDefaultConfig());
settingshtml += this.createHoverCard(user, nonfriend, "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 and $status for the statusname.
`;
for (let config in notificationstrings) {
settingshtml += `