2022-01-04 02:18:28 +05:00
|
|
|
const mongoose = require("mongoose"),
|
2024-06-15 17:46:43 +05:00
|
|
|
Canvas = require("@napi-rs/canvas");
|
2022-01-04 02:18:28 +05:00
|
|
|
|
|
|
|
const genToken = () => {
|
|
|
|
let token = "";
|
|
|
|
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwzy0123456789.-_";
|
2023-07-05 00:58:06 +05:00
|
|
|
for (let i = 0; i < 32; i++) token += characters.charAt(Math.floor(Math.random() * characters.length));
|
2022-12-15 21:02:38 +05:00
|
|
|
|
2022-01-04 02:18:28 +05:00
|
|
|
return token;
|
|
|
|
};
|
|
|
|
|
|
|
|
const userSchema = new mongoose.Schema({
|
2022-08-04 19:26:17 +05:00
|
|
|
id: { type: String },
|
2022-01-04 02:18:28 +05:00
|
|
|
|
2022-08-04 19:26:17 +05:00
|
|
|
rep: { type: Number, default: 0 },
|
|
|
|
bio: { type: String },
|
|
|
|
birthdate: { type: Number },
|
|
|
|
lover: { type: String },
|
2022-01-04 02:18:28 +05:00
|
|
|
|
2022-08-04 19:26:17 +05:00
|
|
|
registeredAt: { type: Number, default: Date.now() },
|
2022-01-04 02:18:28 +05:00
|
|
|
|
2023-07-05 00:58:06 +05:00
|
|
|
achievements: {
|
|
|
|
type: Object,
|
|
|
|
default: {
|
|
|
|
married: {
|
|
|
|
achieved: false,
|
|
|
|
progress: {
|
|
|
|
now: 0,
|
|
|
|
total: 1,
|
|
|
|
},
|
2022-12-15 21:02:38 +05:00
|
|
|
},
|
2023-07-05 00:58:06 +05:00
|
|
|
work: {
|
|
|
|
achieved: false,
|
|
|
|
progress: {
|
|
|
|
now: 0,
|
|
|
|
total: 10,
|
|
|
|
},
|
2022-12-15 21:02:38 +05:00
|
|
|
},
|
2023-07-05 00:58:06 +05:00
|
|
|
firstCommand: {
|
|
|
|
achieved: false,
|
|
|
|
progress: {
|
|
|
|
now: 0,
|
|
|
|
total: 1,
|
|
|
|
},
|
2022-12-15 21:02:38 +05:00
|
|
|
},
|
2023-07-05 00:58:06 +05:00
|
|
|
slots: {
|
|
|
|
achieved: false,
|
|
|
|
progress: {
|
|
|
|
now: 0,
|
|
|
|
total: 3,
|
|
|
|
},
|
2022-12-15 21:02:38 +05:00
|
|
|
},
|
2023-07-05 00:58:06 +05:00
|
|
|
tip: {
|
|
|
|
achieved: false,
|
|
|
|
progress: {
|
|
|
|
now: 0,
|
|
|
|
total: 1,
|
|
|
|
},
|
2022-12-15 21:02:38 +05:00
|
|
|
},
|
2023-07-05 00:58:06 +05:00
|
|
|
rep: {
|
|
|
|
achieved: false,
|
|
|
|
progress: {
|
|
|
|
now: 0,
|
|
|
|
total: 20,
|
|
|
|
},
|
2022-01-04 02:18:28 +05:00
|
|
|
},
|
2023-07-05 00:58:06 +05:00
|
|
|
invite: {
|
|
|
|
achieved: false,
|
|
|
|
progress: {
|
|
|
|
now: 0,
|
|
|
|
total: 1,
|
|
|
|
},
|
2022-12-15 21:02:38 +05:00
|
|
|
},
|
|
|
|
},
|
2023-07-05 00:58:06 +05:00
|
|
|
},
|
2022-01-04 02:18:28 +05:00
|
|
|
|
2023-07-05 00:58:06 +05:00
|
|
|
cooldowns: {
|
|
|
|
type: Object,
|
|
|
|
default: {
|
|
|
|
rep: 0,
|
|
|
|
},
|
|
|
|
},
|
2022-01-04 02:18:28 +05:00
|
|
|
|
2022-08-04 19:26:17 +05:00
|
|
|
afk: { type: String, default: null },
|
|
|
|
reminds: { type: Array, default: [] },
|
|
|
|
logged: { type: Boolean, default: false },
|
2022-12-15 21:02:38 +05:00
|
|
|
apiToken: { type: String, default: genToken() },
|
2022-01-04 02:18:28 +05:00
|
|
|
});
|
|
|
|
|
2023-07-05 00:58:06 +05:00
|
|
|
userSchema.method("getAchievements", async function () {
|
2022-01-04 02:18:28 +05:00
|
|
|
const canvas = Canvas.createCanvas(1800, 250),
|
|
|
|
ctx = canvas.getContext("2d");
|
2022-01-05 00:24:57 +05:00
|
|
|
|
2022-01-04 02:18:28 +05:00
|
|
|
const images = [
|
|
|
|
await Canvas.loadImage(`./assets/img/achievements/achievement${this.achievements.work.achieved ? "_colored" : ""}1.png`),
|
|
|
|
await Canvas.loadImage(`./assets/img/achievements/achievement${this.achievements.firstCommand.achieved ? "_colored" : ""}2.png`),
|
|
|
|
await Canvas.loadImage(`./assets/img/achievements/achievement${this.achievements.married.achieved ? "_colored" : ""}3.png`),
|
|
|
|
await Canvas.loadImage(`./assets/img/achievements/achievement${this.achievements.slots.achieved ? "_colored" : ""}4.png`),
|
|
|
|
await Canvas.loadImage(`./assets/img/achievements/achievement${this.achievements.tip.achieved ? "_colored" : ""}5.png`),
|
|
|
|
await Canvas.loadImage(`./assets/img/achievements/achievement${this.achievements.rep.achieved ? "_colored" : ""}6.png`),
|
2022-12-15 21:02:38 +05:00
|
|
|
await Canvas.loadImage(`./assets/img/achievements/achievement${this.achievements.invite.achieved ? "_colored" : ""}7.png`),
|
2022-01-04 02:18:28 +05:00
|
|
|
];
|
|
|
|
let dim = 0;
|
2022-01-04 21:16:52 +05:00
|
|
|
|
2022-01-04 02:18:28 +05:00
|
|
|
for (let i = 0; i < images.length; i++) {
|
2024-05-06 21:23:24 +05:00
|
|
|
ctx.drawImage(images[i], dim, 10, 350, 200);
|
2022-01-04 02:18:28 +05:00
|
|
|
dim += 200;
|
2022-01-13 00:26:23 +05:00
|
|
|
}
|
2022-01-04 21:16:52 +05:00
|
|
|
|
2024-06-15 17:46:43 +05:00
|
|
|
return (await canvas.encode("png"));
|
2022-01-04 02:18:28 +05:00
|
|
|
});
|
|
|
|
|
2023-07-05 00:58:06 +05:00
|
|
|
module.exports = mongoose.model("User", userSchema);
|