remove invite and react callbacks
This commit is contained in:
@@ -78,73 +78,75 @@ class Callbacks:
|
|||||||
await command.process()
|
await command.process()
|
||||||
|
|
||||||
async def invite(self, room: MatrixRoom, event: InviteMemberEvent) -> None:
|
async def invite(self, room: MatrixRoom, event: InviteMemberEvent) -> None:
|
||||||
"""Callback for when an invite is received. Join the room specified in the invite.
|
#"""Callback for when an invite is received. Join the room specified in the invite.
|
||||||
|
|
||||||
Args:
|
#Args:
|
||||||
room: The room that we are invited to.
|
# room: The room that we are invited to.
|
||||||
|
|
||||||
event: The invite event.
|
# event: The invite event.
|
||||||
"""
|
#"""
|
||||||
logger.debug(f"Got invite to {room.room_id} from {event.sender}.")
|
#logger.debug(f"Got invite to {room.room_id} from {event.sender}.")
|
||||||
|
|
||||||
# Attempt to join 3 times before giving up
|
## Attempt to join 3 times before giving up
|
||||||
for attempt in range(3):
|
#for attempt in range(3):
|
||||||
result = await self.client.join(room.room_id)
|
# result = await self.client.join(room.room_id)
|
||||||
if type(result) == JoinError:
|
# if type(result) == JoinError:
|
||||||
logger.error(
|
# logger.error(
|
||||||
f"Error joining room {room.room_id} (attempt %d): %s",
|
# f"Error joining room {room.room_id} (attempt %d): %s",
|
||||||
attempt,
|
# attempt,
|
||||||
result.message,
|
# result.message,
|
||||||
)
|
# )
|
||||||
else:
|
# else:
|
||||||
break
|
# break
|
||||||
else:
|
#else:
|
||||||
logger.error("Unable to join room: %s", room.room_id)
|
# logger.error("Unable to join room: %s", room.room_id)
|
||||||
|
|
||||||
# Successfully joined room
|
## Successfully joined room
|
||||||
logger.info(f"Joined {room.room_id}")
|
#logger.info(f"Joined {room.room_id}")
|
||||||
|
return
|
||||||
|
|
||||||
async def _reaction(
|
async def _reaction(
|
||||||
self, room: MatrixRoom, event: UnknownEvent, reacted_to_id: str
|
self, room: MatrixRoom, event: UnknownEvent, reacted_to_id: str
|
||||||
) -> None:
|
) -> None:
|
||||||
"""A reaction was sent to one of our messages. Let's send a reply acknowledging it.
|
#"""A reaction was sent to one of our messages. Let's send a reply acknowledging it.
|
||||||
|
|
||||||
Args:
|
#Args:
|
||||||
room: The room the reaction was sent in.
|
# room: The room the reaction was sent in.
|
||||||
|
|
||||||
event: The reaction event.
|
# event: The reaction event.
|
||||||
|
|
||||||
reacted_to_id: The event ID that the reaction points to.
|
# reacted_to_id: The event ID that the reaction points to.
|
||||||
"""
|
#"""
|
||||||
logger.debug(f"Got reaction to {room.room_id} from {event.sender}.")
|
#logger.debug(f"Got reaction to {room.room_id} from {event.sender}.")
|
||||||
|
|
||||||
# Get the original event that was reacted to
|
## Get the original event that was reacted to
|
||||||
event_response = await self.client.room_get_event(room.room_id, reacted_to_id)
|
#event_response = await self.client.room_get_event(room.room_id, reacted_to_id)
|
||||||
if isinstance(event_response, RoomGetEventError):
|
#if isinstance(event_response, RoomGetEventError):
|
||||||
logger.warning(
|
# logger.warning(
|
||||||
"Error getting event that was reacted to (%s)", reacted_to_id
|
# "Error getting event that was reacted to (%s)", reacted_to_id
|
||||||
)
|
# )
|
||||||
return
|
# return
|
||||||
reacted_to_event = event_response.event
|
#reacted_to_event = event_response.event
|
||||||
|
|
||||||
# Only acknowledge reactions to events that we sent
|
## Only acknowledge reactions to events that we sent
|
||||||
if reacted_to_event.sender != self.config.user_id:
|
#if reacted_to_event.sender != self.config.user_id:
|
||||||
return
|
# return
|
||||||
|
|
||||||
# Send a message acknowledging the reaction
|
## Send a message acknowledging the reaction
|
||||||
reaction_sender_pill = make_pill(event.sender)
|
#reaction_sender_pill = make_pill(event.sender)
|
||||||
reaction_content = (
|
#reaction_content = (
|
||||||
event.source.get("content", {}).get("m.relates_to", {}).get("key")
|
# event.source.get("content", {}).get("m.relates_to", {}).get("key")
|
||||||
)
|
#)
|
||||||
message = (
|
#message = (
|
||||||
f"{reaction_sender_pill} reacted to this event with `{reaction_content}`!"
|
# f"{reaction_sender_pill} reacted to this event with `{reaction_content}`!"
|
||||||
)
|
#)
|
||||||
await send_text_to_room(
|
#await send_text_to_room(
|
||||||
self.client,
|
# self.client,
|
||||||
room.room_id,
|
# room.room_id,
|
||||||
message,
|
# message,
|
||||||
reply_to_event_id=reacted_to_id,
|
# reply_to_event_id=reacted_to_id,
|
||||||
)
|
#)
|
||||||
|
return
|
||||||
|
|
||||||
async def decryption_failure(self, room: MatrixRoom, event: MegolmEvent) -> None:
|
async def decryption_failure(self, room: MatrixRoom, event: MegolmEvent) -> None:
|
||||||
"""Callback for when an event fails to decrypt. Inform the user.
|
"""Callback for when an event fails to decrypt. Inform the user.
|
||||||
|
|||||||
Reference in New Issue
Block a user