SquadJS/plugins/discord-admin-broadcast/index.js
2020-09-12 18:59:00 +01:00

53 lines
1.3 KiB
JavaScript

import { COPYRIGHT_MESSAGE } from 'core/constants';
import { ADMIN_BROADCAST } from 'squad-server/events';
export default {
name: 'discord-admin-broadcast',
description:
'The <code>discord-admin-broadcast</code> plugin will send a copy of admin broadcasts made in game to a Discord ' +
'channel.',
defaultEnabled: true,
optionsSpec: {
discordClient: {
required: true,
description: 'The name of the Discord Connector to use.',
default: 'discord'
},
channelID: {
required: true,
description: 'The ID of the channel to log admin broadcasts to.',
default: '',
example: '667741905228136459'
},
color: {
required: false,
description: 'The color of the embed.',
default: 16761867
}
},
init: async (server, options) => {
const channel = await options.discordClient.channels.fetch(options.channelID);
server.on(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
}
}
});
});
}
};