Skip to content

Commit

Permalink
Add env variable DISCORD_RUN_VOICE_BOTS to control if bots run
Browse files Browse the repository at this point in the history
  • Loading branch information
slmnio committed Sep 7, 2023
1 parent dd017ab commit f44c2f1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
3 changes: 3 additions & 0 deletions server/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ CORS_VALID_DOMAINS=slmn.gg,localhost

SLMNGG_LOGS_GUILD_ID=
SLMNGG_LOGS_CHANNEL_ID=

# Set if you want Discord voice bots to run
DISCORD_RUN_VOICE_BOTS=
47 changes: 26 additions & 21 deletions server/src/discord/bot-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,30 +101,34 @@ async function checkBroadcast(id, broadcast) {
}
}

onUpdate(async(id, { newData, oldData }) => {
setTimeout(async () => {
if (id === "Broadcasts") {
broadcastIDs = newData.ids.map(id => cleanID(id));
// check all broadcasts
broadcastIDs.map(id => checkBroadcast(id));
}
if (!process.env.DISCORD_RUN_VOICE_BOTS) {
console.log("Discord voice bots won't run because DISCORD_RUN_VOICE_BOTS is not set.");
} else {
onUpdate(async(id, { newData, oldData }) => {
setTimeout(async () => {
if (id === "Broadcasts") {
broadcastIDs = newData.ids.map(id => cleanID(id));
// check all broadcasts
broadcastIDs.map(id => checkBroadcast(id));
}

if (broadcastIDs.includes(cleanID(id))) {
checkBroadcast(id, newData);
// check broadcast ID
}
if (watchIDs.includes(cleanID(id))) {
broadcastIDs.map(id => checkBroadcast(id));
}
if (broadcastIDs.includes(cleanID(id))) {
checkBroadcast(id, newData);
// check broadcast ID
}
if (watchIDs.includes(cleanID(id))) {
broadcastIDs.map(id => checkBroadcast(id));
}

if (id === "Discord Bots") {
let botData = await getBots(); // update manager?
manager.setTokens(botData.filter(d => d?.token).map(d => d.token));
if (id === "Discord Bots") {
let botData = await getBots(); // update manager?
manager.setTokens(botData.filter(d => d?.token).map(d => d.token));

// manager.createJob("996236081819303936", "bpl4", "assistance");
}
}, 100);
});
// manager.createJob("996236081819303936", "bpl4", "assistance");
}
}, 100);
});
}


/**
Expand Down Expand Up @@ -378,6 +382,7 @@ class DiscordBot {
}

checkJob(currentChannelID) {
console.log("checking job", this.job);
if (!this.job) return this.log(`No job but currently in channel ${currentChannelID}`);

this.log(`Current job is ${this.socketRoom} ${this.job.broadcastKey}/${this.job.taskKey} ${this.job.channelID}`);
Expand Down

0 comments on commit f44c2f1

Please sign in to comment.