-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathexamplebot.js
62 lines (49 loc) · 1.66 KB
/
examplebot.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
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
const BonkBot = require("bonkbot");
let bot = BonkBot.createBot({
account: {
username: "pixelmelt",
password: "password123",
guest: false,
},
// skin: "{skin_object_here}"
});
bot.events.on("ready", async () => {
console.log("Bot is ready");
// let fromurl = await bot.getAddressFromLink("https://bonk.io/710561")
let fromroomname = await bot.getAddressFromRoomName("test")
bot.setAddress(fromroomname)
bot.connect();
});
bot.events.on("connect", () => {
console.log("Bot connected to room!");
bot.events.on("packet", async (packet) => {
bot.autoHandlePacket(packet)
// ignore spammy packets
if (packet.type == "timesync") return;
if (packet.type == "ping") return;
console.log(packet);
});
bot.events.on("banned", async () => {
console.log("Bot was banned from the room!");
});
bot.events.on("disconnected", async () => {
console.log("Bot disconnected from the room!");
});
bot.events.on("chatmessage", async (playerchatevent) => {
let pce = playerchatevent
console.log(`${pce.username}: ${pce.message}`);
// commands!
if(pce.message == "!ping"){
bot.chat("Pong!");
}
});
bot.events.on("join", async (playerjoinevent) => {
let joiningPlayer = bot.getPlayerByID(playerjoinevent.id)
console.log(`${joiningPlayer.username} joined the room!`);
})
bot.events.on("leave", async (playerleaveevent) => {
let leavingPlayer = bot.getPlayerByID(playerleaveevent.id)
console.log(`${leavingPlayer.username} left the room!`);
})
});
bot.init();