Skip to content

Commit

Permalink
Merge pull request #235 from pistachiostudio/d-uid-column
Browse files Browse the repository at this point in the history
DBにDiscord UIDを追加してちょっと処理
  • Loading branch information
quojama authored Jun 28, 2024
2 parents 27c96c4 + 95f3f73 commit ef47a36
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 15 deletions.
19 changes: 10 additions & 9 deletions scripts/db_add_column.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
39 changes: 39 additions & 0 deletions scripts/db_add_duid_by_puuid.py
Original file line number Diff line number Diff line change
@@ -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!")
14 changes: 14 additions & 0 deletions scripts/db_delete_all_records.py
Original file line number Diff line number Diff line change
@@ -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("すべてのレコードが削除されました。")
20 changes: 16 additions & 4 deletions scripts/db_insert_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,30 @@
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")

cur = conn.cursor()

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()
Expand Down
13 changes: 11 additions & 2 deletions src/cogs/vl_rank_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit ef47a36

Please sign in to comment.