forked from wechaty/wechaty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
video-post.ts
92 lines (71 loc) · 2.12 KB
/
video-post.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import PUPPET from 'wechaty-puppet'
import { FileBox } from 'file-box'
import {
WechatyBuilder,
} from '../src/mods/mod.js'
const bot = WechatyBuilder.build({
name : 'video-post-bot',
})
async function testVideoPost () {
const contact = await bot.Contact.find({ id: 'xxx' })
const room = await bot.Room.find({ id: 'xxx' })
if (!contact || !room) {
return
}
const post = await bot.Post.builder()
.add('hello, world')
.add(FileBox.fromQRCode('qr'))
.add(await bot.UrlLink.create('https://wechaty.js.org'))
.build()
await bot.say(post)
bot.on('message', async message => {
// if (message.type() !== message.type.Post) {
// return
// }
// forward video post
await message.forward(contact)
/**
* Video Post
*/
const post2 = await message.toPost()
const counter = post2.counter()
console.info('total tap(like) number:', counter.taps && counter.taps[PUPPET.types.Tap.Like])
console.info('total children number:', counter.descendant)
/**
* Comment
*/
// reply comment
await post2.reply('xxxx')
await post2.reply(FileBox.fromQRCode('qrimage'))
for await (const descendant of post.descendants({ contactId: message.wechaty.currentUser.id })) {
console.info(descendant)
}
/**
* Like
*/
// like message
await post.like(true)
// await post.tap(PostTapType.Like, true)
// check whether we have liked this post
const liked = await post.like()
console.info('liked date:', liked)
// const liked = await post.tap(PostTapType.Like)
// cancel like
await post.like(false)
// await post.tap(PostTapType.Like, false)
// list all likers
for await (const tap of post.taps()) {
console.info('Taper -------')
console.info('taper:', tap.contact)
console.info('date:', tap.date)
console.info('type:', tap.type)
}
for await (const like of post.likes()) {
console.info('-------')
console.info('liker:', like.contact)
console.info('date:', like.date)
console.info('type:', like.type)
}
})
}
void testVideoPost()