提交 54d199fc 编写于 作者: J Jas 提交者: Huan (李卓桓)

support brand checking of contact (#404)

* 1. in wxwebapp,first item in memberList is a random user from the room, 2. some times we can got owneruin or ChatRoomOwner . as those reason, first member from memberlist should not be  here any more

* brand checking support

* example(test) for brand checking

* allow bitwise operate for brand checking

* 1. use tslint:disable-next-line in source insteadof changing no-bitwise to false. 2. contact is ready always

* contact is always ready thanks to framework

* identify contact as official|special|personal

* example of identify official|special|personal account

* code clean

* change source refers to a exactly commit hash
上级 95d35f15
......@@ -78,6 +78,38 @@ async function main() {
log.info('Bot', '#######################')
log.info('Bot', 'Contact number: %d\n', contactList.length)
/**
* official contacts list
*/
for (let i = 0; i < contactList.length; i++) {
const contact = contactList[i]
if (contact.official()) {
log.info('Bot', `official ${i}: ${contact}`)
}
}
/**
* 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()}`)
}
}
/**
* personal contact list
*/
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}`)
}
}
const MAX = 17
for (let i = 0; i < contactList.length; i++ ) {
const contact = contactList[i]
......
......@@ -25,6 +25,8 @@ type ContactObj = {
uin: string,
weixin: string,
avatar: string, // XXX URL of HeadImgUrl
official: boolean,
special: boolean,
}
export type ContactRawObj = {
......@@ -41,6 +43,7 @@ export type ContactRawObj = {
HeadImgUrl: string,
stranger: string, // assign by injectio.js
VerifyFlag: number,
}
/**
......@@ -60,6 +63,16 @@ export type ContactQueryFilter = {
remark?: string | RegExp,
}
/**
* @see https://github.com/Chatie/webwx-app-tracker/blob/7c59d35c6ea0cff38426a4c5c912a086c4c512b2/formatted/webwxApp.js#L3848
*/
const specialContactList: string[] = [
'weibo', 'qqmail', 'fmessage', 'tmessage', 'qmessage', 'qqsync', 'floatbottle',
'lbsapp', 'shakeapp', 'medianote', 'qqfriend', 'readerapp', 'blogapp', 'facebookapp',
'masssendapp', 'meishiapp', 'feedsapp', 'voip', 'blogappweixin', 'weixin', 'brandsessionholder',
'weixinreminder', 'wxid_novlwrv3lqwv11', 'gh_22b87fa7cb3c', 'officialaccounts', 'notification_messages',
]
/**
* Class Contact
*
......@@ -110,6 +123,16 @@ export class Contact implements Sayable {
star: !!rawObj.StarFriend,
stranger: !!rawObj.stranger, // assign by injectio.js
avatar: rawObj.HeadImgUrl,
/**
* @see 1. https://github.com/Chatie/webwx-app-tracker/blob/7c59d35c6ea0cff38426a4c5c912a086c4c512b2/formatted/webwxApp.js#L3243
* @see 2. https://github.com/Urinx/WeixinBot/blob/master/README.md
*/
// tslint:disable-next-line
official: !!rawObj.UserName && !rawObj.UserName.startsWith('@@') && !!(rawObj.VerifyFlag & 8),
/**
* @see 1. https://github.com/Chatie/webwx-app-tracker/blob/7c59d35c6ea0cff38426a4c5c912a086c4c512b2/formatted/webwxApp.js#L3246
*/
special: specialContactList.indexOf(rawObj.UserName) > -1 || /@qqim$/.test(rawObj.UserName),
}
}
......@@ -152,6 +175,58 @@ export class Contact implements Sayable {
return this.obj.stranger
}
/**
* Check if it's a offical account
*
* @returns {boolean|null} True for official account, Flase for contact is not a official account
*
* @example
* ```ts
* const isOfficial = contact.official()
* ```
*/
public official(): boolean {
return !!this.obj && this.obj.official
}
/**
* Check if it's a special contact
*
* the contact who's id in following list will be identify as a special contact
*
* ```ts
* 'weibo', 'qqmail', 'fmessage', 'tmessage', 'qmessage', 'qqsync', 'floatbottle',
* 'lbsapp', 'shakeapp', 'medianote', 'qqfriend', 'readerapp', 'blogapp', 'facebookapp',
* 'masssendapp', 'meishiapp', 'feedsapp', 'voip', 'blogappweixin', 'weixin', 'brandsessionholder',
* 'weixinreminder', 'wxid_novlwrv3lqwv11', 'gh_22b87fa7cb3c', 'officialaccounts', 'notification_messages',
* ```
* @see https://github.com/Chatie/webwx-app-tracker/blob/7c59d35c6ea0cff38426a4c5c912a086c4c512b2/formatted/webwxApp.js#L3848
*
* @returns {boolean|null} True for brand, Flase for contact is not a brand
*
* @example
* ```ts
* const isSpecial = contact.special()
* ```
*/
public special(): boolean {
return !!this.obj && this.obj.special
}
/**
* Check if it's a personal account
*
* @returns {boolean|null} True for personal account, Flase for contact is not a personal account
*
* @example
* ```ts
* const isPersonal = contact.personal()
* ```
*/
public personal(): boolean {
return !this.official()
}
/**
* Check if the contact is star contact.
*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册