mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
Skip is done
This commit is contained in:
parent
ca0caecb85
commit
58e8285a9b
5 changed files with 49 additions and 43 deletions
|
@ -14,7 +14,7 @@ from .videochannel import VideochannelCommand
|
||||||
from .play import PlayCommand
|
from .play import PlayCommand
|
||||||
# from .playmode import PlaymodeCommand
|
# from .playmode import PlaymodeCommand
|
||||||
# from .queue import QueueCommand
|
# from .queue import QueueCommand
|
||||||
# from .skip import SkipCommand
|
from .skip import SkipCommand
|
||||||
from .summon import SummonCommand
|
from .summon import SummonCommand
|
||||||
# from .youtube import YoutubeCommand
|
# from .youtube import YoutubeCommand
|
||||||
# from .soundcloud import SoundcloudCommand
|
# from .soundcloud import SoundcloudCommand
|
||||||
|
@ -42,7 +42,7 @@ available_commands = [
|
||||||
PlayCommand,
|
PlayCommand,
|
||||||
# PlaymodeCommand,
|
# PlaymodeCommand,
|
||||||
# QueueCommand,
|
# QueueCommand,
|
||||||
# SkipCommand,
|
SkipCommand,
|
||||||
SummonCommand,
|
SummonCommand,
|
||||||
# YoutubeCommand,
|
# YoutubeCommand,
|
||||||
# SoundcloudCommand,
|
# SoundcloudCommand,
|
||||||
|
|
|
@ -1,48 +1,21 @@
|
||||||
import typing
|
|
||||||
import discord
|
import discord
|
||||||
|
from typing import *
|
||||||
from royalnet.commands import *
|
from royalnet.commands import *
|
||||||
from royalnet.bots import DiscordBot
|
|
||||||
|
|
||||||
|
|
||||||
class SkipCommand(Command):
|
class SkipCommand(Command):
|
||||||
name: str = "skip"
|
name: str = "skip"
|
||||||
|
|
||||||
aliases = ["s", "next", "n"]
|
aliases = ["s"]
|
||||||
|
|
||||||
description: str = "Salta la canzone attualmente in riproduzione in chat vocale."
|
description: str = "Salta il file attualmente in riproduzione."
|
||||||
|
|
||||||
syntax: str = "[ [guild] ]"
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
async def _legacy_skip_handler(bot: "DiscordBot", guild_name: typing.Optional[str]):
|
|
||||||
# Find the matching guild
|
|
||||||
if guild_name:
|
|
||||||
guilds: typing.List[discord.Guild] = bot.client.find_guild_by_name(guild_name)
|
|
||||||
else:
|
|
||||||
guilds = bot.client.guilds
|
|
||||||
if len(guilds) == 0:
|
|
||||||
raise CommandError("No guilds with the specified name found.")
|
|
||||||
if len(guilds) > 1:
|
|
||||||
raise CommandError("Multiple guilds with the specified name found.")
|
|
||||||
guild = list(bot.client.guilds)[0]
|
|
||||||
# Set the currently playing source as ended
|
|
||||||
voice_client: discord.VoiceClient = bot.client.find_voice_client_by_guild(guild)
|
|
||||||
if voice_client and not (voice_client.is_playing() or voice_client.is_paused()):
|
|
||||||
raise CommandError("Nothing to skip")
|
|
||||||
# noinspection PyProtectedMember
|
|
||||||
voice_client._player.stop()
|
|
||||||
return {}
|
|
||||||
|
|
||||||
_event_name = "_legacy_skip"
|
|
||||||
|
|
||||||
def __init__(self, interface: CommandInterface):
|
|
||||||
super().__init__(interface)
|
|
||||||
if interface.name == "discord":
|
|
||||||
interface.register_herald_action(self._event_name, self._legacy_skip_handler)
|
|
||||||
|
|
||||||
async def run(self, args: CommandArgs, data: CommandData) -> None:
|
async def run(self, args: CommandArgs, data: CommandData) -> None:
|
||||||
guild_name, = args.match(r"(?:\[(.+)])?")
|
if self.interface.name == "discord":
|
||||||
await self.interface.call_herald_action("discord", self._event_name, {
|
message: discord.Message = data.message
|
||||||
"guild_name": guild_name
|
guild: discord.Guild = message.guild
|
||||||
})
|
guild_id: Optional[int] = guild.id
|
||||||
await data.reply(f"⏩ Richiesto lo skip della canzone attuale.")
|
else:
|
||||||
|
guild_id = None
|
||||||
|
response: Dict[str, Any] = await self.interface.call_herald_event("discord", "discord_skip", guild_id=guild_id)
|
||||||
|
await data.reply("⏩ File attuale saltato!")
|
||||||
|
|
|
@ -2,15 +2,15 @@
|
||||||
from .discord_cv import DiscordCvEvent
|
from .discord_cv import DiscordCvEvent
|
||||||
from .discord_summon import DiscordSummonEvent
|
from .discord_summon import DiscordSummonEvent
|
||||||
from .discord_play import DiscordPlayEvent
|
from .discord_play import DiscordPlayEvent
|
||||||
|
from .discord_skip import DiscordSkipEvent
|
||||||
|
|
||||||
# Enter the commands of your Pack here!
|
# Enter the commands of your Pack here!
|
||||||
available_events = [
|
available_events = [
|
||||||
DiscordCvEvent,
|
DiscordCvEvent,
|
||||||
DiscordSummonEvent,
|
DiscordSummonEvent,
|
||||||
DiscordPlayEvent,
|
DiscordPlayEvent,
|
||||||
|
DiscordSkipEvent,
|
||||||
]
|
]
|
||||||
|
|
||||||
# noinspection PyUnreachableCode
|
|
||||||
|
|
||||||
# Don't change this, it should automatically generate __all__
|
# Don't change this, it should automatically generate __all__
|
||||||
__all__ = [command.__name__ for command in available_events]
|
__all__ = [command.__name__ for command in available_events]
|
||||||
|
|
|
@ -36,7 +36,7 @@ class DiscordPlayEvent(Event):
|
||||||
added: List[YtdlDiscord] = []
|
added: List[YtdlDiscord] = []
|
||||||
too_long: List[YtdlDiscord] = []
|
too_long: List[YtdlDiscord] = []
|
||||||
if isinstance(voice_player.playing, PlayableYTDQueue):
|
if isinstance(voice_player.playing, PlayableYTDQueue):
|
||||||
for ytd in ytds:
|
for index, ytd in enumerate(ytds):
|
||||||
if ytd.info.duration >= datetime.timedelta(seconds=self.config["Play"]["max_song_duration"]):
|
if ytd.info.duration >= datetime.timedelta(seconds=self.config["Play"]["max_song_duration"]):
|
||||||
too_long.append(ytd)
|
too_long.append(ytd)
|
||||||
continue
|
continue
|
||||||
|
|
33
royalpack/events/discord_skip.py
Normal file
33
royalpack/events/discord_skip.py
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
import discord
|
||||||
|
from typing import *
|
||||||
|
from royalnet.commands import *
|
||||||
|
from royalnet.serf.discord import *
|
||||||
|
|
||||||
|
|
||||||
|
class DiscordSkipEvent(Event):
|
||||||
|
name = "discord_skip"
|
||||||
|
|
||||||
|
async def run(self,
|
||||||
|
guild_id: Optional[int] = None,
|
||||||
|
**kwargs) -> dict:
|
||||||
|
if not isinstance(self.serf, DiscordSerf):
|
||||||
|
raise UnsupportedError()
|
||||||
|
client: discord.Client = self.serf.client
|
||||||
|
if len(self.serf.voice_players) == 1:
|
||||||
|
voice_player: VoicePlayer = self.serf.voice_players[0]
|
||||||
|
else:
|
||||||
|
if guild_id is None:
|
||||||
|
# TODO: trovare un modo per riprodurre canzoni su più server da Telegram
|
||||||
|
raise InvalidInputError("Non so in che Server riprodurre questo file...\n"
|
||||||
|
"Invia il comando su Discord, per favore!")
|
||||||
|
guild: discord.Guild = client.get_guild(guild_id)
|
||||||
|
if guild is None:
|
||||||
|
raise InvalidInputError("Impossibile trovare il Server specificato.")
|
||||||
|
voice_player: VoicePlayer = self.serf.find_voice_player(guild)
|
||||||
|
if voice_player is None:
|
||||||
|
raise UserError("Il bot non è in nessun canale vocale.\n"
|
||||||
|
"Evocalo prima con [c]summon[/c]!")
|
||||||
|
# Stop the playback of the current song
|
||||||
|
voice_player.voice_client.stop()
|
||||||
|
# Done!
|
||||||
|
return {}
|
Loading…
Reference in a new issue