-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeekoBot.js
More file actions
100 lines (80 loc) · 3.24 KB
/
geekoBot.js
File metadata and controls
100 lines (80 loc) · 3.24 KB
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
93
94
95
96
97
98
99
100
/*
CEO Bot (Standalone)
Adds new bots to their respective teams upon joining the server
*/
var mineflayer = require('mineflayer');
const wrapper = require('./wrapper.js')(bot)
const host = 'localhost';
const port = 25565;
const username = "Geeko"
const spawn = [27,64,-110]
const chatInterval = 30*1000;
var phraseIndex =0
const phrases = ["Good luck!",
"Thanks for saving my forest!",
"Say hi to Lewis for me if you see him.",
"Watch out for those creepers!",
"Bone meal can be used on saplings for a chance to grow faster.",
"You can craft bonemeal from bones.",
"You can get bones by defeating skeletons.",
"Try planting saplings in a 2x2 patter."]
var bot = mineflayer.createBot({
username,
host,
port,
version: false
})
bot.on('error', err => console.log(err))
bot.on('respawn',()=>{console.log('respawn')})
console.log(`${username}|Initializing`)
// Teleport to Geeko hideout
bot.on('login',() => {
console.log(`${username}| Login: Teleporting to geeko spawn`)
bot.chat(`/gamemode 1`)
bot.chat(`/tp ${spawn[0]} ${spawn[1]} ${spawn[2]}`)
bot.chat('/dmap mapset world:surface mapzoom:4')
})
// at set interval, chat random Geeko phrase
setInterval(()=>{
// uncomment for random phrases
// phraseIndex = Math.floor(Math.random() * phrases.length)
bot.chat(phrases[phraseIndex++%phrases.length])
},chatInterval)
function addSpeakerToTeam(chatuser, message) {
// parse chat for team
console.log('Geeko|Parse for team')
var end = message.length - wrapper.TEAM_SUFFIX.length;
teamName = message.substring(wrapper.TEAM_PREFIX.length, end);
console.log(`Found [${teamName}]`)
// test for team? - No easy way to test without waiting for chat response
// make team
console.log('Geeko|Make team')
bot.chat(`/scoreboard teams add ${teamName}`)
// set random color?
console.log('Geeko|Random Color team?')
var colorIndex = Math.floor(Math.random() * wrapper.colors.length - 1);
var color = colorIndex < wrapper.colors.length ? wrapper.colors[colorIndex] : wrapper.colors[0]
bot.chat(`/scoreboard teams option ${teamName} color ${color}`)
// join player to team
console.log('Geeko|Join team')
bot.chat(`/scoreboard teams join ${teamName} ${chatuser}`)
}
function giveBlocks(chatuser) {
bot.chat(`/give @p[name=${chatuser}] grass 64 0 {CanPlaceOn:[sand,sandstone]}`)
bot.chat(`/give @p[name=${chatuser}] sapling 64 3 {CanPlaceOn:[grass]}`)
bot.chat(`/give @p[name=${chatuser}] dye 64 15 {CanPlaceOn:["sapling"]}`)
bot.chat(`/give @p[name=${chatuser}] torch 64 0 {CanPlaceOn:["log",grass,dirt,sand,sandstone]}`)
bot.chat(`/gamemode 2 @p[name=${chatuser}]`) // set player to Adventure mode
}
bot.on('chat', function(chatuser, message) {
// console.log('Geeko|Speaker: ' + chatuser + ', bot username:' + bot.username + '\nmsg: ' + message)
// Ignore messages from this bot
if (chatuser === bot.username) return;
// console.log('Geeko|Checking if chat contains ' + wrapper.TEAM_PREFIX + '___' + wrapper.TEAM_SUFFIX)
if (message.includes(wrapper.TEAM_PREFIX)) {
addSpeakerToTeam(chatuser, message);
giveBlocks(chatuser);
} else if (message === wrapper.RESUPPLY_MSG) {
giveBlocks(chatuser);
}
})