1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-24 03:54:20 +00:00

Add !videochannel command

This commit is contained in:
Steffo 2019-04-24 17:27:05 +02:00
parent 483668fe1f
commit 04151d337a
5 changed files with 53 additions and 9 deletions

View file

@ -24,7 +24,8 @@ logging.getLogger("royalnet.bots.telegram").setLevel(logging.DEBUG)
commands = [PingCommand, ShipCommand, SmecdsCommand, ColorCommand, CiaoruoziCommand, DebugCreateCommand, SyncCommand, commands = [PingCommand, ShipCommand, SmecdsCommand, ColorCommand, CiaoruoziCommand, DebugCreateCommand, SyncCommand,
AuthorCommand, DiarioCommand, RageCommand, DateparserCommand, ReminderCommand, KvactiveCommand, KvCommand, AuthorCommand, DiarioCommand, RageCommand, DateparserCommand, ReminderCommand, KvactiveCommand, KvCommand,
KvrollCommand, VideoinfoCommand, SummonCommand, PlayCommand, SkipCommand, PlaymodeCommand] KvrollCommand, VideoinfoCommand, SummonCommand, PlayCommand, SkipCommand, PlaymodeCommand,
VideochannelCommand]
address, port = "localhost", 1234 address, port = "localhost", 1234

View file

@ -18,9 +18,10 @@ from .summon import SummonCommand
from .play import PlayCommand from .play import PlayCommand
from .skip import SkipCommand from .skip import SkipCommand
from .playmode import PlaymodeCommand from .playmode import PlaymodeCommand
from .videochannel import VideochannelCommand
__all__ = ["NullCommand", "PingCommand", "ShipCommand", "SmecdsCommand", "CiaoruoziCommand", "ColorCommand", __all__ = ["NullCommand", "PingCommand", "ShipCommand", "SmecdsCommand", "CiaoruoziCommand", "ColorCommand",
"SyncCommand", "DiarioCommand", "RageCommand", "DateparserCommand", "AuthorCommand", "ReminderCommand", "SyncCommand", "DiarioCommand", "RageCommand", "DateparserCommand", "AuthorCommand", "ReminderCommand",
"KvactiveCommand", "KvCommand", "KvrollCommand", "VideoinfoCommand", "SummonCommand", "PlayCommand", "KvactiveCommand", "KvCommand", "KvrollCommand", "VideoinfoCommand", "SummonCommand", "PlayCommand",
"SkipCommand", "PlaymodeCommand"] "SkipCommand", "PlaymodeCommand", "VideochannelCommand"]

View file

@ -23,29 +23,29 @@ class ErrorHandlerCommand(Command):
async def common(cls, call: Call): async def common(cls, call: Call):
exception: Exception = call.kwargs["exception"] exception: Exception = call.kwargs["exception"]
if isinstance(exception, NoneFoundError): if isinstance(exception, NoneFoundError):
await call.reply("⚠️ L'elemento richiesto non è stato trovato.") await call.reply(f"⚠️ L'elemento richiesto non è stato trovato.\n[p]{exception}[/p]")
return return
if isinstance(exception, TooManyFoundError): if isinstance(exception, TooManyFoundError):
await call.reply("⚠️ La richiesta effettuata è ambigua, pertanto è stata annullata.") await call.reply(f"⚠️ La richiesta effettuata è ambigua, pertanto è stata annullata.\n[p]{exception}[/p]")
return return
if isinstance(exception, UnregisteredError): if isinstance(exception, UnregisteredError):
await call.reply("⚠️ Devi essere registrato a Royalnet per usare questo comando!") await call.reply("⚠️ Devi essere registrato a Royalnet per usare questo comando.\nUsa il comando [c]sync[/c] per registrarti!")
return return
if isinstance(exception, UnsupportedError): if isinstance(exception, UnsupportedError):
await call.reply("⚠️ Il comando richiesto non è disponibile tramite questa interfaccia.") await call.reply(f"⚠️ Il comando richiesto non è disponibile tramite l'interfaccia [c]{call.interface_name}[/c].")
return return
if isinstance(exception, InvalidInputError): if isinstance(exception, InvalidInputError):
command = call.kwargs["previous_command"] command = call.kwargs["previous_command"]
await call.reply(f"⚠️ Sintassi non valida.\nSintassi corretta: [c]{call.interface_prefix}{command.command_name} {command.command_syntax}[/c]") await call.reply(f"⚠️ Sintassi non valida.\nSintassi corretta: [c]{call.interface_prefix}{command.command_name} {command.command_syntax}[/c]")
return return
if isinstance(exception, InvalidConfigError): if isinstance(exception, InvalidConfigError):
await call.reply("⚠️ Il bot non è stato configurato correttamente, quindi questo comando non può essere eseguito. L'errore è stato segnalato all'amministratore.") await call.reply(f"⚠️ Il bot non è stato configurato correttamente, quindi questo comando non può essere eseguito.\n[p]{exception}[/p]")
return return
if isinstance(exception, RoyalnetError): if isinstance(exception, RoyalnetError):
await call.reply(f"⚠️ La richiesta a Royalnet ha restituito un errore: [p]{exception.exc}[/p]") await call.reply(f"⚠️ La richiesta a Royalnet ha restituito un errore: [p]{exception.exc}[/p]")
return return
if isinstance(exception, ExternalError): if isinstance(exception, ExternalError):
await call.reply("⚠️ Una risorsa esterna necessaria per l'esecuzione del comando non ha funzionato correttamente, quindi il comando è stato annullato.") await call.reply(f"⚠️ Una risorsa esterna necessaria per l'esecuzione del comando non ha funzionato correttamente, quindi il comando è stato annullato.\n[p]{exception}[/p]")
return return
await call.reply(f"❌ Eccezione non gestita durante l'esecuzione del comando:\n[b]{exception.__class__.__name__}[/b]\n[p]{exception}[/p]") await call.reply(f"❌ Eccezione non gestita durante l'esecuzione del comando:\n[b]{exception.__class__.__name__}[/b]\n[p]{exception}[/p]")
log.error(f"Unhandled exception - {exception.__class__.__name__}: {exception}") log.error(f"Unhandled exception - {exception.__class__.__name__}: {exception}")

View file

@ -6,7 +6,7 @@ from ..error import InvalidInputError
class PingCommand(Command): class PingCommand(Command):
command_name = "ping" command_name = "ping"
command_description = "Ping pong!" command_description = "Ping pong dopo un po' di tempo!"
command_syntax = "[time_to_wait]" command_syntax = "[time_to_wait]"
@classmethod @classmethod

View file

@ -0,0 +1,42 @@
import discord
import typing
from ..utils import Command, Call
class VideochannelCommand(Command):
command_name = "videochannel"
command_description = "Converti il canale vocale in un canale video."
command_syntax = "[channelname]"
@classmethod
async def discord(cls, call: Call):
bot = call.interface_obj.client
message: discord.Message = call.kwargs["message"]
channel_name: str = call.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:
await call.reply("⚠️ Non esiste alcun canale vocale con il nome specificato.")
return
elif len(matching_channels) > 1:
await call.reply("⚠️ Esiste più di un canale vocale con il nome specificato.")
return
channel = matching_channels[0]
else:
author: discord.Member = message.author
voice: typing.Optional[discord.VoiceState] = author.voice
if voice is None:
await call.reply("⚠️ Non sei connesso a nessun canale vocale!")
return
channel = voice.channel
await call.reply(f"📹 Per entrare in modalità video, clicca qui: <https://discordapp.com/channels/{channel.guild.id}/{channel.id}>")