adds support for role settings and various fixes
This commit is contained in:
parent
96b2dbb21c
commit
8fe0c9f46b
20 changed files with 1199 additions and 183 deletions
|
@ -4,7 +4,8 @@ import {Contextmenu} from "./contextmenu.js";
|
|||
import {Role} from "./role.js";
|
||||
import {Fullscreen} from "./fullscreen.js";
|
||||
import {Member} from "./member.js";
|
||||
|
||||
import {Settings,RoleList} from "./settings.js";
|
||||
import {Permissions} from "./permissions.js";
|
||||
class Guild{
|
||||
owner:Localuser;
|
||||
headers:Localuser["headers"];
|
||||
|
@ -49,6 +50,9 @@ class Guild{
|
|||
Guild.contextmenu.addbutton("Create invite",function(){
|
||||
console.log(this);
|
||||
},null,_=>true,_=>false);
|
||||
Guild.contextmenu.addbutton("Settings[temp]",function(){
|
||||
this.generateSettings();
|
||||
});
|
||||
/* -----things left for later-----
|
||||
guild.contextmenu.addbutton("Leave Guild",function(){
|
||||
console.log(this)
|
||||
|
@ -60,6 +64,17 @@ class Guild{
|
|||
},null,_=>{return thisuser.isAdmin()})
|
||||
*/
|
||||
}
|
||||
generateSettings(){
|
||||
const settings=new Settings("Settings for "+this.properties.name);
|
||||
|
||||
const s1=settings.addButton("roles");
|
||||
const permlist=[];
|
||||
for(const thing of this.roles){
|
||||
permlist.push([thing.id,thing.permissions]);
|
||||
}
|
||||
s1.options.push(new RoleList(permlist,this,this.updateRolePermissions.bind(this)));
|
||||
settings.show();
|
||||
}
|
||||
constructor(JSON,owner:Localuser,member){
|
||||
|
||||
if(JSON===-1){
|
||||
|
@ -92,6 +107,7 @@ class Guild{
|
|||
this.headchannels.push(thing);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
notisetting(settings){
|
||||
this.message_notifications=settings.message_notifications;
|
||||
|
@ -489,6 +505,41 @@ class Guild{
|
|||
body:JSON.stringify({name: name, type: type})
|
||||
})
|
||||
}
|
||||
async createRole(name:string){
|
||||
const fetched=await fetch(this.info.api.toString()+"/guilds/"+this.id+"roles",{
|
||||
method:"POST",
|
||||
headers:this.headers,
|
||||
body:JSON.stringify({
|
||||
name:name,
|
||||
color:0,
|
||||
permissions:"0"
|
||||
})
|
||||
})
|
||||
const json=await fetched.json();
|
||||
const role=new Role(json,this);
|
||||
this.roleids[role.id]=role;
|
||||
this.roles.push(role);
|
||||
return role;
|
||||
}
|
||||
async updateRolePermissions(id:string,perms:Permissions){
|
||||
const role=this.roleids[id];
|
||||
role.permissions.allow=perms.allow;
|
||||
role.permissions.deny=perms.deny;
|
||||
|
||||
await fetch(this.info.api.toString()+"/guilds/"+this.id+"/roles/"+this.id,{
|
||||
method:"PATCH",
|
||||
headers:this.headers,
|
||||
body:JSON.stringify({
|
||||
color:role.color,
|
||||
hoist:role.hoist,
|
||||
icon:role.icon,
|
||||
mentionable:role.mentionable,
|
||||
name:role.name,
|
||||
permissions:role.permissions.allow.toString(),
|
||||
unicode_emoji:role.unicode_emoji,
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
Guild.setupcontextmenu();
|
||||
export { Guild };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue