Skip to content

Commit

Permalink
Merge pull request #35 from Thomas-Smyth/beta
Browse files Browse the repository at this point in the history
SquadJS v1.2.0 Release
  • Loading branch information
Thomas-Smyth authored Jul 19, 2020
2 parents 2b93d0d + bed8450 commit f7f231d
Show file tree
Hide file tree
Showing 14 changed files with 141 additions and 17 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ SquadJS relies on being able to access the Squad server log directory in order t
4. Start SquadJS: `node index.js`.

## Plugins
* [Discord Admin Broadcast](https://github.com/Thomas-Smyth/SquadJS/tree/master/plugins/discord-admin-broadcast) - Log admin broadcasts to Discord.
* [Discord Admin Cam Logs](https://github.com/Thomas-Smyth/SquadJS/tree/master/plugins/discord-admin-cam-logs) - Log admin cam usage to Discord.
* [Discord Chat](https://github.com/Thomas-Smyth/SquadJS/tree/master/plugins/discord-chat) - Log in game chat to Discord.
* [Discord Chat Admin Request](https://github.com/Thomas-Smyth/SquadJS/tree/master/plugins/discord-chat-admin-request) - Log `!admin` alerts to Discord.
Expand Down
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Server from 'squad-server';
import SquadLayerFilter from 'connectors/squad-layer-filter';

import {
discordAdminBroadcast,
discordAdminCamLogs,
discordChat,
discordChatAdminRequest,
Expand Down Expand Up @@ -40,9 +41,12 @@ async function main() {
// Discord Plugins
const discordClient = new Discord.Client();
await discordClient.login('Discord Login Token');
await discordAdminBroadcast(server, discordClient, 'discordChannelID');
await discordAdminCamLogs(server, discordClient, 'discordChannelID');
await discordChat(server, discordClient, 'discordChannelID');
await discordChatAdminRequest(server, discordClient, 'discordChannelID', { pingGroups: ['discordGroupID'] });
await discordChatAdminRequest(server, discordClient, 'discordChannelID', {
pingGroups: ['discordGroupID']
});
await discordServerStatus(server, discordClient);
await discordTeamkill(server, discordClient, 'discordChannelID');

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "SquadJS",
"version": "1.1.0",
"version": "1.2.0",
"repository": "https://github.com/Thomas-Smyth/SquadJS.git",
"author": "Thomas Smyth <https://github.com/Thomas-Smyth>",
"license": "BSL-1.0",
Expand Down
30 changes: 30 additions & 0 deletions plugins/discord-admin-broadcast/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<div align="center">

<img src="../../assets/squadjs-logo.png" alt="Logo" width="500"/>

#### SquadJS - Discord Admin Broadcast Plugin
</div>

## About
The Discord Admin Broadcast plugin streams admin broadcasts logs to Discord.

## Installation
```js
// Place the following two lines at the top of your index.js file.
import Discord from 'discord.js';
import { discordAdminBroadcast } from 'plugins';

// Place the following two lines in your index.js file before using an Discord plugins.
const discordClient = new Discord.Client();
await discordClient.login('Discord Login Token'); // insert your Discord bot's login token here.

// Place the following lines after all of the above.
await discordAdminBroadcast(
server,
discordClient,
'discordChannelID',
{ // options - the options included below display the defaults and can be removed for simplicity.
color: 16761867 // color of embed
}
);
```
36 changes: 36 additions & 0 deletions plugins/discord-admin-broadcast/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { COPYRIGHT_MESSAGE } from 'core/config';
import { LOG_PARSER_ADMIN_BROADCAST } from 'squad-server/events/log-parser';

export default async function(server, discordClient, channelID, options = {}) {
if (!server) throw new Error('DiscordChat must be provided with a reference to the server.');

if (!discordClient) throw new Error('DiscordChat must be provided with a Discord.js client.');

if (!channelID) throw new Error('DiscordChat must be provided with a channel ID.');

options = {
color: 16761867,
...options
};

const channel = await discordClient.channels.fetch(channelID);

server.on(LOG_PARSER_ADMIN_BROADCAST, async info => {
channel.send({
embed: {
title: 'Admin Broadcast',
color: options.color,
fields: [
{
name: 'Message',
value: `${info.message}`
}
],
timestamp: info.time.toISOString(),
footer: {
text: COPYRIGHT_MESSAGE
}
}
});
});
}
1 change: 1 addition & 0 deletions plugins/discord-chat-admin-request/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ await discordChatAdminRequest(
{ // options - the options included below display the defaults and can be removed for simplicity.
adminPrefix: '!admin', // prefix for an admin request.
pingGroups: ['729853701308678154'], // Groups to ping on a request, leave empty for no ping.
pingDelay: 60 * 1000, // number of ms between pings. other messages will still be logged just without pings.
ignoreChats: ['ChatSquad', 'ChatAdmin'], // an array of chats to not display.
color: '#f44336' // color of embed
}
Expand Down
38 changes: 27 additions & 11 deletions plugins/discord-chat-admin-request/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,35 @@ export default async function(server, discordClient, channelID, options = {}) {
throw new Error('DiscordChatAdminRequest must be provided with a channel ID.');
}

const ignoreChats = options.ignoreChats || [];
const adminPrefix = options.adminPrefix || '!admin';
const pingGroups = options.pingGroups || [];

options = {
color: 16761867,
ignoreChats: [],
adminPrefix: '!admin',
pingGroups: [],
pingDelay: 60 * 1000,
...options
};

let lastPing = null;

const channel = await discordClient.channels.fetch(channelID);

server.on(RCON_CHAT_MESSAGE, async info => {
if (ignoreChats.includes(info.chat)) return;
if (!info.message.startsWith(`${adminPrefix}`)) return;
if (options.ignoreChats.includes(info.chat)) return;
if (!info.message.startsWith(`${options.adminPrefix}`)) return;

const playerInfo = await server.getPlayerBySteamID(info.steamID);
const trimmedMessage = info.message.replace(adminPrefix, '').trim();
const trimmedMessage = info.message.replace(options.adminPrefix, '').trim();

if (trimmedMessage.length === 0) {
await server.rcon.warn(info.steamID, `Please specify what you would like help with when requesting an admin.`);
await server.rcon.warn(
info.steamID,
`Please specify what you would like help with when requesting an admin.`
);
return;
}

channel.send({
content: pingGroups.length ? pingGroups.map(groupID => `<@&${groupID}>`).join(' ') : '',
const message = {
embed: {
title: `${playerInfo.name} has requested admin support!`,
color: options.color,
Expand Down Expand Up @@ -67,6 +71,18 @@ export default async function(server, discordClient, channelID, options = {}) {
text: COPYRIGHT_MESSAGE
}
}
});
};

if (options.pingGroups.length > 0 && (lastPing === null || Date.now() - options.pingDelay > lastPing)) {
message.content = options.pingGroups.map(groupID => `<@&${groupID}>`).join(' ');
lastPing = Date.now();
}

channel.send(message);

await server.rcon.warn(
info.steamID,
`An admin has been notified, please wait for us to get back to you.`
);
});
}
3 changes: 2 additions & 1 deletion plugins/discord-chat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ await discordChat(
'discordChannelID',
{ // options - the options included below display the defaults and can be removed for simplicity.
ignoreChats: ['ChatSquad', 'ChatAdmin'], // an array of chats to not display.
color: 16761867 // color of embed
color: 16761867, // color of embed
chatColors: { 'ChatAll': 16761867 } // change the color of chat types individually. Defaults to color above if not specified.
}
);
```
5 changes: 4 additions & 1 deletion plugins/discord-chat/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export default async function(server, discordClient, channelID, options = {}) {
const ignoreChats = options.ignoreChats || ['ChatSquad', 'ChatAdmin'];

options = {
chatColors: {
...options.chatColors
},
color: 16761867,
...options
};
Expand All @@ -25,7 +28,7 @@ export default async function(server, discordClient, channelID, options = {}) {
channel.send({
embed: {
title: info.chat,
color: options.color,
color: options.chatColors[info.chat] || options.color,
fields: [
{
name: 'Player',
Expand Down
2 changes: 2 additions & 0 deletions plugins/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import autoTKWarn from './auto-tk-warn/index.js';
import discordAdminBroadcast from './discord-admin-broadcast/index.js';
import discordAdminCamLogs from './discord-admin-cam-logs/index.js';
import discordChat from './discord-chat/index.js';
import discordChatAdminRequest from './discord-chat-admin-request/index.js';
Expand All @@ -14,6 +15,7 @@ import teamRandomizer from './team-randomizer/index.js';

export {
autoTKWarn,
discordAdminBroadcast,
discordAdminCamLogs,
discordChat,
discordChatAdminRequest,
Expand Down
6 changes: 4 additions & 2 deletions plugins/mapvote/mapvote-123.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ export default function(server, options = {}) {
});

await server.rcon.broadcast(
`A new map vote has started. Participate in the map vote by typing "!mapvote help" in chat.`
`A new map vote has started. Participate in the map vote by typing "!mapvote help" in chat. Map options to follow...`
);
await server.rcon.broadcast(mapvote.squadLayerFilter.getLayerNames().map((layerName, key) => `${key+1} - ${layerName}`).join(', '));
}
return;
}
Expand All @@ -78,8 +79,9 @@ export default function(server, options = {}) {
});

await server.rcon.broadcast(
`A new map vote has started. Participate in the map vote by typing "!mapvote help" in chat.`
`A new map vote has started. Participate in the map vote by typing "!mapvote help" in chat. Map options to follow...`
);
await server.rcon.broadcast(mapvote.squadLayerFilter.getLayerNames().map((layerName, key) => `${key+1} - ${layerName}`).join(', '));
return;
}

Expand Down
10 changes: 10 additions & 0 deletions squad-server/events/log-parser.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/** Occurs when an admin broadcast is made.
*
* Data:
* - time - Date object of when the event occurred.
* - message - The message that was broadcasted.
* - from - Apparently who broadcasted it, but this is broken in Squad logs.
*/
const LOG_PARSER_ADMIN_BROADCAST = 'LOG_PARSER_ADMIN_BROADCAST';

/** Occurs when a new layer is loaded.
*
* Data:
Expand Down Expand Up @@ -115,6 +124,7 @@ const LOG_PARSER_PLAYER_WOUNDED = 'LOG_PARSER_PLAYER_WOUNDED';
const LOG_PARSER_SERVER_TICK_RATE = 'LOG_PARSER_SERVER_TICK_RATE';

export {
LOG_PARSER_ADMIN_BROADCAST,
LOG_PARSER_NEW_GAME,
LOG_PARSER_PLAYER_CONNECTED,
LOG_PARSER_PLAYER_DAMAGED,
Expand Down
16 changes: 16 additions & 0 deletions squad-server/log-parser/rules/admin-broadcast.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { LOG_PARSER_ADMIN_BROADCAST } from '../../events/log-parser.js';

export default {
regex: /^\[([0-9.:-]+)]\[([ 0-9]*)]LogSquad: ADMIN COMMAND: Message broadcasted <(.+)> from (.+)/,
onMatch: (args, logParser) => {
const data = {
raw: args[0],
time: args[1],
chainID: args[2],
message: args[3],
from: args[4]
};

logParser.server.emit(LOG_PARSER_ADMIN_BROADCAST, data);
}
};
2 changes: 2 additions & 0 deletions squad-server/log-parser/rules/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import AdminBroadcast from './admin-broadcast.js';
import NewGame from './new-game.js';
import PlayerConnected from './player-connected.js';
import PlayerDamaged from './player-damaged.js';
Expand All @@ -10,6 +11,7 @@ import ServerTickRate from './server-tick-rate.js';
import SteamIDConnected from './steamid-connected.js';

export default [
AdminBroadcast,
NewGame,
PlayerConnected,
PlayerDamaged,
Expand Down

0 comments on commit f7f231d

Please sign in to comment.