Skip to content
This repository has been archived by the owner on Nov 19, 2019. It is now read-only.

Commit

Permalink
Upload to origin
Browse files Browse the repository at this point in the history
  • Loading branch information
kyogoi committed Oct 4, 2019
1 parent d2deaa7 commit ec43c9c
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,7 @@ typings/

# next.js build output
.next

# bot configs
config.json
channels.json
6 changes: 6 additions & 0 deletions channels.json.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"voiceChannelID": {
"textChannel": "textChannelID",
"setToPurge": false
}
}
4 changes: 4 additions & 0 deletions config.json.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"prefix": "!",
"token": ""
}
53 changes: 53 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "mc-vc-bot",
"version": "1.0.0",
"description": "A Discord bot that handles the permissions for linked voice and text channels",
"main": "src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/wisnoi/mc-vc-bot.git"
},
"author": "wisnoi",
"license": "MIT",
"bugs": {
"url": "https://github.com/wisnoi/mc-vc-bot/issues"
},
"homepage": "https://github.com/wisnoi/mc-vc-bot#readme",
"dependencies": {
"discord.js": "^11.5.1"
}
}
56 changes: 56 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const Discord = require('discord.js');
const bot = new Discord.Client();
const config = require(__dirname + '/../config.json');
const fs = require('fs');
let channels = require(__dirname + '/../channels.json');

function updateChannels() {
fs.writeFileSync(__dirname + '/../channels.json', JSON.stringify(channels));
}

function purge() {
let isPurged = 0;

Object.keys(channels).forEach(async (id) => {
if (channels[id].setToPurge) {
const textChan = bot.channels.get(channels[id].textChannel);
while (!isPurged) {
await textChan.fetchMessages({ limit: 100 }).then(async (messages) => {
if (messages.array().length > 0) {
await textChan.bulkDelete(messages);
} else {
isPurged = 1;
}
});
}
channels[id].setToPurge = false;
updateChannels();
}
});
}

bot.on('voiceStateUpdate', (oldMember, newMember) => {

// Dealing with a purge channel
if (channels[oldMember.voiceChannelID]) {
console.log(oldMember.voiceChannelID);
let channel = bot.channels.get(oldMember.voiceChannelID);
if (!channel.members.length) {
channels[oldMember.voiceChannelID].setToPurge = true;
updateChannels();
}
}

// Dealing with a purge channel
if (channels[newMember.voiceChannelID]) {
channels[newMember.voiceChannelID].setToPurge = false;
updateChannels();
}

});

bot.on('ready', () => {
setInterval(purge, 1800000);
});

bot.login(config.token);

0 comments on commit ec43c9c

Please sign in to comment.