Various changes along with some initial perm stuff
This commit is contained in:
parent
01c2439c24
commit
f79b108b0d
8 changed files with 319 additions and 22 deletions
|
@ -341,12 +341,10 @@ class guild{
|
|||
})
|
||||
}
|
||||
fillMember(member){
|
||||
member.guild=this;
|
||||
const realroles=[];
|
||||
for(const thing of member.roles){
|
||||
realroles.push(this.getRole(thing));
|
||||
}
|
||||
member.guild=this;
|
||||
member.roles=realroles;
|
||||
return member;
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
<script src="/embed.js"></script>
|
||||
<script src="/message.js"></script>
|
||||
<script src="/channel.js"></script>
|
||||
<script src="/permissions.js"></script>
|
||||
<script src="/role.js"></script>
|
||||
<script src="/guild.js"></script>
|
||||
<script src="/dirrect.js"></script>
|
||||
|
|
|
@ -7,7 +7,7 @@ class localuser{
|
|||
this.headers={"Content-type": "application/json; charset=UTF-8",Authorization:this.userinfo.token};
|
||||
}
|
||||
gottenReady(ready){
|
||||
this.usersettings;
|
||||
this.usersettings=null;
|
||||
this.initialized=true;
|
||||
this.ready=ready;
|
||||
this.guilds=[];
|
||||
|
@ -34,8 +34,9 @@ class localuser{
|
|||
this.guildids[thing.guild_id].notisetting(thing);
|
||||
}
|
||||
for(const thing of ready.d.merged_members){
|
||||
const temp=new member(thing[0]);
|
||||
this.guildids[temp.guild_id].giveMember(temp);
|
||||
const guild=this.guildids[thing[0].guild_id]
|
||||
const temp=new member(thing[0],guild);
|
||||
guild.giveMember(temp);
|
||||
}
|
||||
for(const thing of ready.d.read_state.entries){
|
||||
const guild=this.resolveGuildidFromChannelID(thing.id)
|
||||
|
|
|
@ -1,9 +1,45 @@
|
|||
class member{
|
||||
constructor(memberjson){
|
||||
for(const thing of Object.keys(memberjson)){
|
||||
this[thing]=memberjson[thing];
|
||||
static already={};
|
||||
constructor(memberjson,owner){
|
||||
if(!owner){console.error("Guild not included in the creation of a member object")}
|
||||
this.owner=owner;
|
||||
let membery=memberjson;
|
||||
if(memberjson.guild_member){
|
||||
membery=memberjson.guild_member;
|
||||
this.user=memberjson.user;
|
||||
}
|
||||
for(const thing of Object.keys(membery)){
|
||||
if(thing==="guild"){continue}
|
||||
this[thing]=membery[thing];
|
||||
}
|
||||
this.user=new user(this.user);
|
||||
console.log(this)
|
||||
}
|
||||
get guild(){
|
||||
return this.owner;
|
||||
}
|
||||
get localuser(){
|
||||
return this.guild.localuser;
|
||||
}
|
||||
static async resolve(user,guild){
|
||||
if(!member.already[guild.id]){
|
||||
member.already[guild.id]={};
|
||||
}else if(member.already[guild.id][user.id]){
|
||||
const memb=member.already[guild.id][user.id]
|
||||
if(memb instanceof Promise){
|
||||
return await memb;
|
||||
}
|
||||
return memb;
|
||||
}
|
||||
const promoise= fetch(info.api.toString()+"/v9/users/"+user.id+"/profile?with_mutual_guilds=true&with_mutual_friends_count=true&guild_id="+guild.id,{headers:guild.headers}).then(_=>_.json()).then(json=>{
|
||||
const memb=new member(json,guild);
|
||||
member.already[guild.id][user.id]=memb;
|
||||
guild.fillMember(memb);
|
||||
console.log("resolved")
|
||||
return memb
|
||||
});
|
||||
member.already[guild.id][user.id]=promoise;
|
||||
return await promoise;
|
||||
}
|
||||
hasRole(ID){
|
||||
for(const thing of this.roles){
|
||||
|
@ -14,6 +50,17 @@ class member{
|
|||
}
|
||||
return false;
|
||||
}
|
||||
getColor(){
|
||||
console.log(this);
|
||||
for(const thing of this.roles){
|
||||
const color=thing.getColor();
|
||||
console.log(thing);
|
||||
if(color){
|
||||
return color;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
isAdmin(){
|
||||
console.log(this);
|
||||
return this.guild.properties.owner_id===this.user.id;
|
||||
|
|
|
@ -108,7 +108,14 @@ class cmessage{
|
|||
const username=document.createElement("span");
|
||||
replyline.appendChild(username);
|
||||
const reply=document.createElement("div");
|
||||
username.classList.add("username")
|
||||
username.classList.add("username");
|
||||
|
||||
member.resolve(this.author,this.guild).then(_=>{
|
||||
console.log(_);
|
||||
console.log(_.getColor());
|
||||
username.style.color=_.getColor();
|
||||
});
|
||||
|
||||
reply.classList.add("replytext");
|
||||
replyline.appendChild(reply);
|
||||
const line2=document.createElement("hr");
|
||||
|
@ -165,6 +172,11 @@ class cmessage{
|
|||
const username=document.createElement("span");
|
||||
username.classList.add("username")
|
||||
profileclick(username,this.author);
|
||||
member.resolve(this.author,this.guild).then(_=>{
|
||||
console.log(_);
|
||||
console.log(_.getColor());
|
||||
username.style.color=_.getColor();
|
||||
})
|
||||
username.textContent=this.author.username;
|
||||
const userwrap=document.createElement("tr")
|
||||
userwrap.appendChild(username)
|
||||
|
|
234
webpage/permissions.js
Normal file
234
webpage/permissions.js
Normal file
|
@ -0,0 +1,234 @@
|
|||
class permissions{
|
||||
constructor(b){
|
||||
this.permissions=BigInt(b);
|
||||
}
|
||||
getPermisionbit(b){
|
||||
return Boolean((this.permissions>>BigInt(b))&1n);
|
||||
}
|
||||
setPermisionbit(b,state){
|
||||
const bit=1n<<BigInt(b);
|
||||
this.permissions=(this.permissions & ~bit) | (BigInt(state) << BigInt(b));//thanks to geotale for this code :3
|
||||
}
|
||||
static map
|
||||
static info
|
||||
static makeMap(){
|
||||
permissions.info=[//for people in the future, do not reorder these, the creation of the map realize on the order
|
||||
{
|
||||
name:"CREATE_INSTANT_INVITE",
|
||||
readableName:"Create instance invite",
|
||||
description:"Allows the user to create invites for the guild"
|
||||
},
|
||||
{
|
||||
name:"KICK_MEMBERS",
|
||||
readableName:"Kick members",
|
||||
description:"Allows the user to kick members from the guild"
|
||||
},
|
||||
{
|
||||
name:"BAN_MEMBERS",
|
||||
readableName:"Ban members",
|
||||
description:"Allows the user to ban members from the guild"
|
||||
},
|
||||
{
|
||||
name:"ADMINISTRATOR",
|
||||
readableName:"Administrator",
|
||||
description:"Allows all permissions and bypasses channel permission overwrites"
|
||||
},
|
||||
{
|
||||
name:"MANAGE_CHANNELS",
|
||||
readableName:"Manage channels",
|
||||
description:"Allows the user to manage and edit channels"
|
||||
},
|
||||
{
|
||||
name:"MANAGE_GUILD",
|
||||
readableName:"Manage guild",
|
||||
description:"Allows management and editing of the guild"
|
||||
},
|
||||
{
|
||||
name:"ADD_REACTIONS",
|
||||
readableName:"Add reactions",
|
||||
description:"Allows user to add reactions to messages"
|
||||
},
|
||||
{
|
||||
name:"VIEW_AUDIT_LOG",
|
||||
readableName:"View audit log",
|
||||
description:"Allows the user to view the audit log"
|
||||
},
|
||||
{
|
||||
name:"PRIORITY_SPEAKER",
|
||||
readableName:"Priority speaker",
|
||||
description:"Allows for using priority speaker in a voice channel"
|
||||
},
|
||||
{
|
||||
name:"STREAM",
|
||||
readableName:"Stream",
|
||||
description:"Allows the user to stream"
|
||||
},
|
||||
{
|
||||
name:"VIEW_CHANNEL",
|
||||
readableName:"View channel",
|
||||
description:"Allows the user to view the channel"
|
||||
},
|
||||
{
|
||||
name:"SEND_MESSAGES",
|
||||
readableName:"Send Messages",
|
||||
description:"Allows user to send messages"
|
||||
},
|
||||
{
|
||||
name:"SEND_TTS_MESSAGES",
|
||||
readableName:"Send text-to-speech messages",
|
||||
description:"Allows the user to send text-to-speech messages"
|
||||
},
|
||||
{
|
||||
name:"MANAGE_MESSAGES",
|
||||
readableName:"Manager messages",
|
||||
description:"Allows the user to delete messages that aren't their own"
|
||||
},
|
||||
{
|
||||
name:"EMBED_LINKS",
|
||||
readableName:"Embed links",
|
||||
description:"Allow links sent by this user to auto-embed"
|
||||
},
|
||||
{
|
||||
name:"ATTACH_FILES",
|
||||
readableName:"Attach files",
|
||||
description:"Allows the user to attach files"
|
||||
},
|
||||
{
|
||||
name:"READ_MESSAGE_HISTORY",
|
||||
readableName:"Read message history",
|
||||
description:"Allows user to read the message history"
|
||||
},
|
||||
{
|
||||
name:"MENTION_EVERYONE",
|
||||
readableName:"Mention everyone",
|
||||
description:"Allows the user to mention everyone"
|
||||
},
|
||||
{
|
||||
name:"USE_EXTERNAL_EMOJIS",
|
||||
readableName:"Use external emojis",
|
||||
description:"Allows the user to use external emojis"
|
||||
},
|
||||
{
|
||||
name:"VIEW_GUILD_INSIGHTS",
|
||||
readableName:"View guild insights",
|
||||
description:"Allows the user to see guild insights"
|
||||
},
|
||||
{
|
||||
name:"CONNECT",
|
||||
readableName:"Connect",
|
||||
description:"Allows the user to connect to a voice channel"
|
||||
},
|
||||
{
|
||||
name:"SPEAK",
|
||||
readableName:"Speak",
|
||||
description:"Allows the user to speak in a voice channel"
|
||||
},
|
||||
{
|
||||
name:"MUTE_MEMBERS",
|
||||
readableName:"Mute members",
|
||||
description:"Allows user to mute other members"
|
||||
},
|
||||
{
|
||||
name:"DEAFEN_MEMBERS",
|
||||
readableName:"Deafen members",
|
||||
description:"Allows user to deafen other members"
|
||||
},
|
||||
{
|
||||
name:"MOVE_MEMBERS",
|
||||
readableName:"Move members",
|
||||
description:"Allows the user to move members between voice channels"
|
||||
},
|
||||
{
|
||||
name:"USE_VAD",
|
||||
readableName:"use voice-activity-detection",
|
||||
description:"Allows user to use voice-activity-detection"
|
||||
},
|
||||
{
|
||||
name:"CHANGE_NICKNAME",
|
||||
readableName:"Change nickname",
|
||||
description:"Allows the user to change their own nickname"
|
||||
},
|
||||
{
|
||||
name:"MANAGE_NICKNAMES",
|
||||
readableName:"Manage nicknames",
|
||||
description:"Allows user to change nicknames of other members"
|
||||
},
|
||||
{
|
||||
name:"MANAGE_ROLES",
|
||||
readableName:"Manage roles",
|
||||
description:"Allows user to edit and manage roles"
|
||||
},
|
||||
{
|
||||
name:"MANAGE_WEBHOOKS",
|
||||
readableName:"Manage webhooks",
|
||||
description:"Allows management and editing of webhooks"
|
||||
},
|
||||
{
|
||||
name:"MANAGE_GUILD_EXPRESSIONS",
|
||||
readableName:"Manage guild expressions",
|
||||
description:"Allows for managing emoji, stickers, and soundboards"
|
||||
},
|
||||
{
|
||||
name:"USE_APPLICATION_COMMANDS",
|
||||
readableName:"Use application commands",
|
||||
description:"Allows the user to use application commands"
|
||||
},
|
||||
{
|
||||
name:"REQUEST_TO_SPEAK",
|
||||
readableName:"Request to speak",
|
||||
description:"Allows user to request to speak in stage channel"
|
||||
},
|
||||
{
|
||||
name:"MANAGE_EVENTS",
|
||||
readableName:"Manage events",
|
||||
description:"Allows user to edit and manage events"
|
||||
},
|
||||
{
|
||||
name:"MANAGE_THREADS",
|
||||
readableName:"Manage threads",
|
||||
description:"Allows the user to delete and archive threads and view all private threads"
|
||||
},
|
||||
{
|
||||
name:"CREATE_PUBLIC_THREADS",
|
||||
readableName:"Create public threads",
|
||||
description:"Allows the user to create public threads"
|
||||
},
|
||||
{
|
||||
name:"CREATE_PRIVATE_THREADS",
|
||||
readableName:"Create private threads",
|
||||
description:"Allows the user to create private threads"
|
||||
},
|
||||
{
|
||||
name:"USE_EXTERNAL_STICKERS",
|
||||
readableName:"Use external stickers",
|
||||
description:"Allows user to use external stickers"
|
||||
},
|
||||
{
|
||||
name:"SEND_MESSAGES_IN_THREADS",
|
||||
readableName:"Send messages in threads",
|
||||
description:"Allows the user to send messages in threads"
|
||||
},
|
||||
{
|
||||
name:"USE_EMBEDDED_ACTIVITIES",
|
||||
readableName:"Use embedded activities",
|
||||
description:"Allows the user to use embedded activities"
|
||||
},
|
||||
{
|
||||
name:"MODERATE_MEMBERS",
|
||||
readableName:"Moderate members",
|
||||
description:"Allows the user to time out other users to prevent them from sending or reacting to messages in chat and threads, and from speaking in voice and stage channels"
|
||||
},
|
||||
];
|
||||
permissions.map={};
|
||||
let i=0;
|
||||
for(const thing of permissions.info){
|
||||
permissions.map[i]=thing;
|
||||
permissions.map[thing.name]=i;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
getPermision(name){
|
||||
return this.getPermisionbit(permissions.map[name]);
|
||||
}
|
||||
}
|
||||
permissions.makeMap();
|
|
@ -3,5 +3,19 @@ class role{
|
|||
for(const thing of Object.keys(JSON)){
|
||||
this[thing]=JSON[thing];
|
||||
}
|
||||
this.permissions=new permissions(JSON.permissions);
|
||||
this.owner=owner;
|
||||
console.log(this);
|
||||
}
|
||||
get guild(){
|
||||
return this.owner;
|
||||
}
|
||||
get localuser(){
|
||||
return this.guild.localuser;
|
||||
}
|
||||
getColor(){
|
||||
if(this.color===0){return null};
|
||||
return `#${this.color.toString(16)}`;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const usercache={};
|
||||
//const usercache={};
|
||||
class user{
|
||||
static userids={};
|
||||
static checkuser(userjson){
|
||||
|
@ -16,23 +16,13 @@ class user{
|
|||
this[thing]=userjson[thing];
|
||||
}
|
||||
this.hypotheticalpfp=false;
|
||||
console.log(this);
|
||||
}else{
|
||||
return user.checkuser(userjson);
|
||||
}
|
||||
}
|
||||
async resolvemember(guild){
|
||||
let str;
|
||||
if(usercache[this.id+"+"+guild.id]){
|
||||
return usercache[this.id+"+"+guild.id];
|
||||
}else{
|
||||
const tempy=new Promise((resolve, reject) => {
|
||||
usercache[this.id+"+"+guild.id]={done:false};
|
||||
fetch(info.api.toString()+"/v9/users/"+this.id+"/profile?with_mutual_guilds=true&with_mutual_friends_count=false&guild_id="+guild.id).then(json).then(str=>{
|
||||
return new member(str);
|
||||
});
|
||||
});
|
||||
usercache[this.id+"+"+guild.id]=tempy;
|
||||
}
|
||||
await member.resolve(this,guild);
|
||||
}
|
||||
buildpfp(){
|
||||
const pfp=document.createElement('img');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue