Added Artist/Song library
This commit is contained in:
parent
7015fc1671
commit
68f821b933
5 changed files with 134 additions and 6 deletions
96
libs/ArtistSong.js
Normal file
96
libs/ArtistSong.js
Normal file
|
@ -0,0 +1,96 @@
|
|||
class ArtistSong {
|
||||
constructor (models) {
|
||||
this.models = models
|
||||
}
|
||||
|
||||
/**
|
||||
* Point d'entrée pour l'ajout suppression de favoris
|
||||
* @param {String} type
|
||||
* @param {Function} botSay
|
||||
* @param {String} from
|
||||
* @param {Object} currentSong
|
||||
* @param {Array} line
|
||||
*/
|
||||
action (type, botSay, from, currentSong, line) {
|
||||
let value = currentSong[type]
|
||||
|
||||
if (line.length > 3) {
|
||||
value = ''
|
||||
for (let i = 3; i < line.length; i += 1) {
|
||||
value += ' ' + line[i]
|
||||
}
|
||||
value = value.replace(' ', '')
|
||||
}
|
||||
|
||||
const item = {
|
||||
user: from,
|
||||
type: type,
|
||||
value: value
|
||||
}
|
||||
|
||||
switch (line[2]) {
|
||||
case 'add':
|
||||
this.add(botSay, from, item)
|
||||
break
|
||||
case 'del':
|
||||
this.delete(botSay, from, item)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fonction permettant d'ajouter un favoris
|
||||
* @param {Function} botSay
|
||||
* @param {String} from
|
||||
* @param {Object} item
|
||||
*/
|
||||
add (botSay, from, item) {
|
||||
this.models.Notifications
|
||||
.findOne(item)
|
||||
.then(notification => {
|
||||
if (!notification) {
|
||||
const newItem = new this.models.Notifications(item)
|
||||
newItem.save((err, res) => {
|
||||
if (err) {
|
||||
console.log('ERR:', err)
|
||||
} else {
|
||||
botSay(from, `${item.value} correctement ajouté dans vos favoris`)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
botSay(from, `${item.value} est déjà dans tes favoris, c'est moche de vieillir...`)
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
console.log('ERR:', err)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Fonction permettant de supprimer un favoris
|
||||
* @param {Function} botSay
|
||||
* @param {String} from
|
||||
* @param {Object} item
|
||||
*/
|
||||
delete (botSay, from, item) {
|
||||
this.models.Notifications
|
||||
.findOne(item)
|
||||
.then(notification => {
|
||||
if (notification) {
|
||||
notification.remove((err, res) => {
|
||||
if (err) {
|
||||
console.log('ERR:', err)
|
||||
} else {
|
||||
botSay(from, `${item.value} correctement retiré dans vos favoris`)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
botSay(from, `${item.value} n'est dpas dans tes favoris, c'est moche de vieillir...`)
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
console.log('ERR:', err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ArtistSong
|
|
@ -4,6 +4,10 @@ class Db {
|
|||
this.models = models
|
||||
}
|
||||
|
||||
/**
|
||||
* Fonction sauvegardant en historique le morceau en cours de lecture
|
||||
* @param {Object} value
|
||||
*/
|
||||
saveSong (value) {
|
||||
// Find if previous song was the same (on bot reload)
|
||||
this.models.Histories
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue