mirror of
https://github.com/AsgardEternal/SquadJS.git
synced 2024-09-28 11:54:23 -05:00
Lint
This commit is contained in:
parent
6107612fb2
commit
915ec298f3
2
index.js
2
index.js
@ -17,7 +17,7 @@ async function main() {
|
||||
await server.watch();
|
||||
|
||||
// now mount the plugins
|
||||
server.plugins.forEach(plugin => plugin.mount());
|
||||
server.plugins.forEach((plugin) => plugin.mount());
|
||||
}
|
||||
|
||||
main();
|
||||
|
@ -41,7 +41,10 @@ export default class SquadServerFactory {
|
||||
if (!option.connector) continue;
|
||||
|
||||
// check the connector is listed in the options
|
||||
if (!(optionName in pluginConfig)) throw new Error(`${Plugin.name}: ${optionName} (${option.connector} connector) is missing.`);
|
||||
if (!(optionName in pluginConfig))
|
||||
throw new Error(
|
||||
`${Plugin.name}: ${optionName} (${option.connector} connector) is missing.`
|
||||
);
|
||||
|
||||
// get the name of the connector
|
||||
const connectorName = pluginConfig[optionName];
|
||||
@ -50,17 +53,23 @@ export default class SquadServerFactory {
|
||||
if (connectors[connectorName]) continue;
|
||||
|
||||
// create the connector
|
||||
connectors[connectorName] = await SquadServerFactory.createConnector(server, option.connector, connectorName, config.connectors[connectorName])
|
||||
connectors[connectorName] = await SquadServerFactory.createConnector(
|
||||
server,
|
||||
option.connector,
|
||||
connectorName,
|
||||
config.connectors[connectorName]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// initialise plugins
|
||||
Logger.verbose('SquadServerFactory', 1, 'Initialising plugins...');
|
||||
|
||||
for(const pluginConfig of config.plugins) {
|
||||
for (const pluginConfig of config.plugins) {
|
||||
if (!pluginConfig.enabled) continue;
|
||||
|
||||
if (!plugins[pluginConfig.plugin]) throw new Error(`Plugin ${pluginConfig.plugin} does not exist.`);
|
||||
if (!plugins[pluginConfig.plugin])
|
||||
throw new Error(`Plugin ${pluginConfig.plugin} does not exist.`);
|
||||
|
||||
const Plugin = plugins[pluginConfig.plugin];
|
||||
|
||||
@ -81,7 +90,10 @@ export default class SquadServerFactory {
|
||||
Logger.verbose('SquadServerFactory', 1, `Starting ${type} connector ${connectorName}...`);
|
||||
|
||||
if (type === 'squadlayerpool') {
|
||||
return server.squadLayers[connectorConfig.type](connectorConfig.filter, connectorConfig.activeLayerFilter);
|
||||
return server.squadLayers[connectorConfig.type](
|
||||
connectorConfig.filter,
|
||||
connectorConfig.activeLayerFilter
|
||||
);
|
||||
}
|
||||
|
||||
if (type === 'discord') {
|
||||
@ -169,18 +181,18 @@ export default class SquadServerFactory {
|
||||
<p>${option.description}</p>
|
||||
<h6>Default</h6>
|
||||
<pre><code>${
|
||||
typeof option.default === 'object'
|
||||
? JSON.stringify(option.default, null, 2)
|
||||
: option.default
|
||||
}</code></pre>`;
|
||||
typeof option.default === 'object'
|
||||
? JSON.stringify(option.default, null, 2)
|
||||
: option.default
|
||||
}</code></pre>`;
|
||||
|
||||
if (option.example)
|
||||
optionInfo += `<h6>Example</h6>
|
||||
<pre><code>${
|
||||
typeof option.example === 'object'
|
||||
? JSON.stringify(option.example, null, 2)
|
||||
: option.example
|
||||
}</code></pre>`;
|
||||
typeof option.example === 'object'
|
||||
? JSON.stringify(option.example, null, 2)
|
||||
: option.example
|
||||
}</code></pre>`;
|
||||
|
||||
options.push(optionInfo);
|
||||
}
|
||||
|
@ -52,7 +52,11 @@ export default class SquadServer extends EventEmitter {
|
||||
}
|
||||
|
||||
async watch() {
|
||||
Logger.verbose('SquadServer', 1, `Beginning to watch ${this.options.host}:${this.options.queryPort}...`);
|
||||
Logger.verbose(
|
||||
'SquadServer',
|
||||
1,
|
||||
`Beginning to watch ${this.options.host}:${this.options.queryPort}...`
|
||||
);
|
||||
await this.squadLayers.pull();
|
||||
|
||||
await this.rcon.connect();
|
||||
|
@ -11,8 +11,12 @@ export default class BasePlugin {
|
||||
this.options[optionName] = connectors[this.rawOptions[optionName]];
|
||||
} else {
|
||||
if (option.required) {
|
||||
if (!(optionName in this.rawOptions)) throw new Error(`${this.constructor.name}: ${optionName} is required but missing.`);
|
||||
if (option.default === this.rawOptions[optionName]) throw new Error(`${this.constructor.name}: ${optionName} is required but is the default value.`);
|
||||
if (!(optionName in this.rawOptions))
|
||||
throw new Error(`${this.constructor.name}: ${optionName} is required but missing.`);
|
||||
if (option.default === this.rawOptions[optionName])
|
||||
throw new Error(
|
||||
`${this.constructor.name}: ${optionName} is required but is the default value.`
|
||||
);
|
||||
}
|
||||
|
||||
this.options[optionName] = this.rawOptions[optionName] || option.default;
|
||||
@ -41,4 +45,4 @@ export default class BasePlugin {
|
||||
verbose(...args) {
|
||||
Logger.verbose(this.constructor.name, ...args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,43 +30,37 @@ export default class DBLog extends BasePlugin {
|
||||
}
|
||||
|
||||
async prepareToMount() {
|
||||
this.createModel(
|
||||
'Server',
|
||||
{
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true
|
||||
},
|
||||
name: {
|
||||
type: DataTypes.STRING
|
||||
}
|
||||
this.createModel('Server', {
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true
|
||||
},
|
||||
name: {
|
||||
type: DataTypes.STRING
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
this.createModel(
|
||||
'TickRate',
|
||||
{
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true
|
||||
},
|
||||
time: {
|
||||
type: DataTypes.DATE,
|
||||
notNull: true
|
||||
},
|
||||
tickRate: {
|
||||
type: DataTypes.FLOAT,
|
||||
notNull: true
|
||||
}
|
||||
this.createModel('TickRate', {
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true
|
||||
},
|
||||
time: {
|
||||
type: DataTypes.DATE,
|
||||
notNull: true
|
||||
},
|
||||
tickRate: {
|
||||
type: DataTypes.FLOAT,
|
||||
notNull: true
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
this.models.Server.hasMany(
|
||||
this.models.TickRate,
|
||||
{ foreignKey: { name: 'server', allowNull: false }, onDelete: 'CASCADE' }
|
||||
);
|
||||
this.models.Server.hasMany(this.models.TickRate, {
|
||||
foreignKey: { name: 'server', allowNull: false },
|
||||
onDelete: 'CASCADE'
|
||||
});
|
||||
|
||||
await this.models.Server.sync();
|
||||
await this.models.TickRate.sync();
|
||||
@ -96,10 +90,14 @@ export default class DBLog extends BasePlugin {
|
||||
}
|
||||
|
||||
unmount() {
|
||||
this.server.removeEventListener('TICK_RATE', this.onTickRate)
|
||||
this.server.removeEventListener('TICK_RATE', this.onTickRate);
|
||||
}
|
||||
|
||||
async onTickRate(info) {
|
||||
await this.models.TickRate.create({ server: this.server.id, time: info.time, tickRate: info.tickRate});
|
||||
await this.models.TickRate.create({
|
||||
server: this.server.id,
|
||||
time: info.time,
|
||||
tickRate: info.tickRate
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -72,7 +72,12 @@ export default class DiscordAdminCamLogs extends DiscordBasePlugin {
|
||||
}
|
||||
|
||||
async onPlayerUnPossess(info) {
|
||||
if (info.player === null || info.switchPossess === true || !(info.player.steamID in this.adminsInCam)) return;
|
||||
if (
|
||||
info.player === null ||
|
||||
info.switchPossess === true ||
|
||||
!(info.player.steamID in this.adminsInCam)
|
||||
)
|
||||
return;
|
||||
|
||||
await this.sendDiscordMessage({
|
||||
embed: {
|
||||
|
@ -70,7 +70,7 @@ export default class DiscordAdminRequest extends DiscordBasePlugin {
|
||||
}
|
||||
|
||||
unmount() {
|
||||
this.server.removeEventListener(`CHAT_COMMAND:${this.options.command}`, this.onChatCommand)
|
||||
this.server.removeEventListener(`CHAT_COMMAND:${this.options.command}`, this.onChatCommand);
|
||||
}
|
||||
|
||||
async onChatCommand(info) {
|
||||
@ -116,10 +116,7 @@ export default class DiscordAdminRequest extends DiscordBasePlugin {
|
||||
}
|
||||
};
|
||||
|
||||
if (
|
||||
this.options.pingGroups.length > 0 &&
|
||||
Date.now() - this.options.pingDelay > this.lastPing
|
||||
) {
|
||||
if (this.options.pingGroups.length > 0 && Date.now() - this.options.pingDelay > this.lastPing) {
|
||||
message.content = this.options.pingGroups.map((groupID) => `<@&${groupID}>`).join(' ');
|
||||
this.lastPing = Date.now();
|
||||
}
|
||||
|
@ -19,7 +19,8 @@ export default class DiscordBasePlugin extends BasePlugin {
|
||||
}
|
||||
|
||||
async sendDiscordMessage(message) {
|
||||
if (typeof message === 'object' && 'embed' in message) message.embed.footer = { text: COPYRIGHT_MESSAGE };
|
||||
if (typeof message === 'object' && 'embed' in message)
|
||||
message.embed.footer = { text: COPYRIGHT_MESSAGE };
|
||||
|
||||
await this.channel.send(message);
|
||||
}
|
||||
|
@ -83,8 +83,7 @@ export default class DiscordRcon extends BasePlugin {
|
||||
if (!message.member._roles.includes(role)) continue;
|
||||
|
||||
for (const allowedCommand of allowedCommands)
|
||||
if (commandPrefix[1].toLowerCase() === allowedCommand.toLowerCase())
|
||||
hasPermission = true;
|
||||
if (commandPrefix[1].toLowerCase() === allowedCommand.toLowerCase()) hasPermission = true;
|
||||
}
|
||||
|
||||
if (!hasPermission) {
|
||||
|
@ -44,7 +44,7 @@ export default class DiscordServerStatus extends BasePlugin {
|
||||
constructor(server, options, connectors) {
|
||||
super(server, options, connectors);
|
||||
|
||||
this.update = this.update.bind(this);
|
||||
this.update = this.update.bind(this);
|
||||
}
|
||||
|
||||
mount() {
|
||||
|
@ -39,7 +39,7 @@ export default class DiscordSubsystemRestarter extends BasePlugin {
|
||||
this.onMessage = this.onMessage.bind(this);
|
||||
}
|
||||
|
||||
mount(){
|
||||
mount() {
|
||||
this.options.discordClient.on('message', this.onMessage);
|
||||
}
|
||||
|
||||
@ -69,6 +69,4 @@ export default class DiscordSubsystemRestarter extends BasePlugin {
|
||||
message.reply('restarted the SquadJS LogParser subsystem.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ export default class SeedingMode extends BasePlugin {
|
||||
}
|
||||
|
||||
mount() {
|
||||
this.interval = setInterval(this.broadcast, this.options.interval);
|
||||
this.interval = setInterval(this.broadcast, this.options.interval);
|
||||
}
|
||||
|
||||
unmount() {
|
||||
@ -63,10 +63,7 @@ export default class SeedingMode extends BasePlugin {
|
||||
}
|
||||
|
||||
async broadcast() {
|
||||
if (
|
||||
this.server.a2sPlayerCount !== 0 &&
|
||||
this.server.a2sPlayerCount < this.options.liveThreshold
|
||||
)
|
||||
if (this.server.a2sPlayerCount !== 0 && this.server.a2sPlayerCount < this.options.liveThreshold)
|
||||
await this.server.rcon.broadcast(this.options.seedingMessage);
|
||||
else if (
|
||||
this.server.a2sPlayerCount !== 0 &&
|
||||
|
Loading…
Reference in New Issue
Block a user