Skip to content
This repository has been archived by the owner on Jun 27, 2024. It is now read-only.

Commit

Permalink
prepublish and 'song > 3' is always false
Browse files Browse the repository at this point in the history
Error condicional cambiando el '&&' por un '||'

Error ortográfico 'lont' a 'lint'.
  • Loading branch information
DavichoStar committed Feb 24, 2021
1 parent 1949485 commit fed306f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 23 deletions.
4 changes: 1 addition & 3 deletions lib/Music.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ class Music {
}
isStreamValid(url) {
const pattern = /^((http|https):\/\/|www)[\w\d.-]+([a-z]{2,4})+(\/[\w\d.?%-=]+)?:\d+(\/\w*)?/gi;
if (!url || url == '')
return false;
return pattern.test(url);
}
connectBot(message) {
Expand Down Expand Up @@ -180,10 +178,10 @@ class Music {
throw `${error}`;
}
connection.on('error', (error) => {
new Error(`error interno inesperado: ${error.stack}`);
if (message && message.channel)
message.channel.send(this.notaMsg('fail', 'Algo salió mal con la conexión. Volviendo a intentar...'));
this.playSong(message, servidores);
throw `Error interno inesperado: ${error.stack}`;
});
dispatcher.on('error', (error) => {
new Error(`error interno inesperado: ${error.stack}`);
Expand Down
30 changes: 12 additions & 18 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ class StarMusic extends Music_1.default {
const cancion = {
id: video.id,
autorID: message.author.id,
position: servidores?.songs.length || 0,
position: servidores.songs.length || 0,
title: video.title,
url: video.url,
channelId: video.author.channelID,
duration: video.durationSec
};
servidores.songs.push(cancion);
if (servidores?.songs.length === 1)
if (servidores.songs.length === 1)
this.playSong(message, servidores);
index++;
});
Expand All @@ -86,7 +86,7 @@ class StarMusic extends Music_1.default {
const cancion = {
id: result.id,
autorID: message.author.id,
position: servidores?.songs.length || 0,
position: servidores.songs.length || 0,
title: result.title,
url: result.url,
channelId: result.channelId,
Expand Down Expand Up @@ -176,13 +176,13 @@ class StarMusic extends Music_1.default {
const cancion = {
id: videos[song_number].id,
autorID: message.author.id,
position: servidores?.songs.length || 0,
position: servidores.songs.length || 0,
title: videos[song_number].title,
url: videos[song_number].url,
channelId: videos[song_number].channelId
};
servidores?.songs.push(cancion);
if (servidores?.songs.length == 0 ||
servidores.songs.push(cancion);
if (servidores.songs.length == 0 ||
!message.client.voice?.connections.find((val) => val.channel.guild.id == message.guild.id))
this.playSong(message, servidores);
else
Expand Down Expand Up @@ -232,12 +232,12 @@ class StarMusic extends Music_1.default {
const cancion = {
id: videos[song_number].id,
autorID: message.author.id,
position: servidores?.songs.length || 0,
position: servidores.songs.length || 0,
title: videos[song_number].title,
url: videos[song_number].url,
channelId: videos[song_number].channelId
};
servidores?.songs.push(cancion);
servidores.songs.push(cancion);
if (servidores.songs.length == 0 ||
!message.client.voice?.connections.find((val) => val.channel.guild.id == message.guild.id))
this.playSong(message, servidores);
Expand All @@ -258,7 +258,7 @@ class StarMusic extends Music_1.default {
searchResult.results.forEach((result) => videos.push({
id: result.id,
autorID: message.author.id,
position: servidores?.songs.length || 0,
position: servidores.songs.length || 0,
title: result.title,
url: result.url,
channelId: result.channelId,
Expand Down Expand Up @@ -453,7 +453,7 @@ class StarMusic extends Music_1.default {
async repeat(message, song) {
if (!message.guild || !message.member)
return undefined;
if (song && song < 0 && song > 3)
if (song && (song < 0 || song > 3))
message.channel.send(this.notaMsg('fail', 'Solamente puedes colocar 0, 1, 2 o 3'));
let servidores = this._guilds.get(message.guild.id);
if (!servidores)
Expand Down Expand Up @@ -491,9 +491,7 @@ class StarMusic extends Music_1.default {
if (!message.guild || !message.member)
return undefined;
const servidores = this._guilds.get(message.guild.id);
if (song && isNaN(song))
message.channel.send(this.notaMsg('fail', 'Debes de pasar un dato del tipo número.'));
else if (!servidores)
if (!servidores)
message.channel.send(this.notaMsg('fail', 'No se pudo encontrar una cola para este servidor.'));
else if (servidores.songs.length <= 0)
message.channel.send(this.notaMsg('fail', 'La cola esta vacía.'));
Expand Down Expand Up @@ -570,8 +568,6 @@ class StarMusic extends Music_1.default {
if (!message.guild || !message.member)
return undefined;
const servidores = this._guilds.get(message.guild.id);
if (song && isNaN(song))
message.channel.send(this.notaMsg('fail', 'Debes de pasar un dato del tipo número.'));
if (!servidores)
message.channel.send(this.notaMsg('fail', 'No se ha encontrado ninguna cola para este servidor.'));
else if (servidores.isRadio)
Expand All @@ -597,8 +593,6 @@ class StarMusic extends Music_1.default {
if (!message.guild || !message.member)
return undefined;
const voiceConnection = message.client.voice?.connections.find((val) => (message.guild ? val.channel.guild.id == message.guild.id : false));
if (volume && isNaN(volume))
message.channel.send(this.notaMsg('fail', 'Debes de pasar un dato del tipo número.'));
if (!voiceConnection)
message.channel.send(this.notaMsg('fail', 'No se reproduce música.'));
else if (this._guilds.get(message.guild.id)?.isRadio)
Expand All @@ -607,7 +601,7 @@ class StarMusic extends Music_1.default {
message.channel.send(this.notaMsg('fail', 'Sólo los administradores o quien puso la canción actual pueden cambiar el volumen.'));
else {
const dispatcher = voiceConnection.dispatcher;
if (!volume || isNaN(volume))
if (!volume)
message.channel.send(this.notaMsg('fail', 'Sin volumen especificado.'));
else if (volume > 200 || volume <= 0)
message.channel.send(this.notaMsg('fail', 'Volumen fuera de rango, debe estar dentro de 1 a 200'));
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"lint:fix": "npx eslint --ext .ts ./src --fix",
"deploy:docs": "gh-pages -d docs",
"build": "tsc -b",
"prepublish": "npm run lont:fix && npm run build"
"prepublish": "npm run lint:fix && npm run build"
},
"author": "DavichoStar",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ export default class StarMusic extends Music {
async repeat(message: Message, song?: 0 | 1 | 2 | 3): Promise<void> {
if (!message.guild || !message.member) return undefined;

if (song && song < 0 && song > 3) message.channel.send(this.notaMsg('fail', 'Solamente puedes colocar 0, 1, 2 o 3'));
if (song && (song < 0 || song > 3)) message.channel.send(this.notaMsg('fail', 'Solamente puedes colocar 0, 1, 2 o 3'));

let servidores = this._guilds.get(message.guild.id);
if (!servidores) message.channel.send(this.notaMsg('fail', 'No se ha encontrado ninguna cola para este servidor'));
Expand Down

0 comments on commit fed306f

Please sign in to comment.