mirror of
https://github.com/Genshin-bots/gsuid_core.git
synced 2025-05-12 06:55:49 +08:00
🎨 从Event
获取bot_id
This commit is contained in:
parent
c45149c23d
commit
1619311abe
@ -16,13 +16,14 @@ class _Bot:
|
||||
self.bot = ws
|
||||
self.logger = GsLogger(self.bot_id, ws)
|
||||
self.queue = asyncio.queues.Queue()
|
||||
self.background_tasks = set()
|
||||
self.bg_tasks = set()
|
||||
|
||||
async def target_send(
|
||||
self,
|
||||
message: Union[Message, List[Message], str, bytes],
|
||||
target_type: Literal['group', 'direct', 'channel', 'sub_channel'],
|
||||
target_id: Optional[str],
|
||||
bot_id: str,
|
||||
):
|
||||
if isinstance(message, Message):
|
||||
message = [message]
|
||||
@ -35,21 +36,19 @@ class _Bot:
|
||||
message = [MessageSegment.image(message)]
|
||||
send = MessageSend(
|
||||
content=message,
|
||||
bot_id=self.bot_id,
|
||||
bot_id=bot_id,
|
||||
target_type=target_type,
|
||||
target_id=target_id,
|
||||
)
|
||||
logger.info(f'[发送消息] {send}')
|
||||
logger.info(f'[发送消息to] {target_id}')
|
||||
await self.bot.send_bytes(msgjson.encode(send))
|
||||
|
||||
async def _process(self):
|
||||
while True:
|
||||
data = await self.queue.get()
|
||||
task = asyncio.create_task(data)
|
||||
self.background_tasks.add(task)
|
||||
task.add_done_callback(
|
||||
lambda _: self.background_tasks.discard(task)
|
||||
)
|
||||
self.bg_tasks.add(task)
|
||||
task.add_done_callback(lambda _: self.bg_tasks.discard(task))
|
||||
|
||||
|
||||
class Bot:
|
||||
@ -64,6 +63,7 @@ class Bot:
|
||||
message,
|
||||
self.ev.user_type,
|
||||
self.ev.group_id if self.ev.group_id else self.ev.user_id,
|
||||
self.ev.bot_id,
|
||||
)
|
||||
|
||||
async def target_send(
|
||||
@ -72,4 +72,6 @@ class Bot:
|
||||
target_type: Literal['group', 'direct', 'channel', 'sub_channel'],
|
||||
target_id: Optional[str],
|
||||
):
|
||||
return await self.bot.target_send(message, target_type, target_id)
|
||||
return await self.bot.target_send(
|
||||
message, target_type, target_id, self.ev.bot_id
|
||||
)
|
||||
|
20
poetry.lock
generated
20
poetry.lock
generated
@ -583,14 +583,14 @@ test = ["anyio[trio] (>=3.2.1,<4.0.0)", "black (==22.10.0)", "coverage[toml] (>=
|
||||
|
||||
[[package]]
|
||||
name = "fastapi-amis-admin"
|
||||
version = "0.4.3"
|
||||
version = "0.5.0"
|
||||
description = "FastAPI-Amis-Admin is a high-performance, efficient and easily extensible FastAPI admin framework. Inspired by Django-admin, and has as many powerful functions as Django-admin. "
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
files = [
|
||||
{file = "fastapi_amis_admin-0.4.3-py3-none-any.whl", hash = "sha256:0f244020bb79971253054908267c7f59e6fe3ecdfe73d99fecf9d0e99cc2be52"},
|
||||
{file = "fastapi_amis_admin-0.4.3.tar.gz", hash = "sha256:914b82abb653d1fda318b59451ed88d9740cce1d5915cc05c06b1d8fee98d9d1"},
|
||||
{file = "fastapi_amis_admin-0.5.0-py3-none-any.whl", hash = "sha256:82f232c27b277d83f8829c1be07ec64ebbc94acf6bfd6fadf30c1f9fc9ed2704"},
|
||||
{file = "fastapi_amis_admin-0.5.0.tar.gz", hash = "sha256:f17d9cba8e2b32374d5a6f6576b98867d5777668a92885663a01b7a0faf206ff"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
@ -609,20 +609,20 @@ test = ["aiosqlite (>=0.15.0)", "fastapi-amis-admin[standard]", "httpx (>=0.23.0
|
||||
|
||||
[[package]]
|
||||
name = "fastapi-user-auth"
|
||||
version = "0.4.3"
|
||||
version = "0.5.0"
|
||||
description = "FastAPI-User-Auth is a simple and powerful FastAPI user RBAC authentication and authorization library. Based on FastAPI-Amis-Admin and provides a freely extensible visual management interface."
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
files = [
|
||||
{file = "fastapi_user_auth-0.4.3-py3-none-any.whl", hash = "sha256:4c8dae90e64e00d9a8b2a5caf47c6174d5313c9fee3b61c17e532049fbca4c9e"},
|
||||
{file = "fastapi_user_auth-0.4.3.tar.gz", hash = "sha256:63cd2430b88cc158244206150b313da2fa5a97f8f8cebb3477d93a7e92b5975f"},
|
||||
{file = "fastapi_user_auth-0.5.0-py3-none-any.whl", hash = "sha256:de93a520b1c0458887cad796f6d79c9d214ada82e4ffd8312635cca374b1ee0b"},
|
||||
{file = "fastapi_user_auth-0.5.0.tar.gz", hash = "sha256:86022bb540e984500e13674379f74ce04db6974fef66de3fb92b57ae876f8bd1"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
bcrypt = ">=4.0.0"
|
||||
email-validator = "*"
|
||||
fastapi-amis-admin = ">=0.4.0,<0.5.0"
|
||||
fastapi-amis-admin = ">=0.5.0,<0.6.0"
|
||||
passlib = ">=1.7.4"
|
||||
pydantic = ">=1.9"
|
||||
sqlmodelx = ">=0.0.2"
|
||||
@ -1469,14 +1469,14 @@ tests = ["check-manifest", "coverage", "defusedxml", "markdown2", "olefile", "pa
|
||||
|
||||
[[package]]
|
||||
name = "platformdirs"
|
||||
version = "3.0.0"
|
||||
version = "3.1.0"
|
||||
description = "A small Python package for determining appropriate platform-specific dirs, e.g. a \"user data dir\"."
|
||||
category = "dev"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
files = [
|
||||
{file = "platformdirs-3.0.0-py3-none-any.whl", hash = "sha256:b1d5eb14f221506f50d6604a561f4c5786d9e80355219694a1b244bcd96f4567"},
|
||||
{file = "platformdirs-3.0.0.tar.gz", hash = "sha256:8a1228abb1ef82d788f74139988b137e78692984ec7b08eaa6c65f1723af28f9"},
|
||||
{file = "platformdirs-3.1.0-py3-none-any.whl", hash = "sha256:13b08a53ed71021350c9e300d4ea8668438fb0046ab3937ac9a29913a1a1350a"},
|
||||
{file = "platformdirs-3.1.0.tar.gz", hash = "sha256:accc3665857288317f32c7bebb5a8e482ba717b474f3fc1d18ca7f9214be0cef"},
|
||||
]
|
||||
|
||||
[package.extras]
|
||||
|
@ -16,8 +16,8 @@ colorama==0.4.6 ; python_full_version >= "3.8.1" and python_full_version < "4.0.
|
||||
dnspython==2.3.0 ; python_full_version >= "3.8.1" and python_version < "4.0"
|
||||
email-validator==1.3.1 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
et-xmlfile==1.1.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
fastapi-amis-admin==0.4.3 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
fastapi-user-auth==0.4.3 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
fastapi-amis-admin==0.5.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
fastapi-user-auth==0.5.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
fastapi==0.92.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
frozenlist==1.3.3 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
gitdb==4.0.10 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
|
Loading…
x
Reference in New Issue
Block a user