mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-25 06:42:51 +02:00
Lyrics Command
This commit is contained in:
@@ -91,7 +91,7 @@ Xiao is a Discord bot coded in JavaScript with
|
|||||||
|
|
||||||
## Commands
|
## Commands
|
||||||
|
|
||||||
Total: 354
|
Total: 355
|
||||||
|
|
||||||
### Utility:
|
### Utility:
|
||||||
|
|
||||||
@@ -243,6 +243,7 @@ Total: 354
|
|||||||
* **kickstarter:** Searches Kickstarter for your query.
|
* **kickstarter:** Searches Kickstarter for your query.
|
||||||
* **know-your-meme:** Searches Know Your Meme for your query.
|
* **know-your-meme:** Searches Know Your Meme for your query.
|
||||||
* **league-of-legends:** Responds with information on a League of Legends champion.
|
* **league-of-legends:** Responds with information on a League of Legends champion.
|
||||||
|
* **lyrics:** Responds with lyrics to a song.
|
||||||
* **manga:** Searches AniList for your query, getting manga results.
|
* **manga:** Searches AniList for your query, getting manga results.
|
||||||
* **map:** Responds with a map of a specific location.
|
* **map:** Responds with a map of a specific location.
|
||||||
* **mayo-clinic:** Searches Mayo Clinic for your query.
|
* **mayo-clinic:** Searches Mayo Clinic for your query.
|
||||||
@@ -546,6 +547,8 @@ here.
|
|||||||
* horoscope ([Horoscope Data](https://astrology.tv/horoscope/daily/))
|
* horoscope ([Horoscope Data](https://astrology.tv/horoscope/daily/))
|
||||||
- [Axis Order Bot](https://www.reddit.com/r/axisorderbot/wiki/index)
|
- [Axis Order Bot](https://www.reddit.com/r/axisorderbot/wiki/index)
|
||||||
* axis-cult (Prayer Data)
|
* axis-cult (Prayer Data)
|
||||||
|
- [AZLyrics](https://www.azlyrics.com/)
|
||||||
|
* lyrics (Lyrics Data)
|
||||||
- [Bob Ross](https://www.bobross.com/)
|
- [Bob Ross](https://www.bobross.com/)
|
||||||
* bob-ross (Himself)
|
* bob-ross (Himself)
|
||||||
- [Bowserinator](https://github.com/Bowserinator/)
|
- [Bowserinator](https://github.com/Bowserinator/)
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
const Command = require('../../structures/Command');
|
||||||
|
const request = require('node-superfetch');
|
||||||
|
const { shorten } = require('../../util/Util');
|
||||||
|
// eslint-disable-next-line max-len
|
||||||
|
const top = '<!-- Usage of azlyrics.com content by any third-party lyrics provider is prohibited by our licensing agreement. Sorry about that. -->';
|
||||||
|
const bottom = '<!-- MxM banner -->';
|
||||||
|
const lyricRegex = new RegExp(`${top}(.+)${bottom}`);
|
||||||
|
|
||||||
|
module.exports = class LyricsCommand extends Command {
|
||||||
|
constructor(client) {
|
||||||
|
super(client, {
|
||||||
|
name: 'lyrics',
|
||||||
|
aliases: ['az-lyrics'],
|
||||||
|
group: 'search',
|
||||||
|
memberName: 'lyrics',
|
||||||
|
description: 'Responds with lyrics to a song.',
|
||||||
|
credit: [
|
||||||
|
{
|
||||||
|
name: 'AZLyrics',
|
||||||
|
url: 'https://www.azlyrics.com/',
|
||||||
|
reason: 'Lyrics Data'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
key: 'artist',
|
||||||
|
prompt: 'What artist would you like to get the lyrics of?',
|
||||||
|
type: 'string',
|
||||||
|
parse: artist => artist.replace(/[^A-Za-z0-9]+/, '')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'song',
|
||||||
|
prompt: 'What song would you like to get the lyrics of?',
|
||||||
|
type: 'string',
|
||||||
|
parse: song => song.replace(/[^A-Za-z0-9]+/, '')
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async run(msg, { artist, song }) {
|
||||||
|
try {
|
||||||
|
const lyrics = await this.getLyrics(artist, song);
|
||||||
|
const url = `https://www.azlyrics.com/lyrics/${artist}/${song}.html`;
|
||||||
|
return msg.say(`${shorten(lyrics, 1750)}\n\n**Read the Rest:** ${url}`);
|
||||||
|
} catch (err) {
|
||||||
|
if (err.code === 404) return msg.say('Could not find any results.');
|
||||||
|
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async getLyrics(artist, song) {
|
||||||
|
const { text } = await request.get(`https://www.azlyrics.com/lyrics/${artist}/${song}.html`);
|
||||||
|
const lyrics = text.match(lyricRegex)[1];
|
||||||
|
return lyrics
|
||||||
|
.replace(/<br>/g, '\n')
|
||||||
|
.replace(/<\/?div>/g, '')
|
||||||
|
.trim();
|
||||||
|
}
|
||||||
|
};
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xiao",
|
"name": "xiao",
|
||||||
"version": "110.1.5",
|
"version": "110.2.0",
|
||||||
"description": "Your personal server companion.",
|
"description": "Your personal server companion.",
|
||||||
"main": "Xiao.js",
|
"main": "Xiao.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user