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

code clean

上级 7d55b7a5
......@@ -97,7 +97,6 @@
"node": ">= 8.5"
},
"dependencies": {
"@types/node": "^9.4.0",
"@types/ws": "^4.0.1",
"bl": "^1.2.0",
"brolog": "^1.2.0",
......@@ -125,6 +124,7 @@
"@types/fluent-ffmpeg": "^2.1.0",
"@types/glob": "^5.0.0p",
"@types/mime": "^2.0.0",
"@types/node": "^10.0.0",
"@types/puppeteer": "^1.0.0",
"@types/raven": "^2.1.0",
"@types/read-pkg-up": "^3.0.0",
......@@ -159,7 +159,7 @@
"sinon-test": "^2.1.2",
"sloc": "^0.2.0",
"ts-node": "^6.0.0",
"tslint": "^5.9.0",
"tslint": "^5.9.1",
"tslint-eslint-rules": "^5.1.0",
"tslint-jsdoc-rules": "^0.1.0",
"tuling123-client": "^0.0.1",
......
......@@ -44,8 +44,6 @@ export interface ContactQueryFilter {
alias?: string | RegExp,
}
export type ContactQueryName = keyof ContactQueryFilter
/**
* All wechat contacts(friend) will be encapsulated as a Contact.
*
......
......@@ -19,7 +19,6 @@ export {
} from './puppet-accessory'
export {
Room,
RoomMemberQueryName,
RoomMemberQueryFilter,
RoomQueryFilter,
} from './room'
......@@ -62,16 +62,16 @@ export interface PuppetOptions {
wechaty: Wechaty,
}
export type PuppetContactClass = typeof Contact & Constructor<{}>
export type PuppetFriendRequestClass = typeof FriendRequest & Constructor<{}>
export type PuppetMessageClass = typeof Message & Constructor<{}>
export type PuppetRoomClass = typeof Room & Constructor<{}>
export type PuppetContact = typeof Contact & Constructor<{}>
export type PuppetFriendRequest = typeof FriendRequest & Constructor<{}>
export type PuppetMessage = typeof Message & Constructor<{}>
export type PuppetRoom = typeof Room & Constructor<{}>
export interface PuppetClasses {
Contact: PuppetContactClass,
FriendRequest: PuppetFriendRequestClass,
Message: PuppetMessageClass,
Room: PuppetRoomClass,
Contact: PuppetContact,
FriendRequest: PuppetFriendRequest,
Message: PuppetMessage,
Room: PuppetRoom,
}
/**
......@@ -86,17 +86,17 @@ export abstract class Puppet extends EventEmitter implements Sayable {
public watchdog: Watchdog
// tslint:disable-next-line:variable-name
public Contact: PuppetContactClass
public Contact: PuppetContact
// tslint:disable-next-line:variable-name
public FriendRequest: PuppetFriendRequestClass
public FriendRequest: PuppetFriendRequest
// tslint:disable-next-line:variable-name
public Message: PuppetMessageClass
public Message: PuppetMessage
// tslint:disable-next-line:variable-name
public Room: PuppetRoomClass
public Room: PuppetRoom
constructor(
public options: PuppetOptions,
classes: PuppetClasses,
public classes: PuppetClasses,
) {
super()
......
......@@ -38,8 +38,6 @@ export interface RoomMemberQueryFilter {
contactAlias?: string,
}
export type RoomMemberQueryName = keyof RoomMemberQueryFilter
export interface RoomQueryFilter {
topic: string | RegExp,
}
......
......@@ -24,15 +24,15 @@ import {
log,
} from './config'
export type ProfileSection = 'cookies' | 'ToBeAdded'
export interface ProfileSchema {
cookies?: any[]
cookies?: any[]
}
export type ProfileSection = keyof ProfileSchema
export class Profile {
private obj : ProfileSchema
private file : string | null
private obj : ProfileSchema
private file? : string
constructor(
public name = config.profile,
......@@ -40,7 +40,7 @@ export class Profile {
log.verbose('Profile', 'constructor(%s)', name)
if (!name) {
this.file = null
this.file = undefined
} else {
this.file = path.isAbsolute(name)
? name
......@@ -58,7 +58,7 @@ export class Profile {
return `Profile<${this.name}>`
}
public load(): void {
public async load(): Promise<void> {
log.verbose('Profile', 'load() file: %s', this.file)
this.obj = {}
......@@ -80,7 +80,7 @@ export class Profile {
}
}
public save(): void {
public async save(): Promise<void> {
log.verbose('Profile', 'save() file: %s', this.file)
if (!this.file) {
log.verbose('Profile', 'save() no file, NOOP')
......@@ -100,15 +100,15 @@ export class Profile {
}
}
public get(section: ProfileSection): null | any {
public async get<T = any>(section: ProfileSection): Promise<null | T> {
log.verbose('Profile', 'get(%s)', section)
if (!this.obj) {
return null
}
return this.obj[section]
return this.obj[section] as any as T
}
public set(section: ProfileSection, data: any): void {
public async set(section: ProfileSection, data: any): Promise<void> {
log.verbose('Profile', 'set(%s, %s)', section, data)
if (!this.obj) {
this.obj = {}
......@@ -116,12 +116,12 @@ export class Profile {
this.obj[section] = data
}
public destroy(): void {
public async destroy(): Promise<void> {
log.verbose('Profile', 'destroy() file: %s', this.file)
this.obj = {}
if (this.file && fs.existsSync(this.file)) {
fs.unlinkSync(this.file)
this.file = null
this.file = undefined
}
}
}
......
......@@ -18,17 +18,13 @@
* @ignore
*/
import {
// config,
Raven,
log,
} from '../config'
import Misc from '../misc'
import {
Room,
// RoomEventName,
RoomMemberQueryName,
RoomMemberQueryFilter,
// RoomQueryFilter,
} from '../abstract-puppet/'
import PuppetWeb from './puppet-web'
......@@ -257,7 +253,10 @@ export class WebRoom extends Room {
/**
* @private
*/
private parseMap(parseContent: RoomMemberQueryName, memberList?: WebRoomRawMember[]): Map<string, string> {
private parseMap(
parseSection: keyof RoomMemberQueryFilter,
memberList?: WebRoomRawMember[],
): Map<string, string> {
const mapList: Map<string, string> = new Map<string, string>()
if (memberList && memberList.map) {
memberList.forEach(member => {
......@@ -265,7 +264,7 @@ export class WebRoom extends Room {
const contact = WebContact.load(member.UserName)
contact.puppet = this.puppet
switch (parseContent) {
switch (parseSection) {
case 'name':
tmpName = contact.name()
break
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册