Compare commits

..

No commits in common. "1affded96764382fc056fbcd64a35d3ff06f6d0f" and "0d7a544bfd91c1f1cd195ac7eb4afa35a7cf1af5" have entirely different histories.

6 changed files with 16 additions and 35 deletions

View File

@ -1,21 +1,4 @@
/**
* @class
* @desc A class that describe an action, used each time an event matches a pattern described in the configuration file
* @property {Object} message The complete message. See discord.js documentation for mor informations
* @property {string} target
* @property {string} action
* @property {string[]} params The parameters for the action
*/
class GuildAction {
/**
* @constructor
* @desc Create a new GuildAction, setting its attributes to the given values
* @param {Object} parameters
* @param {Object} parameters.message
* @param {string} parameters.target
* @param {string} parameters.action
* @param {string[]} parameters.params
*/
constructor({ target, action, message, params }) {
this.target = target;
this.action = action;

View File

@ -12,6 +12,12 @@ const { GuildAction } = require('./guild_action')
* @property {callback} [on_expire] A function to call if the ttl is reached before being triggered
*/
/**
* @typedef {Object} ActionParams
* @property {Object} message The complete message. See discord.js documentation for more informations
* @property {string[]} params The parameters for the action
*/
/**
* @class
*/

View File

@ -15,7 +15,6 @@ function shuffle_array(arr) {
class Playlist {
#current_index
#tracks
#name
/**
* @constructor
@ -23,10 +22,9 @@ class Playlist {
* @param {Track[]} [parameters.tracks=[]] The tracks that compose the playlist
* @param {number} [parameters.current_index=0] The id of the currently played track
*/
constructor({ tracks = [], current_index = 0, name = null } = {}) {
constructor({ tracks = [], current_index = 0 } = {}) {
this.#current_index = current_index
this.#tracks = tracks.map(t => t instanceof Track ? t : new Track(t))
this.#name = name
}
/**
@ -36,8 +34,7 @@ class Playlist {
clone() {
return new Playlist({
current_index: this.#current_index,
tracks: this.#tracks.map(t => t.clone()),
name: this.#name
tracks: this.#tracks.map(t => t.clone())
})
}
@ -154,14 +151,6 @@ class Playlist {
toString() {
return this.#tracks.join(', ')
}
get_name() {
return this.#name
}
set_name(name = null) {
this.#name = name
}
}
module.exports = { Playlist }

View File

@ -13,7 +13,7 @@ class PlaylistsManager {
return (async () => {
const playlists = data || await PlaylistsManager.readFile(filepath)
Object.entries(playlists).forEach(([title, tracks]) => {
playlists[title] = new Playlist({ tracks, name: title })
playlists[title] = new Playlist({ tracks })
})
this.#playlists = playlists
this.#filepath = filepath
@ -37,9 +37,9 @@ class PlaylistsManager {
}
async register({ message, params }) {
const player = this.#gmanager.get_manager(message, 'player')
let playlist_title = params[0] || player.get_playlist().get_name()
const playlist_title = params[0]
if (playlist_title) {
const player = this.#gmanager.get_manager(message, 'player')
this.#playlists[playlist_title] = player.get_playlist().clone()
await PlaylistsManager.writeFile(this.#filepath, this.#playlists)
message.channel.send(`:white_check_mark: Playlist \`${playlist_title}\` saved`)

View File

@ -16,7 +16,7 @@ class ResourceManager {
/**
* Do a research and send the search results back to the Discord channel it's been asked for
* @param {GuildAction}
* @param {ActionParams}
* @return {Track[]} An array of objects representing the search results.
*/
async search({ message, params }) {

View File

@ -23,7 +23,10 @@ class Track {
*/
constructor({url, title, full_title, length, source, last_played = 0, play_count = 0} = {}) {
if (typeof length === 'string') {
this.#length = from_string_to_seconds(length)
this.#length = length
.split(':')
.map(v => parseInt(v))
.reduce((acc, v) => acc * 60 + v)
} else {
this.#length = length
}