Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const fs = require('fs');
- AnkiStudy = new Map();
- module.exports.run = (Brie, message, args) => {
- let cards;
- if (fs.existsSync(`c:/Brie/fs/${message.author.id}.txt`)) {
- cards = fs.readFileSync(`c:/Brie/fs/${message.author.id}.txt`, "utf8");
- } else {
- message.reply(`Você não tem conteúdo para estudar.`);
- }
- cardsSplited = cards.split("&1");
- userAnki = AnkiStudy.get(message.author.id);
- if (userAnki === undefined) {
- userCards = new Map();
- cardsSplited.forEach(card => {
- userCards.set(card, "Ainda não estudado");
- });
- AnkiStudy.set(message.author.id, userCards);
- message.channel.send(`Adicionado **${cardsSplited.length}** novos cards para o seu estudo!`);
- } else {
- cardsChecked = [];
- getCard();
- function getCard() {
- RNG = Math.floor(Math.random() * cardsSplited.length);
- console.log(cardsChecked)
- cardToStudy = userAnki.get(cardsSplited[RNG])
- if (cardsChecked.includes(cardToStudy)) getCard();
- if (cardToStudy !== "Ainda não estudado") {
- cardsChecked.push(cardsSplited[RNG]);
- getCard();
- } else if (cardsChecked.length === cardsSplited.length) {
- return message.reply(`Você já estudou todos os cards! Adicione mais e tente novamente.`);
- } else {
- const Discord = require("discord.js");
- theCard = cardsSplited[RNG].split("&0");
- Frente = theCard[0];
- Verso = theCard[1];
- const embedCard = new Discord.RichEmbed()
- .setTitle(`Card número: ${RNG}`)
- .setColor("RANDOM")
- .setDescription(`:zap: Frente: ${Frente}`)
- message.channel.send(embedCard).then(msg => {
- msg.react("▶");
- const emojiFilter = ["♥"];
- const filter = (reaction, user) => !emojiFilter.includes(reaction.emoji.name) && user.id === message.author.id;
- collector = msg.createReactionCollector(filter, { max: 1, time: 180000 });
- collector.on("collect", collected => {
- if (collected.emoji.name === "▶") {
- embedCard.setDescription(`:zap: Verso: ${Verso}\n\n✅ = Acertou\n❌ = Errou`);
- msg.edit(embedCard).then(async msgVerso => {
- await msgVerso.clearReactions();
- await msgVerso.react("✅");
- await msgVerso.react("❌");
- const emojiFilterVerso = ["♥"]
- const filterVerso = (reactionVerso, userVerso) => !emojiFilterVerso.includes(reactionVerso.emoji.name) && userVerso.id === message.author.id;
- collectorVerso = msgVerso.createReactionCollector(filterVerso, { max: 1, time: 180000 });
- collectorVerso.on("collect", collectedVerso => {
- switch (collectedVerso.emoji.name) {
- case "✅": respostaCorreta(cardsSplited[RNG]);
- break;
- case "❌": respostaErrada(cardsSplited[RNG]);
- break;
- default: message.reply(`O que está tentando fazer? :thinking:`);
- break;
- }
- });
- });
- function respostaCorreta(card) {
- console.log(userAnki.set(card, "Estudou"));
- console.log(`${card} => acertou`)
- }
- function respostaErrada(card) {
- console.log(userAnki.set(card, "Ainda não estudado"));
- console.log(`${card} => errou`)
- }
- } else {
- message.reply(`wut..?`);
- }
- });
- });
- };
- };
- };
- };
- module.exports.help = {
- name: "anki"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement