Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(
) -> None:
super().__init__(platform_config, event_queue)
self.settings = platform_settings
self.client_self_id: str | None = None
self.bot_self_id: str | None = None
self.registered_handlers = []
# 指令注册相关
self.enable_command_register = self.config.get("discord_command_register", True)
Expand Down Expand Up @@ -92,10 +92,10 @@ async def send_by_session(

message_obj.message_str = message_chain.get_plain_text()
message_obj.sender = MessageMember(
user_id=str(self.client_self_id),
user_id=str(self.bot_self_id),
nickname=self.client.user.display_name,
)
message_obj.self_id = cast(str, self.client_self_id)
message_obj.self_id = cast(str, self.bot_self_id)
Comment thread
Soulter marked this conversation as resolved.
message_obj.session_id = session.session_id
message_obj.message = message_chain.chain

Expand Down Expand Up @@ -128,8 +128,8 @@ async def run(self) -> None:
# 初始化回调函数
async def on_received(message_data) -> None:
logger.debug(f"[Discord] 收到消息: {message_data}")
if self.client_self_id is None:
self.client_self_id = message_data.get("bot_id")
if self.bot_self_id is None:
self.bot_self_id = message_data.get("bot_id")
Comment thread
Soulter marked this conversation as resolved.
abm = await self.convert_message(data=message_data)
await self.handle_msg(abm)

Expand Down Expand Up @@ -241,7 +241,7 @@ def _convert_message_to_abm(self, data: dict) -> AstrBotMessage:
)
abm.message = message_chain
abm.raw_message = message
abm.self_id = cast(str, self.client_self_id)
abm.self_id = cast(str, self.bot_self_id)
abm.session_id = str(message.channel.id)
abm.message_id = str(message.id)
return abm
Expand Down Expand Up @@ -465,7 +465,7 @@ async def dynamic_callback(
)
abm.message = [Plain(text=message_str_for_filter)]
abm.raw_message = ctx.interaction
abm.self_id = cast(str, self.client_self_id)
abm.self_id = cast(str, self.bot_self_id)
Comment thread
Soulter marked this conversation as resolved.
abm.session_id = str(ctx.channel_id)
abm.message_id = str(ctx.interaction.id)

Expand Down
34 changes: 17 additions & 17 deletions astrbot/core/platform/sources/misskey/misskey_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def __init__(

self.api: MisskeyAPI | None = None
self._running = False
self.client_self_id = ""
self.bot_self_id = ""
self._bot_username = ""
self._user_cache = {}

Expand Down Expand Up @@ -138,10 +138,10 @@ async def run(self) -> None:

try:
user_info = await self.api.get_current_user()
self.client_self_id = str(user_info.get("id", ""))
self.bot_self_id = str(user_info.get("id", ""))
self._bot_username = user_info.get("username", "")
logger.info(
f"[Misskey] 已连接用户: {self._bot_username} (ID: {self.client_self_id})",
f"[Misskey] 已连接用户: {self._bot_username} (ID: {self.bot_self_id})",
)
except Exception as e:
logger.error(f"[Misskey] 获取用户信息失败: {e}")
Expand Down Expand Up @@ -312,9 +312,9 @@ async def _handle_chat_message(self, data: dict[str, Any]) -> None:
)
room_id = data.get("toRoomId")
logger.debug(
f"[Misskey] 收到聊天事件: sender_id={sender_id}, room_id={room_id}, is_self={sender_id == self.client_self_id}",
f"[Misskey] 收到聊天事件: sender_id={sender_id}, room_id={room_id}, is_self={sender_id == self.bot_self_id}",
)
if sender_id == self.client_self_id:
if sender_id == self.bot_self_id:
return

if room_id:
Expand Down Expand Up @@ -354,13 +354,13 @@ def _is_bot_mentioned(self, note: dict[str, Any]) -> bool:
mentions = note.get("mentions", [])
if self._bot_username and f"@{self._bot_username}" in text:
return True
if self.client_self_id in [str(uid) for uid in mentions]:
if self.bot_self_id in [str(uid) for uid in mentions]:
return True

reply = note.get("reply")
if reply and isinstance(reply, dict):
reply_user_id = str(reply.get("user", {}).get("id", ""))
if reply_user_id == self.client_self_id:
if reply_user_id == self.bot_self_id:
return bool(self._bot_username and f"@{self._bot_username}" in text)

return False
Expand Down Expand Up @@ -598,7 +598,7 @@ async def _upload_comp(comp) -> object | None:
visibility, visible_user_ids = resolve_message_visibility(
user_id=user_id_for_cache,
user_cache=self._user_cache,
self_id=self.client_self_id,
self_id=self.bot_self_id,
default_visibility=self.default_visibility,
)
logger.debug(
Expand Down Expand Up @@ -637,14 +637,14 @@ async def convert_message(self, raw_data: dict[str, Any]) -> AstrBotMessage:
message = create_base_message(
raw_data,
sender_info,
self.client_self_id,
self.bot_self_id,
is_chat=False,
)
cache_user_info(
self._user_cache,
sender_info,
raw_data,
self.client_self_id,
self.bot_self_id,
is_chat=False,
)

Expand All @@ -656,7 +656,7 @@ async def convert_message(self, raw_data: dict[str, Any]) -> AstrBotMessage:
message,
raw_text,
self._bot_username,
self.client_self_id,
self.bot_self_id,
)
message_parts.extend(text_parts)

