Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redesign #29

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/flake8.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Set up Python 3.8
- name: Set up Python 3.11
uses: actions/setup-python@v1
with:
python-version: 3.8
python-version: 3.11
- name: Install dependencies
run: python -m pip install discord.py[voice] flake8
- name: Run flake8
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Set up Python 3.8
- name: Set up Python 3.11
uses: actions/setup-python@v1
with:
python-version: 3.8
python-version: 3.11
- name: Install dependencies
run: python -m pip install discord.py[voice] pytest
- name: Run pytest
Expand Down
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))
116 changes: 116 additions & 0 deletions extensions/play.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import random
import discord
from discord import app_commands
from discord.ext import commands
from application.player import Player
from application.game import Game
from constants import roles


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

@app_commands.command(name='ゲーム作成', description='新しい人狼ゲームを作成します')
@app_commands.guild_only()
async def _create_game_app_command(self, interaction: discord.Interaction):
match self.bot.game.status:
case 'playing':
await interaction.response.send_message('既にゲームが進行中です', ephemeral=True)
return
case 'waiting':
await interaction.response.send_message('既に参加者を募集中です', ephemeral=True)
return
self.bot.game.status = 'waiting'
self.bot.game.channel = interaction.channel
await interaction.response.send_message('参加者の募集を開始しました')

@app_commands.command(name='ゲーム開始', description='人狼ゲームを開始します')
@app_commands.guild_only()
async def _start_game_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

n = len(self.bot.game.players)
role = roles.simple[n]
role_list = random.sample(role, n)
for i in range(n):
player = self.bot.game.players[i]
user = self.bot.get_user(player.id)
role = role_list[i]
await user.send(f'あなたの役職は {role} です')
if role == '村':
continue

player.set_role(role)

await interaction.response.send_message('役職が配布されました。配布された自分の役職を確認し、準備を完了させてください。')
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):
match self.bot.game.status:
case 'nothing':
await interaction.response.send_message('参加者を募集していません', ephemeral=True)
return
case 'waiting':
await interaction.response.send_message('参加者を募集中です', ephemeral=True)
return
case 'playing':
await interaction.response.send_message('人狼ゲームが進行中です', ephemeral=True)
return

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

This file was deleted.

Loading