Skip to content

Commit

Permalink
changed additional info flow
Browse files Browse the repository at this point in the history
  • Loading branch information
HiroshigeAoki committed Dec 21, 2023
1 parent b2ac51d commit 54bcb00
Show file tree
Hide file tree
Showing 22 changed files with 607 additions and 128 deletions.
44 changes: 44 additions & 0 deletions alembic/versions/a24e3d8bc61d_change_additional_info_workflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""change_additional_info_workflow
Revision ID: a24e3d8bc61d
Revises: c578e9099890
Create Date: 2023-12-21 14:11:17.707521
"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql

# revision identifiers, used by Alembic.
revision: str = 'a24e3d8bc61d'
down_revision: Union[str, None] = 'c578e9099890'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('games_info', sa.Column('additional_info_1', sa.JSON(), nullable=True))
op.add_column('games_info', sa.Column('additional_info_2', sa.JSON(), nullable=True))
op.add_column('games_info', sa.Column('additional_info_3', sa.JSON(), nullable=True))
op.add_column('games_info', sa.Column('additional_info_4', sa.JSON(), nullable=True))
op.add_column('games_info', sa.Column('additional_info_5', sa.JSON(), nullable=True))
op.add_column('games_info', sa.Column('total_additional_info', sa.Integer(), nullable=True))
op.drop_column('games_info', 'has_additional_info')
op.drop_column('participants', 'additional_url')
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('participants', sa.Column('additional_url', mysql.VARCHAR(length=255), nullable=True))
op.add_column('games_info', sa.Column('has_additional_info', mysql.TINYINT(display_width=1), autoincrement=False, nullable=True))
op.drop_column('games_info', 'total_additional_info')
op.drop_column('games_info', 'additional_info_5')
op.drop_column('games_info', 'additional_info_4')
op.drop_column('games_info', 'additional_info_3')
op.drop_column('games_info', 'additional_info_2')
op.drop_column('games_info', 'additional_info_1')
# ### end Alembic commands ###
2 changes: 1 addition & 1 deletion alembic/versions/c578e9099890_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def upgrade() -> None:
sa.Column("is_criminal", sa.Boolean(), nullable=True),
sa.Column("char_name", sa.String(length=255), nullable=False),
sa.Column("char_url", sa.String(length=255), nullable=False),
sa.Column("additional_url", sa.String(length=255), nullable=True),
sa.Column("additional_info", sa.String(length=255), nullable=True),
sa.Column("vote_target_id", sa.String(length=255), nullable=True),
sa.Column("vote_target_name", sa.String(length=255), nullable=True),
sa.Column("vote_reason", sa.String(length=255), nullable=True),
Expand Down
49 changes: 39 additions & 10 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,25 @@
signing_secret=settings.SLACK_SIGNING_SECRET,
)

temporary_storage = {}


"""
ゲームの流れ
1. 管理者が `/invite_players`コマンドを実行して、参加者を招待。
2. 管理者が `/prepare` コマンドを実行して、ゲームの事前情報を参加者に送信。
3. 管理者が `start_game` コマンドを実行して、ゲームを開始。ゲームに関する質疑応答を行う。
- `/start_game 10` のようにすると制限時間を10分に設定し、全体に通知出来る。(以下の`/start`コマンドも同様)
- `/start_game 10` のようにすると制限時間を10分に設定し、全体に通知出来る。(以下の`/start_vote`コマンド以外の`/start`コマンドも同様)
4. 管理者が `/start_discussion` コマンドを実行して、議論を開始。
5. 管理者が `/start_organizing` コマンドを実行して、これまでの整理パートを開始
6. 管理者が `/start_final_discussion` コマンドを実行して、最終議論を開始。
- この時、追加情報があれば参加者に送られる
7. 管理者が `/start_vote` コマンドを実行して、モーダルを通じて投票を開始。
- インタラクティブメッセージとモーダルを通じて、追加情報があるかと、何番目の追加情報を送るかを選択
(optional) 管理者が `/start_organizing` コマンドを実行して、これまでの整理パートを開始。(整理する時間があるかはシナリオによる)
※ ユーザー毎が個別に議論を行うシナリオには対応していない
6. 管理者が `/start_vote` コマンドを実行して、モーダルを通じて投票を開始。
- この時、アノテーション用のスプレッドシートに全ての発話が保存される。
8. 参加者が `/vote` コマンドを実行して、投票を行う。
9. 全ての参加者が投票を終えたら、管理者はモーダルを通じて各プレイヤーのポイントと犯人役が勝利したかを記入する。
10. 参加者は、投票後、アノテーション用のスプレッドシートにアノテーションを行い、終わったら、「アノテーション完了ボタン」を押す。
11. 管理者のポイント記入と、参加者のアノテーションが完了したタイミングで、結果が発表される。
7. 参加者が `/vote` コマンドを実行して、投票を行う。
8. 全ての参加者が投票を終えたら、管理者はモーダルを通じて各プレイヤーのポイントと犯人役が勝利したかを記入する。
9. 参加者は、投票後、アノテーション用のスプレッドシートにアノテーションを行い、終わったら、「アノテーション完了ボタン」を押す。
10. 管理者のポイント記入と、参加者のアノテーションが完了したタイミングで、結果が発表される。
"""


