mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
y no commit
This commit is contained in:
parent
71cc0e35dd
commit
85468ec78d
5 changed files with 46 additions and 10 deletions
|
@ -12,14 +12,13 @@ loop = asyncio.get_event_loop()
|
||||||
|
|
||||||
log = logging.root
|
log = logging.root
|
||||||
log.addHandler(logging.StreamHandler())
|
log.addHandler(logging.StreamHandler())
|
||||||
log.setLevel(logging.DEBUG)
|
|
||||||
logging.getLogger("royalnet.bots.telegram").setLevel(logging.DEBUG)
|
logging.getLogger("royalnet.bots.telegram").setLevel(logging.DEBUG)
|
||||||
logging.getLogger("royalnet.bots.discord").setLevel(logging.DEBUG)
|
logging.getLogger("royalnet.bots.discord").setLevel(logging.DEBUG)
|
||||||
logging.getLogger("royalnet.network.royalnetserver").setLevel(logging.DEBUG)
|
logging.getLogger("royalnet.network.royalnetserver").setLevel(logging.DEBUG)
|
||||||
|
|
||||||
commands = [PingCommand, ShipCommand, SmecdsCommand, ColorCommand, CiaoruoziCommand, DebugCreateCommand, SyncCommand,
|
commands = [PingCommand, ShipCommand, SmecdsCommand, ColorCommand, CiaoruoziCommand, DebugCreateCommand, SyncCommand,
|
||||||
AuthorCommand, DiarioCommand, RageCommand, DateparserCommand, ReminderCommand, KvactiveCommand, KvCommand,
|
AuthorCommand, DiarioCommand, RageCommand, DateparserCommand, ReminderCommand, KvactiveCommand, KvCommand,
|
||||||
KvrollCommand, VideoinfoCommand, SummonCommand]
|
KvrollCommand, VideoinfoCommand, SummonCommand, PlayCommand]
|
||||||
|
|
||||||
master = RoyalnetServer("localhost", 1234, "sas")
|
master = RoyalnetServer("localhost", 1234, "sas")
|
||||||
tg_bot = TelegramBot(os.environ["TG_AK"], "ws://localhost:1234", "sas", commands, os.environ["DB_PATH"], Royal, Telegram, "tg_id", error_command=ErrorHandlerCommand)
|
tg_bot = TelegramBot(os.environ["TG_AK"], "ws://localhost:1234", "sas", commands, os.environ["DB_PATH"], Royal, Telegram, "tg_id", error_command=ErrorHandlerCommand)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from .playmodes import PlayMode, Playlist, Pool
|
from .playmodes import PlayMode, Playlist, Pool
|
||||||
from .youtubedl import YtdlFile, YtdlInfo
|
from .youtubedl import YtdlFile, YtdlInfo
|
||||||
|
from .royalaudiofile import RoyalAudioFile
|
||||||
|
|
||||||
__all__ = ["PlayMode", "Playlist", "Pool", "YtdlFile", "YtdlInfo"]
|
__all__ = ["PlayMode", "Playlist", "Pool", "YtdlFile", "YtdlInfo"]
|
||||||
|
|
|
@ -13,17 +13,17 @@ log = _logging.getLogger(__name__)
|
||||||
class RoyalAudioFile(YtdlFile):
|
class RoyalAudioFile(YtdlFile):
|
||||||
ytdl_args = {
|
ytdl_args = {
|
||||||
"logger": log, # Log messages to a logging.Logger instance.
|
"logger": log, # Log messages to a logging.Logger instance.
|
||||||
"quiet": True, # Do not print messages to stdout.
|
|
||||||
"noplaylist": True, # Download single video instead of a playlist if in doubt.
|
|
||||||
"no_warnings": True, # Do not print out anything for warnings.,
|
|
||||||
"format": "bestaudio" # Fetch the best audio format available
|
"format": "bestaudio" # Fetch the best audio format available
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, info: "YtdlInfo", **ytdl_args):
|
def __init__(self, info: "YtdlInfo", **ytdl_args):
|
||||||
super().__init__(info, outtmpl="%(title)s-%(id)s.%(ext)s", **ytdl_args)
|
# Overwrite the new ytdl_args
|
||||||
|
self.ytdl_args = {**self.ytdl_args, **ytdl_args}
|
||||||
|
super().__init__(info, outtmpl="%(title)s-%(id)s.%(ext)s", **self.ytdl_args)
|
||||||
# Find the audio_filename with a regex (should be video.opus)
|
# Find the audio_filename with a regex (should be video.opus)
|
||||||
self.audio_filename = re.sub(rf"\.{self.info.ext}$", ".opus", self.video_filename)
|
self.audio_filename = re.sub(rf"\.{self.info.ext}$", ".mp3", self.video_filename)
|
||||||
# Convert the video to opus
|
# Convert the video to mp3
|
||||||
|
# Actually not needed, but we do this anyways for compression reasons
|
||||||
converter = ffmpeg.input(self.video_filename) \
|
converter = ffmpeg.input(self.video_filename) \
|
||||||
.output(self.audio_filename)
|
.output(self.audio_filename)
|
||||||
converter.run()
|
converter.run()
|
||||||
|
@ -40,4 +40,4 @@ class RoyalAudioFile(YtdlFile):
|
||||||
os.remove(self.audio_filename)
|
os.remove(self.audio_filename)
|
||||||
|
|
||||||
def as_audio_source(self):
|
def as_audio_source(self):
|
||||||
return discord.FFmpegPCMAudio(self.audio_filename)
|
return discord.FFmpegPCMAudio(f"./{self.audio_filename}")
|
||||||
|
|
|
@ -15,8 +15,9 @@ from .kv import KvCommand
|
||||||
from .kvroll import KvrollCommand
|
from .kvroll import KvrollCommand
|
||||||
from .videoinfo import VideoinfoCommand
|
from .videoinfo import VideoinfoCommand
|
||||||
from .summon import SummonCommand
|
from .summon import SummonCommand
|
||||||
|
from .play import PlayCommand
|
||||||
|
|
||||||
|
|
||||||
__all__ = ["NullCommand", "PingCommand", "ShipCommand", "SmecdsCommand", "CiaoruoziCommand", "ColorCommand",
|
__all__ = ["NullCommand", "PingCommand", "ShipCommand", "SmecdsCommand", "CiaoruoziCommand", "ColorCommand",
|
||||||
"SyncCommand", "DiarioCommand", "RageCommand", "DateparserCommand", "AuthorCommand", "ReminderCommand",
|
"SyncCommand", "DiarioCommand", "RageCommand", "DateparserCommand", "AuthorCommand", "ReminderCommand",
|
||||||
"KvactiveCommand", "KvCommand", "KvrollCommand", "VideoinfoCommand", "SummonCommand"]
|
"KvactiveCommand", "KvCommand", "KvrollCommand", "VideoinfoCommand", "SummonCommand", "PlayCommand"]
|
||||||
|
|
35
royalnet/commands/play.py
Normal file
35
royalnet/commands/play.py
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
import typing
|
||||||
|
from ..utils import Command, Call
|
||||||
|
from ..network import Message
|
||||||
|
|
||||||
|
|
||||||
|
class PlayMessage(Message):
|
||||||
|
def __init__(self, url: str):
|
||||||
|
self.url: str = url
|
||||||
|
|
||||||
|
|
||||||
|
class PlaySuccessful(Message):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class PlayError(Message):
|
||||||
|
def __init__(self, reason: str):
|
||||||
|
self.reason: str = reason
|
||||||
|
|
||||||
|
|
||||||
|
class PlayCommand(Command):
|
||||||
|
command_name = "play"
|
||||||
|
command_description = "Riproduce una canzone in chat vocale."
|
||||||
|
command_syntax = "(url)"
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def common(cls, call: Call):
|
||||||
|
url: str = call.args[0]
|
||||||
|
response: typing.Union[PlaySuccessful, PlayError] = await call.net_request(PlayMessage(url), "discord")
|
||||||
|
if isinstance(response, PlayError):
|
||||||
|
await call.reply(f"⚠️ Si è verificato un'errore nella richiesta di riproduzione:\n[c]{response.reason}[/c]")
|
||||||
|
return
|
||||||
|
elif isinstance(response, PlaySuccessful):
|
||||||
|
await call.reply(f"✅ Richiesta la riproduzione di [c]{url}[/c].")
|
||||||
|
return
|
||||||
|
raise TypeError(f"Received unexpected response in the PlayCommand: {response.__class__.__name__}")
|
Loading…
Reference in a new issue