Added join button for manully triggering the bot

This commit is contained in:
Myx
2023-10-18 21:53:12 +02:00
parent ba7d6aef1e
commit d1bffddd46
4 changed files with 28 additions and 2 deletions

2
bot.ts
View File

@@ -62,7 +62,7 @@ discordClient.on('ready', async () => {
* @param retries - The number of retries to attempt if no voice channels are found.
* @returns Promise<void>
*/
async function joinRandomChannel(retries = 12) {
export async function joinRandomChannel(retries = 12) {
if (!discordClient.guilds.cache.size) {
console.log(LoggerColors.Red, 'No guilds found');
scheduleNextJoin();

View File

@@ -6,6 +6,25 @@ document.addEventListener('DOMContentLoaded', (event) => {
})
});
document.getElementById('joinButton').addEventListener('click', function() {
this.disabled = true;
fetch('/join')
.then(response => response.text())
.then(data => {
console.log(data);
setTimeout(() => {
this.disabled = false;
}, 40000);
})
.catch((error) => {
console.error('Error:', error);
setTimeout(() => {
this.disabled = false;
}, 1000);
});
});
function loadNextPlaybackTime() {
fetch('/nextplaybacktime')
.then(response => response.text())

View File

@@ -25,6 +25,8 @@
<button type="submit" class="btn btn-primary btn-block">Upload</button>
</form>
<button id="joinButton" class="btn btn-info btn-block">Join</button>
<div id="nextPlaybackTime" class="mb-4">
Endpoint not loading!?
</div>

View File

@@ -1,4 +1,4 @@
import { nextPlayBackTime } from './../bot';
import { joinRandomChannel, nextPlayBackTime } from './../bot';
import express from 'express';
import multer, { diskStorage } from 'multer';
import path from 'path';
@@ -149,6 +149,11 @@ app.delete('/sounds/:filename', (req, res) => {
app.use(express.static(path.join(__dirname, "web")));
app.get('/join', (_req, res) => {
joinRandomChannel();
res.send('Joining random channel.');
});
/**
* Starts the web server on either http or https protocol based on the availability of SSL certificates.
* @returns void