Compare commits
4 Commits
c6c5d9c9a7
...
bce9abd10a
Author | SHA1 | Date | |
---|---|---|---|
bce9abd10a | |||
c84831aac2 | |||
10b280d6dc | |||
84182d0d28 |
@ -20,7 +20,7 @@ License: `GNU GENERAL PUBLIC LICENSE Version 3`
|
||||
Author discord: `a31#6403`
|
||||
Author email: `a31@demb.design`
|
||||
Source code on github: <https://github.com/norohind/SileroTTSBot>
|
||||
Source code on gitea's a31 instance: <https://gitea.demb.design/a31/SileroTTSBot>
|
||||
Source code on gitea a31's instance: <https://gitea.demb.design/a31/SileroTTSBot>
|
||||
Invite link: https://discord.com/oauth2/authorize?client_id={self.bot.user.id}&scope=bot%20applications.commands
|
||||
"""
|
||||
|
||||
|
@ -25,8 +25,29 @@ class TTSCore(commands.Cog, Observ.Observer):
|
||||
self.tts_queues: dict[int, list[discord.AudioSource]] = defaultdict(list)
|
||||
self.speakers_adapter: SpeakersSettingsAdapterDiscord = speakers_settings_adapter
|
||||
|
||||
@commands.command('drop')
|
||||
async def drop_queue(self, ctx: Context):
|
||||
"""
|
||||
Drop tts queue for current server
|
||||
|
||||
:param ctx:
|
||||
:return:
|
||||
"""
|
||||
try:
|
||||
del self.tts_queues[ctx.guild.id]
|
||||
await ctx.send('Queue dropped')
|
||||
|
||||
except KeyError:
|
||||
await ctx.send('Failed on dropping queue')
|
||||
|
||||
@commands.command('exit')
|
||||
async def leave_voice(self, ctx: Context):
|
||||
"""
|
||||
Disconnect bot from current channel, it also drop messages queue
|
||||
|
||||
:param ctx:
|
||||
:return:
|
||||
"""
|
||||
if ctx.guild.voice_client is not None:
|
||||
await ctx.guild.voice_client.disconnect(force=False)
|
||||
await ctx.channel.send(f"Left voice channel")
|
||||
@ -64,6 +85,10 @@ class TTSCore(commands.Cog, Observ.Observer):
|
||||
if voice_client is None:
|
||||
voice_client: discord.VoiceClient = await user_voice_state.channel.connect()
|
||||
|
||||
if user_voice_state.channel.id != voice_client.channel.id:
|
||||
await message.channel.send('We are in different voice channels')
|
||||
return
|
||||
|
||||
speaker: Speakers = self.speakers_adapter.get_speaker(message.guild.id, message.author.id)
|
||||
|
||||
# check if message will fail on synthesis
|
||||
@ -101,14 +126,21 @@ class TTSCore(commands.Cog, Observ.Observer):
|
||||
return
|
||||
|
||||
def queue_player(self, message: discord.Message):
|
||||
voice_client: Optional[discord.VoiceClient] = message.guild.voice_client
|
||||
if voice_client is None:
|
||||
# don't play anything and clear queue for whole guild
|
||||
del self.tts_queues[message.guild.id]
|
||||
return
|
||||
|
||||
for sound_source in self.tts_queues[message.guild.id]:
|
||||
voice_client.play(sound_source)
|
||||
if len(self.tts_queues[message.guild.id]) == 0:
|
||||
return
|
||||
|
||||
voice_client: Optional[discord.VoiceClient] = message.guild.voice_client
|
||||
if voice_client is None:
|
||||
# don't play anything and clear queue for whole guild
|
||||
break
|
||||
|
||||
try:
|
||||
voice_client.play(sound_source)
|
||||
|
||||
except discord.errors.ClientException: # Here we expect Not connected to voice
|
||||
break
|
||||
|
||||
while voice_client.is_playing():
|
||||
time.sleep(0.1)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user