add new [e] command.
Some checks are pending
Build-nightly / docker (push) Waiting to run

This commit is contained in:
Umiko 2025-05-05 04:25:04 +07:00
parent 5d410ab994
commit 411f359921
4 changed files with 84 additions and 0 deletions

View File

@ -40,6 +40,7 @@ class CommandProcessor:
"contacts": user_commands.ContactsBot, "contacts": user_commands.ContactsBot,
"help": user_commands.HelpCommand, "help": user_commands.HelpCommand,
"p": user_commands.PlayPauseCommand, "p": user_commands.PlayPauseCommand,
"e": user_commands.QueueCommand,
"u": user_commands.PlayUrlCommand, "u": user_commands.PlayUrlCommand,
"sv": user_commands.ServiceCommand, "sv": user_commands.ServiceCommand,
"s": user_commands.StopCommand, "s": user_commands.StopCommand,

View File

@ -1,6 +1,7 @@
from __future__ import annotations from __future__ import annotations
from typing import List, Optional, TYPE_CHECKING from typing import List, Optional, TYPE_CHECKING
import os import os
import re
from bot.commands.command import Command from bot.commands.command import Command
from bot.player.enums import Mode, State, TrackType from bot.player.enums import Mode, State, TrackType
@ -582,6 +583,68 @@ class DownloadCommand(Command):
else: else:
return self.translator.translate("Nothing is playing") return self.translator.translate("Nothing is playing")
class QueueCommand(Command):
@property
def help(self) -> str:
return self.translator.translate(
"QUERY Adds a track to the queue. If no track is playing, plays immediately."
)
def __call__(self, arg: str, user: User) -> Optional[str]:
if not arg:
raise errors.InvalidArgumentError
self.run_async(
self.ttclient.send_message,
self.translator.translate("Searching..."),
user,
)
try:
if re.match(r'http[s]?://', arg):
# Kalau URL, langsung stream
tracks = self.module_manager.streamer.get(arg, user.is_admin if user is not None else True)
self.player.add_to_queue(tracks)
# Kalau gak lagi main apa-apa, langsung play
if not self.player.is_playing():
self.player.play_next()
if self.config.general.send_channel_messages:
self.run_async(
self.ttclient.send_message,
self.translator.translate(
"{nickname} added a stream URL to the queue."
).format(nickname=user.nickname),
type=2,
)
return self.translator.translate("Added stream URL to the queue.")
else:
# Kalau bukan URL, cari lagu dari service
track_list = self.service_manager.service.search(arg)
self.player.add_to_queue(track_list)
if not self.player.is_playing():
self.player.play_next()
if self.config.general.send_channel_messages:
self.run_async(
self.ttclient.send_message,
self.translator.translate(
"{nickname} added {request} to the queue."
).format(nickname=user.nickname, request=arg),
type=2,
)
return self.translator.translate("Added {} to the queue.").format(
track_list[0].name
)
except errors.NothingFoundError:
return self.translator.translate("Nothing is found for your query")
except errors.ServiceError:
return self.translator.translate(
"The selected service is currently unavailable"
)
class ChangeLogCommand(Command): class ChangeLogCommand(Command):
@property @property
def help(self) -> str: def help(self) -> str:

View File

@ -181,6 +181,25 @@ class Player:
raise ValueError() raise ValueError()
self._player.speed = arg self._player.speed = arg
def add_to_queue(self, tracks: List[Track]) -> None:
"""Adds tracks to the queue."""
self.track_list.extend(tracks)
logging.debug(f"Added {len(tracks)} track(s) to the queue.")
# If nothing is playing, start playing the next track
if self.state == State.Stopped and len(self.track_list) > 0:
self.play_next()
def play_next(self) -> None:
"""Play the next track in the queue."""
if len(self.track_list) > 0:
self.track_index = 0 # Start with the first track
self.track = self.track_list[self.track_index]
self._play(self.track.url)
self.state = State.Playing
else:
self.state = State.Stopped
def seek_back(self, step: Optional[float] = None) -> None: def seek_back(self, step: Optional[float] = None) -> None:
step = step if step else self.config.seek_step step = step if step else self.config.seek_step
if step <= 0: if step <= 0:

View File

@ -1,5 +1,6 @@
This change log is written to find out the changes that have been made by Pandora, and the source code still refers to TTMediaBot. This change log is written to find out the changes that have been made by Pandora, and the source code still refers to TTMediaBot.
5/5/2025 5/5/2025
Added new command: e, to add either link or new song to the extended track. if nothing is playing, it plays the track directly.
Fix user rights to upload file, hopefully... Fix user rights to upload file, hopefully...
5/4/2025 5/4/2025