Added list and add commands
This commit is contained in:
44
index.js
44
index.js
@@ -3,6 +3,7 @@ const client = new Discord.Client();
|
|||||||
const config = require("./config/config.json");
|
const config = require("./config/config.json");
|
||||||
const Genius = require("./genius");
|
const Genius = require("./genius");
|
||||||
const levenshtein = require('js-levenshtein');
|
const levenshtein = require('js-levenshtein');
|
||||||
|
const fs = require("fs");
|
||||||
|
|
||||||
client.on('ready', () => {
|
client.on('ready', () => {
|
||||||
console.log(`Logged in as ${client.user.tag}!`);
|
console.log(`Logged in as ${client.user.tag}!`);
|
||||||
@@ -90,6 +91,49 @@ client.on('message', message => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (command === "add") {
|
||||||
|
Genius.search_song(args.join(" "), (err, song) => {
|
||||||
|
if (err) {
|
||||||
|
message.channel.send("Je connais pas \"" + args.join(" ") + "\".");
|
||||||
|
} else {
|
||||||
|
fs.readFile('data.json', (err, data) => {
|
||||||
|
if (err) throw err;
|
||||||
|
data = JSON.parse(data);
|
||||||
|
if (data[message.author.id] === undefined) {
|
||||||
|
data[message.author.id] = [];
|
||||||
|
}
|
||||||
|
data[message.author.id].push({
|
||||||
|
id: song.id,
|
||||||
|
title: song.title_with_featured,
|
||||||
|
artist: song.primary_artist.name
|
||||||
|
});
|
||||||
|
fs.writeFile('data.json', JSON.stringify(data, null, 4), (err) => {
|
||||||
|
if (err) throw err;
|
||||||
|
message.reply("J'ai ajouté \"" + song.title + "\" à votre liste");
|
||||||
|
});
|
||||||
|
})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (command === "list") {
|
||||||
|
fs.readFile('data.json', (err, data) => {
|
||||||
|
if (err) throw err;
|
||||||
|
data = JSON.parse(data);
|
||||||
|
const songs = data[message.author.id];
|
||||||
|
if (songs === undefined) {
|
||||||
|
message.reply("Vous n'avez pas encore ajouté de musiques");
|
||||||
|
} else {
|
||||||
|
let newMessage = "```\nListe de " + message.author.username + "\n";
|
||||||
|
songs.forEach(song => {
|
||||||
|
newMessage += song.artist + " - " + song.title + "\n";
|
||||||
|
});
|
||||||
|
newMessage += "```";
|
||||||
|
message.channel.send(newMessage);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
client.login(config["discord-token"]);
|
client.login(config["discord-token"]);
|
||||||
Reference in New Issue
Block a user