mirror of
https://github.com/AsgardEternal/SquadJS.git
synced 2024-09-28 14:04:25 -05:00
DiscordRcon plugin
This commit is contained in:
parent
122a4a5ec0
commit
47b8b3321a
23
README.md
23
README.md
@ -207,6 +207,29 @@ The following is a list of plugins built into SquadJS, you can click their title
|
||||
]</code></pre>
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>DiscordRcon</summary>
|
||||
<h2>DiscordRcon</h2>
|
||||
<p>The <code>DiscordRcon</code> plugin allows a specified Discord channel to be used as a RCON console to run RCON commands</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>ID of channel to turn into RCON console.</p>
|
||||
<h6>Default</h6>
|
||||
<pre><code></code></pre><h6>Example</h6>
|
||||
<pre><code>667741905228136459</code></pre>
|
||||
<h4>prependAdminNameInBroadcast</h4>
|
||||
<h6>Description</h6>
|
||||
<p>Prepend admin names when making announcements.</p>
|
||||
<h6>Default</h6>
|
||||
<pre><code>false</code></pre>
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>IntervalledBroadcasts</summary>
|
||||
<h2>IntervalledBroadcasts</h2>
|
||||
|
11
config.json
11
config.json
@ -74,9 +74,16 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"plugin": "IntervalledBroadcasts",
|
||||
"plugin": "DiscordRcon",
|
||||
"enabled": true,
|
||||
"broadcasts": ["TEST TEST TEST"],
|
||||
"discordClient": "discord",
|
||||
"channelID": "",
|
||||
"prependAdminNameInBroadcast": false
|
||||
},
|
||||
{
|
||||
"plugin": "IntervalledBroadcasts",
|
||||
"enabled": false,
|
||||
"broadcasts": [],
|
||||
"interval": 300000
|
||||
},
|
||||
{
|
||||
|
71
squad-server/plugins/discord-rcon.js
Normal file
71
squad-server/plugins/discord-rcon.js
Normal file
@ -0,0 +1,71 @@
|
||||
import BasePlugin from './base-plugin.js';
|
||||
|
||||
export default class DiscordRcon extends BasePlugin {
|
||||
static get description() {
|
||||
return (
|
||||
'The <code>DiscordRcon</code> plugin allows a specified Discord channel to be used as a RCON console to ' +
|
||||
'run RCON commands'
|
||||
);
|
||||
}
|
||||
|
||||
static get defaultEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
static get optionsSpecification() {
|
||||
return {
|
||||
discordClient: {
|
||||
required: true,
|
||||
description: 'Discord connector name.',
|
||||
connector: 'discord',
|
||||
default: 'discord'
|
||||
},
|
||||
channelID: {
|
||||
required: true,
|
||||
description: 'ID of channel to turn into RCON console.',
|
||||
default: '',
|
||||
example: '667741905228136459'
|
||||
},
|
||||
prependAdminNameInBroadcast: {
|
||||
required: false,
|
||||
description: 'Prepend admin names when making announcements.',
|
||||
default: false
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
constructor(server, options) {
|
||||
super();
|
||||
|
||||
options.discordClient.on('message', async (message) => {
|
||||
if (message.author.bot || message.channel.id !== options.channelID) return;
|
||||
|
||||
let command = message.content;
|
||||
|
||||
if (options.prependAdminNameInBroadcast && command.match(/^adminbroadcast/i))
|
||||
command = command.replace(
|
||||
/^AdminBroadcast /i,
|
||||
`AdminBroadcast ${message.member.displayName}: `
|
||||
);
|
||||
|
||||
for (const responseMessage of this.splitLongResponse(await server.rcon.execute(command)))
|
||||
await message.channel.send(`\`\`\`${responseMessage}\`\`\``);
|
||||
});
|
||||
}
|
||||
|
||||
splitLongResponse(response) {
|
||||
const responseMessages = [''];
|
||||
|
||||
for (const line of response.split('\n')) {
|
||||
if (responseMessages[responseMessages.length - 1].length + line.length > 1994) {
|
||||
responseMessages.push(line);
|
||||
} else {
|
||||
responseMessages[responseMessages.length - 1] = `${
|
||||
responseMessages[responseMessages.length - 1]
|
||||
}\n${line}`;
|
||||
}
|
||||
}
|
||||
|
||||
return responseMessages;
|
||||
}
|
||||
}
|
@ -1,8 +1,9 @@
|
||||
import ChatCommands from './chat-commands.js';
|
||||
import DiscordRcon from './discord-rcon.js';
|
||||
import IntervalledBroadcasts from './intervalled-broadcasts.js';
|
||||
import SeedingMode from './seeding-mode.js';
|
||||
|
||||
const plugins = [ChatCommands, IntervalledBroadcasts, SeedingMode];
|
||||
const plugins = [ChatCommands, DiscordRcon, IntervalledBroadcasts, SeedingMode];
|
||||
|
||||
const pluginsByName = {};
|
||||
for (const plugin of plugins) {
|
||||
|
Loading…
Reference in New Issue
Block a user