Banning/kicking members
This commit is contained in:
parent
dbee2f3628
commit
3ccb7e63e1
5 changed files with 175 additions and 3 deletions
|
@ -1,6 +1,7 @@
|
|||
import { User } from "./user.js";
|
||||
import { Role } from "./role.js";
|
||||
import { SnowFlake } from "./snowflake.js";
|
||||
import { Dialog } from "./dialog.js";
|
||||
class Member {
|
||||
static already = {};
|
||||
owner;
|
||||
|
@ -161,5 +162,61 @@ class Member {
|
|||
profileclick(html) {
|
||||
//to be implemented
|
||||
}
|
||||
get name() {
|
||||
return this.nick || this.user.username;
|
||||
}
|
||||
kick() {
|
||||
let reason = "";
|
||||
const menu = new Dialog(["vdiv",
|
||||
["title", "Kick " + this.name + " from " + this.guild.properties.name],
|
||||
["textbox", "Reason:", "", function (e) {
|
||||
reason = e.target.value;
|
||||
}],
|
||||
["button", "", "submit", () => {
|
||||
this.kickAPI(reason);
|
||||
menu.hide();
|
||||
}]]);
|
||||
menu.show();
|
||||
}
|
||||
kickAPI(reason) {
|
||||
const headers = structuredClone(this.guild.headers);
|
||||
headers["x-audit-log-reason"] = reason;
|
||||
fetch(`${this.info.api}/guilds/${this.guild.id}/members/${this.id}`, {
|
||||
method: "DELETE",
|
||||
headers,
|
||||
});
|
||||
}
|
||||
ban() {
|
||||
let reason = "";
|
||||
const menu = new Dialog(["vdiv",
|
||||
["title", "Ban " + this.name + " from " + this.guild.properties.name],
|
||||
["textbox", "Reason:", "", function (e) {
|
||||
reason = e.target.value;
|
||||
}],
|
||||
["button", "", "submit", () => {
|
||||
this.banAPI(reason);
|
||||
menu.hide();
|
||||
}]]);
|
||||
menu.show();
|
||||
}
|
||||
banAPI(reason) {
|
||||
const headers = structuredClone(this.guild.headers);
|
||||
headers["x-audit-log-reason"] = reason;
|
||||
fetch(`${this.info.api}/guilds/${this.guild.id}/bans/${this.id}`, {
|
||||
method: "PUT",
|
||||
headers
|
||||
});
|
||||
}
|
||||
hasPermission(name) {
|
||||
if (this.isAdmin()) {
|
||||
return true;
|
||||
}
|
||||
for (const thing of this.roles) {
|
||||
if (thing.permissions.getPermission(name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
export { Member };
|
||||
|
|
|
@ -96,6 +96,34 @@ class User {
|
|||
})
|
||||
});
|
||||
});
|
||||
this.contextmenu.addbutton("Kick member", function (member) {
|
||||
member.kick();
|
||||
}, null, function (member) {
|
||||
if (!member)
|
||||
return false;
|
||||
const us = member.guild.member;
|
||||
if (member.id === us.id) {
|
||||
return false;
|
||||
}
|
||||
if (member.id === member.guild.properties.owner_id) {
|
||||
return false;
|
||||
}
|
||||
return (us.hasPermission("KICK_MEMBERS")) || false;
|
||||
});
|
||||
this.contextmenu.addbutton("Ban member", function (member) {
|
||||
member.ban();
|
||||
}, null, function (member) {
|
||||
if (!member)
|
||||
return false;
|
||||
const us = member.guild.member;
|
||||
if (member.id === us.id) {
|
||||
return false;
|
||||
}
|
||||
if (member.id === member.guild.properties.owner_id) {
|
||||
return false;
|
||||
}
|
||||
return (us.hasPermission("BAN_MEMBERS")) || false;
|
||||
});
|
||||
}
|
||||
static clear() {
|
||||
this.userids = {};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue