-
Notifications
You must be signed in to change notification settings - Fork 3
/
chat.ts
35 lines (29 loc) · 980 Bytes
/
chat.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
import { Bot } from "mineflayer";
interface Message {
bot: Bot;
message: string;
}
export class ChatBuffer {
private chatStack: Message[] = [];
private messageWaitTime: number;
constructor(messageWaitTime: number = 2000) {
this.messageWaitTime = messageWaitTime;
}
public start() {
if (this.chatStack.length > 0) {
let info = this.chatStack.shift() as Message;
console.log(`${info.bot.player.username} sending>>>`, info.message);
info.bot.chat(info.message);
}
setTimeout(this.start.bind(this), this.messageWaitTime);
}
public addChat(bot: Bot, message: string, directTo: string | null = null) {
message.split('\n').forEach(message => {
if (!directTo) {
this.chatStack.push({ bot, message });
} else {
this.chatStack.push({ bot, message: `/msg ${directTo} ` + message });
}
});
}
}