1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-12-17 23:24:20 +00:00
royalnet/royalpack/commands/videochannel.py

50 lines
2.3 KiB
Python
Raw Normal View History

2020-05-10 22:46:12 +00:00
from typing import *
2019-11-11 08:56:08 +00:00
import discord
2020-05-10 22:46:12 +00:00
import royalnet.commands as rc
2019-11-11 08:56:08 +00:00
2020-05-10 22:46:12 +00:00
class VideochannelCommand(rc.Command):
2019-11-11 08:56:08 +00:00
name: str = "videochannel"
aliases = ["golive", "live", "video"]
description: str = "Converti il canale vocale in un canale video."
2019-11-29 19:05:09 +00:00
syntax = "[nomecanale]"
2019-11-11 08:56:08 +00:00
2020-05-10 22:46:12 +00:00
async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None:
2019-11-29 19:05:09 +00:00
if self.interface.name != "discord":
2020-05-10 22:46:12 +00:00
raise rc.UnsupportedError(f"{self} non è supportato su {self.interface.name}.")
2019-11-29 19:05:09 +00:00
bot: discord.Client = self.serf.client
message: discord.Message = data.message
channel_name: str = args.optional(0)
if channel_name:
2020-05-10 22:46:12 +00:00
guild: Optional[discord.Guild] = message.guild
2019-11-29 19:05:09 +00:00
if guild is not None:
2020-05-10 22:46:12 +00:00
channels: List[discord.abc.GuildChannel] = guild.channels
2019-11-11 08:56:08 +00:00
else:
2019-11-29 19:05:09 +00:00
channels = bot.get_all_channels()
2020-05-10 22:46:12 +00:00
matching_channels: List[discord.VoiceChannel] = []
2019-11-29 19:05:09 +00:00
for channel in channels:
if isinstance(channel, discord.VoiceChannel):
if channel.name == channel_name:
matching_channels.append(channel)
if len(matching_channels) == 0:
2020-05-10 22:46:12 +00:00
raise rc.InvalidInputError("Non esiste alcun canale vocale con il nome specificato.")
2019-11-29 19:05:09 +00:00
elif len(matching_channels) > 1:
2020-05-10 22:46:12 +00:00
raise rc.UserError("Esiste più di un canale vocale con il nome specificato.")
2019-11-29 19:05:09 +00:00
channel = matching_channels[0]
2019-11-11 08:56:08 +00:00
else:
2019-11-29 19:05:09 +00:00
author: discord.Member = message.author
2020-05-10 22:46:12 +00:00
voice: Optional[discord.VoiceState] = author.voice
2019-11-29 19:05:09 +00:00
if voice is None:
2020-05-10 22:46:12 +00:00
raise rc.InvalidInputError("Non sei connesso a nessun canale vocale.")
2019-11-29 19:05:09 +00:00
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}>")