Compare commits
2 Commits
cf04e37f89
...
48999e0d63
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
48999e0d63 | ||
|
|
2c25be1de7 |
@@ -98,7 +98,7 @@ exports.checkIn = async () => {
|
|||||||
let reqOptions;
|
let reqOptions;
|
||||||
await this.checkConfig();
|
await this.checkConfig();
|
||||||
// Check if there is an ID found, if not add the node to the server. If there was an ID, check in with the server to make sure it has the correct information
|
// Check if there is an ID found, if not add the node to the server. If there was an ID, check in with the server to make sure it has the correct information
|
||||||
if (clientId === 0) {
|
if (runningClientConfig.id === 0) {
|
||||||
// ID was not found in the config, creating a new node
|
// ID was not found in the config, creating a new node
|
||||||
reqOptions = new requests.requestOptions("/nodes/newNode", "POST");
|
reqOptions = new requests.requestOptions("/nodes/newNode", "POST");
|
||||||
requests.sendHttpRequest(reqOptions, JSON.stringify(), (responseObject) => {
|
requests.sendHttpRequest(reqOptions, JSON.stringify(), (responseObject) => {
|
||||||
|
|||||||
@@ -1,150 +0,0 @@
|
|||||||
//Config
|
|
||||||
import { getTOKEN, getGuildID, getApplicationID } from './utilities/configHandler.js';
|
|
||||||
// Commands
|
|
||||||
import ping from './commands/ping.js';
|
|
||||||
import join from './commands/join.js';
|
|
||||||
import leave from './commands/leave.js';
|
|
||||||
import status from './commands/status.js';
|
|
||||||
// Debug
|
|
||||||
import ModuleDebugBuilder from "./utilities/moduleDebugBuilder.js";
|
|
||||||
const log = new ModuleDebugBuilder("bot", "app");
|
|
||||||
// Modules
|
|
||||||
import { Client, GatewayIntentBits } from 'discord.js';
|
|
||||||
// Utilities
|
|
||||||
import registerCommands from './utilities/registerCommands.js';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Host Process Object Builder
|
|
||||||
*
|
|
||||||
* This constructor is used to easily construct responses to the host process
|
|
||||||
*/
|
|
||||||
class HPOB {
|
|
||||||
/**
|
|
||||||
* Build an object to be passed to the host process
|
|
||||||
* @param command The command to that was run ("Status", "Join", "Leave", "ChgPreSet")
|
|
||||||
* @param response The response from the command that was run
|
|
||||||
*/
|
|
||||||
constructor(command = "Status"||"Join"||"Leave"||"ChgPreSet", response) {
|
|
||||||
this.cmd = command;
|
|
||||||
this.msg = response;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the Discord client
|
|
||||||
const client = new Client({
|
|
||||||
intents: [
|
|
||||||
GatewayIntentBits.Guilds,
|
|
||||||
GatewayIntentBits.GuildMessages,
|
|
||||||
GatewayIntentBits.MessageContent,
|
|
||||||
GatewayIntentBits.GuildVoiceStates
|
|
||||||
]
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* When the parent process sends a message, this will interpret the message and act accordingly
|
|
||||||
*
|
|
||||||
* DRB IPC Message Structure:
|
|
||||||
* msg.cmd = The command keyword; Commands covered on the server side
|
|
||||||
* msg.params = An array containing the parameters for the command
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
process.on('message', (msg) => {
|
|
||||||
log.DEBUG('IPC Message: ', msg);
|
|
||||||
const guildID = getGuilds()[0];
|
|
||||||
|
|
||||||
log.DEBUG("Guild Name: ", getGuildNameFromID(guildID));
|
|
||||||
switch (msg.cmd) {
|
|
||||||
// Check the status of the bot
|
|
||||||
case "Status":
|
|
||||||
log.INFO("Status command run from IPC");
|
|
||||||
|
|
||||||
status({guildID: guildID, callback: (statusObj) => {
|
|
||||||
log.DEBUG("Status Object string: ", statusObj);
|
|
||||||
if (!statusObj.voiceConnection) return process.send(new HPOB("Status", "VDISCONN"));
|
|
||||||
}});
|
|
||||||
break;
|
|
||||||
|
|
||||||
// Check the params for a server ID and if so join the server
|
|
||||||
case "Join":
|
|
||||||
log.INFO("Join command run from IPC");
|
|
||||||
|
|
||||||
join({guildID: guildID, guildObj: client.guilds.cache.get(guildID), channelID: msg.params.channelID, callback: () => {
|
|
||||||
process.send(new HPOB("Join", "AIDS"));
|
|
||||||
}})
|
|
||||||
break;
|
|
||||||
|
|
||||||
// Check to see if the bot is in a server and if so leave
|
|
||||||
case "Leave":
|
|
||||||
log.INFO("Leave command run from IPC");
|
|
||||||
|
|
||||||
leave({guildID: guildID, callback: (response) => {
|
|
||||||
process.send(new HPOB("Leave", response));
|
|
||||||
}});
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
// Command doesn't exist
|
|
||||||
log.INFO("Unknown command run from IPC");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// When the client is connected and ready
|
|
||||||
client.on('ready', () =>{
|
|
||||||
log.INFO(`${client.user.tag} is ready`)
|
|
||||||
process.send({'msg': "INIT READY"});
|
|
||||||
});
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Saved For later
|
|
||||||
client.on('messageCreate', (message) => {
|
|
||||||
log.DEBUG(`Message Sent by: ${message.author.tag}\n\t'${message.content}'`);
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
|
|
||||||
// When a command is sent
|
|
||||||
client.on('interactionCreate', (interaction) => {
|
|
||||||
if (interaction.isChatInputCommand()){
|
|
||||||
switch (interaction.commandName) {
|
|
||||||
case "ping":
|
|
||||||
ping(interaction);
|
|
||||||
break;
|
|
||||||
case "join":
|
|
||||||
join({ interaction: interaction });
|
|
||||||
break;
|
|
||||||
case "leave":
|
|
||||||
leave({ interaction: interaction });
|
|
||||||
break;
|
|
||||||
case "status":
|
|
||||||
status({ interaction: interaction });
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
interaction.reply({ content: 'Command not found, try one that exists', fetchReply: true })
|
|
||||||
.then((message) => log.DEBUG(`Reply sent with content ${message.content}`))
|
|
||||||
.catch((err) => log.ERROR(err));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
function loginBot(){
|
|
||||||
client.login(getTOKEN());
|
|
||||||
}
|
|
||||||
|
|
||||||
function getGuilds() {
|
|
||||||
return client.guilds.cache.map(guild => guild.id)
|
|
||||||
}
|
|
||||||
|
|
||||||
function getGuildNameFromID(guildID) {
|
|
||||||
return client.guilds.cache.map((guild) => {
|
|
||||||
if (guild.id === guildID) return guild.name;
|
|
||||||
})[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
function main(){
|
|
||||||
registerCommands(() => {
|
|
||||||
loginBot();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
main();
|
|
||||||
//module.exports = client;
|
|
||||||
2907
Client/discord-bot/package-lock.json
generated
2907
Client/discord-bot/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,25 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "discord-bot",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"description": "",
|
|
||||||
"main": "app.js",
|
|
||||||
"scripts": {
|
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
|
||||||
},
|
|
||||||
"keywords": [],
|
|
||||||
"author": "",
|
|
||||||
"license": "ISC",
|
|
||||||
"dependencies": {
|
|
||||||
"@discordjs/builders": "^1.4.0",
|
|
||||||
"@discordjs/opus": "^0.9.0",
|
|
||||||
"@discordjs/rest": "^1.4.0",
|
|
||||||
"@discordjs/voice": "^0.14.0",
|
|
||||||
"@mapbox/node-pre-gyp": "^1.0.10",
|
|
||||||
"debug": "^4.3.4",
|
|
||||||
"discord.js": "^14.7.1",
|
|
||||||
"node-gyp": "^9.3.0",
|
|
||||||
"libsodium-wrappers": "^0.7.10",
|
|
||||||
"alsa-capture": "0.3.0"
|
|
||||||
},
|
|
||||||
"type": "module"
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
# Discord Radio Bot: Command & Control - Client: Discord Bot (Client)
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
Explanation here
|
|
||||||
|
|
||||||
## Requirements
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
Requirements here (not modules, that will be installed with npm)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
Notes here
|
|
||||||
|
|
||||||
### Installation here
|
|
||||||
```shell
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
## Configuration
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
Notes here
|
|
||||||
|
|
||||||
### Configuration here
|
|
||||||
```shell
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### Usage here
|
|
||||||
```javascript
|
|
||||||
|
|
||||||
```
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
// Debug
|
|
||||||
import Debug from 'debug';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create the different logging methods for a function
|
|
||||||
* Namespace template = ("[app]:[fileName]:['INFO', 'WARNING', 'DEBUG', 'ERROR']")
|
|
||||||
* @param {string} appName The name of the app to be used in the 'app' portion of the namespace
|
|
||||||
* @param {string} fileName The name of the file calling the builder to be used in the 'fileName' portion of the namespace
|
|
||||||
*/
|
|
||||||
export default class ModuleDebugBuilder {
|
|
||||||
constructor(appName, fileName) {
|
|
||||||
this.INFO = Debug(`${appName}:${fileName}:INFO`);
|
|
||||||
this.DEBUG = Debug(`${appName}:${fileName}:DEBUG`);
|
|
||||||
this.WARN = Debug(`${appName}:${fileName}:WARNING`);
|
|
||||||
this.ERROR = Debug(`${appName}:${fileName}:ERROR`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
import {SlashCommandBuilder} from "@discordjs/builders";
|
|
||||||
import {REST} from "@discordjs/rest";
|
|
||||||
import {getApplicationID, getGuildID, getTOKEN} from "./configHandler.js";
|
|
||||||
import { Routes, ChannelType } from "discord.js";
|
|
||||||
// Debug
|
|
||||||
import ModuleDebugBuilder from "./moduleDebugBuilder.js";
|
|
||||||
const log = new ModuleDebugBuilder("bot", "registerCommands");
|
|
||||||
|
|
||||||
const pingCommand = new SlashCommandBuilder()
|
|
||||||
.setName("ping")
|
|
||||||
.setDescription("Confirm the bot is online")
|
|
||||||
.toJSON();
|
|
||||||
|
|
||||||
const joinCommand = new SlashCommandBuilder()
|
|
||||||
.setName('join')
|
|
||||||
.setDescription('Joins a voice channel')
|
|
||||||
.addChannelOption((option) => option
|
|
||||||
.setName('voicechannel')
|
|
||||||
.setDescription('The Channel to voiceController')
|
|
||||||
.setRequired(false)
|
|
||||||
.addChannelTypes(ChannelType.GuildVoice))
|
|
||||||
.toJSON();
|
|
||||||
|
|
||||||
const leaveCommand = new SlashCommandBuilder()
|
|
||||||
.setName("leave")
|
|
||||||
.setDescription("Leave current voice channel")
|
|
||||||
.toJSON();
|
|
||||||
|
|
||||||
const statusCommand = new SlashCommandBuilder()
|
|
||||||
.setName("status")
|
|
||||||
.setDescription("Returns if the bot is connected to a channel or not")
|
|
||||||
.toJSON();
|
|
||||||
|
|
||||||
export default async function registerCommands(callback){
|
|
||||||
const commands = [
|
|
||||||
pingCommand,
|
|
||||||
joinCommand,
|
|
||||||
leaveCommand,
|
|
||||||
statusCommand
|
|
||||||
];
|
|
||||||
|
|
||||||
try {
|
|
||||||
const rest = new REST({ version: '10' }).setToken(getTOKEN());
|
|
||||||
const clientID = getApplicationID();
|
|
||||||
const guildID = getGuildID();
|
|
||||||
|
|
||||||
await rest.put(Routes.applicationGuildCommands(clientID, guildID), {
|
|
||||||
body: commands,
|
|
||||||
});
|
|
||||||
log.DEBUG("Successfully registered the following commands: ", commands)
|
|
||||||
callback();
|
|
||||||
} catch (err) {
|
|
||||||
log.ERROR(err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,19 +5,18 @@ const log = new DebugBuilder("client", "httpRequests");
|
|||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
// Modules
|
// Modules
|
||||||
const http = require("http");
|
const http = require("http");
|
||||||
|
const { nodeObject } = require("./recordHelper.js");
|
||||||
var runningClientConfig = new nodeObject({_id: process.env.CLIENT_ID, _ip: process.env.CLIENT_IP, _name: process.env.CLIENT_NAME, _port: process.env.CLIENT_PORT, _location: process.env.CLIENT_LOCATION, _nearbySystems: process.env.CLIENT_NEARBY_SYSTEMS, _online: process.env.CLIENT_ONLINE});
|
|
||||||
|
|
||||||
exports.requestOptions = class requestOptions {
|
exports.requestOptions = class requestOptions {
|
||||||
constructor(path, method, hostname = undefined, headers = undefined, port = undefined) {
|
constructor(path, method, hostname = undefined, headers = undefined, port = undefined) {
|
||||||
if (method === "POST"){
|
if (method === "POST"){
|
||||||
this.hostname = hostname ?? runningClientConfig.hostname
|
this.hostname = hostname ?? process.env.SERVER_HOSTNAME ?? process.env.SERVER_IP;
|
||||||
this.path = path
|
this.path = path;
|
||||||
this.port = port ?? runningClientConfig.port
|
this.port = port ?? process.env.SERVER_PORT;
|
||||||
this.method = method
|
this.method = method;
|
||||||
this.headers = headers ?? {
|
this.headers = headers ?? {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user