mirror of
https://github.com/Myxelium/RandomMemerBot.git
synced 2026-04-09 08:59:39 +00:00
Added join button for manully triggering the bot
This commit is contained in:
2
bot.ts
2
bot.ts
@@ -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();
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user