-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
48 lines (40 loc) · 1.52 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const Discord = require("discord.js");
const config = require("./config.json");
const RustPlus = require('@liamcottle/rustplus.js');
const rustplus = new RustPlus(config.RUST_SERVER_IP, config.RUST_SERVER_PORT, config.RUST_PLAYER_ID, config.RUST_PLAYER_TOKEN);
const client = new Discord.Client();
var discordConnected = false;
var rustConnected = false;
client.login(config.BOT_TOKEN);
client.once('ready', () => {
client.user.setActivity('Rust+');
const channel = client.channels.cache.get(config.DISCORD_CHANNEL_ID);
channel.send('Rust+ connected...');
discordConnected = true;
});
client.on("message", message => {
if (message.channel == client.channels.cache.get(config.DISCORD_CHANNEL_ID) && !message.author.bot && discordConnected) {
rustplus.sendTeamMessage("[BOT]" + message.author.username + ": " + message.content);
}
});
//RUST
rustplus.on('connected', () => {
rustplus.sendTeamMessage('[BOT]Rust+ connected.');
rustConnected = true;
});
rustplus.on('message', (message) => {
try{
if (discordConnected) {
if (message.broadcast) {
if (message.broadcast.teamMessage.message.name){
const channel = client.channels.cache.get(config.DISCORD_CHANNEL_ID);
var msgText = message.broadcast.teamMessage.message.message;
if (!msgText.includes("[BOT]") && !msgText.includes("!bot")) {
channel.send(message.broadcast.teamMessage.message.name + ": " + message.broadcast.teamMessage.message.message);
}
}
}
}
}catch(e){
}
});