Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug where multiple notifications are sent #7

Merged
merged 1 commit into from
Nov 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ const Discord = require("discord.js");
const intents = [
Discord.Intents.FLAGS.GUILDS,
Discord.Intents.FLAGS.GUILD_VOICE_STATES,
Discord.Intents.FLAGS.GUILD_MESSAGES
Discord.Intents.FLAGS.GUILD_MESSAGES,
Discord.Intents.FLAGS.DIRECT_MESSAGES
];

const commands: Command[] = [
Expand All @@ -53,8 +54,6 @@ bot.listen(function (client: Client) {
console.log("BanDev | 1.0.0");
console.log("===");
console.log("AWAITING COMMANDS...");

client.user.setActivity('bandev.uk/notify', { type: 'PLAYING' });
});

// When something changes in a
Expand Down
10 changes: 9 additions & 1 deletion src/Bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class Bot {
this.ready = ready;
this.client.login(this.token);
this.onInteraction();
this.onMessage();
this.onReady();
}

Expand All @@ -62,7 +63,14 @@ export class Bot {

private onReady() {
this.client.on("ready", client => {
this.ready(this.client);
client.user.setActivity('bandev.uk/notify', { type: 'PLAYING' });
this.ready(client);
});
}

private onMessage() {
this.client.on("messageCreate", async message => {
console.log(message)
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/stateUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ export function stateUpdate(discord, before, updated) {

}

if(updated.streaming) {
if(updated.streaming && !before.streaming) {

// User is streaming
return send(discord, `${member.displayName} is live in ${updated.channel.name}`, `🔴`, member, updateChannel);

}

if(updated.selfVideo) {
if(updated.selfVideo && !before.selfVideo) {

// User has camera on
return send(discord, `${member.displayName} turned their camera on in ${updated.channel.name}`, `📷`, member, updateChannel);
Expand Down