1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00

Commands, commands, commands!

This commit is contained in:
Steffo 2019-11-29 20:05:09 +01:00
parent 2771db22ae
commit a55e71d4f7
8 changed files with 49 additions and 40 deletions

View file

@ -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,

View file

@ -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"<https://discordapp.com/channels/{channel.guild.id}/{channel.id}>\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"<https://discordapp.com/channels/{channel.guild.id}/{channel.id}>")
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"<https://discordapp.com/channels/{channel.guild.id}/{channel.id}>\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"<https://discordapp.com/channels/{channel.guild.id}/{channel.id}>")

View file

@ -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!

View file

@ -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 *

View file

@ -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 *

View file

@ -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)

View file

@ -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):

View file

@ -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):