Compare commits
2 Commits
1395130d6d
...
956dc89107
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
956dc89107 | ||
|
|
976c44838e |
@@ -24,8 +24,10 @@ export const checkForUpdates = async () => {
|
|||||||
console.log('Update completed successfully. Restarting the application...');
|
console.log('Update completed successfully. Restarting the application...');
|
||||||
// Restart the application to apply the updates
|
// Restart the application to apply the updates
|
||||||
restartApplication();
|
restartApplication();
|
||||||
|
return true
|
||||||
} else {
|
} else {
|
||||||
console.log('The application is up to date.');
|
console.log('The application is up to date.');
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error checking for updates:', error);
|
console.error('Error checking for updates:', error);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { io } from "socket.io-client";
|
import { io } from "socket.io-client";
|
||||||
import { logIntoServerWrapper, nodeCheckStatus, nodeJoinServer, nodeLeaveServer, nodeGetUsername, nodeCheckDiscordClientStatus, nodeCheckCurrentSystem } from "./socketClientWrappers.mjs";
|
import { logIntoServerWrapper, nodeCheckStatus, nodeJoinServer, nodeLeaveServer, nodeGetUsername, nodeCheckDiscordClientStatus, nodeCheckCurrentSystem, nodeUpdate } from "./socketClientWrappers.mjs";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the socket connection with the server, this will handle disconnects within itself
|
* Initialize the socket connection with the server, this will handle disconnects within itself
|
||||||
@@ -24,6 +24,9 @@ export const initSocketConnection = async (localNodeConfig) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Node events/commands
|
// Node events/commands
|
||||||
|
// Requested the node update itself
|
||||||
|
socket.on('node-update', nodeUpdate);
|
||||||
|
|
||||||
// Requested to join a discord guild and listen to a system
|
// Requested to join a discord guild and listen to a system
|
||||||
socket.on('node-join', nodeJoinServer);
|
socket.on('node-join', nodeJoinServer);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,17 @@
|
|||||||
import { checkIfDiscordVCConnected, joinDiscordVC, leaveDiscordVC, getDiscordUsername, checkIfClientIsOpen } from '../discordAudioBot/dabWrappers.mjs';
|
import { checkIfDiscordVCConnected, joinDiscordVC, leaveDiscordVC, getDiscordUsername, checkIfClientIsOpen } from '../discordAudioBot/dabWrappers.mjs';
|
||||||
import { getCurrentSystem } from '../op25Handler/op25Handler.mjs';
|
import { getCurrentSystem } from '../op25Handler/op25Handler.mjs';
|
||||||
|
import { checkForUpdates } from './selfUpdater.mjs';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the bot has an update available
|
||||||
|
* @param {any} socketCallback The callback function to return the result
|
||||||
|
* @callback {boolean} If the node has an update available or not
|
||||||
|
*/
|
||||||
|
export const nodeUpdate = async (socketCallback) => {
|
||||||
|
socketCallback(await checkForUpdates());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper to log into the server
|
* Wrapper to log into the server
|
||||||
@@ -15,6 +27,7 @@ export const logIntoServerWrapper = async (socket, localNodeConfig) => {
|
|||||||
sendNodeUpdateWrapper(socket, localNodeConfig);
|
sendNodeUpdateWrapper(socket, localNodeConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send the server an update
|
* Send the server an update
|
||||||
* @param {any} socket The socket connection with the server
|
* @param {any} socket The socket connection with the server
|
||||||
@@ -76,6 +89,7 @@ export const nodeCheckDiscordClientStatus = async (socketCallback) => {
|
|||||||
socketCallback(await checkIfClientIsOpen());
|
socketCallback(await checkIfClientIsOpen());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check what system the local node is currently listening to
|
* Check what system the local node is currently listening to
|
||||||
* @callback {boolean} If the node has an open discord client or not
|
* @callback {boolean} If the node has an open discord client or not
|
||||||
|
|||||||
@@ -25,16 +25,9 @@ prompt_user() {
|
|||||||
|
|
||||||
# Function to prompt user for capabilities options and store the result in a variable
|
# Function to prompt user for capabilities options and store the result in a variable
|
||||||
prompt_capabilities() {
|
prompt_capabilities() {
|
||||||
options=("radio" "placeholder1" "placeholder2") # Add more options as needed
|
default_capabilities="radio" # Default value
|
||||||
echo "Select the capabilities of this node (comma-separated):"
|
read -p "Select CLIENT_CAPABILITIES (comma-separated, default: $default_capabilities): " capabilities
|
||||||
select option in "${options[@]}"; do
|
capabilities="${capabilities:-$default_capabilities}" # Use default value if input is empty
|
||||||
if [[ "$option" ]]; then
|
|
||||||
capabilities="$option"
|
|
||||||
break
|
|
||||||
else
|
|
||||||
echo "Invalid selection. Please try again."
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
echo "$capabilities"
|
echo "$capabilities"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,7 +49,7 @@ prompt_nearby_system() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
echo "\"$system_name\": {
|
echo "\"$system_name\": {
|
||||||
\"frequencies\": [$(echo "$frequencies" | sed 's/,/","/g')],
|
\"frequencies\": [\"$(echo "$frequencies" | sed 's/,/","/g')\"],
|
||||||
\"mode\": \"$mode\",
|
\"mode\": \"$mode\",
|
||||||
\"trunkFile\": \"$trunk_file\",
|
\"trunkFile\": \"$trunk_file\",
|
||||||
\"whitelistFile\": \"$whitelist_file\"
|
\"whitelistFile\": \"$whitelist_file\"
|
||||||
@@ -120,6 +113,7 @@ systems_json="${systems_json%,}" # Remove trailing comma
|
|||||||
systems_json+="}"
|
systems_json+="}"
|
||||||
|
|
||||||
# Append the created systems to the presets file
|
# Append the created systems to the presets file
|
||||||
|
mkdir -p ./config
|
||||||
echo "$systems_json" >> "./config/radioPresets.json"
|
echo "$systems_json" >> "./config/radioPresets.json"
|
||||||
|
|
||||||
echo "Systems added to radioPresets.json."
|
echo "Systems added to radioPresets.json."
|
||||||
@@ -149,7 +143,7 @@ echo "$service_content" > /etc/systemd/system/discord-radio-bot.service
|
|||||||
systemctl daemon-reload
|
systemctl daemon-reload
|
||||||
systemctl stop discord-radio-bot.service
|
systemctl stop discord-radio-bot.service
|
||||||
|
|
||||||
echo "Discord Client Node install completed!"
|
echo "\n\n\t\tDiscord Client Node install completed!\n\n"
|
||||||
|
|
||||||
####------------------- OP25 Installation
|
####------------------- OP25 Installation
|
||||||
# Clone OP25 from the git repository
|
# Clone OP25 from the git repository
|
||||||
@@ -195,4 +189,4 @@ systemctl stop op25-multi_rx.service
|
|||||||
echo "Installing OP25..."
|
echo "Installing OP25..."
|
||||||
./install.sh
|
./install.sh
|
||||||
|
|
||||||
echo "OP25 installation completed!"
|
echo "\n\n\t\tOP25 installation completed!\n\n"
|
||||||
32
server/discordBot/commands/update.mjs
Normal file
32
server/discordBot/commands/update.mjs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import { SlashCommandBuilder } from 'discord.js';
|
||||||
|
import { requestNodeUpdate } from '../../modules/socketServerWrappers.mjs';
|
||||||
|
|
||||||
|
// Exporting data property that contains the command structure for discord including any params
|
||||||
|
export const data = new SlashCommandBuilder()
|
||||||
|
.setName('update')
|
||||||
|
.setDescription('Updates all nodes currently logged on');
|
||||||
|
|
||||||
|
// Exporting other properties
|
||||||
|
export const example = "/update"; // An example of how the command would be run in discord chat, this will be used for the help command
|
||||||
|
export const deferInitialReply = false; // If we the initial reply in discord should be deferred. This gives extra time to respond, however the method of replying is different.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The function to run when the command is called by a discord user
|
||||||
|
* @param {any} nodeIo The nodeIO server for manipulation of sockets
|
||||||
|
* @param {any} interaction The interaction object
|
||||||
|
*/
|
||||||
|
export const execute = async (nodeIo, interaction) => {
|
||||||
|
try {
|
||||||
|
const sockets = await nodeIo.allSockets();
|
||||||
|
console.log("All open sockets: ",sockets);
|
||||||
|
await sockets.map(openSocket => {
|
||||||
|
requestNodeUpdate(openSocket);
|
||||||
|
})
|
||||||
|
//await interaction.reply(`**Online Sockets: '${sockets}'**`);
|
||||||
|
await interaction.reply('**Pong.**');
|
||||||
|
//await interaction.channel.send('**Pong.**');
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
// await interaction.reply(err.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -283,3 +283,18 @@ export const requestBotLeaveServer = async (socket, guildId) => {
|
|||||||
// Send the command to the node
|
// Send the command to the node
|
||||||
await sendNodeCommand(socket, "node-leave", guildId);
|
await sendNodeCommand(socket, "node-leave", guildId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Requset a given socket node to update themselves
|
||||||
|
* @param {any} socket The socket object of the node to request to update
|
||||||
|
*/
|
||||||
|
export const requestNodeUpdate = async (socket) => {
|
||||||
|
await sendNodeCommand(socket, 'node-update', (status) => {
|
||||||
|
if (status) {
|
||||||
|
console.log("Node is out of date, updating now", socket.node.name);
|
||||||
|
} else {
|
||||||
|
console.log("Node is up to date", socket.node.name);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user