Fix quote tts
This commit is contained in:
9
bot.py
9
bot.py
@@ -795,11 +795,12 @@ async def quote_random_slash(ctx: SlashContext, author: Optional[str] = None, tt
|
||||
if tts:
|
||||
voice: discord.VoiceState = ctx.author.voice
|
||||
if voice.channel is not None:
|
||||
async def after_play(e: discord.DiscordException, vp: discord.VoiceProtocol):
|
||||
await vp.disconnect(force=True)
|
||||
source, tts_destroyer = text_to_speech(author + " sagte: " + quote)
|
||||
vp: discord.VoiceClient = await connect_and_play(voice.channel, source)
|
||||
while vp.is_playing() and vp.channel == voice.channel:
|
||||
await asyncio.sleep(0.5)
|
||||
|
||||
source, tts_destroyer = text_to_speech(quote)
|
||||
await connect_and_play(voice.channel, source, after_play=after_play)
|
||||
await vp.disconnect()
|
||||
tts_destroyer()
|
||||
|
||||
|
||||
|
||||
@@ -53,8 +53,8 @@ def text_to_speech(text: str, lang: str = "de") -> (discord.AudioSource, Callabl
|
||||
|
||||
async def connect_and_play(
|
||||
channel: discord.VoiceChannel, source: discord.AudioSource,
|
||||
after_play: Optional[Callable[[discord.DiscordException, discord.VoiceProtocol], Coroutine[Any, Any, Any]]] = None
|
||||
) -> Optional[discord.VoiceProtocol]:
|
||||
after_play: Optional[Callable[[discord.DiscordException, discord.VoiceProtocol], Any]] = None
|
||||
) -> Optional[discord.VoiceClient]:
|
||||
# noinspection PyTypeChecker
|
||||
client: discord.VoiceClient = await channel.connect()
|
||||
after_callback: Optional[Callable[[discord.DiscordException], Any]]
|
||||
@@ -62,8 +62,7 @@ async def connect_and_play(
|
||||
after_callback = None
|
||||
else:
|
||||
def callback(exc: discord.DiscordException) -> Any:
|
||||
loop = asyncio.get_event_loop()
|
||||
return loop.run_until_complete(after_play(exc, client))
|
||||
after_play(exc, client)
|
||||
|
||||
after_callback = callback
|
||||
|
||||
|
||||
Reference in New Issue
Block a user