Changes including leaving and deleting servers
This commit is contained in:
131
webpage/guild.js
131
webpage/guild.js
@@ -4,14 +4,22 @@ class guild{
|
||||
guild.contextmenu.addbutton("Copy Guild id",function(){
|
||||
console.log(this)
|
||||
navigator.clipboard.writeText(this.id);
|
||||
})
|
||||
});
|
||||
|
||||
guild.contextmenu.addbutton("Mark as read",function(){
|
||||
console.log(this)
|
||||
this.markAsRead();
|
||||
})
|
||||
});
|
||||
|
||||
guild.contextmenu.addbutton("Create Invite",function(){
|
||||
guild.contextmenu.addbutton("Leave guild",function(){
|
||||
this.confirmleave();
|
||||
},null,function(_){return _.properties.owner_id!==_.member.user.id});
|
||||
|
||||
guild.contextmenu.addbutton("Delete guild",function(){
|
||||
this.confirmDelete();
|
||||
},null,function(_){return _.properties.owner_id===_.member.user.id});
|
||||
|
||||
guild.contextmenu.addbutton("Create invite",function(){
|
||||
console.log(this);
|
||||
},null,_=>true,_=>false);
|
||||
/* -----things left for later-----
|
||||
@@ -59,6 +67,40 @@ class guild{
|
||||
}
|
||||
}
|
||||
}
|
||||
confirmleave(){
|
||||
const full= new fullscreen([
|
||||
"vdiv",
|
||||
["title",
|
||||
"Are you sure you want to leave?"
|
||||
],
|
||||
["hdiv",
|
||||
["button",
|
||||
"",
|
||||
"Yes, I'm sure",
|
||||
_=>{
|
||||
this.leave().then(_=>{
|
||||
full.hide();
|
||||
});
|
||||
}
|
||||
],
|
||||
["button",
|
||||
"",
|
||||
"Nevermind",
|
||||
_=>{
|
||||
full.hide();
|
||||
}
|
||||
]
|
||||
|
||||
]
|
||||
]);
|
||||
full.show();
|
||||
}
|
||||
async leave(){
|
||||
return fetch(info.api.toString()+"/users/@me/guilds/"+this.id,{
|
||||
method:"DELETE",
|
||||
headers:this.headers
|
||||
})
|
||||
}
|
||||
printServers(){
|
||||
let build=""
|
||||
for(const thing of this.headchannels){
|
||||
@@ -124,6 +166,89 @@ class guild{
|
||||
sortchannels(){
|
||||
this.headchannels.sort((a,b)=>{return a.position-b.position;});
|
||||
}
|
||||
generateGuildIcon(){
|
||||
const divy=document.createElement("div");
|
||||
divy.classList.add("servernoti");
|
||||
|
||||
const noti=document.createElement("div");
|
||||
noti.classList.add("unread");
|
||||
divy.append(noti);
|
||||
this.owner.guildhtml[this.id]=divy;
|
||||
if(this.properties.icon!=null){
|
||||
const img=document.createElement("img");
|
||||
img.classList.add("pfp","servericon");
|
||||
img.src=info.cdn.toString()+"icons/"+this.properties.id+"/"+this.properties.icon+".png";
|
||||
divy.appendChild(img)
|
||||
img.onclick=()=>{
|
||||
console.log(this.loadGuild)
|
||||
this.loadGuild();
|
||||
this.loadChannel();
|
||||
}
|
||||
guild.contextmenu.bind(img,this);
|
||||
}else{
|
||||
const div=document.createElement("div");
|
||||
let build="";
|
||||
for(const char of this.properties.name.split(" ")){
|
||||
build+=char[0];
|
||||
}
|
||||
div.innerText=build;
|
||||
div.classList.add("blankserver","servericon")
|
||||
divy.appendChild(div)
|
||||
div.onclick=()=>{
|
||||
this.loadGuild();
|
||||
this.loadChannel();
|
||||
}
|
||||
guild.contextmenu.bind(div,this)
|
||||
}
|
||||
return divy;
|
||||
}
|
||||
confirmDelete(){
|
||||
let confirmname="";
|
||||
const full= new fullscreen([
|
||||
"vdiv",
|
||||
["title",
|
||||
"Are you sure you want to delete "+this.properties.name+"?"
|
||||
],
|
||||
["textbox",
|
||||
"Name of server:",
|
||||
"",
|
||||
function(){
|
||||
confirmname=this.value;
|
||||
}
|
||||
]
|
||||
,
|
||||
["hdiv",
|
||||
["button",
|
||||
"",
|
||||
"Yes, I'm sure",
|
||||
_=>{
|
||||
console.log(confirmname)
|
||||
if(confirmname!==this.properties.name){
|
||||
return;
|
||||
}
|
||||
this.delete().then(_=>{
|
||||
full.hide();
|
||||
});
|
||||
}
|
||||
],
|
||||
["button",
|
||||
"",
|
||||
"Nevermind",
|
||||
_=>{
|
||||
full.hide();
|
||||
}
|
||||
]
|
||||
|
||||
]
|
||||
]);
|
||||
full.show();
|
||||
}
|
||||
async delete(){
|
||||
return fetch(info.api.toString()+"/guilds/"+this.id+"/delete",{
|
||||
method:"POST",
|
||||
headers:this.headers,
|
||||
})
|
||||
}
|
||||
unreads(html){
|
||||
if(html){
|
||||
this.html=html;
|
||||
|
Reference in New Issue
Block a user