diff --git a/examples/room-bot.ts b/examples/room-bot.ts index 19c21d97dc04cc940680afa89d3facd208cf797a..e6f6fbb0655aaa9edbfaa2b25730f1d189a550bc 100644 --- a/examples/room-bot.ts +++ b/examples/room-bot.ts @@ -121,28 +121,33 @@ bot /** * Global Event: room-join */ -.on('room-join', async function(this, room, inviteeList, inviter) { +.on('room-join', async function(room, inviteeList, inviter) { log.info( 'Bot', 'EVENT: room-join - Room %s got new member %s, invited by %s', await room.topic(), inviteeList.map(c => c.name()).join(','), inviter.name(), ) + const topic = await room.topic() + room.say(`welcome to ${topic}!`, inviteeList[0]) }) /** * Global Event: room-leave */ -.on('room-leave', async function(this, room, leaverList) { +.on('room-leave', async function(room, leaverList) { log.info('Bot', 'EVENT: room-leave - Room %s lost member %s', await room.topic(), leaverList.map(c => c.name()).join(','), ) + const topic = await room.topic() + const name = leaverList[0] ? leaverList[0].name() : 'no contact!' + room.say(`kick off ${name} from ${topic}!` ) }) /** * Global Event: room-topic */ -.on('room-topic', function(this, room, topic, oldTopic, changer) { +.on('room-topic', function(room, topic, oldTopic, changer) { try { log.info('Bot', 'EVENT: room-topic - Room %s change topic from %s to %s by member %s', room, @@ -150,6 +155,7 @@ bot topic, changer, ) + room.say(`room-topic - change topic from ${oldTopic} to ${topic} by member ${changer.name()}` ) } catch (e) { log.error('Bot', 'room-topic event exception: %s', e.stack) } @@ -380,6 +386,7 @@ async function createDingRoom(contact: Contact): Promise { if (!helperContact) { log.warn('Bot', 'getHelperContact() found nobody') + contact.say(`You don't have a friend called ${HELPER_CONTACT_NAME}, because create a new room at least need 3 contacts, please set [HELPER_CONTACT_NAME] in the code first!`) return } diff --git a/src/room.ts b/src/room.ts index 5a9dda3c0e31eb3e0b8ec934f200b86d43404d87..3ed4ea55ca7d8ab198681f0e11715f78d604c8f2 100644 --- a/src/room.ts +++ b/src/room.ts @@ -318,7 +318,7 @@ export class Room extends Accessory implements Sayable { } await this.puppet.messageSendText({ roomId: this.id, - contactId: replyToList[0].id, + contactId: (replyToList && replyToList.length && replyToList[0].id) || undefined, }, text) } else if (textOrContactOrFile instanceof FileBox) { await this.puppet.messageSendFile({