Skip to content
This repository was archived by the owner on Jun 25, 2024. It is now read-only.

Commit 4ef9cc0

Browse files
committed
修正個人檔案錯誤處理
1 parent 719371a commit 4ef9cc0

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

cogs/profileCard/__init__.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import aiohttp
23
from discord_slash.context import ComponentContext
34
from discord_slash.model import ButtonStyle
45
from discord_slash.utils.manage_components import create_actionrow, create_button
@@ -41,7 +42,10 @@ async def get_profile(self, server: int, uid: int, cache: bool = True):
4142
f"{self.apiUrl}/profile",
4243
params={"server": server, "uid": str(uid).zfill(9), "cache": "true" if cache else "false"},
4344
) as resp:
44-
data = await resp.json()
45+
try:
46+
data = await resp.json()
47+
except:
48+
raise errors.GameApiError
4549

4650
self.logger.info(f"get_profile /{server}/{uid:09d}: {resp.status}")
4751

main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from utils.state_manger import StateManger, State
1616

1717
__author__ = "IanDesuyo"
18-
__version__ = "3.1.8"
18+
__version__ = "3.1.9"
1919

2020

2121
class AIKyaru(AutoShardedBot):

utils/errors.py

+10
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import uuid
1111
import utils
1212
import traceback
13+
import asyncio
1314

1415

1516
class GameApiError(Exception):
@@ -56,6 +57,10 @@ class RecordDeleted(Exception):
5657
pass
5758

5859

60+
class GameProfileNotLinked(Exception):
61+
pass
62+
63+
5964
async def handle_error(bot: Bot, ctx: Union[Context, SlashContext, ComponentContext], error):
6065
if isinstance(ctx, ComponentContext):
6166
# don't send new message, edit the origin one.
@@ -78,9 +83,14 @@ async def do_edit_origin(content: str = "", embed=None, components=None):
7883
return await ctx.send(f"我沒有權限... 需要`{','.join(error.missing_perms)}`")
7984
if isinstance(error, commands.NoPrivateMessage):
8085
return await ctx.send("此功能僅限群組使用")
86+
if isinstance(error, asyncio.TimeoutError):
87+
return await ctx.send("與伺服器連線超時 :(")
88+
8189

8290
# game api errors
8391

92+
if isinstance(error, GameProfileNotLinked):
93+
return await ctx.send("此用戶尚未綁定遊戲ID")
8494
if isinstance(error, ProfileNotFound):
8595
return ctx.send("找不到此玩家... 你還記得你的ID嗎?")
8696
if isinstance(error, GameApiError):

0 commit comments

Comments
 (0)