mirror of
https://github.com/AsgardEternal/SquadJS.git
synced 2024-09-28 14:04:25 -05:00
DiscordBasePlugin & DiscordChat plugin
This commit is contained in:
parent
7d7d4369f0
commit
0cc1c9c01b
@ -87,7 +87,7 @@
|
||||
},
|
||||
{
|
||||
"plugin": "DiscordAdminRequest",
|
||||
"enabled": false,
|
||||
"enabled": true,
|
||||
"discordClient": "discord",
|
||||
"channelID": "",
|
||||
"ignoreChats": [],
|
||||
|
@ -1,7 +1,7 @@
|
||||
import BasePlugin from './base-plugin.js';
|
||||
import DiscordBasePlugin from './discord-base-plugin.js';
|
||||
import { COPYRIGHT_MESSAGE } from '../utils/constants.js';
|
||||
|
||||
export default class DiscordAdminBroadcast extends BasePlugin {
|
||||
export default class DiscordAdminBroadcast extends DiscordBasePlugin {
|
||||
static get description() {
|
||||
return (
|
||||
'The <code>DiscordAdminBroadcast</code> plugin will send a copy of admin broadcasts made in game to a Discord ' +
|
||||
@ -15,12 +15,7 @@ export default class DiscordAdminBroadcast extends BasePlugin {
|
||||
|
||||
static get optionsSpecification() {
|
||||
return {
|
||||
discordClient: {
|
||||
required: true,
|
||||
description: 'Discord connector name.',
|
||||
connector: 'discord',
|
||||
default: 'discord'
|
||||
},
|
||||
...DiscordBasePlugin.optionsSpecification,
|
||||
channelID: {
|
||||
required: true,
|
||||
description: 'The ID of the channel to log admin broadcasts to.',
|
||||
@ -36,26 +31,24 @@ export default class DiscordAdminBroadcast extends BasePlugin {
|
||||
}
|
||||
|
||||
constructor(server, options) {
|
||||
super();
|
||||
super(server, options);
|
||||
|
||||
options.discordClient.channels.fetch(options.channelID).then((channel) => {
|
||||
server.on('ADMIN_BROADCAST', async (info) => {
|
||||
await channel.send({
|
||||
embed: {
|
||||
title: 'Admin Broadcast',
|
||||
color: options.color,
|
||||
fields: [
|
||||
{
|
||||
name: 'Message',
|
||||
value: `${info.message}`
|
||||
}
|
||||
],
|
||||
timestamp: info.time.toISOString(),
|
||||
footer: {
|
||||
text: COPYRIGHT_MESSAGE
|
||||
server.on('ADMIN_BROADCAST', async (info) => {
|
||||
await this.sendDiscordMessage({
|
||||
embed: {
|
||||
title: 'Admin Broadcast',
|
||||
color: options.color,
|
||||
fields: [
|
||||
{
|
||||
name: 'Message',
|
||||
value: `${info.message}`
|
||||
}
|
||||
],
|
||||
timestamp: info.time.toISOString(),
|
||||
footer: {
|
||||
text: COPYRIGHT_MESSAGE
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import BasePlugin from './base-plugin.js';
|
||||
import DiscordBasePlugin from './discord-base-plugin.js';
|
||||
import { COPYRIGHT_MESSAGE } from '../utils/constants.js';
|
||||
|
||||
export default class DiscordAdminRequest extends BasePlugin {
|
||||
export default class DiscordAdminRequest extends DiscordBasePlugin {
|
||||
static get description() {
|
||||
return (
|
||||
'The <code>DiscordAdminRequest</code> plugin will ping admins in a Discord channel when a player requests ' +
|
||||
@ -10,17 +10,12 @@ export default class DiscordAdminRequest extends BasePlugin {
|
||||
}
|
||||
|
||||
static get defaultEnabled() {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
static get optionsSpecification() {
|
||||
return {
|
||||
discordClient: {
|
||||
required: true,
|
||||
description: 'Discord connector name.',
|
||||
connector: 'discord',
|
||||
default: 'discord'
|
||||
},
|
||||
...DiscordBasePlugin.optionsSpecification,
|
||||
channelID: {
|
||||
required: true,
|
||||
description: 'The ID of the channel to log admin broadcasts to.',
|
||||
@ -64,69 +59,67 @@ export default class DiscordAdminRequest extends BasePlugin {
|
||||
}
|
||||
|
||||
constructor(server, options) {
|
||||
super();
|
||||
super(server, options);
|
||||
|
||||
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;
|
||||
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);
|
||||
for (const ignorePhrase of options.ignorePhrases) {
|
||||
if (info.message.includes(ignorePhrase)) return;
|
||||
}
|
||||
|
||||
if (info.message.length === 0) {
|
||||
await server.rcon.warn(
|
||||
info.player.steamID,
|
||||
`An admin has been notified, please wait for us to get back to you.`
|
||||
`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 this.sendDiscordMessage(message);
|
||||
|
||||
await server.rcon.warn(
|
||||
info.player.steamID,
|
||||
`An admin has been notified, please wait for us to get back to you.`
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
29
squad-server/plugins/discord-base-plugin.js
Normal file
29
squad-server/plugins/discord-base-plugin.js
Normal file
@ -0,0 +1,29 @@
|
||||
import BasePlugin from './base-plugin.js';
|
||||
|
||||
export default class DiscordBasePlugin extends BasePlugin {
|
||||
static get optionsSpecification() {
|
||||
return {
|
||||
discordClient: {
|
||||
required: true,
|
||||
description: 'Discord connector name.',
|
||||
connector: 'discord',
|
||||
default: 'discord'
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
constructor(server, options) {
|
||||
super();
|
||||
|
||||
this.discordClient = options.discordClient;
|
||||
this.channelID = options.channelID;
|
||||
|
||||
this.channel = null;
|
||||
}
|
||||
|
||||
async sendDiscordMessage(message, channelID = this.channelID) {
|
||||
if (this.channel === null) this.channel = await this.discordClient.channels.fetch(channelID);
|
||||
|
||||
await this.channel.send(message);
|
||||
}
|
||||
}
|
80
squad-server/plugins/discord-chat.js
Normal file
80
squad-server/plugins/discord-chat.js
Normal file
@ -0,0 +1,80 @@
|
||||
import DiscordBasePlugin from './discord-base-plugin.js';
|
||||
|
||||
import { COPYRIGHT_MESSAGE } from '../utils/constants.js';
|
||||
|
||||
export default class DiscordChat extends DiscordBasePlugin {
|
||||
static get description() {
|
||||
return 'The <code>DiscordChat</code> plugin will log in-game chat to a Discord channel.';
|
||||
}
|
||||
|
||||
static get defaultEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
static get optionsSpecification() {
|
||||
return {
|
||||
...DiscordBasePlugin.optionsSpecification,
|
||||
channelID: {
|
||||
required: true,
|
||||
description: 'The ID of the channel to log admin broadcasts to.',
|
||||
default: '',
|
||||
example: '667741905228136459'
|
||||
},
|
||||
chatColors: {
|
||||
required: false,
|
||||
description: 'The color of the embed for each chat.',
|
||||
default: {},
|
||||
example: { ChatAll: 16761867 }
|
||||
},
|
||||
color: {
|
||||
required: false,
|
||||
description: 'The color of the embed.',
|
||||
default: 16761867
|
||||
},
|
||||
ignoreChats: {
|
||||
required: false,
|
||||
default: ['ChatSquad'],
|
||||
description: 'A list of chat names to ignore.'
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
constructor(server, options) {
|
||||
super(server, options);
|
||||
|
||||
server.on('CHAT_MESSAGE', async (info) => {
|
||||
if (options.ignoreChats.includes(info.chat)) return;
|
||||
|
||||
await this.sendDiscordMessage({
|
||||
embed: {
|
||||
title: info.chat,
|
||||
color: options.chatColors[info.chat] || options.color,
|
||||
fields: [
|
||||
{
|
||||
name: 'Player',
|
||||
value: info.player.name,
|
||||
inline: true
|
||||
},
|
||||
{
|
||||
name: 'SteamID',
|
||||
value: `[${info.player.steamID}](https://steamcommunity.com/profiles/${info.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
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user