Skip to content
Closed

labă #429

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Official [PyLav](https://github.com/PyLav/PyLav) Cogs for [Red-DiscordBot](https://github.com/Cog-Creators/Red-DiscordBot)
# Official [PyLav]([https://github.com/PyLav/PyLav](https://github.com/1Example/PyLav)) Cogs for [Red-DiscordBot](https://github.com/Cog-Creators/Red-DiscordBot)
[![Crowdin](https://badges.crowdin.net/pylav/localized.svg)](https://crowdin.com/project/pylav)[![GitHub license](https://img.shields.io/github/license/PyLav/PyLav.svg)](https://github.com/PyLav/Py-Lav/blob/develop/LICENSE)
[![Support Server](https://img.shields.io/discord/970987707834720266)](https://discord.com/invite/vnmcXqtgeY)

About Cogs
---------------------------
Expand Down Expand Up @@ -30,22 +29,13 @@ Documentation
Getting Started
-------------------------------------
> **Warning**
> Make sure to follow [PyLav Setup](https://github.com/PyLav/PyLav/blob/develop/SETUP.md)
> Make sure to follow [PyLav Setup](https://github.com/1Example/PyLav/blob/develop/SETUP.md)


If you already have a Red instance with PyLav setup then you can do the following
```
[p]load downloader
[p]repo add PyLav https://github.com/PyLav/Red-Cogs
[p]repo add PyLav https://github.com/1Example/PyLav-Cogs
[p]cog install PyLav audio
[p]load audio
```

Translations
------------------------------------
You can help translating the project into your language here:
[![Crowdin](https://badges.crowdin.net/pylav/localized.svg)](https://crowdin.com/project/pylav)

------------------------------

## Join our support server [![Support Server](https://img.shields.io/discord/970987707834720266?style=social)](https://discord.com/invite/vnmcXqtgeY)
2 changes: 1 addition & 1 deletion audio/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
],
"required_cogs": {},
"requirements": [
"Py-Lav[all]>=1.15.14,<1.16"
"Py-Lav[all] @ git+https://github.com/1Example/PyLav@develop"
],
"short": "A media player cog",
"tags": [
Expand Down
121 changes: 118 additions & 3 deletions audio/slash_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from pylav.extension.red.utils.validators import valid_query_attachment
from pylav.helpers.format.strings import shorten_string
from pylav.logging import getLogger
from pylav.nodes.api.responses.track import Track as Track_namespace_conflict
from pylav.players.query.obj import Query
from pylav.players.tracks.obj import Track
from pylav.type_hints.bot import DISCORD_COG_TYPE_MIXIN, DISCORD_INTERACTION_TYPE
Expand Down Expand Up @@ -247,11 +248,23 @@ async def slash_play(
context = await self.bot.get_context(interaction)
if context.interaction and not context.interaction.response.is_done():
await context.defer(ephemeral=True)
if query == "FqgqQW21tQ@#1g2fasf2":
return await context.send(
embed=await self.pylav.construct_embed(
description=_("You have not selected something to play."),
messageable=context,
),
ephemeral=True,
)
if query is None:
if attachments := context.message.attachments:
query = "\n".join(
attachment.url for attachment in attachments if valid_query_attachment(attachment.filename)
)
if query is not None:
_track = self._track_cache.get(query)
if _track is not None:
query = _track
if not query:
await context.send(
embed=await self.pylav.construct_embed(
Expand Down Expand Up @@ -289,9 +302,6 @@ async def slash_play(
)
return
player = await self.pylav.connect_player(channel=channel, requester=context.author)
queries = [await Query.from_string(qf) for q in query.split("\n") if (qf := q.strip("<>").strip())]
total_tracks_enqueue = 0
single_track = None
if isinstance(enqueue_type, app_commands.Choice):
enqueue_type = enqueue_type.value
match enqueue_type:
Expand All @@ -304,6 +314,29 @@ async def slash_play(
case __:
priority = 100
index = None
if isinstance(query, (Track, Track_namespace_conflict)):
track = await Track.build_track(
node=player.node,
data=query,
requester=context.author.id,
query=None,
player_instance=player,
)
if track is None:
return
await player.add(track=track, requester=context.author.id, index=index)
if (not (player.is_active or player.queue.empty())) or priority == -1:
await player.next(requester=context.author)
_query = await track.query()
queries = [] if _query is None else [_query]
await self._process_play_message(context, track, 1, queries)
return
if isinstance(query, str):
queries = [await Query.from_string(qf) for q in query.split("\n") if (qf := q.strip("<>").strip())]
else:
queries = []
total_tracks_enqueue = 0
single_track = None
LOGGER.info(f"Priority: {priority}, Index: {index}")
if queries:
single_track, total_tracks_enqueue = await self._process_play_queries(
Expand All @@ -313,3 +346,85 @@ async def slash_play(
await player.next(requester=context.author)

await self._process_play_message(context, single_track, total_tracks_enqueue, queries)

@slash_play.autocomplete("query")
async def slash_play_autocomplete_query(
self, interaction: DISCORD_INTERACTION_TYPE, current: str
):
if not interaction.response.is_done():
await interaction.response.defer(ephemeral=True)
# If it looks like a URL, don't show autocomplete
if current and (current.startswith("http://") or current.startswith("https://")):
return [
Choice(
name=shorten_string(max_length=100, string=current),
value=current,
)
]
if not current:
return [
Choice(
name=shorten_string(max_length=100, string=_("Type to search YouTube...")),
value="FqgqQW21tQ@#1g2fasf2",
)
]
search_query = f"ytsearch:{current}"
original_query = await Query.from_string(search_query)
try:
response = await interaction.client.pylav.search_query(
original_query,
fullsearch=True,
player=interaction.client.pylav.get_player(interaction.guild.id),
)
except Exception as e:
LOGGER.debug(f"Error searching for {original_query}", exc_info=e)
return [
Choice(
name=shorten_string(max_length=100, string=_("Error searching YouTube")),
value="FqgqQW21tQ@#1g2fasf2",
)
]
if not response:
return [
Choice(
name=shorten_string(max_length=100, string=_("No results found on YouTube")),
value="FqgqQW21tQ@#1g2fasf2",
)
]
match response.loadType:
case "track":
tracks = [response.data]
case "search":
tracks = response.data
case "playlist":
tracks = response.data.tracks
case __:
tracks = []
tracks = tracks[:25]
if not tracks:
return [
Choice(
name=shorten_string(max_length=100, string=_("No results found on YouTube")),
value="FqgqQW21tQ@#1g2fasf2",
)
]
choices = []
node = interaction.client.pylav.get_my_node()
if node is None:
node = await interaction.client.pylav.node_manager.find_best_node(feature="youtube")
player = interaction.client.pylav.get_player(interaction.guild.id)
for track in tracks:
track = await Track.build_track(
node=node, data=track, query=original_query, requester=interaction.user.id, player_instance=player
)
if track is None:
continue
track_id = hashlib.md5(track.encoded.encode()).hexdigest()
self._track_cache[track_id] = track
choices.append(
Choice(
name=await track.get_track_display_name(max_length=95, unformatted=True, with_url=False),
value=track_id,
)
)
return choices
2 changes: 1 addition & 1 deletion plconfig/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
],
"required_cogs": {},
"requirements": [
"Py-Lav[all]>=1.15.14,<1.16"
"Py-Lav[all] @ git+https://github.com/1Example/PyLav@develop"
],
"short": "Configure PyLav's global settings.",
"tags": [
Expand Down
2 changes: 1 addition & 1 deletion plcontroller/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
],
"required_cogs": {},
"requirements": [
"Py-Lav[all]>=1.15.14,<1.16"
"Py-Lav[all] @ git+https://github.com/1Example/PyLav@develop"
],
"short": "A media player cog",
"tags": [
Expand Down
2 changes: 1 addition & 1 deletion pleffects/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
],
"required_cogs": {},
"requirements": [
"Py-Lav[all]>=1.15.14,<1.16"
"Py-Lav[all] @ git+https://github.com/1Example/PyLav@develop"
],
"short": "Commands to manage and apply effects to the players.",
"tags": [
Expand Down
2 changes: 1 addition & 1 deletion pllocal/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
],
"required_cogs": {},
"requirements": [
"Py-Lav[all]>=1.15.14,<1.16"
"Py-Lav[all] @ git+https://github.com/1Example/PyLav@develop"
],
"short": "Commands to interact with local media files.",
"tags": [
Expand Down
2 changes: 1 addition & 1 deletion pllyrics/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
],
"required_cogs": {},
"requirements": [
"Py-Lav[all]>=1.15.14,<1.16"
"Py-Lav[all] @ git+https://github.com/1Example/PyLav@develop"
],
"short": "Get lyric for songs.",
"tags": [
Expand Down
2 changes: 1 addition & 1 deletion plmanagednode/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
],
"required_cogs": {},
"requirements": [
"Py-Lav[all]>=1.15.14,<1.16"
"Py-Lav[all] @ git+https://github.com/1Example/PyLav@develop"
],
"short": "Commands to configure Pylav's managed node.",
"tags": [
Expand Down
2 changes: 1 addition & 1 deletion plmigrator/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"permissions": [],
"required_cogs": {},
"requirements": [
"Py-Lav[all]>=1.15.14,<1.16"
"Py-Lav[all] @ git+https://github.com/1Example/PyLav@develop"
],
"short": "Convert your Audio settings to PyLav.",
"tags": [
Expand Down
2 changes: 1 addition & 1 deletion plnodes/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
],
"required_cogs": {},
"requirements": [
"Py-Lav[all]>=1.15.14,<1.16"
"Py-Lav[all] @ git+https://github.com/1Example/PyLav@develop"
],
"short": "A collection of node controller commands for PyLav.",
"tags": [
Expand Down
2 changes: 1 addition & 1 deletion plnotifier/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
],
"required_cogs": {},
"requirements": [
"Py-Lav[all]>=1.15.14,<1.16"
"Py-Lav[all] @ git+https://github.com/1Example/PyLav@develop"
],
"short": "Configure PyLav's notifications.",
"tags": [
Expand Down
3 changes: 3 additions & 0 deletions plplaylists/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@
- Create playlist from files.
- If no URL is provided, it will upload the playlist file from the current attached filed.
- If a URL is provided, it will upload the playlist file from the URL.
- `/playlist append <playlist> [url]`
- Append a URL or song to a playlist.
- URL to append - any direct link including radio streams e.g. https://radio.example.com/stream
Loading
Loading