music: implement now playing
This commit is contained in:
		
							parent
							
								
									b3342d9d36
								
							
						
					
					
						commit
						adc7b3de6d
					
				
					 1 changed files with 56 additions and 6 deletions
				
			
		| 
						 | 
					@ -247,7 +247,7 @@ async function enqueue(
 | 
				
			||||||
        embeds: [
 | 
					        embeds: [
 | 
				
			||||||
          {
 | 
					          {
 | 
				
			||||||
            title: `<:ms_tick:503341995348066313> Added to queue`,
 | 
					            title: `<:ms_tick:503341995348066313> Added to queue`,
 | 
				
			||||||
            color: 0x3fdcee,
 | 
					            color: 0x00cc00,
 | 
				
			||||||
            fields: [
 | 
					            fields: [
 | 
				
			||||||
              {
 | 
					              {
 | 
				
			||||||
                name: "Title",
 | 
					                name: "Title",
 | 
				
			||||||
| 
						 | 
					@ -290,7 +290,7 @@ async function enqueue(
 | 
				
			||||||
      embeds: [
 | 
					      embeds: [
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
          title: `:musical_note: Now Playing`,
 | 
					          title: `:musical_note: Now Playing`,
 | 
				
			||||||
          color: 0x18e3c8,
 | 
					          color: 0x0088cc,
 | 
				
			||||||
          fields: [
 | 
					          fields: [
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
              name: "Title",
 | 
					              name: "Title",
 | 
				
			||||||
| 
						 | 
					@ -325,7 +325,6 @@ async function enqueue(
 | 
				
			||||||
      thumbnail,
 | 
					      thumbnail,
 | 
				
			||||||
      length,
 | 
					      length,
 | 
				
			||||||
      start: Date.now(),
 | 
					      start: Date.now(),
 | 
				
			||||||
      end: Date.now() + length,
 | 
					 | 
				
			||||||
      stream,
 | 
					      stream,
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					@ -355,6 +354,8 @@ async function youtubeSearch(msg, str) {
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const NOWPLAYING_BAR_LENGTH = 30;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const command = new Command("music");
 | 
					const command = new Command("music");
 | 
				
			||||||
command.addAlias("m");
 | 
					command.addAlias("m");
 | 
				
			||||||
command.category = "misc";
 | 
					command.category = "misc";
 | 
				
			||||||
| 
						 | 
					@ -420,7 +421,7 @@ command.callback = async function (msg, line) {
 | 
				
			||||||
                  title:
 | 
					                  title:
 | 
				
			||||||
                    "<a:loading:493087964918972426> Processing playlist...",
 | 
					                    "<a:loading:493087964918972426> Processing playlist...",
 | 
				
			||||||
                  description: `${playlist.length} tracks`,
 | 
					                  description: `${playlist.length} tracks`,
 | 
				
			||||||
                  color: 0xff8037,
 | 
					                  color: 0xcc0088,
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
              ],
 | 
					              ],
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
| 
						 | 
					@ -449,7 +450,7 @@ command.callback = async function (msg, line) {
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                  title: "<:ms_tick:503341995348066313> Done processing",
 | 
					                  title: "<:ms_tick:503341995348066313> Done processing",
 | 
				
			||||||
                  description: `${playlist.length} tracks`,
 | 
					                  description: `${playlist.length} tracks`,
 | 
				
			||||||
                  color: 0xff8037,
 | 
					                  color: 0xcc0088,
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
              ],
 | 
					              ],
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
| 
						 | 
					@ -518,7 +519,56 @@ command.callback = async function (msg, line) {
 | 
				
			||||||
      } else {
 | 
					      } else {
 | 
				
			||||||
        return "You are not in a voice channel.";
 | 
					        return "You are not in a voice channel.";
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    case "np":
 | 
					    case "np": {
 | 
				
			||||||
 | 
					      if (!voiceStorage.has(msg.guildID))
 | 
				
			||||||
 | 
					        return "The bot is not in a voice channel.";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      const connection = voiceStorage.get(msg.guildID);
 | 
				
			||||||
 | 
					      const nowPlaying = connection._music_nowplaying;
 | 
				
			||||||
 | 
					      if (!nowPlaying || !connection.playing)
 | 
				
			||||||
 | 
					        return "Nothing is currently playing.";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      const position = Date.now() - nowPlaying.start;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      const timeEnd = formatTime(nowPlaying.length);
 | 
				
			||||||
 | 
					      const timePos = formatTime(position);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      const progress = position / length;
 | 
				
			||||||
 | 
					      const barLength = Math.round(progress * NOWPLAYING_BAR_LENGTH);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      const bar = `\`[${"=".repeat(barLength)}${" ".repeat(
 | 
				
			||||||
 | 
					        NOWPLAYING_BAR_LENGTH - barLength
 | 
				
			||||||
 | 
					      )}]\``;
 | 
				
			||||||
 | 
					      const time = `\`${timePos}${" ".repeat(
 | 
				
			||||||
 | 
					        NOWPLAYING_BAR_LENGTH + 2 - timePos.length - timeEnd.length
 | 
				
			||||||
 | 
					      )}${timeEnd}\``;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      return {
 | 
				
			||||||
 | 
					        embed: {
 | 
				
			||||||
 | 
					          title: ":musical_note: Now Playing",
 | 
				
			||||||
 | 
					          color: 0x0088cc,
 | 
				
			||||||
 | 
					          fields: [
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					              name: "Title",
 | 
				
			||||||
 | 
					              value: nowPlaying.title
 | 
				
			||||||
 | 
					                ? `[${nowPlaying.title}](${nowPlaying.url})`
 | 
				
			||||||
 | 
					                : nowPlaying.url,
 | 
				
			||||||
 | 
					              inline: true,
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					              name: "Added by",
 | 
				
			||||||
 | 
					              value: `<@${nowPlaying.addedBy}>`,
 | 
				
			||||||
 | 
					              inline: true,
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					              name: bar,
 | 
				
			||||||
 | 
					              value: time,
 | 
				
			||||||
 | 
					              inline: false,
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					          ],
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					      };
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    case "queue":
 | 
					    case "queue":
 | 
				
			||||||
    case "q":
 | 
					    case "q":
 | 
				
			||||||
    case "remove":
 | 
					    case "remove":
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue