Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

acumula a loteria se ninguém ganhar #33

Merged
merged 1 commit into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 19 additions & 30 deletions src/commands/lottery.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
const {
readFile,
changeDB,
msToTime,
format,
} = require("../utils/functions.js")
const { readFile, changeDB, msToTime, format } = require("../utils/functions.js")
const { SlashCommandBuilder, EmbedBuilder } = require("discord.js")

module.exports = {
Expand Down Expand Up @@ -31,10 +26,7 @@ module.exports = {
.setName("amount")
.setNameLocalization("pt-BR", "quantidade")
.setDescription("amount of lottery tickets to buy")
.setDescriptionLocalization(
"pt-BR",
"quantidade de bilhetes para comprar"
)
.setDescriptionLocalization("pt-BR", "quantidade de bilhetes para comprar")
.setMinValue(1)
.setRequired(true)
)
Expand All @@ -44,10 +36,7 @@ module.exports = {
.setName("history")
.setNameLocalization("pt-BR", "histórico")
.setDescription("See the last 10 winners of the lottery")
.setDescriptionLocalization(
"pt-BR",
"Veja os 10 últimos gahnadores da loteria"
)
.setDescriptionLocalization("pt-BR", "Veja os 10 últimos gahnadores da loteria")
),
execute: async ({ guild, user, interaction, instance }) => {
try {
Expand All @@ -60,9 +49,7 @@ module.exports = {
var embed = new EmbedBuilder()
.setColor(15844367)
.addFields({
name:
`:tickets: ${format(amount)} ` +
instance.getMessage(guild, "PURCHASED"),
name: `:tickets: ${format(amount)} ` + instance.getMessage(guild, "PURCHASED"),
value: instance.getMessage(guild, "LOTTERY_COST", {
COST: format(amount * 500),
}),
Expand Down Expand Up @@ -102,13 +89,9 @@ module.exports = {
.setFooter({ text: "by Falcão ❤️" })

if ((await readFile(user.id, "tickets")) > 0) {
embed.data.fields[0].value += instance.getMessage(
guild,
"LOTTERY_TICKETS",
{
TICKETS: await readFile(user.id, "tickets", true),
}
)
embed.data.fields[0].value += instance.getMessage(guild, "LOTTERY_TICKETS", {
TICKETS: await readFile(user.id, "tickets", true),
})
}

await interaction.editReply({
Expand All @@ -117,12 +100,18 @@ module.exports = {
} else {
history = ""
for (winner of lotto.history) {
history += instance.getMessage(guild, "HISTORY", {
FALCOINS: format(winner.prize),
USER: winner.winner,
TICKETS: winner.userTickets,
TOTAL: winner.totalTickets,
})
if (winner.winner != undefined) {
history += instance.getMessage(guild, "HISTORY", {
FALCOINS: format(winner.prize),
USER: winner.winner,
TICKETS: winner.userTickets,
TOTAL: winner.totalTickets,
})
} else {
history += instance.getMessage(guild, "HISTORY_NO_WINNER", {
FALCOINS: format(winner.prize),
})
}
}

var embed = new EmbedBuilder()
Expand Down
44 changes: 14 additions & 30 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
const { randint, changeDB, format } = require("./utils/functions.js")
const {
Client,
GatewayIntentBits,
Collection,
EmbedBuilder,
ActionRowBuilder,
ButtonBuilder,
} = require("discord.js")
const { Client, GatewayIntentBits, Collection, EmbedBuilder, ActionRowBuilder, ButtonBuilder } = require("discord.js")
const path = require("path")
require("dotenv").config()
const mongoose = require("mongoose")
Expand Down Expand Up @@ -147,10 +140,7 @@ class Falbot {
})

for (let user of users) {
if (
Date.now() - user.lastVote > 1000 * 60 * 60 * 12 &&
Date.now() - user.lastReminder > 1000 * 60 * 60 * 12
) {
if (Date.now() - user.lastVote > 1000 * 60 * 60 * 12 && Date.now() - user.lastReminder > 1000 * 60 * 60 * 12) {
var discordUser = await this.client.users.fetch(user._id)
const embed = new EmbedBuilder()
.setColor(16776960)
Expand Down Expand Up @@ -239,20 +229,22 @@ class Falbot {
embeds: [embed],
})

if (lotto.history.length >= 10) {
lotto.history.pop()
}

lotto.history.unshift({
prize: lotto.prize,
winner: winnerUser.username,
userTickets: winner.tickets,
totalTickets: numTickets,
})
lotto.prize = randint(3500000, 5000000)
} else {
lotto.history.unshift({
prize: lotto.prize,
})
lotto.prize = lotto.prize + randint(3500000, 5000000)
}
lotto.nextDraw = Date.now() + 604800000 //next one is next week
lotto.prize = randint(3500000, 5000000)

if (lotto.history.length >= 10) lotto.history.pop()
lotto.nextDraw = Date.now() + 604800000 //next one is next week
await lotto.save()
}
}
Expand All @@ -274,9 +266,7 @@ class Falbot {
defaultFilter(interaction) {
var disabledChannels = this._disabledChannels.get(interaction.guild.id)

return !interaction.user.bot &&
!this._banned.includes(interaction.user.id) &&
disabledChannels != undefined
return !interaction.user.bot && !this._banned.includes(interaction.user.id) && disabledChannels != undefined
? !disabledChannels.includes(interaction.channel.id)
: true
}
Expand Down Expand Up @@ -311,9 +301,7 @@ class Falbot {
const language = this.getLanguage(guildUser)
const translations = this._messages[messageId]
if (!translations) {
console.error(
`Could not find the correct message to send for "${messageId}"`
)
console.error(`Could not find the correct message to send for "${messageId}"`)
return "Could not find the correct message to send. Please report this to the bot developer."
}

Expand Down Expand Up @@ -345,13 +333,9 @@ class Falbot {
}
}

perks += `${this.getMessage(guild, "VOTO")}: ${format(
rank.vote
)} Falcoins\n`
perks += `${this.getMessage(guild, "VOTO")}: ${format(rank.vote)} Falcoins\n`

perks += `${this.getMessage(guild, "TRABALHO")}: ${format(
rank.work[0]
)}-${format(rank.work[1])} Falcoins`
perks += `${this.getMessage(guild, "TRABALHO")}: ${format(rank.work[0])}-${format(rank.work[1])} Falcoins`

return perks
}
Expand Down
4 changes: 4 additions & 0 deletions src/utils/json/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,10 @@
"portugues": ":confetti_ball: Loteria de {FALCOINS} falcoins ganha por **{USER}**! ({TICKETS}/{TOTAL} bilhetes)\n",
"english": ":confetti_ball: {FALCOINS} falcoins lotto won by **{USER}**! ({TICKETS}/{TOTAL} bilhetes)\n"
},
"HISTORY_NO_WINNER": {
"portugues": ":moneybag: Ninguém ganhou e o prêmio de {FALCOINS} falcoins foi acumulado.\n",
"english": ":moneybag: No one won and the {FALCOINS} falcoins prize was accumulated.\n"
},
"EVENTS": {
"portugues": "Eventos",
"english": "Events"
Expand Down