Skip to main content

A simple voice library, for hikari.

Project description

Ongaku

A simple voice library for Hikari.

PyPI Ruff Pyright Lavalink

Ongaku is a voice library that allows for playing tracks from a lavalink server, using the Hikari discord API.

Ongaku tries to make everything as simple as possible for new users, but still having full access to add custom plugins and change (or create) session handlers.

Current Features

  • Player control
    • Playlists
    • Queuing
      • Adding songs.
      • Shuffling the queue.
      • Skipping a song or multiple.
      • Deleting via position, or a track object.
      • Clearing the queue.
    • Seeking/Reversing the tracks position.
    • Volume control
    • Setting requestors (users who requested the song.)
  • Events
    • Ready Event (when a session is online.)
    • Player Update Event (when a player gets updated.)
    • Statistics Event (about the server.)
    • Track Start Event
    • Track End Event
    • Track Exception Event
    • Track Stuck Event
    • Empty Queue Event
    • Next Queue Event
  • Sessions
    • BasicSessionHandler (Gives next available session)
  • Others
    • Traces (for debugging code.)
    • Tests (Full test coverage.)

Future Features

  • More session handlers: so there is more methods to use the sessions you have provided.
  • Cache: a method to store information, and fetch it later, from events and rest actions.
  • Filters: support for filters, to change the audio you receive.
  • Changing channels: support for moving to different channels, without leaving and rejoining.
  • Session failures: More control, like seeing why a session failed and allow for reconnecting, or resetting attempts.

Installation

To install ongaku, run the following command:

pip install -U hikari-ongaku

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

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

Getting Started

for more about how to get started see the docs

import typing
import hikari
import ongaku

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

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

@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 play command.
   if not event.content.startswith("!play"):
      return

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

   # Make sure the user is in a valid voice channel.
   voice_state = bot.cache.get_voice_state(event.guild_id, event.author.id)
   if not voice_state or not voice_state.channel_id:
      await bot.rest.create_message(event.channel_id, "you are not in a voice channel.", reply=event.message)
      return

   # Fetch the track from the query string. (This searches just Youtube.)
   result = await client.rest.load_track(f"ytsearch:{query}")

   # If the song is `None` let them know it failed.
   if result is None:
      await bot.rest.create_message(event.channel_id, "No songs were found.", reply=event.message)
      return

   # Create a player (or if it already exists, grab that one!)
   player = client.create_player(event.guild_id)

   # Add the playlist, track or search result to the player.
   if isinstance(result, typing.Sequence):
      player.add(result[0])
   else:
      player.add(result)

   # Tell the player to start playing the song!
   await player.play()

   await bot.rest.create_message(event.channel_id, f"Playing {player.queue[0].info.title}", reply=event.message)

Extensions

Ongaku has two extension built-in:

  • ext.checker - For checking if a song is a URL, or just a query.
  • ext.injection - For injecting player instances into commands.

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hikari_ongaku-1.0.0.tar.gz (60.2 kB view details)

Uploaded Source

Built Distribution

hikari_ongaku-1.0.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file hikari_ongaku-1.0.0.tar.gz.

File metadata

  • Download URL: hikari_ongaku-1.0.0.tar.gz
  • Upload date:
  • Size: 60.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.9

File hashes

Hashes for hikari_ongaku-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f3fd2cf6a77991d920f7acb3a4098ec97fd420cad8af22ec2e1f3153fecd1a4d
MD5 8f82f8f65c9e53a138b94aaa97fea8e1
BLAKE2b-256 6b39901eda1ea73217470af9bc8f160c219db6037cb981a392479a7a787bb8d8

See more details on using hashes here.

File details

Details for the file hikari_ongaku-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for hikari_ongaku-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0ac3985fe9d0406313de641e800c2c5f21d9f6ece38c1ef344648372c2ce977d
MD5 381cbb1d52515b20bdd0a85d4113656c
BLAKE2b-256 26f52bd3ca3617c3ac104884cb7f64a21da1a558e00a6db9efababa57af3dd73

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page