mirror of
https://github.com/Genshin-bots/gsuid_core.git
synced 2025-06-05 23:19:46 +08:00
🎨 update_data_by_uid()
允许bot_id
传入None
This commit is contained in:
parent
81eda3a2c3
commit
4b4379ae4a
@ -334,7 +334,7 @@ class BaseBotIDModel(BaseIDModel):
|
|||||||
cls,
|
cls,
|
||||||
session: AsyncSession,
|
session: AsyncSession,
|
||||||
uid: str,
|
uid: str,
|
||||||
bot_id: str,
|
bot_id: Optional[str] = None,
|
||||||
game_name: Optional[str] = None,
|
game_name: Optional[str] = None,
|
||||||
**data,
|
**data,
|
||||||
) -> int:
|
) -> int:
|
||||||
@ -369,9 +369,11 @@ class BaseBotIDModel(BaseIDModel):
|
|||||||
data[uid_name] = uid
|
data[uid_name] = uid
|
||||||
return await cls.full_insert_data(bot_id=bot_id, **data)
|
return await cls.full_insert_data(bot_id=bot_id, **data)
|
||||||
|
|
||||||
sql = update(cls).where(
|
sql = update(cls).where(and_(getattr(cls, uid_name) == uid))
|
||||||
and_(getattr(cls, uid_name) == uid, cls.bot_id == bot_id)
|
|
||||||
)
|
if bot_id is not None:
|
||||||
|
sql = sql.where(cls.bot_id == bot_id)
|
||||||
|
|
||||||
if data is not None:
|
if data is not None:
|
||||||
query = sql.values(**data)
|
query = sql.values(**data)
|
||||||
query.execution_options(synchronize_session='fetch')
|
query.execution_options(synchronize_session='fetch')
|
||||||
|
@ -11,7 +11,7 @@ async def set_database_value(
|
|||||||
command_start: str,
|
command_start: str,
|
||||||
command_value: str,
|
command_value: str,
|
||||||
uid: str,
|
uid: str,
|
||||||
bot_id: str,
|
bot_id: Optional[str],
|
||||||
value: str,
|
value: str,
|
||||||
):
|
):
|
||||||
fields = model.__fields__
|
fields = model.__fields__
|
||||||
@ -36,7 +36,7 @@ async def set_database_value(
|
|||||||
title = title if title else keyname
|
title = title if title else keyname
|
||||||
if desc:
|
if desc:
|
||||||
if desc == f'{command_start}{command_value}':
|
if desc == f'{command_start}{command_value}':
|
||||||
await model.update_data_by_uid(
|
retcode = await model.update_data_by_uid(
|
||||||
uid,
|
uid,
|
||||||
bot_id,
|
bot_id,
|
||||||
game_name,
|
game_name,
|
||||||
@ -44,5 +44,7 @@ async def set_database_value(
|
|||||||
f'{keyname}': value,
|
f'{keyname}': value,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
if retcode == 0:
|
||||||
return f'✅{title}\n📝已设置为{value}'
|
return f'✅{title}\n📝已设置为{value}'
|
||||||
|
else:
|
||||||
|
return f'❌{title}\n📝设置失败'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user