Skip to content

Commit

Permalink
add lyrics command
Browse files Browse the repository at this point in the history
  • Loading branch information
HugeBrain16 committed Dec 24, 2022
1 parent b335805 commit 569f9bf
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
52 changes: 49 additions & 3 deletions commands/music.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import hikari
import os

import cmdtools
import hikari
import lavasnek_rs
from cmdtools.callback.option import OptionModifier
from lyricsgenius import Genius

from lib import command
from lib import cache
from lib import cache, command

group = command.BaseGroup("Music")
PREFIX = "m+"
Expand Down Expand Up @@ -315,3 +317,47 @@ async def queue(self, ctx):
await self.clear_queue(ctx.attrs.client, ctx.attrs.message)
else:
await ctx.attrs.message.respond(f"Invalid action: `{action}`")


@group.command()
class Lyrics(command.BaseCommand):
__help__ = "Search for lyrics from Genius.com"

def __init__(self):
super().__init__(name="lyrics")

self.add_option("keywords", modifier=OptionModifier.ConsumeRest)

async def error_lyrics(self, ctx):
if isinstance(ctx.error, cmdtools.NotEnoughArgumentError):
if ctx.error.option == "keywords":
await ctx.attrs.message.respond(
"Please enter the keywords you want to use to search."
)
else:
raise ctx.error

async def lyrics(self, ctx):
if "GENIUS_API" in os.environ:
g = Genius(os.environ["GENIUS_API"])
g.verbose = False
g.remove_section_header = True

song = g.search_song(ctx.options.keywords)

if song:
embed = hikari.embeds.Embed()
embed.title = song.full_title
embed.description = song.lyrics
embed.set_thumbnail(song.song_art_image_url)
embed.set_footer(
text="Genius lyrics",
icon="https://images.genius.com/dacc8165080a6ba33911bdda2b99437d.114x114x1.png",
)
embed.color = 0xFFFF00

await ctx.attrs.message.respond(embed=embed)
else:
await ctx.attrs.message.respond("Unable to fetch lyrics.")
else:
await ctx.attrs.message.respond("this feature is unavailabe.")
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ lavasnek_rs = {version = "^0.1.0-alpha.3", allow-prereleases = true}
pymongo = "^4.1.1"
dnspython = "^2.2.1"
danbooru = "^0.0.7"
lyricsgenius = "^3.0.1"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ lavasnek_rs
pymongo
dnspython
danbooru
lyricsgenius

0 comments on commit 569f9bf

Please sign in to comment.