Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated, bumped Discord.js to v14.11.0 + discord plugins + log-parser #300

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

magicoflolis
Copy link

From previous pull request #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'
});

@werewolfboy13
Copy link
Collaborator

werewolfboy13 commented Jul 16, 2023

If the read me was updated make sure you update templates as well if it’s needed.

@magicoflolis
Copy link
Author

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?

@werewolfboy13
Copy link
Collaborator

Just update your current branch/PR

@magicoflolis
Copy link
Author

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 magicoflolis changed the base branch from master to v4 July 23, 2023 01:43
@Seth9
Copy link

Seth9 commented Jul 24, 2023

@magicoflolis you are merging to v4 not master ? v4 looks like abandoned branch

@magicoflolis
Copy link
Author

@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.

@magicoflolis magicoflolis changed the base branch from v4 to master July 25, 2023 18:13
@DrKittens
Copy link
Contributor

Shouldn't the version bump be to 4.0 not 4.7.0?

@magicoflolis
Copy link
Author

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.

@werewolfboy13
Copy link
Collaborator

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.

package.json Outdated Show resolved Hide resolved
@werewolfboy13 werewolfboy13 added core feature request Feature request related to the core SquadJS API major Major Change Testing Required This requires testing before approval. and removed major Major Change labels Jul 27, 2023
Signed-off-by: Magic <[email protected]>
werewolfboy13
werewolfboy13 previously approved these changes Jul 28, 2023
@werewolfboy13 werewolfboy13 requested review from werewolfboy13 and removed request for werewolfboy13 July 28, 2023 00:42
@werewolfboy13
Copy link
Collaborator

I will need some additional testing from users before we can look at getting this approved.

@magicoflolis
Copy link
Author

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 run server.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 doing yarn config set nodeLinker node-modules will only be needed for upgrading from v3 => v4

@DrKittens
Copy link
Contributor

Why is the discord bot commit d19ed9b 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.

@magicoflolis
Copy link
Author

Why is the discord bot commit d19ed9b 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.

@werewolfboy13 werewolfboy13 dismissed their stale review July 29, 2023 21:15

Still being worked on

@werewolfboy13
Copy link
Collaborator

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.

@werewolfboy13 werewolfboy13 marked this pull request as draft July 29, 2023 21:16
Signed-off-by: Magic <[email protected]>
@magicoflolis magicoflolis marked this pull request as ready for review August 3, 2023 00:27
@magicoflolis
Copy link
Author

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/

@magicoflolis
Copy link
Author

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

@werewolfboy13
Copy link
Collaborator

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.

@fantinodavide
Copy link
Contributor

@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

@Seth9
Copy link

Seth9 commented Dec 28, 2023

@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

@lbzepoqo
Copy link
Contributor

May I ask what specific improvement does this have with the log parser?

@magicoflolis
Copy link
Author

@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.

@magicoflolis
Copy link
Author

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 merged log-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 the log-events directory. They must have a regex and onMatch for them to be considered valid. If a file has disabled: 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 and this.matchingLinesPerMinute would both be 0, this would cause "Average matching latency" to be NaN since 0 divided by 0 returns NaN.
  • 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core feature request Feature request related to the core SquadJS API Testing Required This requires testing before approval.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants