From 3f604b09ebb754ae24f8e2dc18ea18053fb25cb7 Mon Sep 17 00:00:00 2001 From: Abheek Dhawan Date: Tue, 6 Apr 2021 23:49:15 -0500 Subject: [PATCH 1/3] Add embed scroll functionality when querying users with role --- bot.js | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 68 insertions(+), 6 deletions(-) diff --git a/bot.js b/bot.js index 6b911c6..aa4cf28 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) { From 7187455015a68f6bd117dd26611daeb936cf6719 Mon Sep 17 00:00:00 2001 From: Abheek Dhawan Date: Tue, 6 Apr 2021 23:53:40 -0500 Subject: [PATCH 2/3] Don't log reaction adds, only reaction removes --- bot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot.js b/bot.js index aa4cf28..f88ca11 100644 --- a/bot.js +++ b/bot.js @@ -963,7 +963,7 @@ client.on('messageReactionAdd', (messageReaction, user) => { if (result.bot_logs_id) { botLogsChannel = result.bot_logs_id; if (message.guild.channels.cache.get(botLogsChannel)) { - message.guild.channels.cache.get(botLogsChannel).send(messageReactionAddEmbed).catch(console.error); + //message.guild.channels.cache.get(botLogsChannel).send(messageReactionAddEmbed).catch(console.error); } } if (result.kulboard_id) { From 6f2542774835c000f925f540111415c8ddc077e6 Mon Sep 17 00:00:00 2001 From: Abheek Dhawan Date: Fri, 9 Apr 2021 18:21:02 -0500 Subject: [PATCH 3/3] Add content to README.md --- README.md | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) 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)