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

Add ZA WARUDO command

This commit is contained in:
Steffo 2019-09-10 01:30:37 +02:00
parent 4ebe2a5577
commit 3c3c777c83
5 changed files with 98 additions and 4 deletions

View file

@ -123,7 +123,7 @@ class DiscordBot(GenericBot):
await command.run(CommandArgs(parameters), data=data)
except InvalidInputError as e:
await data.reply(f":warning: {' '.join(e.args)}\n"
f"Syntax: [c]/{command.name} {command.syntax}[/c]")
f"Syntax: [c]!{command.name} {command.syntax}[/c]")
except Exception as e:
sentry_sdk.capture_exception(e)
error_message = f"🦀 {e.__class__.__name__} 🦀\n"
@ -235,7 +235,7 @@ class DiscordBot(GenericBot):
async def advance_music_data(self, guild: discord.Guild):
"""Try to play the next song, while it exists. Otherwise, just return."""
guild_music_data = self.music_data[guild]
voice_client = self.client.find_voice_client_by_guild(guild)
voice_client: discord.VoiceClient = self.client.find_voice_client_by_guild(guild)
next_source: discord.AudioSource = await guild_music_data.next()
await self.update_activity_with_source_title()
if next_source is None:
@ -244,6 +244,7 @@ class DiscordBot(GenericBot):
def advance(error=None):
if error:
voice_client.disconnect(force=True)
log.error(f"Error while advancing music_data: {error}")
return
self.loop.create_task(self.advance_music_data(guild))

View file

@ -24,6 +24,7 @@ from .dnditem import DnditemCommand
from .dndspell import DndspellCommand
from .trivia import TriviaCommand
from .mm import MmCommand
from .zawarudo import ZawarudoCommand
__all__ = [
"CiaoruoziCommand",
@ -46,5 +47,6 @@ __all__ = [
"DnditemCommand",
"DndspellCommand",
"TriviaCommand",
"MmCommand"
"MmCommand",
"ZawarudoCommand"
]

View file

@ -334,6 +334,8 @@ class MmCommand(Command):
def __init__(self, interface):
super().__init__(interface)
if self.interface.name != "telegram":
return
log.debug("Loading pending MMEvents from the database")
mmevents = self.interface.session.query(self.interface.alchemy.MMEvent) \
.filter(self.interface.alchemy.MMEvent.datetime > datetime.datetime.now()) \

View file

@ -0,0 +1,88 @@
import typing
import discord
import asyncio
from ..command import Command
from ..commandinterface import CommandInterface
from ..commandargs import CommandArgs
from ..commanddata import CommandData
from ...utils import NetworkHandler, asyncify
from ...network import Request, ResponseSuccess
from ...error import *
from ...audio import YtdlDiscord
from ...audio.playmodes import Playlist
if typing.TYPE_CHECKING:
from ...bots import DiscordBot
class ZawarudoNH(NetworkHandler):
message_type = "music_zawarudo"
ytdl_args = {
"format": "bestaudio",
"outtmpl": f"./downloads/%(title)s.%(ext)s"
}
@classmethod
async def discord(cls, bot: "DiscordBot", data: dict):
# Find the matching guild
if data["guild_name"]:
guild = bot.client.find_guild(data["guild_name"])
else:
if len(bot.music_data) == 0:
raise NoneFoundError("No voice clients active")
if len(bot.music_data) > 1:
raise TooManyFoundError("Multiple guilds found")
guild = list(bot.music_data)[0]
# Ensure the guild has a PlayMode before adding the file to it
if not bot.music_data.get(guild):
# TODO: change Exception
raise Exception("No music_data for this guild")
# Start downloading
zw_start: typing.List[YtdlDiscord] = await asyncify(YtdlDiscord.create_and_ready_from_url,
"https://scaleway.steffo.eu/jojo/zawarudo_intro.mp3",
**cls.ytdl_args)
zw_end: typing.List[YtdlDiscord] = await asyncify(YtdlDiscord.create_and_ready_from_url,
"https://scaleway.steffo.eu/jojo/zawarudo_outro.mp3",
**cls.ytdl_args)
# Clear playlist
if bot.music_data[guild] is not None:
bot.music_data[guild].delete()
bot.music_data[guild] = Playlist()
# Get voice client
vc: discord.VoiceClient = bot.client.find_voice_client_by_guild(guild)
channel: discord.VoiceChannel = vc.channel
await bot.add_to_music_data(zw_start, guild)
for member in channel.members:
member: typing.Union[discord.User, discord.Member]
if member.bot:
continue
await member.edit(mute=True)
await asyncio.sleep(data["time"])
await bot.add_to_music_data(zw_end, guild)
for member in channel.members:
member: typing.Union[discord.User, discord.Member]
if member.bot:
continue
await member.edit(mute=False)
return ResponseSuccess()
class ZawarudoCommand(Command):
name: str = "zawarudo"
description: str = "Ferma il tempo!"
syntax = "[ [guild] ] [durata]"
def __init__(self, interface: CommandInterface):
super().__init__(interface)
interface.register_net_handler(ZawarudoNH.message_type, ZawarudoNH)
async def run(self, args: CommandArgs, data: CommandData) -> None:
guild_name, time = args.match(r"(?:\[(.+)])?\s*(.+)?")
if time is None:
time = 5
else:
time = int(time)
await data.reply(f"🕒 ZA WARUDO! TOKI WO TOMARE!")
await self.interface.net_request(Request(ZawarudoNH.message_type, {"time": time, "guild_name": guild_name}), "discord")

View file

@ -42,7 +42,8 @@ if __debug__:
SummonCommand,
VideochannelCommand,
TriviaCommand,
MmCommand
MmCommand,
ZawarudoCommand
]
log.setLevel(logging.DEBUG)
else: