-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
34 lines (26 loc) · 1.1 KB
/
index.js
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
let {createBotServer, EventHandler, Msg} = require('pbbot')
let port = 8081
console.log("开始启动")
EventHandler.handleConnect = async (bot) => {
console.log(`机器人已连接: ${bot.botId.toString()}`)
}
EventHandler.handleDisconnect = async (bot) => {
console.log(`机器人已断开: ${bot.botId.toString()}`)
}
EventHandler.handlePrivateMessage = async (bot, event) => {
let rawMsg = event.rawMessage
let userId = event.userId
console.log(`收到私聊消息,发送者: ${userId.toString()},内容: ${rawMsg}`)
await bot.sendPrivateMessage(event.userId, "hello world")
}
EventHandler.handleGroupMessage = async (bot, event) => {
let rawMsg = event.rawMessage
let userId = event.userId
let groupId = event.groupId
console.log(`收到群聊消息,群号: ${groupId.toString()},发送者: ${userId.toString()},内容: ${rawMsg}`)
if (rawMsg !== "hello") return
let msg = Msg.builder().show("https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png",40005)
await bot.sendGroupMessage(groupId, msg)
}
createBotServer(port)
console.log(`启动成功,端口:${port}`)