Skip to content

Commit

Permalink
🔥 remove old auth logic
Browse files Browse the repository at this point in the history
  • Loading branch information
yanyongyu authored Dec 7, 2024
1 parent 0047b55 commit f229387
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 23 deletions.
15 changes: 5 additions & 10 deletions nonebot/adapters/qq/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,16 +259,14 @@ async def get_access_token(self) -> str:

async def _get_authorization_header(self) -> str:
"""获取当前 Bot 的鉴权信息"""
if self.bot_info.is_group_bot:
return f"QQBot {await self.get_access_token()}"
return f"Bot {self.bot_info.id}.{self.bot_info.token}"
return f"QQBot {await self.get_access_token()}"

async def get_authorization_header(self) -> dict[str, str]:
"""获取当前 Bot 的鉴权信息"""
headers = {"Authorization": await self._get_authorization_header()}
if self.bot_info.is_group_bot:
headers["X-Union-Appid"] = self.bot_info.id
return headers
return {
"Authorization": await self._get_authorization_header(),
"X-Union-Appid": self.bot_info.id,
}

async def handle_event(self, event: Event) -> None:
if isinstance(event, (GuildMessageEvent, QQMessageEvent)):
Expand Down Expand Up @@ -566,9 +564,6 @@ async def _request(self, request: Request) -> Any:
try:
return self._handle_response(response)
except UnauthorizedException as e:
if not self.bot_info.is_group_bot:
raise

log("DEBUG", "Access token expired, try to refresh it.")

# try to refresh access token
Expand Down
16 changes: 3 additions & 13 deletions nonebot/adapters/qq/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ def to_int(self):
| self.at_messages << 30
)

@property
def is_group_enabled(self) -> bool:
"""是否开启群聊功能"""
return self.c2c_group_at_messages is True


class BotInfo(BaseModel):
id: str = Field(alias="id")
Expand All @@ -57,16 +52,11 @@ class BotInfo(BaseModel):
intent: Intents = Field(default_factory=Intents)
use_websocket: bool = True

@property
def is_group_bot(self) -> bool:
"""是否为群机器人"""
return self.intent.is_group_enabled


class Config(BaseModel):
qq_is_sandbox: bool = False
qq_api_base: HttpUrl = Field("https://api.sgroup.qq.com/")
qq_sandbox_api_base: HttpUrl = Field("https://sandbox.api.sgroup.qq.com")
qq_auth_base: HttpUrl = Field("https://bots.qq.com/app/getAppAccessToken")
qq_api_base: HttpUrl = Field("https://api.sgroup.qq.com/") # type: ignore
qq_sandbox_api_base: HttpUrl = Field("https://sandbox.api.sgroup.qq.com") # type: ignore
qq_auth_base: HttpUrl = Field("https://bots.qq.com/app/getAppAccessToken") # type: ignore
qq_verify_webhook: bool = True
qq_bots: list[BotInfo] = Field(default_factory=list)

0 comments on commit f229387

Please sign in to comment.