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 Jun 5, 2024
2 parents 7e4e08c + 13709b2 commit 2c627ab
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 181 deletions.
344 changes: 172 additions & 172 deletions Pipfile.lock

Large diffs are not rendered by default.

18 changes: 17 additions & 1 deletion cogs/characters/cog.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import io
import typing

import discord
import genshin
Expand All @@ -22,19 +23,25 @@ def __init__(self, bot: commands.Bot):
self.bot = bot

@app_commands.command(name="character角色一覽", description="公開展示我的所有角色")
@app_commands.rename(game="遊戲", user="使用者")
@app_commands.rename(game="遊戲", sort_key="排序", user="使用者")
@app_commands.describe(game="選擇遊戲", user="查詢其他成員的資料,不填寫則查詢自己")
@app_commands.choices(
game=[
app_commands.Choice(name="原神", value="genshin"),
app_commands.Choice(name="星穹鐵道", value="hkrpg"),
],
sort_key=[
app_commands.Choice(name="等級", value="LEVEL"),
app_commands.Choice(name="元素", value="ELEMENT"),
app_commands.Choice(name="稀有度", value="RARITY"),
],
)
@SlashCommandLogger
async def slash_characters(
self,
interaction: discord.Interaction,
game: genshin.Game,
sort_key: typing.Literal["LEVEL", "ELEMENT", "RARITY"] = "LEVEL",
user: discord.User | discord.Member | None = None,
):
user = user or interaction.user
Expand All @@ -56,6 +63,15 @@ async def slash_characters(
await interaction.edit_original_response(embed=EmbedTemplate.error(e))
return

# 排序
match sort_key:
case "LEVEL":
characters = sorted(characters, key=lambda x: (x.level, x.rarity, x.element), reverse=True)
case "ELEMENT":
characters = sorted(characters, key=lambda x: (x.element, x.rarity, x.level), reverse=True)
case "RARITY":
characters = sorted(characters, key=lambda x: (x.rarity, x.level, x.element), reverse=True)

try:
# 使用 genshinpyrail 產生圖片
match game:
Expand Down
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3"

services:
genshin-discord-bot:
image: ghcr.io/kt-yeh/genshin-discord-bot:latest
Expand Down
4 changes: 2 additions & 2 deletions genshin_py/client/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,11 @@ async def _claim_reward(
return f"{game_name[game]}今日獎勵已經領過了!"
except genshin.errors.InvalidCookies:
return "Cookie已失效,請從Hoyolab重新取得新Cookie。"
except genshin.errors.GeetestTriggered as exception:
except genshin.errors.DailyGeetestTriggered as exception:
# 使用者選擇設定圖形驗證,回傳網址
if is_geetest is True and config.geetest_solver_url is not None:
url = config.geetest_solver_url
url += f"/geetest/{game}/{user_id}/{exception.gt}/{exception.challenge}"
url += f"/geetest/{game}/{user_id}?gt={exception.gt}&challenge={exception.challenge}"
return f"請到網站上解鎖圖形驗證:[點我開啟連結]({url})\n若出現錯誤則再次使用本指令重新產生連結"
# 提示使用者可以設定圖形驗證
if config.geetest_solver_url is not None:
Expand Down
6 changes: 5 additions & 1 deletion genshin_py/errors_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import sentry_sdk

from database import Database, User
from utility import LOG
from utility import LOG, config

from .errors import GenshinAPIException, UserDataNotFound

Expand Down Expand Up @@ -50,6 +50,10 @@ async def wrapper(*args, **kwargs):
except genshin.errors.InvalidCookies as e:
LOG.FuncExceptionLog(user_id, func.__name__, e)
raise GenshinAPIException(e, "Cookie已失效,請從Hoyolab重新取得新Cookie")
except genshin.errors.GeetestError as e:
LOG.FuncExceptionLog(user_id, func.__name__, e)
url = f"{config.geetest_solver_url}/geetest/starrail_battlechronicle/{user_id}"
raise GenshinAPIException(e, f"觸發 Hoyolab 圖形驗證,請 [>>點擊此連結<<]({url}/) 到網頁上進行手動解鎖。")
except genshin.errors.RedemptionException as e:
LOG.FuncExceptionLog(user_id, func.__name__, e)
raise GenshinAPIException(e, e.original)
Expand Down
7 changes: 4 additions & 3 deletions genshin_py/parser/genshin.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,13 @@ async def parse_genshin_notes(

exped_title = f"{emoji.notes.expedition}探索派遣結果:{exped_finished}/{len(notes.expeditions)}\n"

# 根據樹脂數量,以80作分界,embed顏色從綠色(0x28c828)漸變到黃色(0xc8c828),再漸變到紅色(0xc82828)
# 根據樹脂數量,以樹脂最大值一半作分界,embed顏色從綠色(0x28c828)漸變到黃色(0xc8c828),再漸變到紅色(0xc82828)
r = notes.current_resin
h = notes.max_resin // 2
color = (
0x28C828 + 0x010000 * int(0xA0 * r / 80)
0x28C828 + 0x010000 * int(0xA0 * r / h)
if r < 80
else 0xC8C828 - 0x000100 * int(0xA0 * (r - 80) / 80)
else 0xC8C828 - 0x000100 * int(0xA0 * (r - h) / h)
)
embed = discord.Embed(color=color)

Expand Down

0 comments on commit 2c627ab

Please sign in to comment.