Expand Down Expand Up @@ -685,14 +685,14 @@ async def convert_chat_message(self, raw_data: dict[str, Any]) -> AstrBotMessage
message = create_base_message(
raw_data,
sender_info,
self.client_self_id,
self.bot_self_id,
is_chat=True,
)
cache_user_info(
self._user_cache,
sender_info,
raw_data,
self.client_self_id,
self.bot_self_id,
is_chat=True,
)

Expand All @@ -713,7 +713,7 @@ async def convert_room_message(self, raw_data: dict[str, Any]) -> AstrBotMessage
message = create_base_message(
raw_data,
sender_info,
self.client_self_id,
self.bot_self_id,
is_chat=False,
room_id=room_id,
)
Expand All @@ -722,10 +722,10 @@ async def convert_room_message(self, raw_data: dict[str, Any]) -> AstrBotMessage
self._user_cache,
sender_info,
raw_data,
self.client_self_id,
self.bot_self_id,
is_chat=False,
)
cache_room_info(self._user_cache, raw_data, self.client_self_id)
cache_room_info(self._user_cache, raw_data, self.bot_self_id)

raw_text = raw_data.get("text", "")
message_parts = []
Expand All @@ -736,7 +736,7 @@ async def convert_room_message(self, raw_data: dict[str, Any]) -> AstrBotMessage
message,
raw_text,
self._bot_username,
self.client_self_id,
self.bot_self_id,
)
message_parts.extend(text_parts)
else:
Expand Down
16 changes: 8 additions & 8 deletions astrbot/core/platform/sources/misskey/misskey_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def extract_sender_info(
def create_base_message(
raw_data: dict[str, Any],
sender_info: dict[str, Any],
client_self_id: str,
bot_self_id: str,
is_chat: bool = False,
room_id: str | None = None,
) -> AstrBotMessage:
Expand Down Expand Up @@ -367,7 +367,7 @@ def create_base_message(
session_id if sender_info["sender_id"] else f"{session_prefix}%unknown"
)
message.message_id = str(raw_data.get("id", ""))
message.self_id = client_self_id
message.self_id = bot_self_id

return message

Expand All @@ -376,7 +376,7 @@ def process_at_mention(
message: AstrBotMessage,
raw_text: str,
bot_username: str,
client_self_id: str,
bot_self_id: str,
) -> tuple[list[str], str]:
"""处理@提及逻辑,返回消息部分列表和处理后的文本"""
message_parts = []
Expand All @@ -386,7 +386,7 @@ def process_at_mention(

if bot_username and raw_text.startswith(f"@{bot_username}"):
at_mention = f"@{bot_username}"
message.message.append(Comp.At(qq=client_self_id))
message.message.append(Comp.At(qq=bot_self_id))
remaining_text = raw_text[len(at_mention) :].strip()
if remaining_text:
message.message.append(Comp.Plain(remaining_text))
Expand All @@ -401,7 +401,7 @@ def cache_user_info(
user_cache: dict[str, Any],
sender_info: dict[str, Any],
raw_data: dict[str, Any],
client_self_id: str,
bot_self_id: str,
is_chat: bool = False,
) -> None:
"""缓存用户信息"""
Expand All @@ -410,7 +410,7 @@ def cache_user_info(
"username": sender_info["username"],
"nickname": sender_info["nickname"],
"visibility": "specified",
"visible_user_ids": [client_self_id, sender_info["sender_id"]],
"visible_user_ids": [bot_self_id, sender_info["sender_id"]],
}
else:
user_cache_data = {
Expand All @@ -428,7 +428,7 @@ def cache_user_info(
def cache_room_info(
user_cache: dict[str, Any],
raw_data: dict[str, Any],
client_self_id: str,
bot_self_id: str,
) -> None:
"""缓存房间信息"""
room_data = raw_data.get("toRoom")
Expand All @@ -442,7 +442,7 @@ def cache_room_info(
"room_description": room_data.get("description", ""),
"owner_id": room_data.get("ownerId", ""),
"visibility": "specified",
"visible_user_ids": [client_self_id],
"visible_user_ids": [bot_self_id],
}


Expand Down
3 changes: 2 additions & 1 deletion astrbot/core/platform/sources/telegram/tg_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def __init__(
) -> None:
super().__init__(platform_config, event_queue)
self.settings = platform_settings
self.client_self_id = uuid.uuid4().hex[:8]

base_url = self.config.get(
"telegram_api_base_url",
Expand Down Expand Up @@ -336,6 +335,8 @@ async def convert_message(
return None

def _apply_caption() -> None:
if not update.message:
return
Comment thread
Soulter marked this conversation as resolved.
if update.message.caption:
message.message_str = update.message.caption
message.message.append(Comp.Plain(message.message_str))
Expand Down
1 change: 0 additions & 1 deletion astrbot/core/platform/sources/wecom/wecom_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ def __init__(
) -> None:
super().__init__(platform_config, event_queue)
self.settingss = platform_settings
self.client_self_id = uuid.uuid4().hex[:8]
self.api_base_url = platform_config.get(
"api_base_url",
"https://qyapi.weixin.qq.com/cgi-bin/",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import os
import sys
import time
import uuid
from collections.abc import Callable, Coroutine
from typing import Any, cast

Expand Down Expand Up @@ -324,7 +323,6 @@ def __init__(
) -> None:
super().__init__(platform_config, event_queue)
self.settingss = platform_settings
self.client_self_id = uuid.uuid4().hex[:8]
self.api_base_url = platform_config.get(
"api_base_url",
"https://api.weixin.qq.com/cgi-bin/",
Expand Down
Loading