0
点赞
收藏
分享

微信扫一扫

【数据结构】考研真题攻克与重点知识点剖析 - 第 4 篇:串

岛上码农 04-09 20:00 阅读 1

读取联系人信息

获取当前机器人账号全部联系人信息

bot.on('ready', async () => {
    console.log("机器人准备完毕!!!")
    let contactList = await bot.Contact.findAll()
    for (let index = 0; index < contactList.length; index++) {
        const contact = contactList[index];
        if (contact.payload.name == '番茄土豆') {
            console.log(contact)
        }
    }
})

Contact 对象属性

WechatifiedContactImpl {
	_events: [Object: null prototype] {},
	_eventsCount: 0,
	_maxListeners: undefined,
	id: '@9c7f307a0233472ab92c0d3c8624fd0a2a8522a9d085f0b89a540d23ff76d862',
	payload: {
		address: '',
		alias: '',
		avatar: '/cgi-bin/mmwebwx-bin/webwxgeticon?seq=768678887&username=@9c7f307a0233472ab92c0d3c8624fd0a2a8522a9d085f0b89a540d23ff76d862&skey=@crypt_13d84e54_3b3f2c2d3fa4b54729339f73cdf121e6',
		city: '',
		friend: true,
		gender: 0,
		id: '@9c7f307a0233472ab92c0d3c8624fd0a2a8522a9d085f0b89a540d23ff76d862',
		name: '番茄土豆',
		phone: [],
		province: '',
		signature: '',
		star: false,
		weixin: '',
		type: 1
	},
	[Symbol(kCapture)]: false
}

联系人接口

在这里插入图片描述

存储联系人信息

存储指定联系人头像案例

bot.on('ready', async () => {
    console.log("机器人开始运行!!!")
    const contact = await bot.Contact.find({ name: "番茄土豆" });
    console.log(contact)

    fileBox = await contact.avatar()
    const filePath = './output.jpg';
    fs.writeFile(filePath, fileBox.buffer, 'binary', (err) => {
        if (err) {
            console.error(err);
        } else {
            console.log("save success!!!");
        }
    });
    await contact.say("晚安宝宝")
})

待更新···

举报

相关推荐

考研真题数据结构

0 条评论