mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-27 13:34:28 +00:00
Add playmode command
This commit is contained in:
parent
61cb632929
commit
354cfb318c
6 changed files with 118 additions and 6 deletions
|
@ -39,6 +39,7 @@ from .brawlhalla import BrawlhallaCommand
|
|||
from .diarioshuffle import DiarioshuffleCommand
|
||||
from .funkwhaleplaylist import FunkwhaleplaylistCommand
|
||||
from .voicestatus import VoicestatusCommand
|
||||
from .playmode import PlaymodeCommand
|
||||
|
||||
# Enter the commands of your Pack here!
|
||||
available_commands = [
|
||||
|
@ -82,6 +83,7 @@ available_commands = [
|
|||
DiarioshuffleCommand,
|
||||
FunkwhaleplaylistCommand,
|
||||
VoicestatusCommand,
|
||||
PlaymodeCommand,
|
||||
]
|
||||
|
||||
# Don't change this, it should automatically generate __all__
|
||||
|
|
57
royalpack/commands/playmode.py
Normal file
57
royalpack/commands/playmode.py
Normal file
|
@ -0,0 +1,57 @@
|
|||
from typing import *
|
||||
import royalnet
|
||||
import royalnet.commands as rc
|
||||
import discord
|
||||
from royalnet.backpack.tables import User, Discord
|
||||
|
||||
|
||||
class PlaymodeCommand(rc.Command):
|
||||
name: str = "playmode"
|
||||
|
||||
aliases = ["pm"]
|
||||
|
||||
description: str = "Seleziona la modalità di riproduzione musicale."
|
||||
|
||||
syntax: str = "{queue|pool}"
|
||||
|
||||
async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None:
|
||||
if self.interface.name == "discord":
|
||||
message: discord.Message = data.message
|
||||
guild: discord.Guild = message.guild
|
||||
if guild is None:
|
||||
guild_id = None
|
||||
else:
|
||||
guild_id: Optional[int] = guild.id
|
||||
else:
|
||||
guild_id = None
|
||||
|
||||
user: User = await data.get_author()
|
||||
user_str = None
|
||||
|
||||
if user is not None:
|
||||
try:
|
||||
user_discord: Discord = user.discord[0]
|
||||
except (AttributeError, IndexError):
|
||||
user_str = str(user)
|
||||
else:
|
||||
user_str = str(f"<@{user_discord.discord_id}>")
|
||||
|
||||
response = await self.interface.call_herald_event("discord", "discord_playmode",
|
||||
playable_string=args[0],
|
||||
guild_id=guild_id,
|
||||
user=user_str)
|
||||
|
||||
if response["name"] == "RoyalQueue":
|
||||
await data.reply(f"✅ Modalità di riproduzione impostata a [b]Queue[/b]:\n"
|
||||
f"- Riproduci le canzoni nell'ordine scelto\n"
|
||||
f"- Rimuovi le canzoni dopo averle riprodotte")
|
||||
|
||||
elif response["name"] == "RoyalPool":
|
||||
await data.reply(f"✅ Modalità di riproduzione impostata a [b]Pool[/b]:\n"
|
||||
f"- Aggiungi canzoni al pool con [c]!p[/c], [c]!yt[/c] e [c]!fw[/c]\n"
|
||||
f"- Riproduci all'infinito canzoni casuali dal pool\n"
|
||||
f"- Non è possibile rimuovere canzoni dal pool, [c]!skip[/c]parle manderà solo avanti il pool\n"
|
||||
f"- Interrompi la riproduzione del pool cambiando modalità di riproduzione")
|
||||
|
||||
else:
|
||||
await data.reply(f"✅ Modalità di riproduzione impostata a [c]{response['name']}[/c]!")
|
|
@ -5,6 +5,7 @@ from .discord_play import DiscordPlayEvent
|
|||
from .discord_skip import DiscordSkipEvent
|
||||
from .discord_queue import DiscordQueueEvent
|
||||
from .discord_pause import DiscordPauseEvent
|
||||
from .discord_playable import DiscordPlaymodeEvent
|
||||
|
||||
# Enter the commands of your Pack here!
|
||||
available_events = [
|
||||
|
@ -14,6 +15,7 @@ available_events = [
|
|||
DiscordSkipEvent,
|
||||
DiscordQueueEvent,
|
||||
DiscordPauseEvent,
|
||||
DiscordPlaymodeEvent,
|
||||
]
|
||||
|
||||
# Don't change this, it should automatically generate __all__
|
||||
|
|
48
royalpack/events/discord_playable.py
Normal file
48
royalpack/events/discord_playable.py
Normal file
|
@ -0,0 +1,48 @@
|
|||
import datetime
|
||||
from typing import *
|
||||
|
||||
import discord
|
||||
import royalnet.commands as rc
|
||||
import royalnet.serf.discord as rsd
|
||||
import royalnet.bard.discord as rbd
|
||||
|
||||
from ..utils import RoyalQueue, RoyalPool
|
||||
|
||||
|
||||
class DiscordPlaymodeEvent(rc.Event):
|
||||
name = "discord_playmode"
|
||||
|
||||
async def run(self,
|
||||
playable_string: str,
|
||||
guild_id: Optional[int] = None,
|
||||
user: Optional[str] = None,
|
||||
**kwargs) -> dict:
|
||||
if not isinstance(self.serf, rsd.DiscordSerf):
|
||||
raise rc.UnsupportedError()
|
||||
|
||||
serf: rsd.DiscordSerf = self.serf
|
||||
client: discord.Client = self.serf.client
|
||||
guild: discord.Guild = client.get_guild(guild_id) if guild_id is not None else None
|
||||
candidate_players: List[rsd.VoicePlayer] = serf.find_voice_players(guild)
|
||||
|
||||
if len(candidate_players) == 0:
|
||||
raise rc.UserError("Il bot non è in nessun canale vocale.\n"
|
||||
"Evocalo prima con [c]summon[/c]!")
|
||||
elif len(candidate_players) == 1:
|
||||
voice_player = candidate_players[0]
|
||||
else:
|
||||
raise rc.CommandError("Non so a che Server cambiare Playable...\n"
|
||||
"Invia il comando su Discord, per favore!")
|
||||
|
||||
if playable_string.upper() == "QUEUE":
|
||||
playable = RoyalQueue()
|
||||
elif playable_string.upper() == "POOL":
|
||||
playable = RoyalPool()
|
||||
else:
|
||||
raise rc.InvalidInputError(f"Unknown playable '{playable_string.upper()}'")
|
||||
|
||||
await voice_player.change_playing(playable)
|
||||
|
||||
return {
|
||||
"name": f"{playable.__class__.__qualname__}"
|
||||
}
|
|
@ -1,7 +1,9 @@
|
|||
from .royalqueue import RoyalQueue
|
||||
from .finduser import find_user_api
|
||||
from .royalpool import RoyalPool
|
||||
|
||||
__all__ = [
|
||||
"RoyalQueue",
|
||||
"find_user_api",
|
||||
"RoyalPool",
|
||||
]
|
||||
|
|
|
@ -46,6 +46,7 @@ class RoyalQueue(Playable):
|
|||
self.now_playing = None
|
||||
|
||||
async def destroy(self):
|
||||
if self.now_playing is not None:
|
||||
log.debug(f"Deleting: {self.now_playing}")
|
||||
await self.now_playing.delete_asap()
|
||||
log.debug(f"Deleting: {self.now_playing.ytdl_file}")
|
||||
|
|
Loading…
Reference in a new issue