akf-forum/classes/user.js
Akif Yüce eb197276db
V2.0.0
2022-03-13 16:06:25 +03:00

41 lines
No EOL
967 B
JavaScript

const db = require("quick.db")
module.exports = class User {
constructor(name = "guest", avatar = "/images/guest.png", time = new Date().getTime(), admin= false) {
this.name = name;
this.avatar = avatar;
this.time = time;
this.admin = admin;
}
getId(id = this.id) {
const user = db.get("users." + id);
if (!user) return null;
this.id = Number(id);
const { name = "guest", avatar = "/images/guest.png", time = new Date().getTime(), admin = false } = user;
this.name = name;
this.avatar = avatar;
this.time = time;
this.admin = admin;
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;
}
}