Skip to content

Commit cbbb7f3

Browse files
committed
Squashed commit of the following:
commit 8bf52650bda60ca052c21ebdafc1769972137e40 Author: xtex <[email protected]> Date: Sun Dec 10 13:55:17 2023 +0800 Revert "fix: quick confirm in ~wiki" This reverts commit cb9c9e0. Signed-off-by: xtex <[email protected]> commit 054a3e7e803a9c3b67a80608bce3ca10fb85a52b Author: xtex <[email protected]> Date: Sun Dec 10 13:54:35 2023 +0800 Revert "fix: quick confirm in ~wiki" This reverts commit 618e823. commit 4b35043e691d164fe82b65a73208dd60175ff1df Author: xtex <[email protected]> Date: Sun Dec 10 13:54:05 2023 +0800 Revert "feat: initial quick confirm" This reverts commit dae1c69. commit 7fd4c17ec956519d75042f6f6f14fc126ff8840f Author: xtex <[email protected]> Date: Sun Dec 10 13:53:40 2023 +0800 Revert "build(deps): update matrix-nio" This reverts commit 6311fa9. commit 3aececb6720c3245cacddffc6f8c9acec5c8119a Author: xtex <[email protected]> Date: Sun Dec 10 13:53:35 2023 +0800 Revert "feat: init quick confirm (Teahouse-Studios#1046)" This reverts commit 0f8b85c. Signed-off-by: xtex <[email protected]> Signed-off-by: xtex <[email protected]>
1 parent fc8d071 commit cbbb7f3

File tree

15 files changed

+41
-94
lines changed

15 files changed

+41
-94
lines changed

bots/matrix/bot.py

+12-22
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from bots.matrix import client
1010
from bots.matrix.client import bot
1111
from bots.matrix.info import client_name
12-
from bots.matrix.message import MessageSession, FetchTarget, ReactionMessageSession
12+
from bots.matrix.message import MessageSession, FetchTarget
1313
from core.builtins import PrivateAssets, Url
1414
from core.logger import Logger
1515
from core.parser.message import parser
@@ -50,45 +50,36 @@ async def on_room_member(room: nio.MatrixRoom, event: nio.RoomMemberEvent):
5050
Logger.info(f"Left empty room {room.room_id}")
5151

5252

53-
async def on_message(room: nio.MatrixRoom, event: nio.Event):
53+
async def on_message(room: nio.MatrixRoom, event: nio.RoomMessageFormatted):
5454
if event.sender != bot.user_id and bot.olm:
5555
for device_id, olm_device in bot.device_store[event.sender].items():
5656
if bot.olm.is_device_verified(olm_device):
5757
continue
5858
bot.verify_device(olm_device)
5959
Logger.info(f"trust olm device for device id {event.sender} -> {device_id}")
60-
if isinstance(event, nio.RoomMessageFormatted) and event.source['content']['msgtype'] == 'm.notice':
60+
if event.source['content']['msgtype'] == 'm.notice':
6161
# https://spec.matrix.org/v1.7/client-server-api/#mnotice
6262
return
6363
is_room = room.member_count != 2 or room.join_rule != 'invite'
6464
target_id = room.room_id if is_room else event.sender
6565
reply_id = None
6666
if 'm.relates_to' in event.source['content'] and 'm.in_reply_to' in event.source['content']['m.relates_to']:
6767
reply_id = event.source['content']['m.relates_to']['m.in_reply_to']['event_id']
68-
6968
resp = await bot.get_displayname(event.sender)
7069
if isinstance(resp, nio.ErrorResponse):
7170
Logger.error(f"Failed to get display name for {event.sender}")
7271
return
7372
sender_name = resp.displayname
7473

75-
target = MsgInfo(target_id=f'Matrix|{target_id}',
76-
sender_id=f'Matrix|{event.sender}',
77-
target_from=f'Matrix',
78-
sender_from='Matrix',
79-
sender_name=sender_name,
80-
client_name=client_name,
81-
message_id=event.event_id,
82-
reply_id=reply_id)
83-
session = Session(message=event.source, target=room.room_id, sender=event.sender)
84-
85-
msg = None
86-
if isinstance(event, nio.RoomMessageFormatted):
87-
msg = MessageSession(target, session)
88-
elif isinstance(event, nio.ReactionEvent):
89-
msg = ReactionMessageSession(target, session)
90-
else:
91-
raise NotImplemented
74+
msg = MessageSession(MsgInfo(target_id=f'Matrix|{target_id}',
75+
sender_id=f'Matrix|{event.sender}',
76+
target_from=f'Matrix',
77+
sender_from='Matrix',
78+
sender_name=sender_name,
79+
client_name=client_name,
80+
message_id=event.event_id,
81+
reply_id=reply_id),
82+
Session(message=event.source, target=room.room_id, sender=event.sender))
9283
asyncio.create_task(parser(msg))
9384

