2020-05-15 12:42:39 -05:00
|
|
|
import { COPYRIGHT_MESSAGE } from 'core/config';
|
|
|
|
import { RCON_CHAT_MESSAGE } from 'squad-server/events/rcon';
|
|
|
|
|
2020-06-13 09:33:44 -05:00
|
|
|
export default async function(server, discordClient, channelID, options = {}) {
|
2020-06-13 11:35:00 -05:00
|
|
|
if (!server) throw new Error('DiscordChat must be provided with a reference to the server.');
|
2020-05-15 12:42:39 -05:00
|
|
|
|
2020-06-13 11:35:00 -05:00
|
|
|
if (!discordClient) throw new Error('DiscordChat must be provided with a Discord.js client.');
|
2020-05-15 12:42:39 -05:00
|
|
|
|
2020-06-13 11:35:00 -05:00
|
|
|
if (!channelID) throw new Error('DiscordChat must be provided with a channel ID.');
|
2020-05-15 12:42:39 -05:00
|
|
|
|
|
|
|
const ignoreChats = options.ignoreChats || ['ChatSquad', 'ChatAdmin'];
|
|
|
|
|
|
|
|
options = {
|
2020-07-14 13:57:10 -05:00
|
|
|
chatColors: {
|
|
|
|
...options.chatColors
|
|
|
|
},
|
2020-05-15 12:42:39 -05:00
|
|
|
color: 16761867,
|
|
|
|
...options
|
|
|
|
};
|
|
|
|
|
|
|
|
const channel = await discordClient.channels.fetch(channelID);
|
|
|
|
|
|
|
|
server.on(RCON_CHAT_MESSAGE, async info => {
|
|
|
|
if (ignoreChats.includes(info.chat)) return;
|
|
|
|
|
|
|
|
const playerInfo = await server.getPlayerBySteamID(info.steamID);
|
|
|
|
|
|
|
|
channel.send({
|
|
|
|
embed: {
|
|
|
|
title: info.chat,
|
2020-07-14 13:57:10 -05:00
|
|
|
color: options.chatColors[info.chat] || options.color,
|
2020-05-15 12:42:39 -05:00
|
|
|
fields: [
|
|
|
|
{
|
|
|
|
name: 'Player',
|
|
|
|
value: playerInfo.name,
|
|
|
|
inline: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'SteamID',
|
|
|
|
value: `[${playerInfo.steamID}](https://steamcommunity.com/profiles/${info.steamID})`,
|
|
|
|
inline: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Team & Squad',
|
2020-06-13 11:35:00 -05:00
|
|
|
value: `Team: ${playerInfo.teamID}, Squad: ${playerInfo.squadID || 'Unassigned'}`
|
2020-05-15 12:42:39 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Message',
|
|
|
|
value: `${info.message}`
|
|
|
|
}
|
|
|
|
],
|
|
|
|
timestamp: info.time.toISOString(),
|
|
|
|
footer: {
|
|
|
|
text: COPYRIGHT_MESSAGE
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|