diff --git a/royalpack/commands/__init__.py b/royalpack/commands/__init__.py index 8026721f..e0746a56 100644 --- a/royalpack/commands/__init__.py +++ b/royalpack/commands/__init__.py @@ -7,7 +7,7 @@ from .rage import RageCommand from .reminder import ReminderCommand from .ship import ShipCommand from .smecds import SmecdsCommand -# from .videochannel import VideochannelCommand +from .videochannel import VideochannelCommand # from .trivia import TriviaCommand # from .matchmaking import MatchmakingCommand # from .pause import PauseCommand @@ -35,7 +35,7 @@ available_commands = [ ReminderCommand, ShipCommand, SmecdsCommand, - # VideochannelCommand, + VideochannelCommand, # TriviaCommand, # MatchmakingCommand, # PauseCommand, diff --git a/royalpack/commands/videochannel.py b/royalpack/commands/videochannel.py index a09cd17a..c613591b 100644 --- a/royalpack/commands/videochannel.py +++ b/royalpack/commands/videochannel.py @@ -10,41 +10,40 @@ class VideochannelCommand(Command): description: str = "Converti il canale vocale in un canale video." - syntax = "[channelname]" + syntax = "[nomecanale]" async def run(self, args: CommandArgs, data: CommandData) -> None: - if self.interface.name == "discord": - bot: discord.Client = self.interface.bot - message: discord.Message = data.message - channel_name: str = args.optional(0) - if channel_name: - guild: typing.Optional[discord.Guild] = message.guild - if guild is not None: - channels: typing.List[discord.abc.GuildChannel] = guild.channels - else: - channels = bot.get_all_channels() - matching_channels: typing.List[discord.VoiceChannel] = [] - for channel in channels: - if isinstance(channel, discord.VoiceChannel): - if channel.name == channel_name: - matching_channels.append(channel) - if len(matching_channels) == 0: - raise CommandError("Non esiste alcun canale vocale con il nome specificato.") - elif len(matching_channels) > 1: - raise CommandError("Esiste più di un canale vocale con il nome specificato.") - channel = matching_channels[0] + if self.interface.name != "discord": + raise UnsupportedError(f"{self} non è supportato su {self.interface.name}.") + bot: discord.Client = self.serf.client + message: discord.Message = data.message + channel_name: str = args.optional(0) + if channel_name: + guild: typing.Optional[discord.Guild] = message.guild + if guild is not None: + channels: typing.List[discord.abc.GuildChannel] = guild.channels else: - author: discord.Member = message.author - voice: typing.Optional[discord.VoiceState] = author.voice - if voice is None: - raise CommandError("Non sei connesso a nessun canale vocale.") - channel = voice.channel - if author.is_on_mobile(): - await data.reply(f"📹 Per entrare in modalità video, clicca qui:\n" - f"\n" - f"[b]Attenzione: la modalità video non funziona su Android e iOS![/b]") - return - await data.reply(f"📹 Per entrare in modalità video, clicca qui:\n" - f"") + channels = bot.get_all_channels() + matching_channels: typing.List[discord.VoiceChannel] = [] + for channel in channels: + if isinstance(channel, discord.VoiceChannel): + if channel.name == channel_name: + matching_channels.append(channel) + if len(matching_channels) == 0: + raise InvalidInputError("Non esiste alcun canale vocale con il nome specificato.") + elif len(matching_channels) > 1: + raise UserError("Esiste più di un canale vocale con il nome specificato.") + channel = matching_channels[0] else: - raise UnsupportedError() + author: discord.Member = message.author + voice: typing.Optional[discord.VoiceState] = author.voice + if voice is None: + raise InvalidInputError("Non sei connesso a nessun canale vocale.") + channel = voice.channel + if author.is_on_mobile(): + await data.reply(f"📹 Per entrare in modalità video, clicca qui:\n" + f"\n" + f"[b]Attenzione: la modalità video non funziona su Android e iOS![/b]") + return + await data.reply(f"📹 Per entrare in modalità video, clicca qui:\n" + f"") diff --git a/royalpack/stars/__init__.py b/royalpack/stars/__init__.py index 511a9101..161f9d48 100644 --- a/royalpack/stars/__init__.py +++ b/royalpack/stars/__init__.py @@ -3,6 +3,7 @@ from .api_user_list import ApiUserListStar from .api_user_get import ApiUserGetStar from .api_diario_list import ApiDiarioListStar from .api_diario_get import ApiDiarioGetStar +# from .api_discord_cv import ApiDiscordCvStar # Enter the PageStars of your Pack here! available_page_stars = [ @@ -10,6 +11,7 @@ available_page_stars = [ ApiUserGetStar, ApiDiarioListStar, ApiDiarioGetStar, + # ApiDiscordCvStar, ] # Enter the ExceptionStars of your Pack here! diff --git a/royalpack/stars/api_diario_get.py b/royalpack/stars/api_diario_get.py index ee5bf97c..966fc408 100644 --- a/royalpack/stars/api_diario_get.py +++ b/royalpack/stars/api_diario_get.py @@ -2,7 +2,6 @@ from starlette.requests import Request from starlette.responses import * from royalnet.constellation import * from royalnet.utils import * -from royalnet.backpack.tables import * from ..tables import * diff --git a/royalpack/stars/api_diario_list.py b/royalpack/stars/api_diario_list.py index a4532da0..74043b1a 100644 --- a/royalpack/stars/api_diario_list.py +++ b/royalpack/stars/api_diario_list.py @@ -2,7 +2,6 @@ from starlette.requests import Request from starlette.responses import * from royalnet.constellation import * from royalnet.utils import * -from royalnet.backpack.tables import * from ..tables import * diff --git a/royalpack/stars/api_discord_cv.py b/royalpack/stars/api_discord_cv.py new file mode 100644 index 00000000..8b1e268e --- /dev/null +++ b/royalpack/stars/api_discord_cv.py @@ -0,0 +1,12 @@ +from starlette.requests import Request +from starlette.responses import * +from royalnet.constellation import * +from royalnet.utils import * + + +class ApiDiscordCvStar(PageStar): + path = "/api/discord/cv" + + async def page(self, request: Request) -> JSONResponse: + response = await self.constellation.call_herald_event("discord", "discord_cv") + return JSONResponse(response) diff --git a/royalpack/stars/api_user_get.py b/royalpack/stars/api_user_get.py index 87591b88..c8b95e6d 100644 --- a/royalpack/stars/api_user_get.py +++ b/royalpack/stars/api_user_get.py @@ -3,7 +3,6 @@ from starlette.responses import * from royalnet.constellation import * from royalnet.utils import * from royalnet.backpack.tables import * -from ..tables import * class ApiUserGetStar(PageStar): diff --git a/royalpack/stars/api_user_list.py b/royalpack/stars/api_user_list.py index 91e31c0e..969b9a37 100644 --- a/royalpack/stars/api_user_list.py +++ b/royalpack/stars/api_user_list.py @@ -3,7 +3,6 @@ from starlette.responses import * from royalnet.constellation import * from royalnet.utils import * from royalnet.backpack.tables import * -from ..tables import * class ApiUserListStar(PageStar):