diff --git a/README.md b/README.md index 47b773a..33d398e 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,30 @@ # AwesomeMod -## More info coming soon! +## About +AwesomeMod is a Discord bot that specializes in moderation. It provides neat and rich logs as well as the ability for users to request roles. Additionally, it has the ability to add a voice channel that's named the amount of members, as Discord makes it difficult to keep track of how many members are in your server. The best part - features can be requested whenever and will be viewed and approved as soon as possible! + +## Installation +Currently there's only one way to install the bot on your server - cloning this repository and running it with node. In the future, I plan to add Docker and NPM as viable ways to deploy the bot. As of now, however, follow these steps for installation: + +1. Clone repo: +``` +git clone https://github.com/ADawesomeguy/AwesomeMod.git +``` +2. Enter repo and install dependencies +``` +cd AwesomeMod && npm i +``` +3. Run the bot: +``` +npm run prod +``` + +## Notes +### Creating a Discord Application/Bot +To create your own application and bot using the [Discord Developer Portal](https://discord.com/developers), go to the previous link and sign in. Then create a new application, and click bots on the left. Configure it to your liking, and then copy the token. + + ![](https://raw.githubusercontent.com/ADawesomeguy/AwesomeSciBo/master/images/discord-developer.png) + +That's the most important part of your bot *and don't share it with anyone*. + +## Credit +The bot was made by [@ADawesomeguy](https://github.com/ADawesomeguy). It is licensed under the [Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0.html) diff --git a/bot.js b/bot.js index 223c5e1..55ed58c 100644 --- a/bot.js +++ b/bot.js @@ -609,6 +609,7 @@ async function helpMessage(message) { } async function usersWith(message) { + const threshold = 20; if (message.content.split(" ").length < 2) { message.reply("query must contain at least 3 characters!") return; @@ -619,12 +620,73 @@ async function usersWith(message) { } const roles = message.guild.roles.cache.filter(role => role.name.toLowerCase().includes(message.content.split(" ")[1])); const role = roles.array()[0]; - const roleEmbed = new Discord.MessageEmbed() - .setTitle(`${role.members.array().length} user(s) with the role \`${role.name}\`:`) - .setDescription(" • " + roles.array()[0].members.map(m => m.user.tag).join('\n\n • ')) - .setFooter(`Role ID: ${role.id}`) - .setTimestamp(); - message.channel.send(roleEmbed); + const membersList = roles.array()[0].members.array() + if (membersList.length > threshold) { + let embedContentArray = []; + while(membersList.length) { + embedContentArray.push(membersList.splice(0,threshold)); + } + //console.log(embedContentArray); + let embedArray = []; + embedContentArray.forEach((members, index) => { + const roleEmbed = new Discord.MessageEmbed() + .setTitle(`${role.members.array().length} user(s) with the role \`${role.name}\`:`) + .setDescription(" • " + members.map(m => m.user.tag).join('\n\n • ')) + .setFooter(`Role ID: ${role.id}`) + .setTimestamp(); + embedArray.push(roleEmbed); + }); + message.channel.send(embedArray[0]) + .then(roleMessage => { + let embedIndex = 0; + roleMessage.react('⬅️'); + roleMessage.react('➡️'); + const filter = (reaction, user) => { + return ['⬅️', '➡️'].includes(reaction.emoji.name) && user.id === message.author.id; + }; + + const collector = roleMessage.createReactionCollector(filter, { time: 600000 }); + + collector.on('collect', async (reaction, user) => { + if (reaction.emoji.name === '➡️') { + let index = (embedIndex + 1) % (embedArray.length); + embedIndex = index; + roleMessage.edit(embedArray[index]); + const userReactions = roleMessage.reactions.cache.filter(reaction => reaction.users.cache.has(user.id)); + try { + for (const reaction of userReactions.values()) { + await reaction.users.remove(user.id); + } + } catch (error) { + console.error('Failed to remove reactions.'); + } + } else { + let index = (embedIndex + threshold - 1) % embedArray.length; + embedIndex = index; + roleMessage.edit(embedArray[index]); + const userReactions = roleMessage.reactions.cache.filter(reaction => reaction.users.cache.has(user.id)); + try { + for (const reaction of userReactions.values()) { + await reaction.users.remove(user.id); + } + } catch (error) { + console.error('Failed to remove reactions.'); + } + } + }); + + collector.on('end', () => { + roleMessage.edit("TIMEOUT"); + }) + }); + } else { + const roleEmbed = new Discord.MessageEmbed() + .setTitle(`${role.members.array().length} user(s) with the role \`${role.name}\`:`) + .setDescription(" • " + roles.array()[0].members.map(m => m.user.tag).join('\n\n • ')) + .setFooter(`Role ID: ${role.id}`) + .setTimestamp(); + message.channel.send(roleEmbed); + } } async function aboutServer(message) {