-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
NukeninDark
committed
Aug 4, 2021
1 parent
4a484cb
commit ed1f424
Showing
5 changed files
with
242 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
const Discord = require("discord.js"); | ||
const { perguntas } = require("./configs/perguntasQuiz.json"); | ||
const Sequelize = require("sequelize"); | ||
const { Users } = require("../../database/dbObjects.js"); | ||
|
||
module.exports = { | ||
name: "quiz", | ||
description: `Descubra se você é mais Lana ou Julia.`, | ||
execute(message, args) { | ||
message.reply("Vai começar o quiz de Laninha e Julinha!"); | ||
let perguntaAtual = 0, | ||
laninhaPontos = 0, | ||
julinhaPontos = 0; | ||
this.perguntaQuiz(message, perguntaAtual, laninhaPontos, julinhaPontos); | ||
}, | ||
|
||
async perguntaQuiz(message, perguntaAtual, laninhaPontos, julinhaPontos) { | ||
const quizEmbed = new Discord.MessageEmbed() | ||
.setColor("RANDOM") | ||
.setTitle("Quiz da Gêmeas") | ||
.setDescription("\u200B") | ||
.setThumbnail(perguntas[perguntaAtual].thumbnail) | ||
.setImage(perguntas[perguntaAtual].image) | ||
.setTimestamp() | ||
.setFooter( | ||
message.author.username, | ||
message.author.displayAvatarURL({ dynamic: true }) | ||
) | ||
.addFields( | ||
{ | ||
name: perguntas[perguntaAtual].pergunta, | ||
value: "\u200b", | ||
inline: false, | ||
}, | ||
//{ name: '\u200B', value: '\u200B', inline: false }, | ||
{ | ||
name: "🇦", | ||
value: `**${perguntas[perguntaAtual].A}**`, | ||
inline: true, | ||
}, | ||
{ name: "\u200B", value: "\u200B", inline: true }, | ||
{ | ||
name: "🇧", | ||
value: `**${perguntas[perguntaAtual].B}**`, | ||
inline: true, | ||
}, | ||
{ name: "\u200B", value: "\u200B", inline: false }, | ||
{ | ||
name: "🇨", | ||
value: `**${perguntas[perguntaAtual].C}**`, | ||
inline: true, | ||
}, | ||
{ name: "\u200B", value: "\u200B", inline: true }, | ||
{ | ||
name: "🇩", | ||
value: `**${perguntas[perguntaAtual].D}**`, | ||
inline: true, | ||
} | ||
); | ||
|
||
message.reply(quizEmbed).then( (sentMessage) => { | ||
const emojis = ["🇦", "🇧", "🇨", "🇩"]; | ||
emojis.forEach(async (emoji) => { | ||
await sentMessage.react(emoji); | ||
}); | ||
|
||
const filter = (reaction, user) => | ||
(reaction.emoji.name === emojis[0] || | ||
reaction.emoji.name === emojis[1] || | ||
reaction.emoji.name === emojis[2] || | ||
reaction.emoji.name === emojis[3]) && | ||
user.id === message.author.id; | ||
const collector = sentMessage.createReactionCollector(filter, { | ||
time: 60000, | ||
max: 1, | ||
}); | ||
collector.on("collect", async (r) => { | ||
if ( | ||
r.emoji.name === perguntas[perguntaAtual].Lana[0] || | ||
r.emoji.name === perguntas[perguntaAtual].Lana[1] | ||
) { | ||
message.reply(`Laninha ${r.emoji.name}`); | ||
laninhaPontos++; | ||
} else if ( | ||
r.emoji.name === perguntas[perguntaAtual].Julia[0] || | ||
r.emoji.name === perguntas[perguntaAtual].Julia[1] | ||
) { | ||
message.reply(`Julinha ${r.emoji.name}`); | ||
julinhaPontos++; | ||
} | ||
|
||
if (perguntaAtual < perguntas.length - 1) { | ||
this.perguntaQuiz( | ||
message, | ||
++perguntaAtual, | ||
laninhaPontos, | ||
julinhaPontos | ||
); | ||
} else { | ||
if (laninhaPontos > julinhaPontos) { | ||
laninhaPontos / perguntas.length < 0.6 | ||
? message.reply( | ||
`Laninha are the champion! Lana: ${laninhaPontos}, Julia: ${julinhaPontos}, Porcentagem: ${ | ||
laninhaPontos / perguntas.length | ||
}` | ||
) | ||
: message.reply( | ||
`Laninha foi por pouco! Lana: ${laninhaPontos}, Julia: ${julinhaPontos}, Porcentagem: ${ | ||
laninhaPontos / perguntas.length | ||
}` | ||
); | ||
const user = await Users.findOne({ | ||
where: { user_id: message.author.id }, | ||
}); | ||
await user.lanaWinner() | ||
} else { | ||
julinhaPontos / perguntas.length < 0.6 | ||
? message.reply( | ||
`Julinha are the champion! Lana: ${laninhaPontos}, Julia: ${julinhaPontos}, Porcentagem: ${ | ||
julinhaPontos / perguntas.length | ||
}` | ||
) | ||
: message.reply( | ||
`Julinha foi por pouco! Lana: ${laninhaPontos}, Julia: ${julinhaPontos}, Porcentagem: ${ | ||
julinhaPontos / perguntas.length | ||
}` | ||
); | ||
const user = await Users.findOne({ | ||
where: { user_id: message.author.id }, | ||
}); | ||
await user.increment('quizJulia'); | ||
} | ||
} | ||
}); | ||
}); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const Sequelize = require('sequelize'); | ||
|
||
const sequelizeGemeas = new Sequelize( | ||
"database", | ||
process.env.USERNAME, | ||
process.env.PASSWORD, | ||
{ | ||
host: "localhost", | ||
dialect: "sqlite", | ||
logging: false, | ||
// SQLite only | ||
storage: "./GemeasDB.sqlite", | ||
} | ||
); | ||
|
||
require('./models/Users')(sequelizeGemeas, Sequelize.DataTypes); | ||
|
||
const force = process.argv.includes('--force') || process.argv.includes('-f'); | ||
|
||
sequelizeGemeas.sync({ force }).then(async () => { | ||
console.log('Database synced'); | ||
sequelizeGemeas.close(); | ||
}).catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const Sequelize = require("sequelize"); | ||
|
||
const sequelizeGemeas = new Sequelize( | ||
"GemeasDB", | ||
process.env.USERNAME, | ||
process.env.PASSWORD, | ||
{ | ||
host: "localhost", | ||
dialect: "sqlite", | ||
logging: false, | ||
// SQLite only | ||
storage: "./database/GemeasDB.sqlite", | ||
} | ||
); | ||
|
||
const Users = require("./models/Users")(sequelizeGemeas, Sequelize.DataTypes); | ||
|
||
Users.prototype.addItem = async function(item) { | ||
const useritem = await UserItems.findOne({ | ||
where: { user_id: this.user_id, item_id: item.id }, | ||
}); | ||
|
||
if (useritem) { | ||
useritem.amount += 1; | ||
return useritem.save(); | ||
} | ||
|
||
return UserItems.create({ user_id: this.user_id, item_id: item.id, amount: 1 }); | ||
}; | ||
|
||
Users.prototype.addWinner = async function(winner){ | ||
const affectedRows = await Users.update({ quizUltimo: winner }, { where: { user_id: this.user_id } }); | ||
if (affectedRows > 0) { | ||
return message.reply(`Foi adicionado **${winner}** como vencerdor.`); | ||
} | ||
return message.reply(`Nao foi possivel adicionar **${winner}** como vencedora.`); | ||
} | ||
|
||
Users.prototype.lanaWinner = async function(){ | ||
const twinWinner = await Users.findOne( { where: { user_id: this.user_id } }); | ||
|
||
if (twinWinner) { | ||
return twinWinner.increment('quizLana'); | ||
} | ||
return message.reply('Não foi possivel adicionar o vencedor Lana no Database.') | ||
} | ||
|
||
Users.prototype.juliaWinner = async function(){ | ||
const twinWinner = await Users.findOne( { where: { user_id: this.user_id } }); | ||
|
||
if (twinWinner) { | ||
return twinWinner.increment('quizJulia'); | ||
} | ||
return message.reply('Não foi possivel adicionar o vencedor Julia no Database.') | ||
} | ||
|
||
module.exports = { Users }; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module.exports = (sequelize, DataTypes) => { | ||
return sequelize.define('users', { | ||
user_id: { | ||
type: DataTypes.STRING, | ||
primaryKey: true, | ||
}, | ||
quizLana: { | ||
type: DataTypes.INTEGER, | ||
defaultValue: 0, | ||
allowNull: false, | ||
}, | ||
quizJulia: { | ||
type: DataTypes.INTEGER, | ||
defaultValue: 0, | ||
allowNull: false | ||
}, | ||
quizUltimo: { | ||
type: DataTypes.STRING, | ||
defaultValue: "Sem Histórico", | ||
allowNull: false | ||
} | ||
}, { | ||
timestamps: false, | ||
}); | ||
}; |