提交 29435456 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

Merge branch 'master' of github.com:Chatie/wechaty

language: node_js
node_js:
- "9"
- "8"
os:
- linux
......
......@@ -72,9 +72,12 @@ bot
.on('scan', (url, code) => {
if (!/201|200/.test(String(code))) {
const loginUrl = url.replace(/\/qrcode\//, '/l/')
QrcodeTerminal.generate(loginUrl)
QrcodeTerminal.generate(loginUrl, { small: true }, (qrcode: string) => {
console.log(qrcode)
console.log(url)
console.log(`[${code}] Scan QR Code above url to log in: `)
})
}
console.log(`${url}\n[${code}] Scan QR Code above url to log in: `)
})
.on('message', async m => {
try {
......@@ -100,7 +103,7 @@ bot
/**
* 2. reply qrcode image
*/
const imageMessage = new bot.Message(BOT_QR_CODE_IMAGE_FILE)
const imageMessage = bot.Message.create(BOT_QR_CODE_IMAGE_FILE)
log.info('Bot', 'REPLY: %s', imageMessage)
await m.say(imageMessage)
......
{
"name": "wechaty",
"version": "0.15.30",
"version": "0.15.31",
"description": "Wechat for Bot(Personal Account)",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
......@@ -24,7 +24,7 @@
"lint": "npm run check-node-version && npm run lint:ts && npm run lint:es && npm run lint:sh",
"lint:es": "eslint \"{bin,examples,scripts,src,tests}/**/*.js\" --ignore-pattern=\"tests/fixtures/**\"",
"lint:md": "markdownlint README.md",
"lint:ts": "npm run clean && echo tslint v`tslint --version` && tslint --project tsconfig.json --exclude \"tests/fixtures/**\" --exclude \"dist/\" && tsc --noEmit",
"lint:ts": "tslint --project tsconfig.json --exclude \"tests/fixtures/**\" && tsc --noEmit",
"lint:sh": "bash -n bin/*.sh",
"sloc": "sloc bin examples scripts src tests --details --format cli-table --keys total,source,comment && sloc bin examples scripts src tests",
"ts-node": "ts-node",
......@@ -40,11 +40,6 @@
"demo": "ts-node examples/ding-dong-bot.ts",
"start": "npm run demo"
},
"git": {
"scripts": {
"pre-push": "./scripts/pre-push.sh"
}
},
"repository": {
"type": "git",
"url": "git+https://github.com/chatie/wechaty.git"
......@@ -97,7 +92,7 @@
"node": ">= 8.5"
},
"dependencies": {
"@types/ws": "^4.0.1",
"@types/ws": "^5.1.0",
"bl": "^1.2.0",
"brolog": "^1.2.0",
"clone-class": "^0.6.3",
......@@ -110,8 +105,8 @@
"read-pkg-up": "^3.0.0",
"request": "^2.83.0",
"retry-promise": "^1.0.0",
"rx-queue": "^0.3.1",
"rxjs": "^5.5.0",
"rx-queue": "^0.4.4",
"rxjs": "^6",
"state-switch": "^0.4.5",
"watchdog": "^0.8.1",
"wechat4u": "^0.7.6",
......@@ -126,7 +121,7 @@
"@types/fluent-ffmpeg": "^2.1.0",
"@types/glob": "^5.0.0p",
"@types/mime": "^2.0.0",
"@types/node": "^9.6.7",
"@types/node": "^10.0.3",
"@types/normalize-package-data": "^2.4.0",
"@types/puppeteer": "^1.0.0",
"@types/raven": "^2.1.0",
......@@ -180,9 +175,13 @@
"dist/src",
"src"
],
"git": {
"scripts": {
"pre-push": "./scripts/pre-push.sh"
}
},
"publishConfig": {
"access": "public",
"tagBak": "next",
"tag": "latest"
}
}
......@@ -7,6 +7,8 @@ import { log } from './config'
import { Puppet } from './puppet/'
// use Symbol to prevent conflicting with the child class properties
// This symbol must be exported (for now).
// See: https://github.com/Microsoft/TypeScript/issues/20080
export const PUPPET_ACCESSORY_NAME = Symbol('name')
export abstract class PuppetAccessory extends EventEmitter {
......
......@@ -24,7 +24,6 @@ import {
Browser,
Cookie,
Dialog,
// ElementHandle,
launch,
Page,
} from 'puppeteer'
......@@ -634,7 +633,7 @@ export class Bridge extends EventEmitter {
*/
public async proxyWechaty(
wechatyFunc : string,
...args : any[],
...args : any[]
): Promise<any> {
log.silly('PuppetPuppeteerBridge', 'proxyWechaty(%s%s)',
wechatyFunc,
......
......@@ -67,6 +67,13 @@ export abstract class Message extends PuppetAccessory implements Sayable {
]
}
public static create<T extends typeof Message>(
this: T,
...args: any[]
): T['prototype'] {
return new (this as any)(...args)
}
/**
* @private
*/
......
......@@ -18,7 +18,15 @@
*/
import { EventEmitter } from 'events'
import { StateSwitch } from 'state-switch'
import * as normalize from 'normalize-package-data'
import * as readPkgUp from 'read-pkg-up'
import {
callerResolve,
} from 'hot-import'
import {
StateSwitch,
} from 'state-switch'
import {
Watchdog,
WatchdogFood,
......@@ -49,13 +57,6 @@ import {
RoomQueryFilter,
} from './room'
export interface NpmPackage {
version: string,
peerDependencies?: {
wechaty?: string,
},
}
// XXX: Name??? ScanInfo? ScanEvent? ScanXXX?
export interface ScanData {
avatar: string, // Image Data URL
......@@ -95,7 +96,7 @@ export abstract class Puppet extends EventEmitter implements Sayable {
protected readonly watchdog: Watchdog
private readonly pkg: NpmPackage
private readonly pkg: normalize.Package
constructor(
public options: PuppetOptions,
......@@ -123,17 +124,19 @@ export abstract class Puppet extends EventEmitter implements Sayable {
/**
* 2. Load the package.json for Puppet Plugin version range matching
*
* For: dist/src/puppet/puppet.ts
* We need to up 3 times: ../../../package.json
*/
try {
this.pkg = require('../package.json')
} catch (e) {
this.pkg = require('../../package.json')
const childClassPath = callerResolve('.', __filename)
this.pkg = readPkgUp.sync({ cwd: childClassPath }).pkg
} finally {
if (!this.pkg) {
throw new Error('Cannot found package.json for Puppet Plugin Module')
}
}
normalize(this.pkg)
}
public emit(event: 'error', e: Error) : boolean
......@@ -151,7 +154,7 @@ export abstract class Puppet extends EventEmitter implements Sayable {
public emit(
event: PuppetEventName,
...args: any[],
...args: any[]
): boolean {
return super.emit(event, ...args)
}
......@@ -186,7 +189,23 @@ export abstract class Puppet extends EventEmitter implements Sayable {
*/
public wechatyVersionRange(): string {
// FIXME: for development, we use `*` if not set
return this.pkg.peerDependencies && this.pkg.peerDependencies.wechaty || '*'
return '*'
// TODO: test and uncomment the following codes after promote the `wehcaty-puppet` as a solo NPM module
// if (this.pkg.dependencies && this.pkg.dependencies.wechaty) {
// throw new Error('Wechaty Puppet Implementation should add `wechaty` from `dependencies` to `peerDependencies` in package.json')
// }
// if (!this.pkg.peerDependencies || !this.pkg.peerDependencies.wechaty) {
// throw new Error('Wechaty Puppet Implementation should add `wechaty` to `peerDependencies`')
// }
// if (!this.pkg.engines || !this.pkg.engines.wechaty) {
// throw new Error('Wechaty Puppet Implementation must define `package.engines.wechaty` for a required Version Range')
// }
// return this.pkg.engines.wechaty
}
public abstract async start() : Promise<void>
......
......@@ -218,7 +218,7 @@ export abstract class Room extends PuppetAccessory implements Sayable {
public emit(
event: RoomEventName,
...args: any[],
...args: any[]
): boolean {
return super.emit(event, ...args)
}
......
......@@ -2,9 +2,6 @@ declare module 'bl'
declare module 'blessed-contrib'
declare module 'qrcode-terminal'
declare module '*/package.json' {
export const version: string
}
// Extend the `Window` from Browser
interface Window {
emit: Function, // from puppeteer
......
......@@ -22,7 +22,7 @@ import * as os from 'os'
import * as semver from 'semver'
import {
Constructor,
// Constructor,
cloneClass,
instanceToClass,
} from 'clone-class'
......@@ -113,13 +113,13 @@ export class Wechaty extends PuppetAccessory implements Sayable {
public readonly cuid: string
// tslint:disable-next-line:variable-name
public Contact : typeof Contact & Constructor<Contact>
public Contact : typeof Contact
// tslint:disable-next-line:variable-name
public FriendRequest : typeof FriendRequest & Constructor<FriendRequest>
public FriendRequest : typeof FriendRequest
// tslint:disable-next-line:variable-name
public Message : typeof Message & Constructor<Message>
public Message : typeof Message
// tslint:disable-next-line:variable-name
public Room : typeof Room & Constructor<Room>
public Room : typeof Room
/**
* get the singleton instance of Wechaty
......
......@@ -83,7 +83,8 @@
true,
{
"multiline": "always",
"singleline": "never"
"singleline": "never",
"esSpecCompliant": true
}
],
"triple-equals": [true],
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册