diff --git a/README.md b/README.md index 9ea5a16b8abcaf520392dff4754771b3d822ddf5..53252a1168535f6f4dd92b401dce04792f52e933 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Wechaty [![NPM Version](https://img.shields.io/npm/v/wechaty?color=brightgreen)](https://www.npmjs.com/package/wechaty) [![NPM](https://github.com/wechaty/wechaty/workflows/NPM/badge.svg)](https://github.com/wechaty/wechaty/actions?query=workflow%3ANPM) [![Docker](https://github.com/wechaty/wechaty/workflows/Docker/badge.svg)](https://github.com/wechaty/wechaty/actions?query=workflow%3ADocker) -[![Wechaty](https://wechaty.js.org/img/wechaty-logo.svg)](https://github.com/wechaty/wechaty) +[![Wechaty](https://wechaty.js.org/img/wechaty-logo.svg)](https://wechaty.js.org) [![Downloads](https://img.shields.io/npm/dm/wechaty.svg?style=flat-square)](https://www.npmjs.com/package/wechaty) [![GitHub stars](https://img.shields.io/github/stars/wechaty/wechaty.svg?label=github%20stars)](https://github.com/wechaty/wechaty) @@ -356,12 +356,12 @@ See: ## :sparkling_heart: POWERED BY WECHATY -[![Powered by Wechaty](https://img.shields.io/badge/Powered%20By-Wechaty-brightgreen.svg)](https://github.com/Wechaty/wechaty) +[![Powered by Wechaty](https://img.shields.io/badge/Powered%20By-Wechaty-brightgreen.svg)](https://wechaty.js.org) ### :sparkles: Wechaty Badge ```markdown -[![Powered by Wechaty](https://img.shields.io/badge/Powered%20By-Wechaty-brightgreen.svg)](https://github.com/Wechaty/wechaty) +[![Powered by Wechaty](https://img.shields.io/badge/Powered%20By-Wechaty-brightgreen.svg)](https://wechaty.js.org) ``` Get more embed html/markdown code from [Wiki:Badge](https://github.com/wechaty/wechaty/wiki/Badge) diff --git a/package.json b/package.json index 259ec820266ee4f2209d4c8d0e5c3813958715d3..e75d06f5952f0d8689ba1b66864a2df83c162239 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wechaty", - "version": "0.47.20", + "version": "0.48.1", "description": "Wechaty is Conversational SDK Chatbot Makers, Powered by TypeScript, Docker, and 💖", "main": "dist/src/mod.js", "typings": "dist/src/mod.d.ts", @@ -83,59 +83,59 @@ }, "homepage": "https://github.com/wechaty/", "dependencies": { - "brolog": "^1.8.3", + "brolog": "^1.12.4", "clone-class": "^0.7.3", "cuid": "^2.1.8", "dotenv": "^8.2.0", "in-gfw": "^1.2.0", - "json-rpc-peer": "^0.15.5", + "json-rpc-peer": "^0.16.0", "npm-programmatic": "0.0.12", "open-graph": "^0.2.4", "opencollective": "^1.0.3", - "opencollective-postinstall": "^2.0.2", + "opencollective-postinstall": "^2.0.3", "pkg-dir": "^4.2.0", - "portfinder": "^1.0.25", - "promise-retry": "^1.1.1", + "portfinder": "^1.0.28", + "promise-retry": "^2.0.1", "raven": "^2.6.4", "read-pkg-up": "^7.0.1", "state-switch": "^0.9.9", - "typed-emitter": "^1.2.0", + "typed-emitter": "^1.3.0", "watchdog": "^0.8.17", - "wechaty-puppet-hostie": "^0.9.13", - "wechaty-puppet": "^0.31.5", - "ws": "^7.2.3" + "wechaty-puppet-hostie": "^0.10.0", + "wechaty-puppet": "^0.32.3", + "ws": "^7.3.1" }, "devDependencies": { - "@babel/core": "^7.8.7", - "@babel/node": "^7.8.7", - "@babel/preset-env": "^7.8.7", - "@chatie/eslint-config": "^0.11.5", - "@chatie/git-scripts": "^0.5.2", + "@babel/core": "^7.11.4", + "@babel/node": "^7.10.5", + "@babel/preset-env": "^7.11.0", + "@chatie/eslint-config": "^0.12.1", + "@chatie/git-scripts": "^0.6.2", "@chatie/semver": "^0.4.7", - "@chatie/tsconfig": "^0.8.0", - "@types/cuid": "^1.3.0", + "@chatie/tsconfig": "^0.13.0", + "@types/cuid": "^1.3.1", "@types/dotenv": "^8.2.0", - "@types/glob": "^7.1.1", + "@types/glob": "^7.1.3", "@types/open-graph": "^0.2.0", "@types/promise-retry": "^1.1.3", "@types/raven": "^2.5.3", "@types/retry": "^0.12.0", - "@types/ws": "^7.2.2", + "@types/ws": "^7.2.6", "apiai": "^4.0.3", - "check-node-version": "^4.0.2", - "coveralls": "^3.0.9", + "check-node-version": "^4.0.3", + "coveralls": "^3.1.0", "cross-env": "^7.0.2", "finis": "^0.4.4", "glob": "^7.1.6", - "jsdoc-to-markdown": "^5.0.3", - "markdownlint-cli": "^0.22.0", - "nyc": "^15.0.0", + "jsdoc-to-markdown": "^6.0.1", + "markdownlint-cli": "^0.23.2", + "nyc": "^15.1.0", "pkg-jq": "^0.2.4", "qrcode-terminal": "^0.12.0", "shx": "^0.3.2", "sloc": "^0.2.1", "tstest": "^0.4.10", - "typedoc": "^0.16.11", + "typedoc": "^0.18.0", "wechaty-puppet-mock": "^0.27.2" }, "files_comment__whitelist_npm_publish": "http://stackoverflow.com/a/8617868/1123955", diff --git a/src/user/contact.ts b/src/user/contact.ts index e89088c1b65b55e5a2589aed83903d3e309b2271..ba3c754563d0d6ea58adfe33bc5f3da19db23905 100644 --- a/src/user/contact.ts +++ b/src/user/contact.ts @@ -570,7 +570,7 @@ class Contact extends ContactEventEmitter implements Sayable { } if (typeof phoneList === 'undefined') { - return this.wechaty.puppet.contactPhone(this.id) + return this.payload.phone } try { @@ -583,18 +583,70 @@ class Contact extends ContactEventEmitter implements Sayable { } } - /** - * - * @description - * Should use {@link Contact#friend} instead - * - * @deprecated - * @ignore - */ - public stranger (): null | boolean { - log.warn('Contact', 'stranger() DEPRECATED. use friend() instead.') - if (!this.payload) return null - return !this.friend() + public async corporation (): Promise + public async corporation (remark: string | null): Promise + public async corporation (remark?: string | null): Promise { + log.silly('Contact', 'corporation(%s)', remark) + + if (!this.payload) { + throw new Error('no payload') + } + + if (typeof remark === 'undefined') { + return this.payload.corporation || null + } + + if (this.payload.type !== ContactType.Individual) { + throw new Error('Can not set corporation remark on non individual contact.') + } + + try { + await this.wechaty.puppet.contactCorporationRemark(this.id, remark) + await this.wechaty.puppet.dirtyPayload(PayloadType.Contact, this.id) + this.payload = await this.wechaty.puppet.contactPayload(this.id) + } catch (e) { + log.error('Contact', 'corporation(%s) rejected: %s', remark, e.message) + Raven.captureException(e) + } + } + + public async description (): Promise + public async description (newDescription: string | null): Promise + public async description (newDescription?: string | null): Promise { + log.silly('Contact', 'description(%s)', newDescription) + + if (!this.payload) { + throw new Error('no payload') + } + + if (typeof newDescription === 'undefined') { + return this.payload.description || null + } + + try { + await this.wechaty.puppet.contactDescription(this.id, newDescription) + await this.wechaty.puppet.dirtyPayload(PayloadType.Contact, this.id) + this.payload = await this.wechaty.puppet.contactPayload(this.id) + } catch (e) { + log.error('Contact', 'description(%s) rejected: %s', newDescription, e.message) + Raven.captureException(e) + } + } + + public title (): string | null { + if (!this.payload) { + throw new Error('no payload') + } + + return this.payload.title || null + } + + public coworker (): boolean { + if (!this.payload) { + throw new Error('no payload') + } + + return !!this.payload.coworker } /** @@ -618,33 +670,6 @@ class Contact extends ContactEventEmitter implements Sayable { return this.payload.friend || null } - /** - * @ignore - * @see {@link https://github.com/Chatie/webwx-app-tracker/blob/7c59d35c6ea0cff38426a4c5c912a086c4c512b2/formatted/webwxApp.js#L3243|webwxApp.js#L324} - * @see {@link https://github.com/Urinx/WeixinBot/blob/master/README.md|Urinx/WeixinBot/README} - */ - /** - * @description - * Check if it's a official account, should use {@link Contact#type} instead - * @deprecated - * @ignore - */ - public official (): boolean { - log.warn('Contact', 'official() DEPRECATED. use type() instead') - return !!this.payload && (this.payload.type === ContactType.Official) - } - - /** - * @description - * Check if it's a personal account, should use {@link Contact#type} instead - * @deprecated - * @ignore - */ - public personal (): boolean { - log.warn('Contact', 'personal() DEPRECATED. use type() instead') - return !!this.payload && this.payload.type === ContactType.Personal - } - /** * Enum for ContactType * @enum {number} @@ -768,18 +793,6 @@ class Contact extends ContactEventEmitter implements Sayable { } } - /** - * @description - * Force reload(re-ready()) data for Contact, use {@link Contact#sync} instead - * - * @deprecated - * @ignore - */ - public refresh (): Promise { - log.warn('Contact', 'refresh() DEPRECATED. use sync() instead.') - return this.sync() - } - /** * Force reload data for Contact, Sync data from low-level API again. * diff --git a/src/user/friendship.ts b/src/user/friendship.ts index fb28fd6c9b5e37db3351fa483aa27cad1ea92c72..3b36179be3c0bf222eca1957534f661ac8ad32f3 100644 --- a/src/user/friendship.ts +++ b/src/user/friendship.ts @@ -105,16 +105,6 @@ class Friendship extends EventEmitter implements Acceptable { return contact } - /** - * @description - * use {@link Friendship#add} instead - * @deprecated - */ - public static async send (contact: Contact, hello: string) { - log.warn('Friendship', 'static send() DEPRECATED, use add() instead.') - return this.add(contact, hello) - } - /** * Send a Friend Request to a `contact` with message `hello`. * diff --git a/src/user/message.ts b/src/user/message.ts index 457edf244650e7cf4340a9955823c133f43d35cb..2d3d887fd8227ed663d725ab1fad6ce6196fa49c 100644 --- a/src/user/message.ts +++ b/src/user/message.ts @@ -327,17 +327,6 @@ class Message extends EventEmitter implements Sayable { return room } - /** - * @description - * use {@link Message#text} instead - * - * @deprecated - */ - public content (): string { - log.warn('Message', 'content() DEPRECATED. use text() instead.') - return this.text() - } - /** * Get the text content of the message * @@ -777,17 +766,6 @@ class Message extends EventEmitter implements Sayable { return textWithoutMention.trim() } - /** - * @description - * should use {@link Message#mention} instead - * @deprecated - * @ignore - */ - public async mentioned (): Promise { - log.warn('Message', 'mentioned() DEPRECATED. use mention() instead.') - return this.mentionList() - } - /** * Check if a message is mention self. * @@ -938,16 +916,6 @@ class Message extends EventEmitter implements Sayable { return ageSeconds } - /** - * @description - * use {@link Message#toFileBox} instead - * @deprecated - */ - public async file (): Promise { - log.warn('Message', 'file() DEPRECATED. use toFileBox() instead.') - return this.toFileBox() - } - /** * Extract the Media File from the Message, and put it into the FileBox. * > Tips: diff --git a/src/user/room-invitation.ts b/src/user/room-invitation.ts index e4e3e221b214e71e482b3f57eb71e3914d76ef70..17f36c036cd055779cb5ee3f66caf96225ec433c 100644 --- a/src/user/room-invitation.ts +++ b/src/user/room-invitation.ts @@ -177,36 +177,17 @@ class RoomInvitation implements Acceptable { public async topic (): Promise { const payload = await this.wechaty.puppet.roomInvitationPayload(this.id) - // roomTopic deprecated. use topic instead: return payload.topic || payload.topic || '' } - /** - * @deprecated: use topic() instead - * @ignore - */ - public async roomTopic (): Promise { - return this.topic() - } - public async memberCount (): Promise { log.verbose('RoomInvitation', 'memberCount()') const payload = await this.wechaty.puppet.roomInvitationPayload(this.id) - // roomMemberCount deprecated. use memberCount instead: return payload.memberCount || payload.memberCount || 0 } - /** - * @deprecated: use memberCount() instead - * @ignore - */ - public async roomMemberCount (): Promise { - log.warn('RoomInvitation', 'roomMemberCount() DEPRECATED. use memberCount() instead.') - return this.memberCount() - } - /** * List of Room Members that you known(is friend) * @ignore @@ -216,7 +197,6 @@ class RoomInvitation implements Acceptable { const payload = await this.wechaty.puppet.roomInvitationPayload(this.id) - // roomMemberIdList deprecated. use memberIdList isntead. const contactIdList = payload.memberIdList || payload.memberIdList || [] const contactList = contactIdList.map( @@ -231,15 +211,6 @@ class RoomInvitation implements Acceptable { return contactList } - /** - * @deprecated: use memberList() instead. - * @ignore - */ - public async roomMemberList (): Promise { - log.warn('RoomInvitation', 'roomMemberList() DEPRECATED. use memberList() instead.') - return this.roomMemberList() - } - /** * Get the invitation time * diff --git a/src/user/room.ts b/src/user/room.ts index 7d73824d5a55ddb92c2df2f2af670c49b09d8dc0..fa18a1f95c57ecc7624cdd2a40af004e48c1ca86 100644 --- a/src/user/room.ts +++ b/src/user/room.ts @@ -302,15 +302,6 @@ class Room extends RoomEventEmitter implements Sayable { } } - /** - * @ignore - * @ignore - * @deprecated: Use `sync()` instead - */ - public async refresh (): Promise { - await this.sync() - } - /** * Force reload data for Room, Sync data from puppet API again. * @@ -959,14 +950,6 @@ class Room extends RoomEventEmitter implements Sayable { } } - /** - * @deprecated: use qrCode() instead - */ - public async qrcode () { - log.warn('Room', 'qrcode() is deprecated. use qrCode() instead.') - return this.qrCode() - } - /** * Get QR Code Value of the Room from the room, which can be used as scan and join the room. * > Tips: @@ -1007,18 +990,6 @@ class Room extends RoomEventEmitter implements Sayable { return null } - /** - * Same as function alias - * @param {Contact} contact - * @returns {Promise} - * @deprecated: use room.alias() instead - * @ignore - */ - public async roomAlias (contact: Contact): Promise { - log.warn('Room', 'roomAlias() DEPRECATED. use room.alias() instead') - return this.alias(contact) - } - /** * Check if the room has member `contact`, the return is a Promise and must be `await`-ed * diff --git a/src/wechaty.ts b/src/wechaty.ts index af851ce493511d8c3352217f5aba35fc05989966..82e2af159c2eacfd28a8b4e310b57caee69528f2 100644 --- a/src/wechaty.ts +++ b/src/wechaty.ts @@ -101,9 +101,6 @@ export interface WechatyOptions { memory? : MemoryCard, name? : string, // Wechaty Name - // @deprecated: use `name` instead of `profile` - profile? : null | string, // DEPRECATED: use name instead - puppet? : PuppetModuleName | Puppet, // Puppet name or instance puppetOptions? : PuppetOptions, // Puppet TOKEN ioToken? : string, // Io TOKEN @@ -134,7 +131,7 @@ const PUPPET_MEMORY_NAME = 'puppet' * bot.on('message', message => console.log(`Message: ${message}`)) * bot.start() */ -export class Wechaty extends WechatyEventEmitter implements Sayable { +class Wechaty extends WechatyEventEmitter implements Sayable { public static readonly VERSION = VERSION @@ -176,16 +173,16 @@ export class Wechaty extends WechatyEventEmitter implements Sayable { protected wechatifiedTag? : typeof Tag protected wechatifiedUrlLink? : typeof UrlLink - public get Contact () : typeof Contact { return this.wechatifiedContact! } - public get ContactSelf () : typeof ContactSelf { return this.wechatifiedContactSelf! } - public get Friendship () : typeof Friendship { return this.wechatifiedFriendship! } - public get Image () : typeof Image { return this.wechatifiedImage! } - public get Message () : typeof Message { return this.wechatifiedMessage! } - public get MiniProgram () : typeof MiniProgram { return this.wechatifiedMiniProgram! } - public get Room () : typeof Room { return this.wechatifiedRoom! } - public get RoomInvitation () : typeof RoomInvitation { return this.wechatifiedRoomInvitation! } - public get Tag () : typeof Tag { return this.wechatifiedTag! } - public get UrlLink () : typeof UrlLink { return this.wechatifiedUrlLink! } + public get Contact () : typeof Contact { return guardWechatify(this.wechatifiedContact) } + public get ContactSelf () : typeof ContactSelf { return guardWechatify(this.wechatifiedContactSelf) } + public get Friendship () : typeof Friendship { return guardWechatify(this.wechatifiedFriendship) } + public get Image () : typeof Image { return guardWechatify(this.wechatifiedImage) } + public get Message () : typeof Message { return guardWechatify(this.wechatifiedMessage) } + public get MiniProgram () : typeof MiniProgram { return guardWechatify(this.wechatifiedMiniProgram) } + public get Room () : typeof Room { return guardWechatify(this.wechatifiedRoom) } + public get RoomInvitation () : typeof RoomInvitation { return guardWechatify(this.wechatifiedRoomInvitation) } + public get Tag () : typeof Tag { return guardWechatify(this.wechatifiedTag) } + public get UrlLink () : typeof UrlLink { return guardWechatify(this.wechatifiedUrlLink) } /** * Get the global instance of Wechaty @@ -287,10 +284,6 @@ export class Wechaty extends WechatyEventEmitter implements Sayable { super() log.verbose('Wechaty', 'constructor()') - if (!options.name && options.profile) { - log.verbose('Wechaty', 'constructor() WechatyOptions.profile DEPRECATED. use WechatyOptions.name instead.') - options.name = options.profile - } this.memory = this.options.memory this.id = cuid() @@ -837,17 +830,6 @@ export class Wechaty extends WechatyEventEmitter implements Sayable { } } - /** - * @description - * Should use {@link Wechaty#userSelf} instead - * @deprecated Use `userSelf()` instead - * @ignore - */ - public self (): Contact { - log.warn('Wechaty', 'self() DEPRECATED. use userSelf() instead.') - return this.userSelf() - } - /** * Get current user * @@ -1028,3 +1010,17 @@ export class Wechaty extends WechatyEventEmitter implements Sayable { } } + +/** + * Huan(202008): we will bind the wechaty puppet with user modules (Contact, Room, etc) together inside the start() method + */ +function guardWechatify (userModule?: T): T { + if (!userModule) { + throw new Error('Wechaty user module (for example, wechaty.Room) can not be used before wechaty.start()!') + } + return userModule +} + +export { + Wechaty, +}