9485

@@ -150,7 +141,6 @@ async def start():
150141
bot.add_event_callback(on_invite, nio.InviteEvent)
151142
bot.add_event_callback(on_room_member, nio.RoomMemberEvent)
152143
bot.add_event_callback(on_message, nio.RoomMessageFormatted)
153-
bot.add_event_callback(on_message, nio.ReactionEvent)
154144
bot.add_to_device_callback(on_verify, nio.KeyVerificationEvent)
155145
bot.add_event_callback(on_in_room_verify, nio.RoomMessageUnknown)
156146

bots/matrix/message.py

+1-32
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ async def to_message_chain(self):
198198

199199
async def delete(self):
200200
try:
201-
await bot.room_redact(self.session.target, self.target.message_id)
201+
await bot.room_redact(self.session.target, self.session.message['event_id'])
202202
except Exception:
203203
Logger.error(traceback.format_exc())
204204

@@ -221,37 +221,6 @@ async def __aexit__(self, exc_type, exc_val, exc_tb):
221221
pass
222222

223223

224-
class ReactionMessageSession(MessageSession):
225-
class Feature(MessageSession.Feature):
226-
pass
227-
228-
class Typing(MessageSession.Typing):
229-
pass
230-
231-
def as_display(self, text_only=False):
232-
if text_only:
233-
return ''
234-
return self.session.message['content']['m.relates_to']['key']
235-
236-
async def to_message_chain(self):
237-
return MessageChain([])
238-
239-
def is_quick_confirm(self, target: Union[MessageSession, FinishedSession]) -> bool:
240-
content = self.session.message['content']['m.relates_to']
241-
if content['rel_type'] == 'm.annotation':
242-
if content['key'] in ['👍️', '✔️', '🎉']: # todo: move to config
243-
if target is None:
244-
return True
245-
else:
246-
msg = [target.target.message_id] if isinstance(target, MessageSession) else target.message_id
247-
if content['event_id'] in msg:
248-
return True
249-
return False
250-
251-
asDisplay = as_display
252-
toMessageChain = to_message_chain
253-
254-
255224
class FetchedSession(Bot.FetchedSession):
256225

257226
async def _resolve_matrix_room_(self):

config/config.toml.example

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ debug = false
3131
cache_path = "./cache/"
3232
command_prefix = ["~", "~",]
3333
confirm_command = ["是", "对", "對", "yes", "Yes", "YES", "y", "Y",]
34-
quick_confirm = true
3534
disabled_bots =
3635
locale = "zh_cn"
3736
timezone_offset = "+8"

