mirror of
https://github.com/langbot-app/LangBot.git
synced 2025-11-25 03:15:06 +08:00
* style: remove necessary imports * style: fix F841 * style: fix F401 * style: fix F811 * style: fix E402 * style: fix E721 * style: fix E722 * style: fix E722 * style: fix F541 * style: ruff format * style: all passed * style: add ruff in deps * style: more ignores in ruff.toml * style: add pre-commit
43 lines
1.7 KiB
Python
43 lines
1.7 KiB
Python
from __future__ import annotations
|
|
|
|
import typing
|
|
|
|
from .. import operator, entities, errors
|
|
|
|
|
|
@operator.operator_class(name='next', help='切换到后一个对话', usage='!next')
|
|
class NextOperator(operator.CommandOperator):
|
|
async def execute(
|
|
self, context: entities.ExecuteContext
|
|
) -> typing.AsyncGenerator[entities.CommandReturn, None]:
|
|
if context.session.conversations:
|
|
# 找到当前会话的下一个会话
|
|
for index in range(len(context.session.conversations)):
|
|
if (
|
|
context.session.conversations[index]
|
|
== context.session.using_conversation
|
|
):
|
|
if index == len(context.session.conversations) - 1:
|
|
yield entities.CommandReturn(
|
|
error=errors.CommandOperationError('已经是最后一个对话了')
|
|
)
|
|
return
|
|
else:
|
|
context.session.using_conversation = (
|
|
context.session.conversations[index + 1]
|
|
)
|
|
time_str = (
|
|
context.session.using_conversation.create_time.strftime(
|
|
'%Y-%m-%d %H:%M:%S'
|
|
)
|
|
)
|
|
|
|
yield entities.CommandReturn(
|
|
text=f'已切换到后一个对话: {index} {time_str}: {context.session.using_conversation.messages[0].content}'
|
|
)
|
|
return
|
|
else:
|
|
yield entities.CommandReturn(
|
|
error=errors.CommandOperationError('当前没有对话')
|
|
)
|