Merge branch '3-afficher-le-texte-des-emojis' into 'master'

Resolve "Afficher le texte des emojis"

Closes #3

See merge request Neutrinet/matrix-alertbot!3
This commit is contained in:
HgO 2022-10-26 15:26:16 +00:00
commit b3003d8287
2 changed files with 34 additions and 4 deletions

View file

@ -305,11 +305,12 @@ class Callbacks:
async def key_verification_confirm(self, event: KeyVerificationKey):
sas = self.matrix_client.key_verifications[event.transaction_id]
emoji_list = sas.get_emoji()
emoji_str = " ".join(emoji for emoji, alt_text in emoji_list)
emoji_list, alt_text_list = zip(*sas.get_emoji())
emoji_str = " ".join(emoji_list)
alt_text_str = " ".join(alt_text_list)
logger.info(
f"Received request to verify emojis from {event.sender}: {emoji_str}"
f"Received request to verify emojis from {event.sender}: {emoji_str} ({alt_text_str})"
)
event_response = await self.matrix_client.confirm_short_auth_string(
@ -338,7 +339,14 @@ class Callbacks:
# )
async def key_verification_end(self, event: KeyVerificationMac):
sas = self.matrix_client.key_verifications[event.transaction_id]
try:
sas = self.matrix_client.key_verifications[event.transaction_id]
except KeyError:
logger.error(
f"Unable to find transaction ID {event.transaction_id} sent by {event.sender}"
)
return
try:
todevice_msg = sas.get_mac()
except LocalProtocolError as e:

View file

@ -752,6 +752,28 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase):
fake_sas.get_mac.assert_called_once_with()
self.fake_matrix_client.to_device.assert_called_once_with(fake_sas.get_mac())
async def test_key_verification_end_with_missing_transaction_id(self) -> None:
"""Tests the callback for RoomMessageText with the command prefix"""
# Tests that the bot process messages in the room that contain a command
fake_transaction_id = "fake transaction id"
fake_key_verification_event = Mock(spec=nio.KeyVerificationStart)
fake_key_verification_event.sender = "@some_other_fake_user:example.com"
fake_key_verification_event.transaction_id = fake_transaction_id
self.fake_matrix_client.to_device.return_value = make_awaitable()
fake_sas = Mock()
fake_transactions_dict = {}
self.fake_matrix_client.key_verifications = fake_transactions_dict
# Pretend that we received a text message event
await self.callbacks.key_verification_end(fake_key_verification_event)
# Check that we attempted to execute the command
fake_sas.get_mac.assert_not_called()
self.fake_matrix_client.to_device.assert_not_called()
async def test_key_verification_end_with_mac_error(self) -> None:
"""Tests the callback for RoomMessageText with the command prefix"""
# Tests that the bot process messages in the room that contain a command