-
Notifications
You must be signed in to change notification settings - Fork 10
/
bot.py
49 lines (44 loc) · 1.99 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from ui import SelectTextChannel, SelectVoiceChannel
import discord
import asyncio
from discord.ext import commands
from text2wav import text2wav
from Item import Item
import pyvcroid2
class VoiceroidTTSBot(commands.Cog):
def __init__(self, bot, vc):
self.bot: commands.Bot = bot
self.vcroid: pyvcroid2.VcRoid2 = vc
self.voice_channel: discord.VoiceChannel = None
self.voice_client: discord.VoiceClient = None
@commands.Cog.listener()
async def on_message(self, message: discord.Message):
if message.author.bot: # bot自身のメッセージは何もしない
return
if Item.text_channel is None: # 初期設定
# text channel選択画面出す
text_channels = message.guild.text_channels
await message.channel.send(
"読み上げるテキストチャンネルを選んでください",
view=SelectTextChannel(text_channels=text_channels[:5])
)
# voice channel選択画面出す
voice_channels = message.guild.voice_channels
await message.channel.send(
"ボイスチャンネルを選んでください",
view=SelectVoiceChannel(voice_channels=voice_channels[:5])
)
else:
# ここに読み上げの処理を書く
if not self.voice_client:
self.voice_client = await Item.voice_channel.connect()
if message.channel == Item.text_channel:
# 喋っている途中は待つ
while self.voice_client.is_playing():
await asyncio.sleep(0.1)
print(message.content)
source = discord.FFmpegPCMAudio(text2wav(self.vcroid, message.content))
self.voice_client.play(source)
@commands.command()
async def d(self, ctx: commands.Context):
print(f"debug: {Item.text_channel, Item.voice_channel}")