Notification support
Be warned, there's either a bug in the server or notification level setting isn't implemented on the server side
This commit is contained in:
parent
0d5e4fc94b
commit
31f3fef52d
5 changed files with 141 additions and 0 deletions
|
@ -451,6 +451,21 @@ class channel{
|
|||
headers:this.headers
|
||||
})
|
||||
}
|
||||
get notification(){
|
||||
let notinumber=this.message_notifications;
|
||||
if(+notinumber===3){notinumber=null;}
|
||||
notinumber??=this.owner.message_notifications;
|
||||
switch(+notinumber){
|
||||
case 0:
|
||||
return "all";
|
||||
case 1:
|
||||
return "mentions";
|
||||
case 2:
|
||||
return "none";
|
||||
case 3:
|
||||
return "default";
|
||||
}
|
||||
}
|
||||
messageCreate(messagep,focus){
|
||||
const messagez=new cmessage(messagep.d,this);
|
||||
this.lastmessageid=messagez.id;
|
||||
|
@ -475,6 +490,53 @@ class channel{
|
|||
if(shouldScroll){
|
||||
scrolly.scrollTop = scrolly.scrollHeight;
|
||||
}
|
||||
if(messagez.author===this.owner.owner.user){
|
||||
return;
|
||||
}
|
||||
if(this.owner.owner.lookingguild.prevchannel===this&&document.hasFocus()){
|
||||
return;
|
||||
}
|
||||
if(this.notification==="all"){
|
||||
this.notify(messagez);
|
||||
}else if(this.notification==="mentions"&&messagez.mentionsuser(this.owner.owner.user)){
|
||||
this.notify(messagez);
|
||||
}
|
||||
}
|
||||
notititle(message){
|
||||
return message.author.username+" > "+this.owner.properties.name+" > "+this.name;
|
||||
}
|
||||
notify(message){
|
||||
{
|
||||
const voicy=new voice("sin",800);
|
||||
voicy.play()
|
||||
setTimeout(_=>{voicy.freq=1000},50);
|
||||
setTimeout(_=>{voicy.freq=1300},100);
|
||||
setTimeout(_=>{voicy.stop()},150);
|
||||
}
|
||||
if (!("Notification" in window)) {
|
||||
|
||||
} else if (Notification.permission === "granted") {
|
||||
let noticontent=markdown(message.content).textContent;
|
||||
noticontent||=message.embeds[0].json.title;
|
||||
noticontent||=markdown(message.embeds[0].json.description).textContent;
|
||||
noticontent||="Blank Message";
|
||||
let imgurl=null;
|
||||
const images=message.getimages();
|
||||
if(images.length){
|
||||
const image = images[0];
|
||||
imgurl||=image.proxy_url;
|
||||
imgurl||=image.url;
|
||||
}
|
||||
const notification = new Notification(this.notititle(message),{
|
||||
body:noticontent,
|
||||
icon:message.author.getpfpsrc(),
|
||||
image:imgurl,
|
||||
});
|
||||
} else if (Notification.permission !== "denied") {
|
||||
Notification.requestPermission().then((permission) => {
|
||||
this.notify(message);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
channel.setupcontextmenu();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue