Added a direct youtube command and Readme file
This commit is contained in:
@@ -726,50 +726,39 @@ async def on_command_error(ctx: commands.Context, error: Exception):
|
||||
logging.exception("Unerwarteter Fehler bei Command '%s'", ctx.message.content)
|
||||
await ctx.send(f"❌ Unerwarteter Fehler: `{error}`")
|
||||
|
||||
def is_youtube_url(url: str) -> bool:
|
||||
url = url.strip().lower()
|
||||
return (
|
||||
url.startswith("https://youtu")
|
||||
or url.startswith("http://youtu")
|
||||
or url.startswith("https://www.youtube.com")
|
||||
or url.startswith("http://www.youtube.com")
|
||||
or url.startswith("https://youtube.com")
|
||||
or url.startswith("http://youtube.com")
|
||||
or url.startswith("https://m.youtube.com")
|
||||
or url.startswith("http://m.youtube.com")
|
||||
)
|
||||
|
||||
# ----------------------------
|
||||
# Commands
|
||||
# ----------------------------
|
||||
|
||||
@commands.guild_only()
|
||||
@bot.command(name="call")
|
||||
async def call_command(ctx: commands.Context):
|
||||
def extract_prefixed_youtube_command(content: str) -> Optional[str]:
|
||||
content = content.strip()
|
||||
|
||||
if not content.startswith("!"):
|
||||
return None
|
||||
|
||||
url = content[1:].strip()
|
||||
if not url:
|
||||
return None
|
||||
|
||||
if is_youtube_url(url):
|
||||
return url
|
||||
|
||||
return None
|
||||
|
||||
async def enqueue_youtube_url(ctx: commands.Context, url: str) -> None:
|
||||
state = get_state(ctx.guild.id)
|
||||
|
||||
logging.info("!call von %s in Guild %s", ctx.author, ctx.guild.id)
|
||||
|
||||
async with state.lock:
|
||||
voice_client = await ensure_connected(ctx)
|
||||
await ctx.send(f"📞 Verbunden mit **{voice_client.channel.name}**.")
|
||||
|
||||
|
||||
@commands.guild_only()
|
||||
@bot.command(name="radio")
|
||||
async def radio_command(ctx: commands.Context, *, url: str):
|
||||
state = get_state(ctx.guild.id)
|
||||
|
||||
logging.info("!radio von %s in Guild %s: %s", ctx.author, ctx.guild.id, url)
|
||||
|
||||
async with state.lock:
|
||||
await ensure_connected_or_same_channel(ctx)
|
||||
|
||||
await stop_playback(
|
||||
ctx.guild,
|
||||
clear_queue=True,
|
||||
disconnect=False,
|
||||
reset_mode=True,
|
||||
)
|
||||
|
||||
await play_radio(ctx.guild, url)
|
||||
await ctx.send(f"📻 Radio gestartet: `{url}`")
|
||||
|
||||
|
||||
@commands.guild_only()
|
||||
@bot.command(name="yt")
|
||||
async def yt_command(ctx: commands.Context, *, url: str):
|
||||
state = get_state(ctx.guild.id)
|
||||
|
||||
logging.info("!yt von %s in Guild %s: %s", ctx.author, ctx.guild.id, url)
|
||||
logging.info("YT enqueue von %s in Guild %s: %s", ctx.author, ctx.guild.id, url)
|
||||
|
||||
async with state.lock:
|
||||
await ensure_connected_or_same_channel(ctx)
|
||||
@@ -803,7 +792,78 @@ async def yt_command(ctx: commands.Context, *, url: str):
|
||||
f"➕ Zur Playlist hinzugefügt: **{discord.utils.escape_markdown(entry.title)}** "
|
||||
f"(Position {len(state.queue)})"
|
||||
)
|
||||
# ----------------------------
|
||||
# Commands
|
||||
# ----------------------------
|
||||
@bot.event
|
||||
async def on_message(message: discord.Message):
|
||||
if message.author.bot:
|
||||
return
|
||||
|
||||
if message.guild is None:
|
||||
await bot.process_commands(message)
|
||||
return
|
||||
|
||||
inline_url = extract_prefixed_youtube_command(message.content)
|
||||
|
||||
if inline_url is not None:
|
||||
logging.info(
|
||||
"Direkter !URL-YT-Befehl von %s in Guild %s: %s",
|
||||
message.author,
|
||||
message.guild.id,
|
||||
inline_url,
|
||||
)
|
||||
|
||||
ctx = await bot.get_context(message)
|
||||
|
||||
try:
|
||||
await enqueue_youtube_url(ctx, inline_url)
|
||||
except commands.CommandError as exc:
|
||||
await message.channel.send(f"❌ {exc}")
|
||||
except Exception:
|
||||
logging.exception("Fehler beim direkten !URL-YT-Befehl: %s", inline_url)
|
||||
await message.channel.send("❌ Unerwarteter Fehler beim Verarbeiten der URL.")
|
||||
|
||||
return
|
||||
|
||||
await bot.process_commands(message)
|
||||
|
||||
@commands.guild_only()
|
||||
@bot.command(name="call")
|
||||
async def call_command(ctx: commands.Context):
|
||||
state = get_state(ctx.guild.id)
|
||||
|
||||
logging.info("!call von %s in Guild %s", ctx.author, ctx.guild.id)
|
||||
|
||||
async with state.lock:
|
||||
voice_client = await ensure_connected(ctx)
|
||||
await ctx.send(f"📞 Verbunden mit **{voice_client.channel.name}**.")
|
||||
|
||||
|
||||
@commands.guild_only()
|
||||
@bot.command(name="radio")
|
||||
async def radio_command(ctx: commands.Context, *, url: str):
|
||||
state = get_state(ctx.guild.id)
|
||||
|
||||
logging.info("!radio von %s in Guild %s: %s", ctx.author, ctx.guild.id, url)
|
||||
|
||||
async with state.lock:
|
||||
await ensure_connected_or_same_channel(ctx)
|
||||
|
||||
await stop_playback(
|
||||
ctx.guild,
|
||||
clear_queue=True,
|
||||
disconnect=False,
|
||||
reset_mode=True,
|
||||
)
|
||||
|
||||
await play_radio(ctx.guild, url)
|
||||
await ctx.send(f"📻 Radio gestartet: `{url}`")
|
||||
|
||||
@commands.guild_only()
|
||||
@bot.command(name="yt")
|
||||
async def yt_command(ctx: commands.Context, *, url: str):
|
||||
await enqueue_youtube_url(ctx, url)
|
||||
|
||||
@commands.guild_only()
|
||||
@bot.command(name="pause")
|
||||
@@ -936,7 +996,6 @@ async def list_command(ctx: commands.Context):
|
||||
async with state.lock:
|
||||
await ctx.send(build_list_output(ctx.guild))
|
||||
|
||||
|
||||
@commands.guild_only()
|
||||
@bot.command(name="helpme")
|
||||
async def helpme_command(ctx: commands.Context):
|
||||
@@ -947,6 +1006,7 @@ async def helpme_command(ctx: commands.Context):
|
||||
"`!call` – Bot in deinen Voice-Channel holen\n"
|
||||
"`!radio <url>` – Radio-Stream starten\n"
|
||||
"`!yt <url>` – YouTube-Link sofort starten oder in Queue einreihen\n"
|
||||
"`!https://...` – YouTube-Link direkt ohne !yt einreihen\n"
|
||||
"`!play` – fortsetzen / nächsten Track starten\n"
|
||||
"`!pause` – pausieren\n"
|
||||
"`!stop` – stoppen und Queue löschen\n"
|
||||
@@ -956,7 +1016,6 @@ async def helpme_command(ctx: commands.Context):
|
||||
"`!list` – aktuelle Wiedergabe und Queue anzeigen"
|
||||
)
|
||||
|
||||
|
||||
# ----------------------------
|
||||
# Start
|
||||
# ----------------------------
|
||||
|
||||
Reference in New Issue
Block a user