[
  {
    "path": ".gitignore",
    "content": "node_modules\n"
  },
  {
    "path": "LICENSE",
    "content": "MIT License\n\nCopyright (c) 2021 polemikal\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "# discord-welcome-bot\n\nA great intro sounds for Discord servers!\n\n# Setup the Project\n\n1. Download or clone this project.\n2. Setup the project options from `config.json` file.\n3. Upload the required audio files in `default_files` path and enter audio files name in `config.json`.\n4. Run `app.js` file from terminal. (Example run command: `node app.js`)\n\n**(!) DO NOT FORGET** You must install **FFMPEG** on your system to run.\n\n# Information\n\n**(!)** If there is something that can be added to this project or if you have found anything missing in this project, you can let us know and help us improve the project! [Let us know!](https://github.com/polemikal/discord-slash-commands-bot/issues)\n\n**(!)** This project is shared on behalf of [Serendia Squad](https://discord.com/invite/serendia). If you need any help about this project, you can join this platform and ask questions in your mind.\n\n\n\n\n"
  },
  {
    "path": "app.js",
    "content": "const { Client, VoiceChannel, GuildMember } = require(\"discord.js\");\n\nconst fs = require(\"fs\");\nconst CONFIG = JSON.parse(fs.readFileSync(\"./config.json\", { encoding: \"utf-8\" }));\n\nconst moment = require(\"moment\");\nrequire(\"moment-duration-format\");\n\nconst Voice = new Client({ fetchAllMembers: true, disableMentions: \"none\" });\nVoice.staffJoined = false;\nVoice.playingVoice = false;\nVoice.voiceConnection = null;\nVoice.channelID = null;\n\nVoice.on(\"ready\", async() => {\n\n    Voice.user.setPresence({\n        status: \"dnd\",\n        activity: {\n            name: CONFIG.DEFAULTS.ACTIVITY_TEXT\n        }\n    });\n\n    Voice.log(`Voice client \\'${Voice.user.username}\\' has been activated!`);\n\n    const Guild = Voice.guilds.cache.get(CONFIG.DEFAULTS.GUILD_ID) || Voice.guilds.cache.first();\n    if(!Guild) {\n        Voice.error(\"Guild not found!\");\n        return Voice.destroy();\n    }\n    \n    const Channel = Guild.channels.cache.get(CONFIG.DEFAULTS.VOICE_CHANNEL);\n    if(!Channel) {\n        Voice.error(\"Channel not found!\");\n        return Voice.destroy();\n    }\n\n    Channel.join().then(connection =>{\n            \n        Voice.voiceConnection = connection;\n        Voice.channelID = Channel.id;\n        Voice.log(\"The audio file is playing now...\")\n        if(!Channel.hasStaff()) playVoice(Voice);\n        else Voice.staffJoined = true;\n\n    }).catch(err => {\n        Voice.error(`Cannot connect to voice channel (${Channel.name}) (${Channel.id}): ` + err.message)\n        return Voice.destroy();\n    });\n\n});\n\nVoice.on(\"voiceStateUpdate\", async(oldState, newState) => {\n    if(\n        newState.channelID && (oldState.channelID !== newState.channelID) &&\n        newState.member.isStaff() &&\n        newState.channelID === Voice.channelID &&\n        !newState.channel.hasStaff(newState.member)\n    ) {\n        Voice.staffJoined = true;\n        return playVoice(Voice);\n    }\n    if( \n        oldState.channelID && \n        (oldState.channelID !== newState.channelID) && \n        newState.member.isStaff() && \n        oldState.channelID === Voice.channelID &&\n        !oldState.channel.hasStaff()\n    ) {\n        Voice.staffJoined = false;\n        return playVoice(Voice);\n    }\n});\n\nVoice.login(CONFIG.TOKEN).catch(err => {\n    Voice.error(\"An occured error while connecting to Voice client: \" + err.message);\n    return Voice.destroy();\n});\n\n/**\n * \n * @param {Client} Voice \n */\nfunction playVoice(Voice) {\n    try {\n\n        const Path = Voice.staffJoined === true ? \"./\" + CONFIG.FILES.STAFF : \"./\" + CONFIG.FILES.WELCOME;\n        Voice.playingVoice = true;\n        Voice.voiceConnection.play(Path, {\n            volume: 1\n        }).on(\"finish\", async() => {\n            Voice.playingVoice = false;\n            if(Voice.staffJoined === true) return;\n            playVoice(Voice);\n        });\n\n    } catch(err) {\n\n        return Voice.log(\"An occured error while playing voice file: \" + err.message);\n        \n    }\n};\n\nClient.prototype.log = function(content) {\n    return console.log(`[${moment().format('YYYY-MM-DD HH:mm:ss')}] [VOICE BOT] ${content}`);\n};\n\nClient.prototype.error = function(content) {\n    return console.error(`[${moment().format('YYYY-MM-DD HH:mm:ss')}] [VOICE BOT] ERR! ${content}`);\n};\n\nVoiceChannel.prototype.hasStaff = function(checkMember = false) {\n    if(this.members.some(m => (checkMember !== false ? m.user.id !== checkMember.id : true) && !m.user.bot && m.roles.highest.position >= m.guild.roles.cache.get(CONFIG.DEFAULTS.MIN_STAFF_ROLE).position)) return true; // m.roles.highest.position >= this.guild.roles.cache.get(CONFIG.DEFAULTS.MIN_STAFF_ROLE).position\n    return false;\n}\n\nVoiceChannel.prototype.getStaffs = function(checkMember = false) {\n    return this.members.filter(m => (checkMember !== false ? m.user.id !== checkMember.id : true) && !m.user.bot && m.roles.highest.position >= m.guild.roles.cache.get(CONFIG.DEFAULTS.MIN_STAFF_ROLE).position).size\n}\n\nGuildMember.prototype.isStaff = function() {\n    if(\n        !this.user.bot &&\n        ([...CONFIG.DEFAULTS.AUTHORS].includes(this.id) ||\n        this.hasPermission(\"ADMINISTRATOR\") ||\n        this.roles.highest.position >= this.guild.roles.cache.get(CONFIG.DEFAULTS.MIN_STAFF_ROLE).position\n        )\n    ) return true;\n    return false;\n}\n\n"
  },
  {
    "path": "config.json",
    "content": "{\n    \"DEFAULTS\": {\n        \"AUTHORS\": [],\n        \"ACTIVITY_TEXT\": \"Polemikal Voice System\",\n        \"GUILD_ID\": \"\",\n        \"VOICE_CHANNEL\": \"\",\n        \"MIN_STAFF_ROLE\": \"\"\n    },\n    \"FILES\": {\n        \"WELCOME\": \"default_files/<welcome-voice>.mp3\",\n        \"STAFF\": \"default_files/<staff-voice>.mp3\"\n    },\n    \"TOKEN\": \"BOT_TOKEN\"\n}"
  },
  {
    "path": "package.json",
    "content": "{\n  \"name\": \"dark-voice-bots\",\n  \"version\": \"1.0.0\",\n  \"description\": \"\",\n  \"main\": \"app.js\",\n  \"scripts\": {\n    \"test\": \"echo \\\"Error: no test specified\\\" && exit 1\"\n  },\n  \"author\": \"polemikal\",\n  \"license\": \"ISC\",\n  \"dependencies\": {\n    \"@discordjs/opus\": \"^0.3.3\",\n    \"discord.js\": \"^12.5.1\",\n    \"fs\": \"0.0.1-security\",\n    \"moment\": \"^2.29.1\",\n    \"moment-duration-format\": \"^2.3.2\",\n    \"opusscript\": \"0.0.7\"\n  }\n}\n"
  }
]