Debug: log every incoming m.room.message event in Room.timeline handler
This commit is contained in:
19
index.js
19
index.js
@@ -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}`))
|
||||
|
||||
Reference in New Issue
Block a user