2022-03-13 16:16:46 +03:00
|
|
|
const db = require("quick.db")
|
|
|
|
|
|
|
|
module.exports = class User {
|
|
|
|
|
|
|
|
|
2022-03-13 17:12:09 +03:00
|
|
|
constructor(name = "guest", avatar = "/images/guest.png", time = new Date().getTime(), admin = false, deleted = false) {
|
2022-03-13 16:16:46 +03:00
|
|
|
|
|
|
|
this.name = name;
|
|
|
|
this.avatar = avatar;
|
|
|
|
this.time = time;
|
|
|
|
this.admin = admin;
|
2022-03-13 17:12:09 +03:00
|
|
|
this.deleted = deleted;
|
|
|
|
|
2022-03-13 16:16:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
getId(id = this.id) {
|
2022-03-13 17:12:09 +03:00
|
|
|
const user = db.get("users").find(u => u.id == id);
|
2022-03-13 16:16:46 +03:00
|
|
|
if (!user) return null;
|
|
|
|
this.id = Number(id);
|
2022-03-13 17:12:09 +03:00
|
|
|
const { name = "guest", avatar = "/images/guest.png", time = new Date().getTime(), admin = false, deleted = false } = user;
|
2022-03-13 16:16:46 +03:00
|
|
|
this.name = name;
|
|
|
|
this.avatar = avatar;
|
2022-03-13 17:12:09 +03:00
|
|
|
this.time = time;
|
2022-03-13 16:16:46 +03:00
|
|
|
this.admin = admin;
|
2022-03-13 17:12:09 +03:00
|
|
|
this.deleted = deleted;
|
|
|
|
return this ;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
getName(name1 = this.name) {
|
|
|
|
|
|
|
|
const user = db.get("users").find(u => u.name == name1);
|
|
|
|
if (!user) return null;
|
|
|
|
this.id = Number(user.id);
|
|
|
|
const { name = "guest", avatar = "/images/guest.png", time = new Date().getTime(), admin = false, deleted = false } = user;
|
|
|
|
this.name = name;
|
|
|
|
this.avatar = avatar;
|
|
|
|
this.time = time;
|
|
|
|
this.admin = admin;
|
|
|
|
this.deleted = deleted;
|
2022-04-03 21:01:55 +03:00
|
|
|
return this;
|
2022-03-13 17:12:09 +03:00
|
|
|
|
2022-03-13 16:16:46 +03:00
|
|
|
}
|
2022-03-13 17:12:09 +03:00
|
|
|
takeId() {
|
2022-03-13 16:16:46 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-02-26 21:26:27 +03:00
|
|
|
}
|