Expand Down Expand Up @@ -70,7 +72,34 @@ async def handle_start_any_command(ack: Any, body: Dict[str, Any]) -> None:
`/start_vote` のときは、アノテーション用のスプレッドシート作成も行う。
"""
await ack()
await handlers.handle_start_command(body)
await handlers.handle_start_command(body, temporary_storage)


@app.action("send_additional_info_yes")
async def handle_send_additional_info_yes(ack, body):
"""
追加情報がある場合のモーダルで「はい」を押した場合の処理
"""
await ack()
await handlers.handle_send_additional_info_yes(body)


@app.action("send_additional_info_no")
async def handle_send_additional_info_no(ack, body):
"""
追加情報がある場合のモーダルで「いいえ」を押した場合の処理
"""
await ack()
await handlers.handle_send_additional_info_no(body, temporary_storage)


@app.view("select_additional_info")
async def handle_select_additional_info_submission(ack, body):
"""
送る追加情報を選択したモーダルのcallback
"""
await ack()
await handlers.handle_select_additional_info_submission(body, temporary_storage)


@app.command("/vote")
Expand Down
65 changes: 41 additions & 24 deletions src/gsheet/scenario_sheet.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Dict, List
from typing import Dict, List, Tuple
import json

from src.gsheet.base_sheet import BaseSheet
from src.utils import eject_null
Expand All @@ -23,11 +24,11 @@ class Scenario(BaseSheet):
CHAR3_URL_COL = 16
CHAR4_URL_COL = 17
CHAR5_URL_COL = 18
ADDITIONAL_URL1_COL = 19
ADDITIONAL_URL2_COL = 20
ADDITIONAL_URL3_COL = 21
ADDITIONAL_URL4_COL = 22
ADDITIONAL_URL5_COL = 23
ADDITIONAL_INFO_1_COL = 19
ADDITIONAL_INFO_2_COL = 20
ADDITIONAL_INFO_3_COL = 21
ADDITIONAL_INFO_4_COL = 22
ADDITIONAL_INFO_5_COL = 23

def __init__(
self,
Expand All @@ -49,11 +50,11 @@ def __init__(
char3_url: str,
char4_url: str,
char5_url: str,
additional_url1: str,
additional_url2: str,
additional_url3: str,
additional_url4: str,
additional_url5: str,
additional_info_1: str,
additional_info_2: str,
additional_info_3: str,
additional_info_4: str,
additional_info_5: str,
row_index: int,
) -> None:
self.title = title
Expand All @@ -74,11 +75,11 @@ def __init__(
self.char3_url = char3_url
self.char4_url = char4_url
self.char5_url = char5_url
self.additional_url1 = additional_url1
self.additional_url2 = additional_url2
self.additional_url3 = additional_url3
self.additional_url4 = additional_url4
self.additional_url5 = additional_url5
self.additional_info_1 = additional_info_1
self.additional_info_2 = additional_info_2
self.additional_info_3 = additional_info_3
self.additional_info_4 = additional_info_4
self.additional_info_5 = additional_info_5
self.row_index = row_index

self.strip_strings()
Expand All @@ -105,16 +106,32 @@ def get_char_names(self) -> List[str]:

def get_char_urls(self) -> List[str]:
return eject_null(
[self.char1_url, self.char2_url, self.char3_url, self.char4_url, self.char5_url]
[
self.char1_url,
self.char2_url,
self.char3_url,
self.char4_url,
self.char5_url,
]
)

def get_additional_urls(self) -> List[str]:
return eject_null(
def get_additional_info(self) -> Tuple[List[Dict[str, str]], int]:
additional_info = eject_null(
[
self.additional_url1,
self.additional_url2,
self.additional_url3,
self.additional_url4,
self.additional_url5,
self.additional_info_1,
self.additional_info_2,
self.additional_info_3,
self.additional_info_4,
self.additional_info_5,
]
)

additional_info_dict = {}
try:
for i, info in enumerate(additional_info, start=1):
info_dict = json.loads(info)
additional_info_dict.update({f"additional_info_{i}": info_dict})
except json.JSONDecodeError as e:
raise Exception(f"スプレッドシートのadditional_infoに問題があります。\n{e}")

return additional_info_dict, len(additional_info)
Loading

0 comments on commit 54bcb00

Please sign in to comment.