This repository has been archived by the owner on Nov 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
145 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,3 +59,7 @@ typings/ | |
|
||
# next.js build output | ||
.next | ||
|
||
# bot configs | ||
config.json | ||
channels.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"voiceChannelID": { | ||
"textChannel": "textChannelID", | ||
"setToPurge": false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"prefix": "!", | ||
"token": "" | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |