Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// if want to send msg , you need to delay sometimes
await new Promise(r => setTimeout(r, 1000))
await friendship.contact().say('hello from Wechaty')
console.log('after accept')
} else {
logMsg = 'not auto accepted, because verify message is: ' + friendship.hello()
}
break
/**
*
* 2. Friend Ship Confirmed
*
*/
case Friendship.Type.Confirm:
logMsg = 'friend ship confirmed with ' + friendship.contact().name()
break
}
} catch (e) {
logMsg = e.message
}
console.log(logMsg)
await fileHelper.say(logMsg)
})
async function onFriendship (
request,
) {
try {
const contact = request.contact()
if (request.type() === Friendship.Type.Confirm) {
console.info('New friend ' + contact.name() + ' relationship confirmed!')
return
}
/********************************************
*
* 从这里开始修改 vvvvvvvvvvvv
*
*/
await request.accept()
setTimeout(
async _ => {
await contact.say('thank you for adding me')
},
3000,
async function onFriend(friendship) {
let logMsg,hello;
try {
name = friendship.contact().name()
hello = friendship.hello()
logMsg = name + ',发送了好友请求';
console.log(logMsg);
switch (friendship.type()) {
case Friendship.Type.Receive:
if (config.ACCEPTFRIEND.length == 0) {
console.log('无认证关键词,30秒后将会自动通过好友请求')
await lib.delay(30000);
await friendship.accept();
} else if (config.ACCEPTFRIEND.length>0&&config.ACCEPTFRIEND.includes(hello)) {
console.log(`触发关键词${hello},30秒后自动通过好友请求`)
await lib.delay(3000);
await friendship.accept();
}
break;
case Friendship.Type.Confirm:
logMsg = '已确认添加好友:' + name;
console.log(logMsg)
break;
}
} catch (e) {