SquadJS
SquadJS copied to clipboard
Updated, bumped Discord.js to v14.11.0 + discord plugins + log-parser
From previous pull request https://github.com/Team-Silver-Sphere/SquadJS/pull/297
Changes
Play tested yesterday and everything worked fine, note I have not play tested with every plugin yet.
- Updated README
- Added migration guide for yarn, Node.js, and this version of SquadJS
*/package.json
- Updated dependencies
core/log-parser/index.js
- Improved log parser
- Inspired from uBlock Origin domWatcher. link
- Requires more testing
- Fixed
Average matching latency
being NaN in the log.
squad-server/plugins/*
-
base-plugin.js
=> Added additional utility functions -
discord-base-plugin.js
- Improved sendDiscordMessage function w/ legacy discord.js v12 support
- Added cache and labels feature, all plugins which extend upon
discord-base-plugin.js
will have access to multiple channels. Function can also convert legacy embeds to the newer format.
Recommended to use channelIDs
instead of channelID
"channelIDs": [
{
"label": "my label",
"channelID": "661111905228136459"
}
],
The plugin will convert channelID
to default
as a fallback. TODO prevent duplicate labels.
"channelID": "667741905228136459",
"channelIDs": [
{
"label": "default",
"channelID": "667741905228136459"
}
],
Examples
// Sends to "admin-camera", 767741905228136222
await this.sendDiscordMessage({
content: 'Admin has entered admin cam'
}, 'admin-camera');
// Sends to "teamkills", 661111905228136459
await this.sendDiscordMessage({
content: 'Player has teamkill ...'
}, 'teamkills');
// Sends to "default" label or channelID in options, 667741905228136459
await this.sendDiscordMessage({
content: 'Hello world'
});
If the read me was updated make sure you update templates as well if it’s needed.
If the read me was updated make sure you update templates as well if it’s needed.
Huh I did click build-all before pressing commit, guess I did not add channel IDs in the options section for plugins.
Would I need to create another pull request?
Just update your current branch/PR
Just update your current branch/PR
- Updated README for plugins
- Updated plugins with
channelID
=>channelIDs
- Added
embedInfo
option to CBLInfo.js - Added
embedInfo
option to discord-admin-cam-logs.js - Updated CBLInfo.js to use new format, I just copied the code I have been using for my instance.
- Updated discord-admin-cam-logs.js to use new format, I just copied the code I have been using for my instance.
@magicoflolis you are merging to v4 not master ? v4 looks like abandoned branch
Attempted to merge into the same branch name, just now realized I set it to v4 as the branch I created does not exist.
Shouldn't the version bump be to 4.0 not 4.7.0?
Shouldn't the version bump be to 4.0 not 4.7.0?
Yeah... It should be v4.0.0, I glanced @ the release format & added +1 to the {major}
section.
I will have to fix that on my next commit as I've begone to extend the discord connector code to its own workspace. This is going to allow end users to add there own slash commands and give those commands access to SquadJS this.server
class object.
Can you please leave the versioning bumping to us please? There is some processes that have to be done to the repo before that can happen.
I will need some additional testing from users before we can look at getting this approved.
I will need some additional testing from users before we can look at getting this approved.
I have gone ahead & added the extended discord bot. It will have its own workspace & can also be ran independently from SquadJS. I have also included 3 simple slash commands.
I have not added a usage limit to any of these yet, moving these commands out of there folders will disable them.
-
/ping
- Pings both the bot & connected SquadJS instance, requires clientID.- Server usage permission: Send text messages.
- DM usage permission: Available
-
/rcon
- Execute RCON commands with autocomplete feature, requires clientID + guidID-
AdminBan
is disabled. - Server usage permission: Requires ability to kick discord members.
- DM usage permission: Restricted
-
-
/close
Exits the running node process, will also runserver.unwatch()
before closing, requires clientID + guidID- Server usage permission: Requires administrator role.
- DM usage permission: Restricted
SquadJS plugins & discord slash commands cannot directly interact with each other, yet. Slash commands will only have access to the this.server
class object.
Fixes
- Added
.yarnrc.yml
so doingyarn config set nodeLinker node-modules
will only be needed for upgrading from v3 => v4
Why is the discord bot commit https://github.com/Team-Silver-Sphere/SquadJS/pull/300/commits/d19ed9bb7a5db13842c177df87fa88f31d8dbeca not a seperate PR?
Is this PR in a state where it can be tested or is it still in a development / WIP state where you intent to add new features / fixes?
I've done a bit of testing of this PR at commit de9d9e431c9173dccd0fb1112f5e5a3a2e5067fd which is the one where plugins have their major / minor versions bumped because that kind of maintenance work is something i consider worth integrating quickly and I'm personally happy with functionality / haven't encountered any issues. I can vouch for this PR up to that commit.
Why is the discord bot commit https://github.com/Team-Silver-Sphere/SquadJS/pull/300/commits/d19ed9bb7a5db13842c177df87fa88f31d8dbeca not a seperate PR?
Is this PR in a state where it can be tested or is it still in a development / WIP state where you intent to add new features / fixes?
I've done a bit of testing of this PR at commit de9d9e431c9173dccd0fb1112f5e5a3a2e5067fd which is the one where plugins have their major / minor versions bumped because that kind of maintenance work is something i consider worth integrating quickly and I'm personally happy with functionality / haven't encountered any issues. I can vouch for this PR up to that commit.
Due to the discordjs version bump I needed to update the way factory.js file created the discord bot, however with this change on rare occasions after discordjs login the connector won't be completely ready leading to errors for some plugins. You can see this after u call client.login(token)
& print this client
object to the console you may get a null
readytimestamp
object. I fixed this by adding the Events.ClientReady
listener through a promise.
The entire discord-bot workspace was me getting carried away with the amount of things you can do now with discord.js & SquadJS.
I also test everything before hand & I don't have any plans to add more features to this PR, but I will still be here to fix any bugs along the way.
Once this PR is in a state to be tested please let us know. I am going to move this to a draft state until then.
Once this PR is in a state to be tested please let us know. I am going to move this to a draft state until then.
I believe this PR is ready to be tested. I have included basic discord slash commands as references.
To anyone who wishes to create slash commands, here is the basic layout, store them in your desired (local|global)-commands
folder found in the discord-bot
folder.
import { SlashCommandBuilder } from 'discord.js';
export default {
data: new SlashCommandBuilder()
.setName('name')
.setDescription('description')
async execute(interaction, server) {
...
};
Additional help https://discordjs.guide/
- Fixed a typo causing global commands to not work
- Added ability to create Event listeners for DiscordJS
- Added a guide into the
discord-bot
folder
Squad Servers actively using this PR
Both of these servers I help start & still manage back-end server infrastructure. PSG Hosting also assisted me with migrating a SquadJS instance to use this PR.
- [SSB] Self Sufficient Blueberries
- Operating System: Windows
- [DMH] Dead Man's Hand
- Operating System: Linux
This will be on an on hold status pending some possible OWI changes. Doesn't appear that they will happen but until I hear more most PRs will not be pushed until I have a solid answer to prevent unnecessary dev time wasted.
@magicoflolis I was looking into this PR (still need to test it), it looks very interesting, but as far as I can see, slash commands cannot be created by plugins, instead, each slash command will need to have its own file in discord-bot/local-commands or discord-bot/global-commands. Is that correct?
In case you can confirm what I have previously stated, a solution could be to call the deloyCommands
method only after the factory has loaded all the plugins, instead of after completeing the authentication of the discord bot to let the plugins register new slash commands.
Also, I suspect deloyCommands
to have a typo and that you wanted to name it deployCommands
@magicoflolis Maybe we can only merge changes without "discord-bot"? This will speed up testing, reduce the number of changes and this is not a necessary change for people who want to use the functionalities introduced by Discord.js v14.11.0
discord-bot may be added in the next PR
May I ask what specific improvement does this have with the log parser?
@magicoflolis Maybe we can only merge changes without "discord-bot"? This will speed up testing, reduce the number of changes and this is not a necessary change for people who want to use the functionalities introduced by Discord.js v14.11.0
discord-bot may be added in the next PR
After coming back to this mmmm yeah I put all my eggs in the basket. I might just backup everything and push these changes one at a time.
git pushed the readme and config files even though I reset and excluded them???
Okay starting from the top, I have reset this branch, reworked the code, and pushing changes one at a time.
I have moved the stuff above to this branch old-discordjsv14
Log Parser
- Moved
/squad-server/log-parser
to/core/log-parser/log-events
and mergedlog-readers
with the log parser class.- This means the log parser is no longer split inside three directories.
-
LogParser.loadFiles
function loads and validates all files from thelog-events
directory. They must have aregex
andonMatch
for them to be considered valid. If a file hasdisabled: true
it will not be loaded. - To add any new log parser events, drag-n-drop files into the
log-events
directory and restart SquadJS.
- Fixed the console returning
NaN
for "Average matching latency".- Sometimes
this.matchingLatency
andthis.matchingLinesPerMinute
would both be 0, this would cause "Average matching latency" to beNaN
since 0 divided by 0 returnsNaN
.
- Sometimes
- Reworked
processLine
function, from my testing this change reduced the "Average matching latency" time. - Added typescript definitions, these can always be added to a
types.d.ts
file later down the line.
Misc:
In theory the LogParser could be rewritten to utilize NodeJS Worker.
I have already written the code to make plugins load the same way log-events are loaded. So it would be better to make the loadFiles
function be its own file in the utils
directory.
I have been working on typescript definitions for /core/rcon.js
and /squad-server/index.js
however they are not complete.
Creating typescript definitions could make SquadJS much easier to understand and work with when combined with something like VSCode.