Skip to content

Commit 428ffe9

Browse files
committed
fix: roulette
- /roulette no establecia el cooldown correctamente en algunas ocasiones - los boosts dados por la Ruleta ya no verificarán si sobre-benefician al usuario
1 parent fe137cb commit 428ffe9

3 files changed

Lines changed: 13 additions & 19 deletions

File tree

src/commands/fun/roulette.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,12 @@ command.execute = async (interaction, models, params, client) => {
4747
await interaction.deleteReply()
4848
return await interaction.followUp({ flags: [MessageFlags.Ephemeral], content: "No me la vas a creer, pero no pude encontrar un item indicado para ti :(" })
4949
}
50-
50+
5151
const item = new RouletteItem(interaction, randomItem).build(user, doc);
5252

53-
await item.use()
53+
let afterUse = await item.use();
54+
55+
await afterUse.user.save();
5456

5557
if (notSelected.size > 0) {
5658
await interaction.followUp({
@@ -65,7 +67,7 @@ command.execute = async (interaction, models, params, client) => {
6567

6668
let start = new Date()
6769
let i = 0;
68-
if(query.length === 0) return -1;
70+
if (query.length === 0) return -1;
6971

7072
while (!returnable) {
7173
i++
@@ -78,11 +80,7 @@ command.execute = async (interaction, models, params, client) => {
7880

7981
//console.log(selected ? "🟢 Selected" : "🔴 Negative");
8082

81-
let benefit = false;
82-
83-
if (q.extra?.special === ItemObjetives.Boost) benefit = await WillBenefit(interaction.member, [q.extra.boostobj, BoostObjetives.All])
84-
85-
returnable = selected && !benefit ? q : null
83+
returnable = selected ? q : null
8684

8785
if (moment(date).diff(start, "second") >= 3) returnable = benefit ? -1 : q;
8886
}

src/utils/RouletteItem.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ class RouletteItem {
105105
}
106106

107107
async use() {
108-
let save = true;
109108
let response = null;
110109
//let value = this.#valueWork();
111110

@@ -114,8 +113,6 @@ class RouletteItem {
114113
console.log("🟢 Números:", this.numbers)
115114
console.log("🟢 No-Números:", this.nonumbers)
116115

117-
await this.user.addCount("roulette", 1, false);
118-
119116
switch (this.target.constructor) {
120117
case GuildMemberRoleManager:
121118
if (this.nonumbers === '-') this.target.remove(this.numbers)
@@ -135,9 +132,8 @@ class RouletteItem {
135132
} else if (this.nonumbers === '+') {
136133
if (temproles) {
137134
response = this.addedTemp;
138-
save = false
139135

140-
await LimitedTime(this.interaction.member, null, ms(this.item.extra.duration), {}, this.item.extra.boosttype, this.item.extra.boostobj, this.item.extra.boostvalue);
136+
this.user = await LimitedTime(this.interaction.member, null, ms(this.item.extra.duration), {}, this.item.extra.boosttype, this.item.extra.boostobj, this.item.extra.boostvalue, false, this.user);
141137
} else
142138
this.target.push(this.numbers)
143139
}
@@ -187,9 +183,8 @@ class RouletteItem {
187183
response = this.success;
188184
break;
189185
}
190-
186+
191187
if (!response) response = this.success;
192-
if (save) await this.user.save().catch(e => console.log(e));
193188

194189
await this.interaction.editReply({ embeds: [response] })
195190
return this;

src/utils/functions.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,12 +1038,13 @@ const PetWork = async function (guild) {
10381038
* @param {any} activation_info La del item de la tienda
10391039
* @param {Number} [specialType=false] The special type of this temporary role.
10401040
* @param {Number} [specialObjective=false] The objetive for this special type of temporary role.
1041-
* @param {number} [specialValue=false] The value for the objetive of this special temporary role.
1041+
* @param {number} [specialValue=false] The value for the objetive of this special temporary role.
1042+
* @param {boolean} [save=true] Whether save the user after adding the temporary role or not.
10421043
* @returns Mongoose User document
10431044
*/
1044-
const LimitedTime = async function (victimMember, roleID = 0, duration, activation_info, specialType = null, specialObjective = null, specialValue = null) {
1045+
const LimitedTime = async function (victimMember, roleID = 0, duration, activation_info, specialType = null, specialObjective = null, specialValue = null, save = true, userDoc = null) {
10451046
let role = victimMember.guild.roles.cache.find(x => x.id === roleID);
1046-
let user = await Users.getWork({ user_id: victimMember.id, guild_id: victimMember.guild.id });
1047+
let user = userDoc ?? await Users.getWork({ user_id: victimMember.id, guild_id: victimMember.guild.id });
10471048

10481049
let active_until = moment().add(duration === Infinity ? ms("999y") : duration, "ms").startOf("minute").toDate();
10491050

@@ -1066,7 +1067,7 @@ const LimitedTime = async function (victimMember, roleID = 0, duration, activati
10661067
}
10671068

10681069
user.data.temp_roles.push(toPush);
1069-
await user.save();
1070+
if (save) await user.save();
10701071

10711072
// timeout, por si pasa el tiempo antes de que el bot pueda reiniciarse
10721073
TimeoutIf(duration, async function () {

0 commit comments

Comments
 (0)