import type TypedEventEmitter from 'typed-emitter'; import type { ContactInterface, MessageInterface, RoomInterface, RoomInvitationInterface } from '../user-modules/mod.js'; export declare const ROOM_EVENT_DICT: { invite: string; join: string; leave: string; message: string; topic: string; owner: string; }; export declare type RoomEventName = keyof typeof ROOM_EVENT_DICT; /** * @desc Room Class Event Type * @typedef RoomEventName * @property {string} join - Emit when anyone join any room. * @property {string} topic - Get topic event, emitted when someone change room topic. * @property {string} leave - Emit when anyone leave the room.
* If someone leaves the room by themselves, WeChat will not notice other people in the room, so the bot will never get the "leave" event. */ /** * @desc Room Class Event Function * @typedef RoomEventFunction * @property {Function} room-join - (this: Room, inviteeList: Contact[] , inviter: Contact) => void * @property {Function} room-topic - (this: Room, topic: string, oldTopic: string, changer: Contact) => void * @property {Function} room-leave - (this: Room, leaver: Contact) => void */ /** * @listens Room * @param {RoomEventName} event - Emit WechatyEvent * @param {RoomEventFunction} listener - Depends on the WechatyEvent * @return {this} - this for chain * * @example Event:join * const bot = new Wechaty() * await bot.start() * // after logged in... * const room = await bot.Room.find({topic: 'topic of your room'}) // change `event-room` to any room topic in your WeChat * if (room) { * room.on('join', (room, inviteeList, inviter) => { * const nameList = inviteeList.map(c => c.name()).join(',') * console.log(`Room got new member ${nameList}, invited by ${inviter}`) * }) * } * * @example Event:leave * const bot = new Wechaty() * await bot.start() * // after logged in... * const room = await bot.Room.find({topic: 'topic of your room'}) // change `event-room` to any room topic in your WeChat * if (room) { * room.on('leave', (room, leaverList) => { * const nameList = leaverList.map(c => c.name()).join(',') * console.log(`Room lost member ${nameList}`) * }) * } * * @example Event:message * const bot = new Wechaty() * await bot.start() * // after logged in... * const room = await bot.Room.find({topic: 'topic of your room'}) // change `event-room` to any room topic in your WeChat * if (room) { * room.on('message', (message) => { * console.log(`Room received new message: ${message}`) * }) * } * * @example Event:topic * const bot = new Wechaty() * await bot.start() * // after logged in... * const room = await bot.Room.find({topic: 'topic of your room'}) // change `event-room` to any room topic in your WeChat * if (room) { * room.on('topic', (room, topic, oldTopic, changer) => { * console.log(`Room topic changed from ${oldTopic} to ${topic} by ${changer.name()}`) * }) * } * * @example Event:invite * const bot = new Wechaty() * await bot.start() * // after logged in... * const room = await bot.Room.find({topic: 'topic of your room'}) // change `event-room` to any room topic in your WeChat * if (room) { * room.on('invite', roomInvitation => roomInvitation.accept()) * } * */ declare type RoomEventListenerInvite = (this: RoomInterface, inviter: ContactInterface, invitation: RoomInvitationInterface) => void | Promise; declare type RoomEventListenerJoin = (this: RoomInterface, inviteeList: ContactInterface[], inviter: ContactInterface, date?: Date) => void | Promise; declare type RoomEventListenerLeave = (this: RoomInterface, leaverList: ContactInterface[], remover?: ContactInterface, date?: Date) => void | Promise; declare type RoomEventListenerMessage = (this: RoomInterface, message: MessageInterface, date?: Date) => void | Promise; declare type RoomEventListenerTopic = (this: RoomInterface, topic: string, oldTopic: string, changer: ContactInterface, date?: Date) => void | Promise; declare type RoomEventListenerAnnounce = (this: RoomInterface, announce: string, changer?: ContactInterface, oldAnnounce?: string, date?: Date) => void | Promise; declare type RoomEventListenerOwner = (this: RoomInterface, newOwner: ContactInterface, oldOwner: ContactInterface) => void | Promise; interface RoomEventListeners { invite: RoomEventListenerInvite; join: RoomEventListenerJoin; leave: RoomEventListenerLeave; message: RoomEventListenerMessage; topic: RoomEventListenerTopic; owner: RoomEventListenerOwner; announce: RoomEventListenerAnnounce; } declare const RoomEventEmitter: new () => TypedEventEmitter; export type { RoomEventListeners, RoomEventListenerInvite, RoomEventListenerJoin, RoomEventListenerLeave, RoomEventListenerMessage, RoomEventListenerTopic, RoomEventListenerOwner, RoomEventListenerAnnounce, }; export { RoomEventEmitter, }; //# sourceMappingURL=room-events.d.ts.map