Compare commits
3 Commits
0d7a544bfd
...
1affded967
Author | SHA1 | Date |
---|---|---|
Thibaut Broggi | 1affded967 | |
Thibaut Broggi | 44a8fe413d | |
Thibaut Broggi | 8137afdc7a |
|
@ -1,4 +1,21 @@
|
||||||
|
/**
|
||||||
|
* @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 {
|
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 }) {
|
constructor({ target, action, message, params }) {
|
||||||
this.target = target;
|
this.target = target;
|
||||||
this.action = action;
|
this.action = action;
|
||||||
|
|
|
@ -12,12 +12,6 @@ const { GuildAction } = require('./guild_action')
|
||||||
* @property {callback} [on_expire] A function to call if the ttl is reached before being triggered
|
* @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
|
* @class
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -15,6 +15,7 @@ function shuffle_array(arr) {
|
||||||
class Playlist {
|
class Playlist {
|
||||||
#current_index
|
#current_index
|
||||||
#tracks
|
#tracks
|
||||||
|
#name
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
|
@ -22,9 +23,10 @@ class Playlist {
|
||||||
* @param {Track[]} [parameters.tracks=[]] The tracks that compose the playlist
|
* @param {Track[]} [parameters.tracks=[]] The tracks that compose the playlist
|
||||||
* @param {number} [parameters.current_index=0] The id of the currently played track
|
* @param {number} [parameters.current_index=0] The id of the currently played track
|
||||||
*/
|
*/
|
||||||
constructor({ tracks = [], current_index = 0 } = {}) {
|
constructor({ tracks = [], current_index = 0, name = null } = {}) {
|
||||||
this.#current_index = current_index
|
this.#current_index = current_index
|
||||||
this.#tracks = tracks.map(t => t instanceof Track ? t : new Track(t))
|
this.#tracks = tracks.map(t => t instanceof Track ? t : new Track(t))
|
||||||
|
this.#name = name
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,7 +36,8 @@ class Playlist {
|
||||||
clone() {
|
clone() {
|
||||||
return new Playlist({
|
return new Playlist({
|
||||||
current_index: this.#current_index,
|
current_index: this.#current_index,
|
||||||
tracks: this.#tracks.map(t => t.clone())
|
tracks: this.#tracks.map(t => t.clone()),
|
||||||
|
name: this.#name
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,6 +154,14 @@ class Playlist {
|
||||||
toString() {
|
toString() {
|
||||||
return this.#tracks.join(', ')
|
return this.#tracks.join(', ')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get_name() {
|
||||||
|
return this.#name
|
||||||
|
}
|
||||||
|
|
||||||
|
set_name(name = null) {
|
||||||
|
this.#name = name
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { Playlist }
|
module.exports = { Playlist }
|
||||||
|
|
|
@ -13,7 +13,7 @@ class PlaylistsManager {
|
||||||
return (async () => {
|
return (async () => {
|
||||||
const playlists = data || await PlaylistsManager.readFile(filepath)
|
const playlists = data || await PlaylistsManager.readFile(filepath)
|
||||||
Object.entries(playlists).forEach(([title, tracks]) => {
|
Object.entries(playlists).forEach(([title, tracks]) => {
|
||||||
playlists[title] = new Playlist({ tracks })
|
playlists[title] = new Playlist({ tracks, name: title })
|
||||||
})
|
})
|
||||||
this.#playlists = playlists
|
this.#playlists = playlists
|
||||||
this.#filepath = filepath
|
this.#filepath = filepath
|
||||||
|
@ -37,9 +37,9 @@ class PlaylistsManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
async register({ message, params }) {
|
async register({ message, params }) {
|
||||||
const playlist_title = params[0]
|
|
||||||
if (playlist_title) {
|
|
||||||
const player = this.#gmanager.get_manager(message, 'player')
|
const player = this.#gmanager.get_manager(message, 'player')
|
||||||
|
let playlist_title = params[0] || player.get_playlist().get_name()
|
||||||
|
if (playlist_title) {
|
||||||
this.#playlists[playlist_title] = player.get_playlist().clone()
|
this.#playlists[playlist_title] = player.get_playlist().clone()
|
||||||
await PlaylistsManager.writeFile(this.#filepath, this.#playlists)
|
await PlaylistsManager.writeFile(this.#filepath, this.#playlists)
|
||||||
message.channel.send(`:white_check_mark: Playlist \`${playlist_title}\` saved`)
|
message.channel.send(`:white_check_mark: Playlist \`${playlist_title}\` saved`)
|
||||||
|
|
|
@ -16,7 +16,7 @@ class ResourceManager {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Do a research and send the search results back to the Discord channel it's been asked for
|
* Do a research and send the search results back to the Discord channel it's been asked for
|
||||||
* @param {ActionParams}
|
* @param {GuildAction}
|
||||||
* @return {Track[]} An array of objects representing the search results.
|
* @return {Track[]} An array of objects representing the search results.
|
||||||
*/
|
*/
|
||||||
async search({ message, params }) {
|
async search({ message, params }) {
|
||||||
|
|
|
@ -23,10 +23,7 @@ class Track {
|
||||||
*/
|
*/
|
||||||
constructor({url, title, full_title, length, source, last_played = 0, play_count = 0} = {}) {
|
constructor({url, title, full_title, length, source, last_played = 0, play_count = 0} = {}) {
|
||||||
if (typeof length === 'string') {
|
if (typeof length === 'string') {
|
||||||
this.#length = length
|
this.#length = from_string_to_seconds(length)
|
||||||
.split(':')
|
|
||||||
.map(v => parseInt(v))
|
|
||||||
.reduce((acc, v) => acc * 60 + v)
|
|
||||||
} else {
|
} else {
|
||||||
this.#length = length
|
this.#length = length
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue