Skip to content

Commit

Permalink
abstract puppet passed the linting! (#1166)
Browse files Browse the repository at this point in the history
  • Loading branch information
huan committed Apr 25, 2018
1 parent cff4c22 commit c6959b1
Show file tree
Hide file tree
Showing 37 changed files with 410 additions and 472 deletions.
2 changes: 1 addition & 1 deletion examples/api-ai-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { EventEmitter } from 'events'
import {
config,
Wechaty,
} from '../'
} from '../src/'

// log.level = 'verbose'
// log.level = 'silly'
Expand Down
2 changes: 1 addition & 1 deletion examples/blessed-twins-bot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as qrcode from 'qrcode-terminal'

import {
Wechaty,
} from '../../index'
} from '../../src/'

const screen = blessed.screen({
smartCSR: true,
Expand Down
22 changes: 11 additions & 11 deletions examples/contact-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
// Contact,
Wechaty,
log,
} from '../'
} from '../src/'

const welcome = `
=============== Powered by Wechaty ===============
Expand Down Expand Up @@ -103,16 +103,16 @@ async function onLogin() {
}
}

/**
* Special contact list
*/
// /**
// * Special contact list
// */

for (let i = 0; i < contactList.length; i++) {
const contact = contactList[i]
if (contact.special()) {
log.info('Bot', `special ${i}: ${contact.name()}`)
}
}
// for (let i = 0; i < contactList.length; i++) {
// const contact = contactList[i]
// if (contact.special()) {
// log.info('Bot', `special ${i}: ${contact.name()}`)
// }
// }

/**
* personal contact list
Expand All @@ -121,7 +121,7 @@ async function onLogin() {
for (let i = 0; i < contactList.length; i++) {
const contact = contactList[i]
if (contact.personal()) {
log.info('Bot', `personal ${i}: ${contact.get('name')} : ${contact.id}`)
log.info('Bot', `personal ${i}: ${contact.name()} : ${contact.id}`)
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/ding-dong-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
config,
Wechaty,
log,
} from '../src/index'
} from '../src/'

const BOT_QR_CODE_IMAGE_FILE = path.join(
__dirname,
Expand Down
6 changes: 3 additions & 3 deletions examples/friend-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
// Contact,
log,
Wechaty,
} from '../'
} from '../src/'

const welcome = `
=============== Powered by Wechaty ===============
Expand Down Expand Up @@ -80,7 +80,7 @@ bot
const fileHelper = bot.Contact.load('filehelper')

try {
logMsg = 'received `friend` event from ' + contact.get('name')
logMsg = 'received `friend` event from ' + contact.name()
fileHelper.say(logMsg)
console.log(logMsg)

Expand All @@ -105,7 +105,7 @@ bot
* 2. Friend Ship Confirmed
*
*/
logMsg = 'friend ship confirmed with ' + contact.get('name')
logMsg = 'friend ship confirmed with ' + contact.name()
}
} catch (e) {
logMsg = e.message
Expand Down
2 changes: 1 addition & 1 deletion examples/gist-bot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
config,
Wechaty,
log,
} from '../../'
} from '../../src/'

import { onMessage } from './on-message'
import { onFriend } from './on-friend'
Expand Down
2 changes: 1 addition & 1 deletion examples/gist-bot/on-friend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
FriendRequest,
Wechaty,
// Room,
} from '../../'
} from '../../src/'

