diff --git a/scripts/db_add_column.py b/scripts/db_add_column.py index f1068e6..224f990 100644 --- a/scripts/db_add_column.py +++ b/scripts/db_add_column.py @@ -10,19 +10,20 @@ cur.execute( """ ALTER TABLE val_puuids - ADD COLUMN yesterday_win INTEGER, - ADD COLUMN yesterday_lose INTEGER + ADD COLUMN d_uid INTEGER """ ) + # "yesterday_win"と"yesterday_lose"のカラムに0を設定 -cur.execute( - """ - UPDATE val_puuids - SET yesterday_win = 0, - yesterday_lose = 0 - """ -) +# cur.execute( +# """ +# UPDATE val_puuids +# SET yesterday_win = 0, +# yesterday_lose = 0 +# """ +# ) + # 変更をコミット conn.commit() diff --git a/scripts/db_add_duid_by_puuid.py b/scripts/db_add_duid_by_puuid.py new file mode 100644 index 0000000..56b2364 --- /dev/null +++ b/scripts/db_add_duid_by_puuid.py @@ -0,0 +1,39 @@ +import sqlite3 + +# PUUIDの入力 +puuid_input = input("タスクに追加するPUUIDを入力してください。") + +# Discord UIDの入力 +try: + discord_uid_input = int(input("プレイヤーのDiscord UIDを入力してください。整数です。")) +except ValueError: + print("Discord UIDは整数でなければなりません。") + exit(1) + +# データベースへの接続 +conn = sqlite3.connect("data/takohachi.db") +cur = conn.cursor() + +# PUUIDの存在確認 +cur.execute("SELECT COUNT(*) FROM val_puuids WHERE puuid = ?", (puuid_input,)) +puuid_exists = cur.fetchone()[0] + +if puuid_exists == 0: + print("指定されたPUUIDは存在しません。") + conn.close() + exit(1) + +# Discord UIDの挿入 +cur.execute( + """ + UPDATE val_puuids + SET d_uid = ? + WHERE puuid = ? + """, + (discord_uid_input, puuid_input), +) + +conn.commit() +conn.close() + +print("done!") diff --git a/scripts/db_delete_all_records.py b/scripts/db_delete_all_records.py new file mode 100644 index 0000000..f162a26 --- /dev/null +++ b/scripts/db_delete_all_records.py @@ -0,0 +1,14 @@ +import sqlite3 + +# データベースへの接続 +conn = sqlite3.connect("data/takohachi.db") +cur = conn.cursor() + +# すべてのレコードを削除する +cur.execute("DELETE FROM val_puuids") + +# 変更をコミット +conn.commit() +conn.close() + +print("すべてのレコードが削除されました。") diff --git a/scripts/db_insert_data.py b/scripts/db_insert_data.py index 7902345..2b054d1 100644 --- a/scripts/db_insert_data.py +++ b/scripts/db_insert_data.py @@ -8,7 +8,19 @@ print("ELOは整数でなければなりません。") exit(1) -region_input = input("プレイヤーのリージョンを入力してください。(eu, na, latam, br, ap, kr)") +try: + region_input = input("プレイヤーのリージョンを入力してください。(eu, na, latam, br, ap, kr): ") + if region_input not in ["eu", "na", "latam", "br", "ap", "kr"]: + raise ValueError("無効なリージョンが入力されました。") +except ValueError: + print("無効なリージョンが入力されました。") + exit(1) + +try: + discord_uid_input = int(input("プレイヤーのDiscord UIDを入力してください。整数です。")) +except ValueError: + print("Discord UIDは整数でなければなりません。") + exit(1) conn = sqlite3.connect("data/takohachi.db") @@ -16,10 +28,10 @@ cur.execute( """ - INSERT INTO val_puuids (puuid, region, name, tag, yesterday_elo, yesterday_win, yesterday_lose) - VALUES (?, ?, ?, ?, ?, ?, ?) + INSERT INTO val_puuids (puuid, region, name, tag, yesterday_elo, yesterday_win, yesterday_lose, d_uid) + VALUES (?, ?, ?, ?, ?, ?, ?, ?) """, - (puuid_input, region_input, "xxxxx", "xxxxx", elo_input, 0, 0), + (puuid_input, region_input, "xxxxx", "xxxxx", elo_input, 0, 0, discord_uid_input), ) conn.commit() diff --git a/src/cogs/vl_rank_task.py b/src/cogs/vl_rank_task.py index 8a937c5..7ed2702 100644 --- a/src/cogs/vl_rank_task.py +++ b/src/cogs/vl_rank_task.py @@ -74,7 +74,16 @@ async def printer(self): rows = cur.fetchall() async def fetch(row): - puuid, region, name, tag, yesterday_elo, yesterday_win, yesterday_lose = row + ( + puuid, + region, + name, + tag, + yesterday_elo, + yesterday_win, + yesterday_lose, + d_uid, + ) = row headers = {"Authorization": VALORANT_TOKEN} @@ -175,7 +184,7 @@ async def fetch(row): total_act_rank_loses: int = total_number_of_games - total_act_rank_wins # フォーマットに合わせて整形 - result_string = f"{emoji} `{api_name} #{api_tag}` {rank_emoji}\n- {current_rank_info}\n- Daily changes: {plusminus}{todays_elo}\n- Daily matches: {daily_wins}W/{daily_loses}L\n- Current act: {wins}W/{loses}L\n- Lifetime: {total_act_rank_wins}W/{total_act_rank_loses}L\n\n" # noqa: E501 + result_string = f"{emoji} <@{d_uid}> {rank_emoji}\n- Name: `{api_name}#{api_tag}`\n- {current_rank_info}\n- Daily changes: {plusminus}{todays_elo}\n- Daily matches: {daily_wins}W/{daily_loses}L\n- Current act: {wins}W/{loses}L\n- Lifetime: {total_act_rank_wins}W/{total_act_rank_loses}L\n\n" # noqa: E501 # DBの情報を今日の取得内容で更新 cur.execute(