akf-forum/classes/user.js

41 lines
967 B
JavaScript
Raw Normal View History

2022-02-26 21:26:27 +03:00
const db = require("quick.db")
module.exports = class User {
2022-03-13 16:06:25 +03:00
constructor(name = "guest", avatar = "/images/guest.png", time = new Date().getTime(), admin= false) {
2022-02-26 21:26:27 +03:00
this.name = name;
this.avatar = avatar;
this.time = time;
2022-03-13 16:06:25 +03:00
this.admin = admin;
2022-02-26 21:26:27 +03:00
}
getId(id = this.id) {
const user = db.get("users." + id);
if (!user) return null;
2022-03-13 16:06:25 +03:00
this.id = Number(id);
const { name = "guest", avatar = "/images/guest.png", time = new Date().getTime(), admin = false } = user;
2022-02-26 21:26:27 +03:00
this.name = name;
this.avatar = avatar;
2022-03-13 16:06:25 +03:00
this.time = time;
this.admin = admin;
2022-02-26 21:26:27 +03:00
return this
}
takeId() {
let id = db.get("users");
this.id = id ? id.length : 0;
return this
}
write(id = this.id) {
db.set("users." + id, this)
}
getLink(id = this.id) {
return "/users/" + id;
}
}