export async function onFriend(this: Wechaty, contact: Contact, request?: FriendRequest): Promise<void> {
try {
Expand Down
4 changes: 2 additions & 2 deletions examples/gist-bot/on-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import {
Message,
Wechaty,
} from '../../'
} from '../../src/'

export async function onMessage(this: Wechaty, message: Message): Promise<void> {
try {
Expand All @@ -35,7 +35,7 @@ export async function onMessage(this: Wechaty, message: Message): Promise<void>

console.log((room ? '[' + room.topic() + ']' : '')
+ '<' + sender.name() + '>'
+ ':' + message.toStringDigest(),
+ ':' + message,
)

if (message.self() || room) {
Expand Down
6 changes: 3 additions & 3 deletions examples/gist-bot/on-room-join.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
import {
Contact,
Room,
Sayable,
} from '../../'
Wechaty,
} from '../../src/'

export async function onRoomJoin(
this: Sayable,
this: Wechaty,
room: Room,
inviteeList: Contact[],
inviter: Contact,
Expand Down
9 changes: 5 additions & 4 deletions examples/media-file-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ import * as qrcodeTerminal from 'qrcode-terminal'
*/
import {
config,
MediaMessage,
Message,
// MsgType,
Wechaty,
} from '../'
} from '../src/'

const bot = Wechaty.instance({ profile: config.default.DEFAULT_PROFILE })

bot
Expand All @@ -63,15 +64,15 @@ bot
// || m.type() === MsgType.APP
// || (m.type() === MsgType.TEXT && m.typeSub() === MsgType.LOCATION) // LOCATION
// ) {
if (m instanceof MediaMessage) {
if (m.type() !== Message.Type.TEXT) {
saveMediaFile(m)
}
// }
})
.start()
.catch(e => console.error('bot.start() error: ' + e))

async function saveMediaFile(message: MediaMessage) {
async function saveMediaFile(message: Message) {
const filename = message.filename()
console.log('IMAGE local filename: ' + filename)

Expand Down
2 changes: 1 addition & 1 deletion examples/roger-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const qrcodeTerminal = require('qrcode-terminal')
* to `import { ... } from 'wechaty'`
* when you are runing with Docker or NPM instead of Git Source.
*/
import { Wechaty } from '../'
import { Wechaty } from '../src/'

const bot = Wechaty.instance(/* no profile here because roger bot is too noisy */)

Expand Down
4 changes: 2 additions & 2 deletions examples/room-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import {
Room,
Wechaty,
log,
} from '../'
} from '../src/'

const welcome = `
=============== Powered by Wechaty ===============
Expand Down Expand Up @@ -164,7 +164,7 @@ bot

console.log((room ? '[' + room.topic() + ']' : '')
+ '<' + sender.name() + '>'
+ ':' + message.toStringDigest(),
+ ':' + message,
)

if (message.self()) {
Expand Down
9 changes: 4 additions & 5 deletions examples/speech-to-text-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ const qrcodeTerminal = require('qrcode-terminal')
*/
import {
config,
MediaMessage,
MsgType,
Message,
Wechaty,
} from '../'
} from '../src/'

const bot = Wechaty.instance({ profile: config.default.DEFAULT_PROFILE })

Expand All @@ -56,11 +55,11 @@ bot
.on('message', async function(this, msg) {
console.log(`RECV: ${msg}`)

if (msg.type() !== MsgType.VOICE) {
if (msg.type() !== Message.Type.VOICE) {
return // skip no-VOICE message
}

const mp3Stream = await (msg as MediaMessage).readyStream()
const mp3Stream = await msg.readyStream()

const file = createWriteStream(msg.filename())
mp3Stream.pipe(file)
Expand Down
2 changes: 1 addition & 1 deletion examples/tuling123-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
config,
Wechaty,
log,
} from '../'
} from '../src/'

// log.level = 'verbose'
// log.level = 'silly'
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
"tslint-eslint-rules": "^5.1.0",
"tslint-jsdoc-rules": "^0.1.0",
"tuling123-client": "^0.0.1",
"typescript": "^2.6.1"
"typescript": "^2.8.3"
},
"files_comment__whitelist_npm_publish": "http://stackoverflow.com/a/8617868/1123955",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion src/io-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export class IoClient {
// , m.toStringDigest()
// )

if (/^wechaty|chatie|botie/i.test(m.content()) && !m.self()) {
if (/^wechaty|chatie|botie/i.test(m.text()) && !m.self()) {
m.say('https://www.chatie.io')
.then(_ => log.info('Bot', 'REPLIED to magic word "chatie"'))
}
Expand Down
5 changes: 4 additions & 1 deletion src/io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,10 @@ export class Io {
if (user) {
const loginEvent: IoEvent = {
name : 'login',
payload : user.obj,
payload : {
id: user.id,
name: user.name(),
},
}
this.send(loginEvent)
}
Expand Down
17 changes: 0 additions & 17 deletions src/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
import * as url from 'url'

import { log } from './config'
import { MsgType } from './message'

export class Misc {
public static stripHtml(html?: string): string {
Expand Down Expand Up @@ -249,22 +248,6 @@ export class Misc {
return md5sum.digest('hex')
}

public static msgType(ext: string): MsgType {
switch (ext) {
case 'bmp':
case 'jpeg':
case 'jpg':
case 'png':
return MsgType.IMAGE
case 'gif':
return MsgType.EMOTICON
case 'mp4':
return MsgType.VIDEO
default:
return MsgType.APP
}
}

// public static mime(ext): string {
// switch (ext) {
// case 'pdf':
Expand Down
10 changes: 6 additions & 4 deletions src/puppet-web/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ const retryPromise = require('retry-promise').default
import { log } from '../config'
import Profile from '../profile'
import Misc from '../misc'

import {
MediaData,
MsgRawObj,
} from './schema'
} from './schema'
import { WebContactRawObj } from './web-contact'

export interface InjectResult {
code: number,
Expand Down Expand Up @@ -305,9 +307,9 @@ export class Bridge extends EventEmitter {
}
}

public async contactRemark(contactId: string, remark: string|null): Promise<boolean> {
public async contactAlias(contactId: string, alias: string|null): Promise<boolean> {
try {
return await this.proxyWechaty('contactRemark', contactId, remark)
return await this.proxyWechaty('contactRemark', contactId, alias)
} catch (e) {
log.verbose('PuppetWebBridge', 'contactRemark() exception: %s', e.message)
// Issue #509 return false instead of throw when contact is not a friend.
Expand Down Expand Up @@ -494,7 +496,7 @@ export class Bridge extends EventEmitter {
}
}

public async getContact(id: string): Promise<object> {
public async getContact(id: string): Promise<WebContactRawObj> {
if (id !== id) { // NaN
const err = new Error('NaN! where does it come from?')
log.error('PuppetWebBridge', 'getContact(NaN): %s', err)
Expand Down
4 changes: 2 additions & 2 deletions src/puppet-web/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,14 @@ async function onMessage(
case MsgType.MICROVIDEO:
case MsgType.APP:
log.verbose('PuppetWebEvent', 'onMessage() EMOTICON/IMAGE/VIDEO/VOICE/MICROVIDEO message')
m = new MediaMessage(obj)
m = new WebMessage(obj)
m.puppet = this
break

case MsgType.TEXT:
if (m.typeSub() === MsgType.LOCATION) {
log.verbose('PuppetWebEvent', 'onMessage() (TEXT&LOCATION) message')
m = new MediaMessage(obj)
m = new WebMessage(obj)
}
break
}
Expand Down

0 comments on commit c6959b1

Please sign in to comment.