Skip to content

Commit

Permalink
投票をリアクション&ページネーションからui.Selectに移行
Browse files Browse the repository at this point in the history
  • Loading branch information
1ntegrale9 committed Oct 3, 2023
1 parent ee91c60 commit ecae404
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 260 deletions.
109 changes: 0 additions & 109 deletions application/pagenator.py

This file was deleted.

59 changes: 59 additions & 0 deletions extensions/change_date.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import discord
from discord import app_commands
from discord.ext import commands
from application.game import Game


class ChangeDateCog(commands.Cog):
def __init__(self, bot):
self.bot = bot

@app_commands.command(name='日付変更', description='投票&役職選択完了を確認して日付変更処理を行います')
@app_commands.guild_only()
async def change_date(self, interaction: discord.Interaction):
game: Game = self.bot.game

if not game.is_set_target():
return

guild = game.channel.guild

game.execute()

executed = guild.get_member(game.executed.id)
text = f'投票の結果 {executed.display_name} さんが処刑されました'
await game.channel.send(text)

if game.is_village_win():
text = 'ゲームが終了しました。人狼が全滅したため村人陣営の勝利です!'
await game.channel.send(text)
game = Game()
return

game.raid()

if game.raided is not None:
raided = guild.get_member(game.raided.id)
text = f'{raided.display_name} さんが無残な姿で発見されました'
await game.channel.send(text)

if game.is_werewolf_win():
text = 'ゲームが終了しました。村人陣営の数が人狼陣営の数以下になったため人狼陣営の勝利です!'
await game.channel.send(text)
game = Game()
return

game.fortune()

if game.fortuned is not None:
text = f'占い結果は {game.fortuned} です。'
await guild.get_member(game.players.fortuneteller.id).send(text)

for p in game.players.alives:
p.clear_vote().clear_raid().clear_fortune()

game.days += 1


async def setup(bot: commands.Bot) -> None:
await bot.add_cog(ChangeDateCog(bot))
56 changes: 51 additions & 5 deletions extensions/status.py → extensions/play.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
import discord
from discord import app_commands
from discord.ext import commands
from constants.roles import simple
from application.player import Player
from application.game import Game
from constants import roles


class GameStatus(commands.Cog):
class PlayCog(commands.Cog):
def __init__(self, bot):
self.bot = bot

Expand Down Expand Up @@ -35,7 +37,7 @@ async def _start_game_app_command(self, interaction: discord.Interaction):
return

n = len(self.bot.game.players)
role = simple[n]
role = roles.simple[n]
role_list = random.sample(role, n)
for i in range(n):
player = self.bot.game.players[i]
Expand All @@ -51,6 +53,51 @@ async def _start_game_app_command(self, interaction: discord.Interaction):
self.bot.game.status = 'playing'
await interaction.response.send_message('ゲームが開始されました。それぞれの役職にあった行動をとってください。')

@app_commands.command(name='参加', description='人狼ゲームに参加する')
@app_commands.guild_only()
async def _join_app_command(self, interaction: discord.Interaction):
match self.bot.game.status:
case 'nothing':
await interaction.response.send_message('現在ゲームはありません。', ephemeral=True)
return
case 'playing':
await interaction.response.send_message('現在ゲーム進行中です。', ephemeral=True)
return
for player in self.bot.game.players:
if interaction.user.id == player.id:
await interaction.response.send_message('既にゲームに参加しています。', ephemeral=True)
return
player = Player(interaction.user.id)
self.bot.game.players.append(player)
await interaction.response.send_message(f'{interaction.user.mention} さんが参加しました。')

@app_commands.command(name='退出', description='人狼ゲームから退出する')
@app_commands.guild_only()
async def _left_app_command(self, interaction: discord.Interaction):
match self.bot.game.status:
case 'nothing':
await interaction.response.send_message('現在募集中のゲームはありません。', ephemeral=True)
return
case 'playing':
await interaction.response.send_message('既にゲームが進行中のため退出できません。', ephemeral=True)
return
for player in self.bot.game.players:
if interaction.user.id == player.id:
self.bot.game.players.remove(player)
await interaction.response.send_message(f'{interaction.user.mention} さんが退出しました。')
return
await interaction.response.send_message('ゲームに参加していません。', ephemeral=True)

@app_commands.command(name='仲間の人狼を表示', description='仲間の人狼を表示します')
@app_commands.guild_only()
async def _show_werewolfs_app_command(self, interaction: discord.Interaction):
game: Game = self.bot.game
if game.players.get(interaction.user.id).role != '狼':
await interaction.response.send_message('あなたは人狼ではありません', ephemeral=True)
return
werewolfs = ' '.join(interaction.guild.get_member(player.id).mention for player in self.bot.game.players.werewolfs)
await interaction.response.send_message(f'この村の人狼は {werewolfs} です。', ephemeral=True)

@app_commands.command(name='ステータス確認', description='現在の人狼ゲームのステータスを確認します')
@app_commands.guild_only()
async def _show_game_status_app_command(self, interaction: discord.Interaction):
Expand All @@ -65,6 +112,5 @@ async def _show_game_status_app_command(self, interaction: discord.Interaction):
await interaction.response.send_message('人狼ゲームが進行中です', ephemeral=True)
return


async def setup(bot: commands.Bot) -> None:
await bot.add_cog(GameStatus(bot))
await bot.add_cog(PlayCog(bot))
48 changes: 0 additions & 48 deletions extensions/players.py

This file was deleted.

Loading

0 comments on commit ecae404

Please sign in to comment.