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

merge

......@@ -17,7 +17,6 @@
*
*/
import {
config,
Contact,
Message,
Wechaty,
......@@ -32,7 +31,7 @@ import { generate } from 'qrcode-terminal'
*
*/
const bot = new Wechaty({
name : config.default.DEFAULT_PROFILE,
name : 'ding-dong-bot',
})
/**
......
{
"name": "wechaty",
"version": "0.19.145",
"version": "0.19.148",
"description": "Wechaty is a Bot SDK for Wechat Personal Account",
"main": "dist/src/index.js",
"typings": "dist/src/index.d.ts",
"wechaty": {
"DEFAULT_HEAD": 0,
"DEFAULT_PORT": 8080,
"DEFAULT_PROFILE": "default",
"DEFAULT_PROTOCOL": "io|0.0.1",
"DEFAULT_TOKEN": "WECHATY_IO_TOKEN",
"DEFAULT_APIHOST": "api.chatie.io"
......@@ -91,7 +90,7 @@
"read-pkg-up": "^4.0.0",
"state-switch": "^0.6.2",
"watchdog": "^0.8.1",
"wechaty-puppet": "^0.13.12",
"wechaty-puppet": "^0.13.14",
"ws": "^6.0.0"
},
"devDependencies": {
......
......@@ -30,7 +30,7 @@ test('important variables', async t => {
t.true('token' in config, 'should exist `token` in Config')
// t.ok(config.default.DEFAULT_PUPPET , 'should export DEFAULT_PUPPET')
t.ok(config.default.DEFAULT_PROFILE , 'should export DEFAULT_PROFILE')
// t.ok(config.default.DEFAULT_PROFILE , 'should export DEFAULT_PROFILE')
t.ok(config.default.DEFAULT_PROTOCOL , 'should export DEFAULT_PROTOCOL')
t.ok(config.default.DEFAULT_APIHOST , 'should export DEFAULT_APIHOST')
})
......
......@@ -104,7 +104,7 @@ export interface DefaultSetting {
DEFAULT_PORT : number,
// DEFAULT_PUPPET : PuppetName,
DEFAULT_APIHOST : string,
DEFAULT_PROFILE : string,
// DEFAULT_PROFILE : string,
DEFAULT_TOKEN : string,
DEFAULT_PROTOCOL : string,
}
......@@ -125,8 +125,12 @@ export class Config {
).toLowerCase() as PuppetModuleName
}
public profile = process.env.WECHATY_PROFILE || null // DO NOT set DEFAULT_PROFILE, because sometimes user do not want to save session
public token = process.env.WECHATY_TOKEN || null // DO NOT set DEFAULT, because sometimes user do not want to connect to io cloud service
// DEPRECATED: Use WECHATY_NAME instead
public profile = process.env.WECHATY_PROFILE
public name = process.env.WECHATY_NAME || process.env.WECHATY_PROFILE // replace WECHATY_PROFILE
public token = process.env.WECHATY_TOKEN // DO NOT set DEFAULT, because sometimes user do not want to connect to io cloud service
public debug = !!(process.env.WECHATY_DEBUG)
public httpPort = process.env.PORT || process.env.WECHATY_PORT || DEFAULT_SETTING.DEFAULT_PORT
......@@ -137,6 +141,10 @@ export class Config {
constructor () {
log.verbose('Config', 'constructor()')
this.validApiHost(this.apihost)
if (this.profile) {
log.warn('Config', 'constructor() WECHATY_PROFILE is DEPRECATED, use WECHATY_NAME instead.')
}
}
/**
......
......@@ -26,6 +26,7 @@ export {
Money,
Room,
RoomInvitation,
UrlLink,
} from './user'
export {
......
......@@ -846,8 +846,8 @@ export class Message extends Accessory implements Sayable {
return contact
}
public async toUrl (): Promise<UrlLink> {
log.verbose('Message', 'toUrl()')
public async toUrlLink (): Promise<UrlLink> {
log.verbose('Message', 'toUrlLink()')
if (!this.payload) {
throw new Error('no payload')
......
......@@ -98,11 +98,11 @@ export type WechatyEventName = keyof typeof WECHATY_EVENT_DICT
export interface WechatyOptions {
memory? : MemoryCard,
name? : null | string, // Wechaty Name
profile? : null | string, // DEPRECATED: use name instead
puppet? : PuppetModuleName | Puppet, // Puppet name or instance
puppetOptions? : PuppetOptions, // Puppet TOKEN
ioToken? : string, // Io TOKEN
name? : string, // Wechaty Name
profile? : null | string, // DEPRECATED: use name instead
puppet? : PuppetModuleName | Puppet, // Puppet name or instance
puppetOptions? : PuppetOptions, // Puppet TOKEN
ioToken? : string, // Io TOKEN
}
const PUPPET_MEMORY_NAME = 'puppet'
......@@ -143,7 +143,7 @@ export class Wechaty extends Accessory implements Sayable {
*/
private static globalInstance: Wechaty
private readonly memory : MemoryCard
private memory?: MemoryCard
private lifeTimer? : NodeJS.Timer
private io? : Io
......@@ -239,20 +239,8 @@ export class Wechaty extends Accessory implements Sayable {
options.name = options.profile
}
options.name = options.name === null
? null
: (options.name || config.default.DEFAULT_PROFILE)
this.id = cuid()
this.memory = options.memory
? options.memory
: new MemoryCard(
options.name
? { name: options.name }
: undefined,
)
this.state = new StateSwitch('Wechaty', log)
this.readyState = new StateSwitch('WechatyReady', log)
......@@ -288,7 +276,7 @@ export class Wechaty extends Accessory implements Sayable {
'Wechaty#',
this.id,
`<${this.options && this.options.puppet || ''}>`,
`(${this.memory.name || ''})`,
`(${this.memory && this.memory.name || ''})`,
].join('')
}
......@@ -570,6 +558,10 @@ export class Wechaty extends Accessory implements Sayable {
return
}
if (!this.memory) {
throw new Error('no memory')
}
const puppet = this.options.puppet || config.systemPuppetName()
const puppetMemory = this.memory.multiplex(PUPPET_MEMORY_NAME)
......@@ -636,7 +628,6 @@ export class Wechaty extends Accessory implements Sayable {
const contact = this.ContactSelf.load(contactId)
await contact.ready()
this.emit('login', contact)
await this.memory.save()
})
break
......@@ -645,7 +636,6 @@ export class Wechaty extends Accessory implements Sayable {
const contact = this.ContactSelf.load(contactId)
await contact.ready()
this.emit('logout', contact)
await this.memory.save()
})
break
......@@ -810,8 +800,10 @@ export class Wechaty extends Accessory implements Sayable {
this.state.on('pending')
try {
await this.memory.load()
if (!this.memory) {
this.memory = new MemoryCard(this.options.name)
await this.memory.load()
}
await this.initPuppet()
await this.puppet.start()
......@@ -874,7 +866,6 @@ export class Wechaty extends Accessory implements Sayable {
this.readyState.off(true)
this.state.off('pending')
await this.memory.save()
if (this.lifeTimer) {
clearInterval(this.lifeTimer)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册