Debug: log every incoming m.room.message event in Room.timeline handler

This commit is contained in:
unfunny
2026-09-13 16:35:12 -04:00
parent f0245b22f9
commit 075f685691

View File

@@ -74,17 +74,22 @@ function loadQuotes() {
// Respond to messages in any room this bot is a member of.
client.on('Room.timeline', (event, room) => {
if (event.getType() !== 'm.room.message') return;
if (event.getSender() === userId) return;
const type = event.getType();
if (type !== 'm.room.message') return;
const sender = event.getSender();
const membership = room.getMyMembership();
if (membership !== 'join') return;
const content = event.getContent();
if (!content || typeof content.body !== 'string') return;
const body = typeof content?.body === 'string' ? content.body : '(no body)';
const body = content.body.toLowerCase().trim();
if (body === cmd || body.startsWith(cmd + ' ')) {
console.log(`✉️ [${room.roomId}] membership="${membership}" sender="${sender}" body="${body}"`);
if (sender === userId) return;
if (membership !== 'join') return;
if (body === '(no body)') return;
const lower = body.toLowerCase().trim();
if (lower === cmd || lower.startsWith(cmd + ' ')) {
const quote = quotes[Math.floor(Math.random() * quotes.length)];
client.sendTextMessage(room.roomId, quote)
.then(() => console.log(`🎃 [${room.roomId}] ${quote}`))