mirror of
https://github.com/AsgardEternal/SquadJS.git
synced 2024-09-29 13:24:26 -05:00
60 lines
1.8 KiB
JavaScript
60 lines
1.8 KiB
JavaScript
export default {
|
|
name: 'discord-rcon',
|
|
description:
|
|
'The `discord-rcon` plugin allows a specified Discord channel to be used as a RCON console to run RCON commands.',
|
|
|
|
defaultEnabled: true,
|
|
optionsSpec: {
|
|
discordClient: {
|
|
type: 'DiscordConnector',
|
|
required: true,
|
|
default: 'discord',
|
|
description: 'The name of the Discord Connector to use.'
|
|
},
|
|
channelID: {
|
|
type: 'Discord Channel ID',
|
|
required: true,
|
|
default: 'Discord Channel ID',
|
|
description: 'The ID of the channel you wish to turn into a RCON console.'
|
|
},
|
|
prependAdminNameInBroadcast: {
|
|
type: 'Boolean',
|
|
required: false,
|
|
default: false,
|
|
description: "Prepend the admin's name when he makes an announcement."
|
|
}
|
|
},
|
|
|
|
init: async (server, options) => {
|
|
options.discordClient.on('message', async (message) => {
|
|
if (message.author.bot || message.channel.id !== options.channelID) return;
|
|
|
|
let command = message.content;
|
|
|
|
if (options.prependAdminNameInBroadcast && command.toLowerCase().startsWith('adminbroadcast'))
|
|
command = command.replace(
|
|
/^AdminBroadcast /i,
|
|
`AdminBroadcast ${message.member.displayName}: `
|
|
);
|
|
|
|
const response = await server.rcon.execute(command);
|
|
|
|
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}`;
|
|
}
|
|
}
|
|
|
|
for (const responseMessage of responseMessages) {
|
|
await message.channel.send(`\`\`\`${responseMessage}\`\`\``);
|
|
}
|
|
});
|
|
}
|
|
};
|