DiscordAdminRequest plugin

This commit is contained in:
Thomas Smyth 2020-10-13 12:08:21 +01:00
parent c53347eea0
commit 7d7d4369f0
5 changed files with 207 additions and 1 deletions

View File

@ -240,6 +240,63 @@ The following is a list of plugins built into SquadJS, you can click their title
<pre><code>16761867</code></pre>
</details>
<details>
<summary>DiscordAdminRequest</summary>
<h2>DiscordAdminRequest</h2>
<p>The <code>DiscordAdminRequest</code> plugin will ping admins in a Discord channel when a player requests an admin via the <code>!admin</code> command in in-game chat.</p>
<h3>Options</h3>
<h4>discordClient (Required)</h4>
<h6>Description</h6>
<p>Discord connector name.</p>
<h6>Default</h6>
<pre><code>discord</code></pre>
<h4>channelID (Required)</h4>
<h6>Description</h6>
<p>The ID of the channel to log admin broadcasts to.</p>
<h6>Default</h6>
<pre><code></code></pre><h6>Example</h6>
<pre><code>667741905228136459</code></pre>
<h4>ignoreChats</h4>
<h6>Description</h6>
<p>A list of chat names to ignore.</p>
<h6>Default</h6>
<pre><code>[]</code></pre><h6>Example</h6>
<pre><code>[
"ChatSquad"
]</code></pre>
<h4>ignorePhrases</h4>
<h6>Description</h6>
<p>A list of phrases to ignore.</p>
<h6>Default</h6>
<pre><code>[]</code></pre><h6>Example</h6>
<pre><code>[
"switch"
]</code></pre>
<h4>adminPrefix</h4>
<h6>Description</h6>
<p>The command that calls an admin.</p>
<h6>Default</h6>
<pre><code>!admin</code></pre>
<h4>pingGroups</h4>
<h6>Description</h6>
<p>A list of Discord role IDs to ping.</p>
<h6>Default</h6>
<pre><code>[]</code></pre><h6>Example</h6>
<pre><code>[
"500455137626554379"
]</code></pre>
<h4>pingDelay</h4>
<h6>Description</h6>
<p>Cooldown for pings in milliseconds.</p>
<h6>Default</h6>
<pre><code>60000</code></pre>
<h4>color</h4>
<h6>Description</h6>
<p>The color of the embed.</p>
<h6>Default</h6>
<pre><code>16761867</code></pre>
</details>
<details>
<summary>DiscordRcon</summary>
<h2>DiscordRcon</h2>

View File

@ -85,6 +85,18 @@
"channelID": "",
"color": 16761867
},
{
"plugin": "DiscordAdminRequest",
"enabled": false,
"discordClient": "discord",
"channelID": "",
"ignoreChats": [],
"ignorePhrases": [],
"adminPrefix": "!admin",
"pingGroups": [],
"pingDelay": 60000,
"color": 16761867
},
{
"plugin": "DiscordRcon",
"enabled": false,

View File

@ -157,7 +157,10 @@ export default class SquadServer extends EventEmitter {
const command = data.message.match(/!([^ ]+) ?(.*)/);
if (command)
this.emit(`CHAT_COMMAND:${command[1].toLowerCase()}`, { ...data, message: command[2] });
this.emit(`CHAT_COMMAND:${command[1].toLowerCase()}`, {
...data,
message: command[2].trim()
});
});
this.rcon.on('RCON_ERROR', (data) => {

View File

@ -0,0 +1,132 @@
import BasePlugin from './base-plugin.js';
import { COPYRIGHT_MESSAGE } from '../utils/constants.js';
export default class DiscordAdminRequest extends BasePlugin {
static get description() {
return (
'The <code>DiscordAdminRequest</code> plugin will ping admins in a Discord channel when a player requests ' +
'an admin via the <code>!admin</code> command in in-game chat.'
);
}
static get defaultEnabled() {
return false;
}
static get optionsSpecification() {
return {
discordClient: {
required: true,
description: 'Discord connector name.',
connector: 'discord',
default: 'discord'
},
channelID: {
required: true,
description: 'The ID of the channel to log admin broadcasts to.',
default: '',
example: '667741905228136459'
},
ignoreChats: {
required: false,
description: 'A list of chat names to ignore.',
default: [],
example: ['ChatSquad']
},
ignorePhrases: {
required: false,
description: 'A list of phrases to ignore.',
default: [],
example: ['switch']
},
adminPrefix: {
required: false,
description: 'The command that calls an admin.',
default: '!admin'
},
pingGroups: {
required: false,
description: 'A list of Discord role IDs to ping.',
default: [],
example: ['500455137626554379']
},
pingDelay: {
required: false,
description: 'Cooldown for pings in milliseconds.',
default: 60 * 1000
},
color: {
required: false,
description: 'The color of the embed.',
default: 16761867
}
};
}
constructor(server, options) {
super();
this.lastPing = Date.now();
options.discordClient.channels.fetch(options.channelID).then((channel) => {
server.on(`CHAT_COMMAND:${options.adminPrefix}`, async (info) => {
if (options.ignoreChats.includes(info.chat)) return;
for (const ignorePhrase of options.ignorePhrases) {
if (info.message.includes(ignorePhrase)) return;
}
if (info.message.length === 0) {
await server.rcon.warn(
info.player.steamID,
`Please specify what you would like help with when requesting an admin.`
);
return;
}
const message = {
embed: {
title: `${info.player.name} has requested admin support!`,
color: options.color,
fields: [
{
name: 'Player',
value: info.player.name,
inline: true
},
{
name: 'SteamID',
value: `[${info.player.steamID}](https://steamcommunity.com/profiles/${info.player.steamID})`,
inline: true
},
{
name: 'Team & Squad',
value: `Team: ${info.player.teamID}, Squad: ${info.player.squadID || 'Unassigned'}`
},
{
name: 'Message',
value: info.message
}
],
timestamp: info.time.toISOString(),
footer: {
text: COPYRIGHT_MESSAGE
}
}
};
if (options.pingGroups.length > 0 && Date.now() - options.pingDelay > this.lastPing) {
message.content = options.pingGroups.map((groupID) => `<@&${groupID}>`).join(' ');
this.lastPing = Date.now();
}
await channel.send(message);
await server.rcon.warn(
info.player.steamID,
`An admin has been notified, please wait for us to get back to you.`
);
});
});
}
}

View File

@ -1,6 +1,7 @@
import AutoTKWarn from './auto-tk-warn.js';
import ChatCommands from './chat-commands.js';
import DiscordAdminBroadcast from './discord-admin-broadcast.js';
import DiscordAdminRequest from './discord-admin-request.js';
import DiscordRcon from './discord-rcon.js';
import IntervalledBroadcasts from './intervalled-broadcasts.js';
import SeedingMode from './seeding-mode.js';
@ -9,6 +10,7 @@ const plugins = [
AutoTKWarn,
ChatCommands,
DiscordAdminBroadcast,
DiscordAdminRequest,
DiscordRcon,
IntervalledBroadcasts,
SeedingMode