Skip to content

Commit

Permalink
Fixed bruh count
Browse files Browse the repository at this point in the history
  • Loading branch information
Struck713 committed Sep 17, 2023
1 parent 5c0125f commit 300a37c
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ node_modules/
config.json
.env
dist/
binaries/
binaries/
state.lock
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"build": "npx tsc",
"start": "node dist/src/app.js",
"start": "npm run build && node dist/src/app.js",
"dev": "concurrently \"npx tsc --watch\" \"nodemon -q dist/src/app.js\""
},
"author": "Struck713",
Expand Down
13 changes: 8 additions & 5 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { Client, Events, GatewayIntentBits } from "discord.js";
import { TOKEN } from '../config.json';
import { TOKEN, BRUH } from '../config.json';
import { Commands } from "./lib/command";
import { VoiceManager } from "./lib/voice";
import { StateManager } from "./lib/state";
import { BruhListener } from "./lib/listeners/bruh";

export const client = new Client({ intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates, GatewayIntentBits.MessageContent ] });
export const client = new Client({ intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent ] });
export const voiceManager = new VoiceManager();
export const stateManager = new StateManager();
export const bruhManager = new BruhListener();

client.once(Events.ClientReady, async client => {
console.log(`Logged in as ${client.user.tag}`);
Expand All @@ -26,9 +30,8 @@ client.on(Events.InteractionCreate, async interaction => {

client.on(Events.MessageCreate, async message => {
if (message.author.bot) return;
if (message.content.toLowerCase().includes("bruh")) {
await message.channel.send("bruh");
}
let content = message.content.toLowerCase();
if (message.channelId === BRUH.MESSAGE && content === "bruh") stateManager.bruhCount++;
});

//deploy();
Expand Down
20 changes: 20 additions & 0 deletions src/lib/listeners/bruh.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { client, stateManager } from "../../app";
import { BRUH } from "../../../config.json";

export class BruhListener {

private thread?: NodeJS.Timer;

constructor() {
this.thread = setInterval(() => {
let guild = client.guilds.resolve(BRUH.GUILD);
if (!guild) return;

let channel = guild.channels.resolve(BRUH.VOICE);
if (!channel) return;
channel.edit({ name: `Bruh Count: ${stateManager.bruhCount}`, reason: "New bruh added" });
}, 5 * 60 * 1000); // 5 minutes
}


}
29 changes: 29 additions & 0 deletions src/lib/state.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import fs from "fs";

interface State {
bruhCount: number;
}

export class StateManager {

bruhCount: number = 0;

constructor() {
this.load();
}

load = () => {
if (!fs.existsSync("state.lock")) this.save();

let { bruhCount } = JSON.parse(fs.readFileSync("state.lock", "utf-8")) as State;
this.bruhCount = bruhCount;
}

save = () => {
fs.writeFileSync("state.lock", JSON.stringify({
bruhCount: this.bruhCount
}));
}


}

0 comments on commit 300a37c

Please sign in to comment.