Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
KT-Yeh committed Feb 5, 2024
2 parents 98a9e66 + 5d39b4c commit e8ad51a
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ verify_ssl = true
name = "pypi"

[packages]
genshin = {git = "https://github.com/KT-Yeh/genshin.py"}
genshin = {ref = "gdb", git = "https://github.com/KT-Yeh/genshin.py"}
"discord.py" = "~=2.2"
pillow = "~=9.4"
sentry-sdk = "~=1.16"
Expand Down
6 changes: 3 additions & 3 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 13 additions & 6 deletions cogs/characters/cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,33 @@ def __init__(self, bot: commands.Bot):
self.bot = bot

@app_commands.command(name="character角色一覽", description="公開展示我的所有角色")
@app_commands.rename(game="遊戲")
@app_commands.rename(game="遊戲", user="使用者")
@app_commands.describe(game="選擇遊戲", user="查詢其他成員的資料,不填寫則查詢自己")
@app_commands.choices(
game=[
app_commands.Choice(name="原神", value="genshin"),
app_commands.Choice(name="星穹鐵道", value="hkrpg"),
],
)
@SlashCommandLogger
async def slash_characters(self, interaction: discord.Interaction, game: genshin.Game):
async def slash_characters(
self,
interaction: discord.Interaction,
game: genshin.Game,
user: discord.User | discord.Member | None = None,
):
user = user or interaction.user
try:
match game:
case genshin.Game.GENSHIN:
defer, characters = await asyncio.gather(
interaction.response.defer(),
genshin_py.get_genshin_characters(interaction.user.id),
genshin_py.get_genshin_characters(user.id),
)
case genshin.Game.STARRAIL:
defer, characters = await asyncio.gather(
interaction.response.defer(),
genshin_py.get_starrail_characters(interaction.user.id),
genshin_py.get_starrail_characters(user.id),
)
case _:
return
Expand All @@ -62,7 +69,7 @@ async def slash_characters(self, interaction: discord.Interaction, game: genshin
raise ValueError("沒有圖片")
except Exception:
# 文字呈現
view = DropdownView(interaction.user, characters)
view = DropdownView(user, characters)
await interaction.edit_original_response(content="請選擇角色:", view=view)
return
else:
Expand All @@ -71,7 +78,7 @@ async def slash_characters(self, interaction: discord.Interaction, game: genshin
image = image.convert("RGB")
image.save(fp, "jpeg", optimize=True, quality=90)
fp.seek(0)
embed = EmbedTemplate.normal(f"{interaction.user.display_name} 的角色一覽")
embed = EmbedTemplate.normal(f"{user.display_name} 的角色一覽")
embed.set_image(url="attachment://image.jpeg")
await interaction.edit_original_response(
embed=embed, attachments=[discord.File(fp, "image.jpeg")]
Expand Down
28 changes: 15 additions & 13 deletions cogs/cookie_setting/cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class CookieSettingCog(commands.Cog, name="Cookie 設定"):
def __init__(self, bot: commands.Bot):
self.bot = bot

@app_commands.command(name="cookie設定", description="設定Cookie,第一次使用前必須先使用本指令設定Cookie")
@app_commands.command(
name="cookie設定", description="設定Cookie,第一次使用前必須先使用本指令設定Cookie"
)
@app_commands.rename(option="選項")
@app_commands.choices(
option=[
Expand All @@ -25,24 +27,24 @@ def __init__(self, bot: commands.Bot):
async def slash_cookie(self, interaction: discord.Interaction, option: int):
if option == 0: # 顯示說明如何取得 Cookie
embed = EmbedTemplate.normal(
"**1.** 先複製本文最底下整行程式碼\n"
"**2.** PC或手機使用 **Chrome** 開啟 [HoYoLAB官網](https://www.hoyolab.com)"
",登入帳號後→工具箱→戰績,到能看到自己角色的頁面\n"
"**3.** 如下圖,在網址列輸入 `java`,然後貼上程式碼\n"
"**4.** 按 Enter,網頁會變成顯示你的 Cookie,全選然後複製\n"
f"**5.** 在這裡使用指令 {get_app_command_mention('cookie設定')} 提交已取得的Cookie\n"
". 遇到登入問題嗎?點 [教學連結](https://hackmd.io/66fq-6NsT1Kqxqbpkj1xTA) 查看解決方法\n",
"**1.** 使用 **電腦**瀏覽器 無痕視窗開啟 [HoYoLAB官網](https://www.hoyolab.com) 並登入帳號\n"
"**2.** **F12** 打開瀏覽器開發者工具\n"
"**3.** 切換至 **應用程式 (Application)** 頁面 (參考下圖)\n"
"**4.** 點選左邊 Cookies 底下的網址,右邊就會看到你的 Cookie\n"
"**5.** 找到 **ltuid_v2**、**ltoken_v2**、**ltmid_v2**,複製這三個欄位的值\n"
f"**6.** 在這裡使用指令 {get_app_command_mention('cookie設定')} 貼到對應的欄位\n"
". 遇到問題嗎?點 >>[詳細教學](https://hackmd.io/66fq-6NsT1Kqxqbpkj1xTA)<< 查看解決方法\n",
title="原神小幫手 | 取得Cookie說明",
)
embed.set_image(url="https://i.imgur.com/OQ8arx0.gif")
code_msg = "script: document.write(document.cookie)"
embed.set_image(url="https://i.imgur.com/tgjWuvy.png")
await interaction.response.send_message(embed=embed)
await interaction.followup.send(content=code_msg)

elif option == 1: # 提交已取得的Cookie給小幫手
view = GameSelectionView()
await interaction.response.send_message(
embed=EmbedTemplate.normal("請選擇要設定Cookie的遊戲,不同遊戲可以設定不同帳號的Cookie"),
embed=EmbedTemplate.normal(
"請選擇要設定Cookie的遊戲,不同遊戲可以設定不同帳號的Cookie"
),
view=view,
ephemeral=True,
)
Expand All @@ -51,7 +53,7 @@ async def slash_cookie(self, interaction: discord.Interaction, option: int):
msg = (
"· Cookie的內容包含你個人的識別代碼,不包含帳號與密碼\n"
"· 因此無法用來登入遊戲,也無法更改帳密,Cookie內容大概長這樣:"
"`ltoken=xxxx ltuid=1234 cookie_token=yyyy account_id=1234`\n"
"`ltoken_v2=xxxx ltuid_v2=1234 ltmid_v2=yyyy`\n"
"· 小幫手保存並使用Cookie是為了在Hoyolab網站上取得你的原神資料並提供服務\n"
"· 小幫手將資料保存於雲端主機獨立環境,只與Discord、Hoyolab伺服器連線\n"
"· 更詳細說明可以到 [巴哈說明文](https://forum.gamer.com.tw/Co.php?bsn=36730&sn=162433) 查看,"
Expand Down
18 changes: 9 additions & 9 deletions cogs/cookie_setting/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,6 @@ async def select_callback(self, interaction: discord.Interaction, select: discor
class CookieModal(discord.ui.Modal, title="提交Cookie"):
"""提交 Cookie 的表單"""

cookie: discord.ui.TextInput[discord.ui.Modal] = discord.ui.TextInput(
label="Cookie",
placeholder='請貼上從網頁上取得的Cookie,取得方式請使用指令 "/cookie設定 顯示說明如何取得Cookie"',
style=discord.TextStyle.long,
required=False,
min_length=50,
max_length=2000,
)

ltuid_v2: discord.ui.TextInput[discord.ui.Modal] = discord.ui.TextInput(
label="ltuid_v2",
placeholder="請貼上取得的 ltuid_v2",
Expand Down Expand Up @@ -67,6 +58,15 @@ class CookieModal(discord.ui.Modal, title="提交Cookie"):
max_length=20,
)

cookie: discord.ui.TextInput[discord.ui.Modal] = discord.ui.TextInput(
label="Cookie",
placeholder="非特殊需求本欄請保持空白,此處用來貼完整的 Cookie 字串",
style=discord.TextStyle.long,
required=False,
min_length=50,
max_length=2000,
)

def __init__(self, games: list[genshin.Game]):
self.games: list[genshin.Game] = games
super().__init__()
Expand Down
8 changes: 5 additions & 3 deletions cogs/redemption_code/cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ async def redeem(
# 匹配多組兌換碼並存成list
codes = re.findall(r"[A-Za-z0-9]{5,30}", code)
if len(codes) == 0:
await interaction.response.send_message(embed=EmbedTemplate.error("沒有偵測到兌換碼,請重新輸入"))
await interaction.response.send_message(
embed=EmbedTemplate.error("沒有偵測到兌換碼,請重新輸入")
)
return

codes = codes[:5] if len(codes) > 5 else codes # 避免使用者輸入過多內容
msg = "請點下列連結兌換:\n> "
msg = "請點下列連結兌換:\n"
for i, code in enumerate(codes):
game_host = {genshin.Game.GENSHIN: "genshin", genshin.Game.STARRAIL: "hsr"}
msg += f"{i+1}. [{code}](https://{game_host.get(game)}.hoyoverse.com/gift?code={code})\n"
msg += f"> {i+1}. [{code}](https://{game_host.get(game)}.hoyoverse.com/gift?code={code})\n"

embed = discord.Embed(color=0x8FCE00, description=msg)
await interaction.response.send_message(embed=embed)
Expand Down

0 comments on commit e8ad51a

Please sign in to comment.