add 新增 lottery.py 複習、總複習功能
This commit is contained in:
parent
e2c7bf8896
commit
3b948c5fda
|
|
@ -21,7 +21,7 @@ class Lottery(commands.Cog):
|
||||||
self.aniList = random.sample(range(0, len(self.aniData)), len(self.aniData))
|
self.aniList = random.sample(range(0, len(self.aniData)), len(self.aniData))
|
||||||
self.stop = False
|
self.stop = False
|
||||||
|
|
||||||
# --- Slash Command with Choice ---
|
# --- 建立抽選清單 ---
|
||||||
@app_commands.guilds(discord.Object(id=605678541530726421))
|
@app_commands.guilds(discord.Object(id=605678541530726421))
|
||||||
@app_commands.command(name="建立抽選清單", description="建立寶可夢或動畫角色的抽選清單")
|
@app_commands.command(name="建立抽選清單", description="建立寶可夢或動畫角色的抽選清單")
|
||||||
@app_commands.choices(list_name=[
|
@app_commands.choices(list_name=[
|
||||||
|
|
@ -47,7 +47,7 @@ class Lottery(commands.Cog):
|
||||||
|
|
||||||
await interaction.response.send_message(msg, ephemeral=True)
|
await interaction.response.send_message(msg, ephemeral=True)
|
||||||
|
|
||||||
|
# --- 顯示清單狀態 ---
|
||||||
@app_commands.guilds(discord.Object(id=605678541530726421))
|
@app_commands.guilds(discord.Object(id=605678541530726421))
|
||||||
@app_commands.command(name="抽選清單", description="檢視所有抽選清單及目前抽選狀態")
|
@app_commands.command(name="抽選清單", description="檢視所有抽選清單及目前抽選狀態")
|
||||||
async def show_list(self, interaction: discord.Interaction):
|
async def show_list(self, interaction: discord.Interaction):
|
||||||
|
|
@ -58,6 +58,7 @@ class Lottery(commands.Cog):
|
||||||
f'動畫角色清單:共{len(self.aniData)}個,正準備抽選第 {aniCount} 個'
|
f'動畫角色清單:共{len(self.aniData)}個,正準備抽選第 {aniCount} 個'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# --- 抽寶可夢 ---
|
||||||
@app_commands.guilds(discord.Object(id=605678541530726421))
|
@app_commands.guilds(discord.Object(id=605678541530726421))
|
||||||
@app_commands.command(name="抽寶可夢", description="顯示題目,並於指定秒數後公布答案圖片")
|
@app_commands.command(name="抽寶可夢", description="顯示題目,並於指定秒數後公布答案圖片")
|
||||||
@app_commands.describe(t="倒數秒數(需大於5)")
|
@app_commands.describe(t="倒數秒數(需大於5)")
|
||||||
|
|
@ -71,18 +72,13 @@ class Lottery(commands.Cog):
|
||||||
return
|
return
|
||||||
|
|
||||||
if interaction.user.voice and interaction.user.voice.channel:
|
if interaction.user.voice and interaction.user.voice.channel:
|
||||||
if interaction.guild.voice_client is None:
|
vc = interaction.guild.voice_client or await interaction.user.voice.channel.connect()
|
||||||
vc = await interaction.user.voice.channel.connect()
|
|
||||||
else:
|
|
||||||
vc = interaction.guild.voice_client
|
|
||||||
|
|
||||||
idx = self.pokeList[self.getPokeCount]
|
idx = self.pokeList[self.getPokeCount]
|
||||||
poke = self.pokeData[idx]
|
poke = self.pokeData[idx]
|
||||||
self.getPokeCount += 1
|
self.getPokeCount += 1
|
||||||
|
|
||||||
await interaction.response.send_message(
|
await interaction.response.send_message(f'第 {self.getPokeCount} 抽\n{poke["name"]} \n倒數 {t} 秒,開始!')
|
||||||
f'第 {self.getPokeCount} 抽\n{poke["name"]} \n倒數 {t} 秒,開始!'
|
|
||||||
)
|
|
||||||
|
|
||||||
await asyncio.sleep(t - 5)
|
await asyncio.sleep(t - 5)
|
||||||
if not vc.is_playing():
|
if not vc.is_playing():
|
||||||
|
|
@ -100,6 +96,7 @@ class Lottery(commands.Cog):
|
||||||
else:
|
else:
|
||||||
await interaction.response.send_message("請先加入語音頻道", ephemeral=True)
|
await interaction.response.send_message("請先加入語音頻道", ephemeral=True)
|
||||||
|
|
||||||
|
# --- 抽動畫角色 ---
|
||||||
@app_commands.guilds(discord.Object(id=605678541530726421))
|
@app_commands.guilds(discord.Object(id=605678541530726421))
|
||||||
@app_commands.command(name="抽動畫角色", description="顯示題目,並於指定秒數後公布答案圖片")
|
@app_commands.command(name="抽動畫角色", description="顯示題目,並於指定秒數後公布答案圖片")
|
||||||
@app_commands.describe(t="倒數秒數(需大於5)")
|
@app_commands.describe(t="倒數秒數(需大於5)")
|
||||||
|
|
@ -113,18 +110,13 @@ class Lottery(commands.Cog):
|
||||||
return
|
return
|
||||||
|
|
||||||
if interaction.user.voice and interaction.user.voice.channel:
|
if interaction.user.voice and interaction.user.voice.channel:
|
||||||
if interaction.guild.voice_client is None:
|
vc = interaction.guild.voice_client or await interaction.user.voice.channel.connect()
|
||||||
vc = await interaction.user.voice.channel.connect()
|
|
||||||
else:
|
|
||||||
vc = interaction.guild.voice_client
|
|
||||||
|
|
||||||
idx = self.aniList[self.getAniCount]
|
idx = self.aniList[self.getAniCount]
|
||||||
ani = self.aniData[idx]
|
ani = self.aniData[idx]
|
||||||
self.getAniCount += 1
|
self.getAniCount += 1
|
||||||
|
|
||||||
await interaction.response.send_message(
|
await interaction.response.send_message(f'第 {self.getAniCount} 抽\n{ani["animate"]} 的 {ani["character"]}\n倒數 {t} 秒,開始!')
|
||||||
f'第 {self.getAniCount} 抽\n{ani["animate"]} 的 {ani["character"]}\n倒數 {t} 秒,開始!'
|
|
||||||
)
|
|
||||||
|
|
||||||
await asyncio.sleep(t - 5)
|
await asyncio.sleep(t - 5)
|
||||||
if not vc.is_playing():
|
if not vc.is_playing():
|
||||||
|
|
@ -142,6 +134,49 @@ class Lottery(commands.Cog):
|
||||||
else:
|
else:
|
||||||
await interaction.response.send_message("請先加入語音頻道", ephemeral=True)
|
await interaction.response.send_message("請先加入語音頻道", ephemeral=True)
|
||||||
|
|
||||||
|
# --- 新增:動畫角色單一複習 ---
|
||||||
|
@app_commands.guilds(discord.Object(id=605678541530726421))
|
||||||
|
@app_commands.command(name="動畫角色複習", description="顯示指定編號的角色")
|
||||||
|
@app_commands.describe(num="想要查看的角色編號 (從 1 開始)")
|
||||||
|
async def check_ani(self, interaction: discord.Interaction, num: int = 1):
|
||||||
|
if num <= 0 or num > len(self.aniData):
|
||||||
|
await interaction.response.send_message(f'超過範圍 1~{len(self.aniData)}', ephemeral=True)
|
||||||
|
return
|
||||||
|
|
||||||
|
ani = self.aniData[num - 1]
|
||||||
|
embed = discord.Embed(title=f'第 {num} 號角色', timestamp=datetime.datetime.now(), color=0x34f4b4)
|
||||||
|
embed.add_field(name="動畫:", value=ani["animate"], inline=True)
|
||||||
|
embed.add_field(name="角色:", value=ani["character"], inline=True)
|
||||||
|
embed.set_image(url=ani["url"])
|
||||||
|
await interaction.response.send_message(embed=embed)
|
||||||
|
|
||||||
|
# --- 新增:動畫角色總複習 ---
|
||||||
|
@app_commands.guilds(discord.Object(id=605678541530726421))
|
||||||
|
@app_commands.command(name="動畫角色總複習", description="每 2 秒顯示一位動畫角色,直到結束")
|
||||||
|
async def check_all_ani(self, interaction: discord.Interaction):
|
||||||
|
self.stop = False
|
||||||
|
await interaction.response.send_message("動畫角色總複習開始,如需停止請輸入 /停止", ephemeral=True)
|
||||||
|
|
||||||
|
current_idx = 0
|
||||||
|
while current_idx < len(self.aniData):
|
||||||
|
if self.stop:
|
||||||
|
await interaction.followup.send("複習已由指令中止。")
|
||||||
|
return
|
||||||
|
|
||||||
|
ani = self.aniData[current_idx]
|
||||||
|
current_idx += 1
|
||||||
|
|
||||||
|
embed = discord.Embed(title=f'總複習:第 {current_idx} 號角色', timestamp=datetime.datetime.now(), color=0x34f4b4)
|
||||||
|
embed.add_field(name="動畫:", value=ani["animate"], inline=True)
|
||||||
|
embed.add_field(name="角色:", value=ani["character"], inline=True)
|
||||||
|
embed.set_image(url=ani["url"])
|
||||||
|
|
||||||
|
await interaction.followup.send(embed=embed)
|
||||||
|
await asyncio.sleep(2)
|
||||||
|
|
||||||
|
await interaction.followup.send("複習完畢!")
|
||||||
|
|
||||||
|
# --- 停止複習 ---
|
||||||
@app_commands.guilds(discord.Object(id=605678541530726421))
|
@app_commands.guilds(discord.Object(id=605678541530726421))
|
||||||
@app_commands.command(name="停止", description="停止顯示總複習清單")
|
@app_commands.command(name="停止", description="停止顯示總複習清單")
|
||||||
async def stop_check_all_ani(self, interaction: discord.Interaction):
|
async def stop_check_all_ani(self, interaction: discord.Interaction):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue