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

Add includeChats property #323

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,14 +295,15 @@ Interested in creating your own plugin? [See more here](./squad-server/plugins/r
<h3>Options</h3>
<ul><li><h4>commands</h4>
<h6>Description</h6>
<p>An array of objects containing the following properties: <ul><li><code>command</code> - The command that initiates the message.</li><li><code>type</code> - Either <code>warn</code> or <code>broadcast</code>.</li><li><code>response</code> - The message to respond with.</li><li><code>ignoreChats</code> - A list of chats to ignore the commands in. Use this to limit it to admins.</li></ul></p>
<p>An array of objects containing the following properties: <ul><li><code>command</code> - The command that initiates the message.</li><li><code>type</code> - Either <code>warn</code> or <code>broadcast</code>.</li><li><code>response</code> - The message to respond with.</li><li><code>ignoreChats/includeChats</code> - Either one can be used to limit to specific in-game chats, being <code>ChatAll</code>, <code>ChatTeam</code>, <code>ChatSquad</code> and <code>ChatAdmin</code></li></ul></p>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were these changes made manually? If so, they will be overwritten when the readme is regenerated from the plugin option specification.

<h6>Default</h6>
<pre><code>[
{
"command": "squadjs",
"type": "warn",
"response": "This server is powered by SquadJS.",
"ignoreChats": []
"ignoreChats": [],
"includeChats": []
}
]</code></pre></li></ul>
</details>
Expand Down
3 changes: 2 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
"command": "squadjs",
"type": "warn",
"response": "This server is powered by SquadJS.",
"ignoreChats": []
"ignoreChats": [],
"includeChats": []
}
]
},
Expand Down
10 changes: 8 additions & 2 deletions squad-server/plugins/chat-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ export default class ChatCommands extends BasePlugin {
'<li><code>type</code> - Either <code>warn</code> or <code>broadcast</code>.</li>' +
'<li><code>response</code> - The message to respond with.</li>' +
'<li><code>ignoreChats</code> - A list of chats to ignore the commands in. Use this to limit it to admins.</li>' +
'<li><code>includeChats</code> - A list of chats to include the commands in. Use this to limit it to admins.</li>' +
'</ul>',
default: [
{
command: 'squadjs',
type: 'warn',
response: 'This server is powered by SquadJS.',
ignoreChats: []
ignoreChats: [],
includeChats: []
}
]
}
Expand All @@ -39,7 +41,11 @@ export default class ChatCommands extends BasePlugin {
async mount() {
for (const command of this.options.commands) {
this.server.on(`CHAT_COMMAND:${command.command.toLowerCase()}`, async (data) => {
if (command.ignoreChats.includes(data.chat)) return;
let ignoreChats = command.ignoreChats ?? [];
let includeChats = command.includeChats ?? [];

if (ignoreChats.includes(data.chat)) return;
if (includeChats.length > 0 && !includeChats.includes(data.chat)) return;

if (command.type === 'broadcast') {
await this.server.rcon.broadcast(command.response);
Expand Down