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

Some new commands (that don't really work)

This commit is contained in:
Steffo 2019-12-02 21:25:56 +01:00
parent 58e8285a9b
commit 5603f40e9f
6 changed files with 50 additions and 141 deletions

View file

@ -16,14 +16,16 @@ from .play import PlayCommand
# from .queue import QueueCommand # from .queue import QueueCommand
from .skip import SkipCommand from .skip import SkipCommand
from .summon import SummonCommand from .summon import SummonCommand
# from .youtube import YoutubeCommand from .youtube import YoutubeCommand
# from .soundcloud import SoundcloudCommand from .soundcloud import SoundcloudCommand
# from .zawarudo import ZawarudoCommand # from .zawarudo import ZawarudoCommand
from .emojify import EmojifyCommand from .emojify import EmojifyCommand
from .leagueoflegends import LeagueoflegendsCommand from .leagueoflegends import LeagueoflegendsCommand
from .diarioquote import DiarioquoteCommand from .diarioquote import DiarioquoteCommand
# from .mp3 import Mp3Command # from .mp3 import Mp3Command
from .peertube import PeertubeCommand from .peertube import PeertubeCommand
from .googlevideo import GooglevideoCommand
from .yahoovideo import YahoovideoCommand
# Enter the commands of your Pack here! # Enter the commands of your Pack here!
available_commands = [ available_commands = [
@ -44,14 +46,16 @@ available_commands = [
# QueueCommand, # QueueCommand,
SkipCommand, SkipCommand,
SummonCommand, SummonCommand,
# YoutubeCommand, YoutubeCommand,
# SoundcloudCommand, SoundcloudCommand,
# ZawarudoCommand, # ZawarudoCommand,
EmojifyCommand, EmojifyCommand,
LeagueoflegendsCommand, LeagueoflegendsCommand,
DiarioquoteCommand, DiarioquoteCommand,
# Mp3Command, # Mp3Command,
PeertubeCommand, PeertubeCommand,
GooglevideoCommand,
YahoovideoCommand,
] ]
# Don't change this, it should automatically generate __all__ # Don't change this, it should automatically generate __all__

View file

@ -0,0 +1,13 @@
from .play import PlayCommand
class GooglevideoCommand(PlayCommand):
name: str = "googlevideo"
aliases = ["gv"]
description: str = "Cerca un video su Google Video e lo aggiunge alla coda della chat vocale."
syntax = "{ricerca}"
_URL_FORMAT = "gvsearch:{url}"

View file

@ -15,6 +15,8 @@ class PlayCommand(Command):
syntax = "{url}" syntax = "{url}"
_URL_FORMAT = "{url}"
async def run(self, args: CommandArgs, data: CommandData) -> None: async def run(self, args: CommandArgs, data: CommandData) -> None:
url = args.joined() url = args.joined()
# if not (url.startswith("http://") or url.startswith("https://")): # if not (url.startswith("http://") or url.startswith("https://")):
@ -29,7 +31,8 @@ class PlayCommand(Command):
else: else:
guild_id = None guild_id = None
response: Dict[str, Any] = await self.interface.call_herald_event("discord", "discord_play", response: Dict[str, Any] = await self.interface.call_herald_event("discord", "discord_play",
url=url, guild_id=guild_id) url=self._URL_FORMAT.format(url=url),
guild_id=guild_id)
too_long: List[Dict[str, Any]] = response["too_long"] too_long: List[Dict[str, Any]] = response["too_long"]
if len(too_long) > 0: if len(too_long) > 0:
@ -51,3 +54,6 @@ class PlayCommand(Command):
else: else:
reply += numberemojiformat([a["title"] for a in added]) reply += numberemojiformat([a["title"] for a in added])
await data.reply(reply) await data.reply(reply)
if len(added) + len(too_long) == 0:
raise ExternalError("Nessun video trovato.")

View file

@ -1,77 +1,13 @@
import typing from .play import PlayCommand
import pickle
import datetime
import discord
from royalnet.commands import *
from royalnet.utils import asyncify
from royalnet.audio import YtdlDiscord
from royalnet.bots import DiscordBot
class SoundcloudCommand(Command): class SoundcloudCommand(PlayCommand):
name: str = "soundcloud" name: str = "soundcloud"
aliases = ["sc"] aliases = ["sc"]
description: str = "Cerca una canzone su Soundcloud e la aggiunge alla coda della chat vocale." description: str = "Cerca un video su SoundCloud e lo aggiunge alla coda della chat vocale."
syntax = "[ [guild] ] {url}" syntax = "{ricerca}"
@staticmethod _URL_FORMAT = "scsearch:{url}"
async def _legacy_soundcloud_handler(bot: "DiscordBot", guild_name: typing.Optional[str], search: str):
# Find the matching guild
if guild_name:
guilds: typing.List[discord.Guild] = bot.client.find_guild_by_name(guild_name)
else:
guilds = bot.client.guilds
if len(guilds) == 0:
raise CommandError("Server non trovato.")
if len(guilds) > 1:
raise CommandError("Il nome del server è ambiguo.")
guild = list(bot.client.guilds)[0]
# Ensure the guild has a PlayMode before adding the file to it
if not bot.music_data.get(guild):
raise CommandError("Il bot non è in nessun canale vocale.")
# Create url
ytdl_args = {
"format": "bestaudio/best",
"outtmpl": f"./downloads/{datetime.datetime.now().timestamp()}_%(title)s.%(ext)s"
}
# Start downloading
dfiles: typing.List[YtdlDiscord] = await asyncify(YtdlDiscord.create_from_url, f'scsearch:{search}',
**ytdl_args)
await bot.add_to_music_data(dfiles, guild)
# Create response dictionary
return {
"videos": [{
"title": dfile.info.title,
"discord_embed_pickle": str(pickle.dumps(dfile.info.to_discord_embed()))
} for dfile in dfiles]
}
_event_name = "_legacy_soundcloud"
def __init__(self, interface: CommandInterface):
super().__init__(interface)
if interface.name == "discord":
interface.register_herald_action(self._event_name, self._legacy_soundcloud_handler)
async def run(self, args: CommandArgs, data: CommandData) -> None:
guild_name, search = args.match(r"(?:\[(.+)])?\s*<?(.+)>?")
if search.startswith("http://") or search.startswith("https://"):
raise CommandError(f"Il comando [c]{self.interface.prefix}soundcloud[/c] funziona solo per cercare audio su"
f" Soundcloud con un dato nome.\n"
f"Se vuoi riprodurre una canzone da un URL, usa [c]{self.interface.prefix}play[/c]!")
response = await self.interface.call_herald_action("discord", self._event_name, {
"guild_name": guild_name,
"search": search
})
if len(response["videos"]) == 0:
raise CommandError(f"Il video non può essere scaricato a causa di un blocco imposto da Soundcloud.")
for video in response["videos"]:
if self.interface.name == "discord":
# This is one of the unsafest things ever
embed = pickle.loads(eval(video["discord_embed_pickle"]))
await data.message.channel.send(content="▶️ Aggiunto alla coda:", embed=embed)
else:
await data.reply(f"▶️ Aggiunto alla coda: [i]{video['title']}[/i]")

View file

@ -0,0 +1,13 @@
from .play import PlayCommand
class YahoovideoCommand(PlayCommand):
name: str = "yahoovideo"
aliases = ["yv"]
description: str = "Cerca un video su Yahoo Video e lo aggiunge alla coda della chat vocale."
syntax = "{ricerca}"
_URL_FORMAT = "yvsearch:{url}"

View file

@ -1,76 +1,13 @@
import typing from .play import PlayCommand
import pickle
import datetime
import discord
from royalnet.commands import *
from royalnet.utils import asyncify
from royalnet.audio import YtdlDiscord
from royalnet.bots import DiscordBot
class YoutubeCommand(Command): class YoutubeCommand(PlayCommand):
name: str = "youtube" name: str = "youtube"
aliases = ["yt"] aliases = ["yt"]
description: str = "Cerca un video su YouTube e lo aggiunge alla coda della chat vocale." description: str = "Cerca un video su YouTube e lo aggiunge alla coda della chat vocale."
syntax = "[ [guild] ] {url}" syntax = "{ricerca}"
@classmethod _URL_FORMAT = "ytsearch:{url}"
async def _legacy_youtube_handler(cls, bot: "DiscordBot", guild_name: typing.Optional[str], search: str):
# Find the matching guild
if guild_name:
guilds: typing.List[discord.Guild] = bot.client.find_guild_by_name(guild_name)
else:
guilds = bot.client.guilds
if len(guilds) == 0:
raise CommandError("Server non trovato.")
if len(guilds) > 1:
raise CommandError("Il nome del server è ambiguo.")
guild = list(bot.client.guilds)[0]
# Ensure the guild has a PlayMode before adding the file to it
if not bot.music_data.get(guild):
raise CommandError("Il bot non è in nessun canale vocale.")
# Create url
ytdl_args = {
"format": "bestaudio/best",
"outtmpl": f"./downloads/{datetime.datetime.now().timestamp()}_%(title)s.%(ext)s"
}
# Start downloading
dfiles: typing. List[YtdlDiscord] = await asyncify(YtdlDiscord.create_from_url, f'ytsearch:{search}', **ytdl_args)
await bot.add_to_music_data(dfiles, guild)
# Create response dictionary
return {
"videos": [{
"title": dfile.info.title,
"discord_embed_pickle": str(pickle.dumps(dfile.info.to_discord_embed()))
} for dfile in dfiles]
}
_event_name = "_legacy_youtube"
def __init__(self, interface: CommandInterface):
super().__init__(interface)
if interface.name == "discord":
interface.register_herald_action(self._event_name, self._legacy_youtube_handler)
async def run(self, args: CommandArgs, data: CommandData) -> None:
guild_name, search = args.match(r"(?:\[(.+)])?\s*<?(.+)>?")
if search.startswith("http://") or search.startswith("https://"):
raise CommandError(f"Il comando [c]{self.interface.prefix}youtube[/c] funziona solo per cercare video su"
f" YouTube con un dato nome.\n"
f"Se vuoi riprodurre una canzone da un URL, usa [c]{self.interface.prefix}play[/c]!")
response = await self.interface.call_herald_action("discord", self._event_name, {
"guild_name": guild_name,
"search": search
})
if len(response["videos"]) == 0:
raise CommandError(f"Il video non può essere scaricato a causa di un blocco imposto da YouTube.")
for video in response["videos"]:
if self.interface.name == "discord":
# This is one of the unsafest things ever
embed = pickle.loads(eval(video["discord_embed_pickle"]))
await data.message.channel.send(content="▶️ Aggiunto alla coda:", embed=embed)
else:
await data.reply(f"▶️ Aggiunto alla coda: [i]{video['title']}[/i]")