debug logging, better comments, notification of failed verification, etc.

This commit is contained in:
William Kray
2025-04-09 13:12:57 -07:00
parent b467a58655
commit 78e604c542
4 changed files with 48 additions and 17 deletions
+3 -1
View File
@@ -166,7 +166,9 @@ validation:
level up to that required to send messages in your room, and leave the DM. level up to that required to send messages in your room, and leave the DM.
not the most user-friendly experience, but may help cut down if you are experiencing not the most user-friendly experience, but may help cut down if you are experiencing
significant spam in your rooms. significant spam in your rooms. every permitted user goes in the state event, so this
will become problematic and expensive for very large rooms... strong recommend not to
use this if you expect to have thousands of room members.
# installation # installation
+2 -1
View File
@@ -121,7 +121,8 @@ redact_on_ban: true
# can be boolean (true/false) for all-or-nothing behavior, # can be boolean (true/false) for all-or-nothing behavior,
# or pass a list of room IDs to only verify users in certain rooms # or pass a list of room IDs to only verify users in certain rooms
# use this in conjunction with room power-levels that require elevated permission # use this in conjunction with room power-levels that require elevated permission
# to send messages in a room. # to send messages in a room. do not enable this for rooms that will have more than
# a few hundred users as this will be very expensive when it comes to state resolution!
check_if_human: false check_if_human: false
# list of phrases that users must type to verify they are human # list of phrases that users must type to verify they are human
+31 -3
View File
@@ -302,9 +302,10 @@ class CommunityBot(Plugin):
else: else:
pass pass
except Exception as e: except Exception as e:
self.log.debug( # commenting this out because it generates a lot of noise
f"Found something funny in the banlist {list_id} for {rule['content']}: {e}" #self.log.debug(
) # f"Found something funny in the banlist {list_id} for {rule['content']}: {e}"
#)
pass pass
# if we haven't exited by now, we must not be banned! # if we haven't exited by now, we must not be banned!
return is_banned return is_banned
@@ -767,6 +768,11 @@ class CommunityBot(Plugin):
await self.do_sync() await self.do_sync()
# greeting activities # greeting activities
room_id = str(evt.room_id) room_id = str(evt.room_id)
self.log.debug(f"New join in room {room_id} by {evt.sender}")
self.log.debug(f"Greeting rooms config: {self.config['greeting_rooms']}")
self.log.debug(f"Check if human config: {self.config['check_if_human']}")
self.log.debug(f"Verification phrases config: {self.config['verification_phrases']}")
if room_id in self.config["greeting_rooms"]: if room_id in self.config["greeting_rooms"]:
if on_banlist: if on_banlist:
return return
@@ -804,6 +810,8 @@ class CommunityBot(Plugin):
elif isinstance(self.config["check_if_human"], list): elif isinstance(self.config["check_if_human"], list):
verification_enabled = evt.room_id in self.config["check_if_human"] verification_enabled = evt.room_id in self.config["check_if_human"]
self.log.debug(f"Verification enabled for room {room_id}: {verification_enabled}")
if not verification_enabled: if not verification_enabled:
return return
@@ -827,6 +835,8 @@ class CommunityBot(Plugin):
# Get the required power level for sending messages # Get the required power level for sending messages
required_level = events.get(str(EventType.ROOM_MESSAGE), events_default) required_level = events.get(str(EventType.ROOM_MESSAGE), events_default)
self.log.debug(f"User {evt.sender} has power level {user_level}, required level is {required_level}")
# If user already has sufficient power level, skip verification # If user already has sufficient power level, skip verification
if user_level >= required_level: if user_level >= required_level:
self.log.debug(f"User {evt.sender} already has sufficient power level ({user_level} >= {required_level})") self.log.debug(f"User {evt.sender} already has sufficient power level ({user_level} >= {required_level})")
@@ -836,6 +846,7 @@ class CommunityBot(Plugin):
return return
# Create DM room with name # Create DM room with name
try:
dm_room = await self.client.create_room( dm_room = await self.client.create_room(
preset=RoomCreatePreset.PRIVATE, preset=RoomCreatePreset.PRIVATE,
invitees=[evt.sender], invitees=[evt.sender],
@@ -847,6 +858,12 @@ class CommunityBot(Plugin):
} }
] ]
) )
self.log.info(f"Created DM room {dm_room} for {evt.sender}")
except Exception as e:
self.log.error(f"Failed to initiate verification process: {e}")
return
# Select random verification phrase # Select random verification phrase
verification_phrase = random.choice(self.config["verification_phrases"]) verification_phrase = random.choice(self.config["verification_phrases"])
@@ -865,6 +882,7 @@ class CommunityBot(Plugin):
Please send a message to this chat with the phrase: "{verification_phrase}" """ Please send a message to this chat with the phrase: "{verification_phrase}" """
await self.client.send_notice(dm_room, greeting) await self.client.send_notice(dm_room, greeting)
self.log.info(f"Started verification process for {evt.sender} in room {room_id}")
except Exception as e: except Exception as e:
self.log.error(f"Failed to start verification process: {e}") self.log.error(f"Failed to start verification process: {e}")
@@ -902,6 +920,11 @@ Please send a message to this chat with the phrase: "{verification_phrase}" """
evt.room_id, evt.room_id,
f"Something went wrong: {str(e)}. Please report this to the room moderators." f"Something went wrong: {str(e)}. Please report this to the room moderators."
) )
if self.config["notification_room"]:
await self.client.send_notice(
self.config["notification_room"],
f"User verification failed for {evt.sender} in room {evt.room_id}, you may need to manually verify them."
)
finally: finally:
await self.client.leave_room(evt.room_id) await self.client.leave_room(evt.room_id)
del self._verification_states[evt.room_id] del self._verification_states[evt.room_id]
@@ -912,6 +935,11 @@ Please send a message to this chat with the phrase: "{verification_phrase}" """
evt.room_id, evt.room_id,
"You have run out of attempts. Please contact a room moderator for assistance." "You have run out of attempts. Please contact a room moderator for assistance."
) )
if self.config["notification_room"]:
await self.client.send_notice(
self.config["notification_room"],
f"User verification failed for {evt.sender} in room {evt.room_id}, you may need to manually verify them."
)
await self.client.leave_room(evt.room_id) await self.client.leave_room(evt.room_id)
del self._verification_states[evt.room_id] del self._verification_states[evt.room_id]
else: else:
+1 -1
View File
@@ -1,6 +1,6 @@
maubot: 0.1.0 maubot: 0.1.0
id: org.jobmachine.communitybot id: org.jobmachine.communitybot
version: 0.2.1 version: 0.2.2
license: MIT license: MIT
modules: modules:
- community - community