mirror of
https://github.com/AsgardEternal/SquadJS.git
synced 2024-09-28 14:04:25 -05:00
init afk plugin for v2
This commit is contained in:
parent
e30bacbfe0
commit
de49addc95
@ -66,6 +66,12 @@
|
||||
"enabled": true,
|
||||
"message": "Please apologise for ALL TKs in ALL chat!"
|
||||
},
|
||||
{
|
||||
"plugin": "AutoKickAFK",
|
||||
"enabled": true,
|
||||
"warning": "",
|
||||
"updateInterval": 3
|
||||
},
|
||||
{
|
||||
"plugin": "ChatCommands",
|
||||
"enabled": true,
|
||||
|
69
squad-server/plugins/auto-kick-afk.js
Normal file
69
squad-server/plugins/auto-kick-afk.js
Normal file
@ -0,0 +1,69 @@
|
||||
import BasePlugin from './base-plugin.js';
|
||||
|
||||
export default class AutoKickAFK extends BasePlugin {
|
||||
static get description() {
|
||||
return 'The <code>AutoKickAFK</code> plugin will automatically kick players that are not in a squad after a specified ammount of time.';
|
||||
}
|
||||
|
||||
static get defaultEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
static get optionsSpecification() {
|
||||
return {
|
||||
warning: {
|
||||
required: false,
|
||||
description:
|
||||
'If enabled SquadJS will warn a player once before kicking them. To disable remove the message `""`',
|
||||
default: 'Players not in a squad are unassigned and will be kicked in 3 minutes'
|
||||
},
|
||||
updateInterval: {
|
||||
required: true,
|
||||
description: 'How frequently to check if players are AFK in minutes.',
|
||||
default: 3
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
constructor(server, options) {
|
||||
super();
|
||||
|
||||
this.playerDict = {};
|
||||
|
||||
const intervalMS = options.updateInterval * 60 * 1000;
|
||||
|
||||
setInterval(async () => {
|
||||
console.log(server.players);
|
||||
const lookup = {};
|
||||
for (const player of server.players) {
|
||||
lookup[player.steamID] = player;
|
||||
|
||||
// marks player if not in a Squad
|
||||
if (player.squadID === null) {
|
||||
if (player.steamID in this.playerDict) {
|
||||
this.playerDict[player.steamID] += 1;
|
||||
} else {
|
||||
this.playerDict[player.steamID] = 0;
|
||||
}
|
||||
} else if (player.steamID in this.playerDict) {
|
||||
// remove player from list if they joined a squad
|
||||
delete this.playerDict[player.steamID];
|
||||
}
|
||||
}
|
||||
|
||||
const copy = Object.assign({}, this.playerDict);
|
||||
for (const [steamID, count] of Object.entries(copy)) {
|
||||
if (count >= 1) {
|
||||
await server.rcon.kick(steamID);
|
||||
delete this.playerDict[steamID];
|
||||
}
|
||||
if (count === 0 && options.warning !== '') {
|
||||
await server.rcon.warn(steamID, options.warning);
|
||||
} else {
|
||||
await server.rcon.kick(steamID);
|
||||
delete this.playerDict[steamID];
|
||||
}
|
||||
}
|
||||
}, intervalMS);
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
import AutoTKWarn from './auto-tk-warn.js';
|
||||
import AutoKickAFK from './auto-kick-afk.js';
|
||||
import ChatCommands from './chat-commands.js';
|
||||
import DiscordAdminBroadcast from './discord-admin-broadcast.js';
|
||||
import DiscordAdminCamLogs from './discord-admin-cam-logs.js';
|
||||
@ -14,6 +15,7 @@ import SeedingMode from './seeding-mode.js';
|
||||
|
||||
const plugins = [
|
||||
AutoTKWarn,
|
||||
AutoKickAFK,
|
||||
ChatCommands,
|
||||
DiscordAdminBroadcast,
|
||||
DiscordAdminCamLogs,
|
||||
|
Loading…
Reference in New Issue
Block a user