core/builtins/message/__init__.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
from core.builtins.message.internal import *
88
from core.builtins.tasks import MessageTaskManager
99
from core.builtins.temp import ExecutionLockList
10-
from core.builtins.utils import confirm_command, quick_confirm
10+
from core.builtins.utils import confirm_command
1111
from core.exceptions import WaitCancelException
12-
from core.types.message import MessageSession as MessageSessionT, FinishedSession, MsgInfo, Session
12+
from core.types.message import MessageSession as MessageSessionT, MsgInfo, Session
1313
from core.utils.i18n import Locale
1414
from core.utils.text import parse_time_string
1515
from database import BotDBUtil
@@ -52,14 +52,12 @@ async def wait_confirm(self, message_chain=None, quote=True, delete=True, append
5252
await send.delete()
5353
if result.as_display(text_only=True) in confirm_command:
5454
return True
55-
if quick_confirm and result.is_quick_confirm(send):
56-
return True
5755
return False
5856
else:
5957
raise WaitCancelException
6058

6159
async def wait_next_message(self, message_chain=None, quote=True, delete=False,
62-
append_instruction=True) -> (MessageSessionT, FinishedSession):
60+
append_instruction=True) -> MessageSessionT:
6361
sent = None
6462
ExecutionLockList.remove(self)
6563
if message_chain is not None:
@@ -74,7 +72,7 @@ async def wait_next_message(self, message_chain=None, quote=True, delete=False,
7472
if delete and sent is not None:
7573
await sent.delete()
7674
if result is not None:
77-
return (result, sent)
75+
return result
7876
else:
7977
raise WaitCancelException
8078

core/builtins/tasks.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def add_task(cls, session: MessageSession, flag, all_=False, reply=None):
2323
Logger.debug(cls._list)
2424

2525
@classmethod
26-
def get_result(cls, session: MessageSession) -> MessageSession:
26+
def get_result(cls, session: MessageSession):
2727
if 'result' in cls._list[session.target.target_id][session.target.sender_id][session]:
2828
return cls._list[session.target.target_id][session.target.sender_id][session]['result']
2929
else:

core/builtins/utils/__init__.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33

44

55
confirm_command = Config('confirm_command', default=["是", "对", "對", "yes", "Yes", "YES", "y", "Y"])
6-
quick_confirm = Config('quick_confirm', default=True)
76
command_prefix = Config('command_prefix', default=['~', '~']) # 消息前缀
87

98

109
class EnableDirtyWordCheck:
1110
status = False
1211

1312

14-
__all__ = ["confirm_command", "quick_confirm", "command_prefix", "EnableDirtyWordCheck", "PrivateAssets", "Secret"]
13+
__all__ = ["confirm_command", "command_prefix", "EnableDirtyWordCheck", "PrivateAssets", "Secret"]

core/types/message/__init__.py

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import asyncio
2-
from typing import List, Self, Union, Dict
2+
from typing import List, Union, Dict
33

44
from core.exceptions import FinishedException
55
from .chain import MessageChain
@@ -141,13 +141,13 @@ async def wait_confirm(self, message_chain=None, quote=True, delete=True):
141141
"""
142142
raise NotImplementedError
143143

144-
async def wait_next_message(self, message_chain=None, quote=True, delete=False, append_instruction=True) -> (Self, FinishedSession):
144+
async def wait_next_message(self, message_chain=None, quote=True, delete=False, append_instruction=True):
145145
"""
146146
一次性模板,用于等待对象的下一条消息。
147147
:param message_chain: 需要发送的确认消息,可不填
148148
:param quote: 是否引用传入dict中的消息(默认为True)
149149
:param delete: 是否在触发后删除消息
150-
:return: 下一条消息的MessageChain对象和发出的提示消息
150+
:return: 下一条消息的MessageChain对象
151151
"""
152152
raise NotImplementedError
153153

@@ -201,13 +201,6 @@ async def check_native_permission(self):
201201
"""
202202
raise NotImplementedError
203203

204-
def is_quick_confirm(self, target: Union[Self, FinishedSession] = None) -> bool:
205-
"""
206-
用于检查消息是否可用作快速确认事件。
207-
:param target: 确认的目标消息
208-
"""
209-
return False
210-
211204
async def fake_forward_msg(self, nodelist):
212205
"""
213206
用于发送假转发消息(QQ)。

modules/chemical_code/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,9 @@ async def timer(start):
243243

244244
await asyncio.gather(ans(msg, csr['name'], random_mode), timer(time_start))
245245
else:
246-
result, _ = await msg.wait_next_message([Plain(msg.locale.t('chemical_code.message.showid', id=csr["id"])),
247-
Image(newpath), Plain(msg.locale.t('chemical_code.message.captcha',
248-
times=set_timeout))], append_instruction=False)
246+
result = await msg.wait_next_message([Plain(msg.locale.t('chemical_code.message.showid', id=csr["id"])),
247+
Image(newpath), Plain(msg.locale.t('chemical_code.message.captcha',
248+
times=set_timeout))], append_instruction=False)
249249
if play_state[msg.target.target_id]['active']:
250250
if result.as_display(text_only=True) == csr['name']:
251251
send_ = msg.locale.t('chemical_code.message.correct')

modules/ncmusic/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ async def search(msg: Bot.MessageSession, keyword: str):
4949
if len(result['result']['songs']) > 10:
5050
send_msg.append(Plain(msg.locale.t('ncmusic.message.search.collapse')))
5151
send_msg.append(Plain(msg.locale.t('ncmusic.message.search.prompt')))
52-
query, _ = await msg.wait_next_message(send_msg)
52+
query = await msg.wait_next_message(send_msg)
5353
query = query.as_display(text_only=True)
5454
try:
5555
query = int(query)
@@ -87,7 +87,7 @@ async def search(msg: Bot.MessageSession, keyword: str):
8787
send_msg += msg.locale.t('ncmusic.message.search.collapse')
8888
send_msg += '\n'
8989
send_msg += msg.locale.t('ncmusic.message.search.prompt')
90-
query, _ = await msg.wait_next_message(send_msg)
90+
query = await msg.wait_next_message(send_msg)
9191
query = query.as_display(text_only=True)
9292
try:
9393
query = int(query)

modules/summary/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ async def _(msg: Bot.MessageSession):
2828
qc = CoolDown('call_openai', msg)
2929
c = qc.check(60)
3030
if c == 0 or msg.target.target_from == 'TEST|Console' or is_superuser:
31-
f_msg, _ = await msg.wait_next_message(msg.locale.t('summary.message'), append_instruction=False)
31+
f_msg = await msg.wait_next_message(msg.locale.t('summary.message'), append_instruction=False)
3232
try:
3333
f = re.search(r'\[Ke:forward,id=(.*?)\]', f_msg.as_display()).group(1)
3434
except AttributeError:

modules/twenty_four/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ async def _(msg: Bot.MessageSession):
108108
numbers = [random.randint(1, 13) for _ in range(4)]
109109
has_solution_flag = await has_solution(numbers)
110110

111-
answer, _ = await msg.wait_next_message(msg.locale.t('twenty_four.message', numbers=numbers), append_instruction=False)
111+
answer = await msg.wait_next_message(msg.locale.t('twenty_four.message', numbers=numbers), append_instruction=False)
112112
expression = answer.as_display(text_only=True)
113113
if play_state[msg.target.target_id]['active']:
114114
if expression.lower() in no_solution:

modules/wiki/wiki.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import filetype
66

7-
from core.builtins import Bot, Plain, Image, Voice, Url, confirm_command, quick_confirm
7+
from core.builtins import Bot, Plain, Image, Voice, Url, confirm_command
88
from core.component import module
99
from core.exceptions import AbuseWarning
1010
from core.logger import Logger
@@ -346,13 +346,11 @@ async def image_and_voice():
346346

347347
async def wait_confirm():
348348
if wait_msg_list and session.Feature.wait:
349-
confirm, sent = await session.wait_next_message(wait_msg_list, delete=True, append_instruction=False)
349+
confirm = await session.wait_next_message(wait_msg_list, delete=True, append_instruction=False)
350350
auto_index = False
351351
index = 0
352352
if confirm.as_display(text_only=True) in confirm_command:
353353
auto_index = True
354-
elif quick_confirm and confirm.is_quick_confirm(sent):
355-
auto_index = True
356354
elif confirm.as_display(text_only=True).isdigit():
357355
index = int(confirm.as_display()) - 1
358356
else:

poetry.lock

+6-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pycryptodome = "^3.18.0"
5454
langconv = "^0.2.0"
5555
toml = "^0.10.2"
5656
khl-py = "^0.3.16"
57-
matrix-nio = "^0.22.0"
57+
matrix-nio = "^0.21.2"
5858
attrs = "^23.1.0"
5959
uvicorn = {extras = ["standard"], version = "^0.23.2"}
6060
pyjwt = {extras = ["crypto"], version = "^2.8.0"}

requirements.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1145,9 +1145,9 @@ matplotlib==3.7.2 ; python_full_version >= "3.8.1" and python_full_version < "4.
11451145
--hash=sha256:f081c03f413f59390a80b3e351cc2b2ea0205839714dbc364519bcf51f4b56ca \
11461146
--hash=sha256:fdbb46fad4fb47443b5b8ac76904b2e7a66556844f33370861b4788db0f8816a \
11471147
--hash=sha256:fdcd28360dbb6203fb5219b1a5658df226ac9bebc2542a9e8f457de959d713d0
1148-
matrix-nio==0.22.1 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0" \
1149-
--hash=sha256:36a7175a41b145026db7f3bf004577aa8906d09ed8c53f276452ac06ed8635e4 \
1150-
--hash=sha256:65956252c516f0b42b359d5816fbb66e2617a1f2c02ae45f2730257b815656d8
1148+
matrix-nio==0.21.2 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0" \
1149+
--hash=sha256:414301fc25662af3e3436de5b955980474c03b0f3001f1b041c49743ede73232 \
1150+
--hash=sha256:95bec84dd0d4eca4f0ce252d2f630d435edbc41bb405448d88916a3783479237
11511151
monotonic==1.6 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0" \
11521152
--hash=sha256:3a55207bcfed53ddd5c5bae174524062935efed17792e9de2ad0205ce9ad63f7 \
11531153
--hash=sha256:68687e19a14f11f26d140dd5c86f3dba4bf5df58003000ed467e0e2a69bca96c

0 commit comments

Comments
 (0)