Skip to content

hikari-ongaku/ongaku-lavalyrics

Repository files navigation

Ongaku

A simple voice library for Hikari.

PyPI Ruff Pyright Ongaku

Ongaku LavaLyrics is an extension for Ongaku that allows you to fetch lyrics for songs!

Current Features

  • Fetching Currently Playing songs
  • Fetching Songs

Installation

To install ongaku-lavalyrics, run the following command:

pip install -U ongaku-lavalyrics

To check if ongaku-lavalyrics has successfully installed or not, run the following command:

python3 -m ongaku-lavalyrics
# On Windows you may need to run:
py -m ongaku-lavalyrics

Getting Started

import typing
import hikari
import ongaku
from ongaku.ext.lavalyrics import LavaLyricsExtension

# Create a GatewayBot (RESTBot's are not supported.)
bot = hikari.GatewayBot(token="...")

# Create the ongaku client
client = ongaku.Client(bot)

# Add the LavaLyrics extension
client.add_extension(LavaLyricsExtension, LavaLyricsExtension(client))

@bot.listen()
async def message_event(
    event: hikari.GuildMessageCreateEvent
) -> None:
    # Ignore anything that has no content, is not a human, or is not in a guild.
    if not event.content or not event.is_human or not event.guild_id:
        return

    # Ignore anything that is not the lyrics command.
    if not event.content.startswith("!lyrics"):
        return

    # Get the query from lyrics "command".
    query = event.content.strip("!lyrics ")

    # Search youtube for the song.
    result = await client.rest.load_track(query)

    # Make sure the result is not None.
    if result is None:
        await bot.rest.create_message(
            event.channel_id,
            "Could not find requested track.",
            reply=event.message,
        )
        return

    # Get the extension.
    ll = client.get_extension(LavaLyricsExtension)

    # Compare the track types.
    if isinstance(result, typing.Sequence):
        track = result[0]
    
    elif isinstance(result, ongaku.Playlist):
        await bot.rest.create_message(
            event.channel_id,
            "I cannot find lyrics for a playlist!",
            reply=event.message,
        )
        return
    
    else:
        track = result
    
    # Fetch the lyrics for the song.
    lyrics = await ll.fetch_lyrics(track)

    # Make sure the lyrics were not None.
    if lyrics is None:
        await bot.rest.create_message(
            event.channel_id,
            "Could not find lyrics for the requested track.",
            reply=event.message,
        )
        return

    # Turn lyrics into an embed.
    embed = hikari.Embed(
        title=f"Lyrics for {track.info.title}",
        description="\n".join([lyric.line for lyric in lyrics.lines])
    )

    # Send the lyrics as an embed.
    await bot.rest.create_message(
        event.channel_id,
        embed=embed,
        reply=event.message,
    )

Issues and support

For general usage help or questions, see the #ongaku channel in the hikari discord, if you have found a bug or have a feature request, feel free to open an issue.

Links

About

An Ongaku extension that adds support for LavaLyrics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages