From 3fd08ad2f529da38b07f8d5e8a2529757086a593 Mon Sep 17 00:00:00 2001 From: WubzyGD Date: Wed, 22 Dec 2021 14:07:56 -0700 Subject: [PATCH] fix some inefficient regex --- commands/dev/blacklist.js | 4 +-- commands/fun/bite.js | 2 +- commands/fun/slap.js | 2 +- commands/moderation/warn.js | 2 +- commands/social/bio.js | 2 +- commands/social/bonk.js | 2 +- commands/social/creampie.js | 2 +- commands/social/feed.js | 2 +- commands/social/handhold.js | 2 +- commands/social/heal.js | 2 +- commands/social/hug.js | 2 +- commands/social/kill.js | 2 +- commands/social/kiss.js | 2 +- commands/social/pat.js | 2 +- commands/social/simp.js | 2 +- commands/social/spank.js | 2 +- commands/social/wink.js | 2 +- slash/userinfo.js.dev | 56 +++++++++++++++++++++++++++++++++++++ slashtemplate.js | 2 ++ 19 files changed, 76 insertions(+), 18 deletions(-) create mode 100644 slash/userinfo.js.dev create mode 100644 slashtemplate.js diff --git a/commands/dev/blacklist.js b/commands/dev/blacklist.js index 34aadd6..8dde578 100644 --- a/commands/dev/blacklist.js +++ b/commands/dev/blacklist.js @@ -61,7 +61,7 @@ module.exports = { } if (['a', 'add'].includes(args[0].toLowerCase())) { - let blacklistUser = args[1].match(/^<@(?:!?)(?:\d+)>$/) && mention && client.users.cache.has(mention.id) ? mention.id : client.users.cache.has(args[1]) ? client.users.cache.get(args[1]).id : null; + let blacklistUser = args[1].match(/^<@!?\d+>$/) && mention && client.users.cache.has(mention.id) ? mention.id : client.users.cache.has(args[1]) ? client.users.cache.get(args[1]).id : null; if (!blacklistUser) {return message.reply("You must specify a user to blacklist!");} let usersData = await UserData.findOne( { uid: blacklistUser } ) || new UserData({uid: blacklistUser}); @@ -76,7 +76,7 @@ module.exports = { } if (['r', 'rem', 'remove', 'd', 'del', 'delete'].includes(args[0].toLowerCase())) { - let blacklistedUser = args[1].match(/^<@(?:!?)(?:\d+)>$/) && mention && client.users.cache.has(mention.id) ? mention.id : client.users.cache.has(args[1]) ? client.users.cache.get(args[1]).id : null; + let blacklistedUser = args[1].match(/^<@!?\d+>$/) && mention && client.users.cache.has(mention.id) ? mention.id : client.users.cache.has(args[1]) ? client.users.cache.get(args[1]).id : null; if (!blacklistedUser) { return message.reply("You need to specify who you're letting free..." );} let userData = await UserData.findOne( { uid: blacklistedUser } ) || new UserData({uid: blacklistedUser}); diff --git a/commands/fun/bite.js b/commands/fun/bite.js index 630aad6..f267694 100644 --- a/commands/fun/bite.js +++ b/commands/fun/bite.js @@ -20,7 +20,7 @@ module.exports = { let saves = savess.saves; if (!args.length) { return message.channel.send(message.guild ? "Please mention someone to bite!" : "Oi! I get it if you don't like me but you can't just waltz into my DMs and bite me!");} - if (mention && args[0].match(/^<@(?:!?)(?:\d+)>$/)) { + if (mention && args[0].match(/^<@!?\d+>$/)) { if (!message.guild) {return message.reply("Oi! I get it if you don't like me but you can't just waltz into my DMs and bite me!");} if (!message.guild.members.cache.has(mention.id)) {return message.reply("That user is not in this server!");} if (message.author.id === mention.id) {return message.reply("Ew quit tryna bite yourself, that's weird.");} diff --git a/commands/fun/slap.js b/commands/fun/slap.js index f44348d..5a480a4 100644 --- a/commands/fun/slap.js +++ b/commands/fun/slap.js @@ -21,7 +21,7 @@ module.exports = { let saves = savess.saves; if (!args.length) { return message.channel.send(message.guild ? "Please mention someone to slap!" : "Oi! You don't get to waltz into my DM just to slap me!");} - if (mention && args[0].match(/^<@(?:!?)(?:\d+)>$/)) { + if (mention && args[0].match(/^<@!?\d+>$/)) { if (!message.guild) {return message.reply("Oi! You don't get to waltz into my DM just to slap me!");} if (!message.guild.members.cache.has(mention.id)) {return message.reply("That user is not in this server!");} if (message.author.id === mention.id) {return message.reply("Wait wouldn't slapping yourself be a form of self-harm? ToS is that you??");} diff --git a/commands/moderation/warn.js b/commands/moderation/warn.js index f421d02..c591d29 100644 --- a/commands/moderation/warn.js +++ b/commands/moderation/warn.js @@ -24,7 +24,7 @@ module.exports = { if (!message.member.permissions.has("MANAGE_MESSAGES") && !message.member.permissions.has("MANAGE_GUILD")) {return message.reply("You must be a server moderator (manage messages or manage server permissions) to use this command.");} if (args.length < 2 && !['check', 'c', 'list', 'l', 'clear', 'e', 'empty'].includes(args[0].toLowerCase())) {return message.channel.send("You must provide a reason for warning the user, or `check` or `clear`.");} - let user = message.mentions.members.first() && args[0].match(/^<@(?:!?)(?:\d+)>$/) ? message.mentions.members.first() : message.guild.members.cache.has(args[0]) ? message.guild.members.cache.get(args[0]) : null; + let user = message.mentions.members.first() && args[0].match(/^<@!?\d+>$/) ? message.mentions.members.first() : message.guild.members.cache.has(args[0]) ? message.guild.members.cache.get(args[0]) : null; if (!user && args.length > 1) {return message.channel.send("Either you didn't mention a user, or I can't find that user!");} if (args.length > 1) {args.shift();} diff --git a/commands/social/bio.js b/commands/social/bio.js index 8252244..99a7c1b 100644 --- a/commands/social/bio.js +++ b/commands/social/bio.js @@ -18,7 +18,7 @@ module.exports = { let tu = await UserData.findOne({uid: message.author.id}) ? await UserData.findOne({uid: message.author.id}) : new UserData({uid: message.author.id}); if (['v', 'view', 'check'].includes(args[0].toLowerCase())) { - let person = args[1] ? args[1].match(/^<@(?:!?)(?:\d+)>$/) && message.mentions.users.first() ? message.mentions.users.first().id : message.guild && message.guild.members.cache.has(args[1]) ? args[1] : message.author.id : message.author.id; + let person = args[1] ? args[1].match(/^<@!?\d+>$/) && message.mentions.users.first() ? message.mentions.users.first().id : message.guild && message.guild.members.cache.has(args[1]) ? args[1] : message.author.id : message.author.id; let pud = await UserData.findOne({uid: person}); if (!pud || !pud.bio || !pud.bio.length) {return message.reply(person === message.author.id ? "You don't have a bio set!" : "That user has no bio for me to show you!");} return message.channel.send({embeds: [new Discord.MessageEmbed() diff --git a/commands/social/bonk.js b/commands/social/bonk.js index b497ae3..2407a9a 100644 --- a/commands/social/bonk.js +++ b/commands/social/bonk.js @@ -28,7 +28,7 @@ module.exports = { .setTimestamp()]} : "I fucking dare you to hit me." );} - if (mention && args[0].match(/^<@(?:!?)(?:\d+)>$/)) { + if (mention && args[0].match(/^<@!?\d+>$/)) { if (!message.guild) {return message.reply("I dare you to hit me.");} if (!message.guild.members.cache.has(mention.id)) {return message.reply("You missed your bonk..");} if (message.author.id === mention.id) {return message.reply("I should bonk you for attempting to self harm.");} diff --git a/commands/social/creampie.js b/commands/social/creampie.js index 1252c48..254478d 100644 --- a/commands/social/creampie.js +++ b/commands/social/creampie.js @@ -27,7 +27,7 @@ module.exports = { .setTimestamp()]} : "Do. Not. Touch. Me." );} - if (mention && args[0].match(/^<@(?:!?)(?:\d+)>$/)) { + if (mention && args[0].match(/^<@!?\d+>$/)) { if (!message.guild) {return message.reply("No means no.");} if (!message.guild.members.cache.has(mention.id)) {return message.reply("I guess they didn't want your creampie..");} if (message.author.id === mention.id) {return message.reply("You can't give yourself a creampie..weirdo.");} diff --git a/commands/social/feed.js b/commands/social/feed.js index 3213cac..8bd7ca5 100644 --- a/commands/social/feed.js +++ b/commands/social/feed.js @@ -27,7 +27,7 @@ module.exports = { .setTimestamp()]} : "Sorry..I'm kinda full right now." );} - if (mention && args[0].match(/^<@(?:!?)(?:\d+)>$/)) { + if (mention && args[0].match(/^<@!?\d+>$/)) { if (!message.guild) {return message.reply("weirdchamp.");} if (!message.guild.members.cache.has(mention.id)) {return message.reply("I guess that person didn't want any food..");} if (message.author.id === mention.id) {return message.reply("You can't feed yourself. **Starve.**");} diff --git a/commands/social/handhold.js b/commands/social/handhold.js index 6a0969a..e8fb12a 100644 --- a/commands/social/handhold.js +++ b/commands/social/handhold.js @@ -27,7 +27,7 @@ module.exports = { .setTimestamp()]} : "Yikes... I'm kinda germaphobic you know. Maybe try asking in a server?" );} - if (mention && args[0].match(/^<@(?:!?)(?:\d+)>$/)) { + if (mention && args[0].match(/^<@!?\d+>$/)) { if (!message.guild) {return message.reply("Please make sure you're in a server so you can mention someone other than me to hold hands with!");} if (!message.guild.members.cache.has(mention.id)) {return message.reply("That user is not in this server!");} if (message.author.id === mention.id) {return message.reply("Holding your own hand... I mean it's possible? Same effect, though? Eh, not really.");} diff --git a/commands/social/heal.js b/commands/social/heal.js index b91fbb3..9af3036 100644 --- a/commands/social/heal.js +++ b/commands/social/heal.js @@ -27,7 +27,7 @@ module.exports = { .setTimestamp()]} : "I am immortal, I don't need healing." );} - if (mention && args[0].match(/^<@(?:!?)(?:\d+)>$/)) { + if (mention && args[0].match(/^<@!?\d+>$/)) { if (!message.guild) {return message.reply("I am immortal, I don't need healing.");} if (!message.guild.members.cache.has(mention.id)) {return message.reply("It's too late..they're already gone to a better place..");} if (message.author.id === mention.id) {return message.reply("You can't heal yourself because....I SAID SO");} diff --git a/commands/social/hug.js b/commands/social/hug.js index bdad84e..6c67fd1 100644 --- a/commands/social/hug.js +++ b/commands/social/hug.js @@ -28,7 +28,7 @@ module.exports = { .setTimestamp()]} : "Sorry, but I'm a bot, and I can't hug you. Go into a server and ask for some hugs!" );} - if (mention && args[0].match(/^<@(?:!?)(?:\d+)>$/)) { + if (mention && args[0].match(/^<@!?\d+>$/)) { if (!message.guild) {return message.reply("Please make sure you're in a server so you can mention someone other than me to hug!");} if (!message.guild.members.cache.has(mention.id)) {return message.reply("That user is not in this server!");} if (message.author.id === mention.id) {return message.reply("Sorry if you're that lonely, but you can't hug yourself!");} diff --git a/commands/social/kill.js b/commands/social/kill.js index f34f90f..a5759c0 100644 --- a/commands/social/kill.js +++ b/commands/social/kill.js @@ -27,7 +27,7 @@ module.exports = { .setTimestamp()]} : "You can't kill me..don't even try." );} - if (mention && args[0].match(/^<@(?:!?)(?:\d+)>$/)) { + if (mention && args[0].match(/^<@!?\d+>$/)) { if (!message.guild) {return message.reply("You can't kill me..don't even try.");} if (!message.guild.members.cache.has(mention.id)) {return message.reply("The person must have ran from their inevitable death..");} if (message.author.id === mention.id) {return message.reply("Uhhh no. Please don't try to hurt yourself..");} diff --git a/commands/social/kiss.js b/commands/social/kiss.js index 6473b88..42aafb7 100644 --- a/commands/social/kiss.js +++ b/commands/social/kiss.js @@ -25,7 +25,7 @@ module.exports = { .setTimestamp()]} : "I'm not really into that kind of thing. Maybe try asking in a server?" );} - if (mention && args[0].match(/^<@(?:!?)(?:\d+)>$/)) { + if (mention && args[0].match(/^<@!?\d+>$/)) { if (!message.guild) {return message.reply("Please make sure you're in a server so you can mention someone other than me to kiss!");} if (!message.guild.members.cache.has(mention.id)) {return message.reply("That user is not in this server!");} if (message.author.id === mention.id) {return message.reply("A self-kiss ought to be a little hard, don't you think?");} diff --git a/commands/social/pat.js b/commands/social/pat.js index 0b017d5..f37027d 100644 --- a/commands/social/pat.js +++ b/commands/social/pat.js @@ -29,7 +29,7 @@ module.exports = { .setTimestamp()]} : "Sorry, but I'm only able to pat one person, and it's not you ^^" );} - if (mention && args[0].match(/^<@(?:!?)(?:\d+)>$/)) { + if (mention && args[0].match(/^<@!?\d+>$/)) { if (!message.guild) {return message.reply("Please make sure you're in a server so you can mention someone other than me to pat!");} if (!message.guild.members.cache.has(mention.id)) {return message.reply("That user is not in this server!");} if (message.author.id === mention.id) {return message.reply("Self pats just don't work mate. Maybe try asking for some!");} diff --git a/commands/social/simp.js b/commands/social/simp.js index 6cfed19..2859908 100644 --- a/commands/social/simp.js +++ b/commands/social/simp.js @@ -27,7 +27,7 @@ module.exports = { .setTimestamp()]} : "Nobody simps for me. That's just weird. Be weird to someone else." );} - if (mention && args[0].match(/^<@(?:!?)(?:\d+)>$/)) { + if (mention && args[0].match(/^<@!?\d+>$/)) { if (!message.guild) {return message.reply("Listen I get it I get it you like me and all but I'm gonna have to get a restraining order real soon.");} if (!message.guild.members.cache.has(mention.id)) {return message.reply("They already left you. Get over it.");} if (message.author.id === mention.id) {return message.reply("You can't simp for yourself you lonely fuck.");} diff --git a/commands/social/spank.js b/commands/social/spank.js index 8151c0e..37cabf7 100644 --- a/commands/social/spank.js +++ b/commands/social/spank.js @@ -19,7 +19,7 @@ module.exports = { let savess = await Saves.findOne({name: 'spank'}) ? await Saves.findOne({name: 'spank'}) : new Saves({name: 'spank'}); let saves = savess.saves; if (!args.length) {return message.channel.send("You have to mention someone to spank!");} - if (mention && args[0].match(/^<@(?:!?)(?:\d+)>$/)) { + if (mention && args[0].match(/^<@!?\d+>$/)) { if (!message.guild) {return message.reply("Please make sure you're in a server so you can mention someone other than me to spank!");} if (!message.guild.members.cache.has(mention.id)) {return message.reply("That user is not in this server!");} if (message.author.id === mention.id) {return message.reply("You turn around and... whoop your own ass? Nah, I don't think it really works.");} diff --git a/commands/social/wink.js b/commands/social/wink.js index 2080b12..9ae79ad 100644 --- a/commands/social/wink.js +++ b/commands/social/wink.js @@ -27,7 +27,7 @@ module.exports = { .setTimestamp()]} : "W-why are you winking at me privately..do it in a server! " );} - if (mention && args[0].match(/^<@(?:!?)(?:\d+)>$/)) { + if (mention && args[0].match(/^<@!?\d+>$/)) { if (!message.guild) {return message.reply("Please make sure you're in a server so you can mention someone other than me to hold hands with!");} if (!message.guild.members.cache.has(mention.id)) {return message.reply("That user is not in this server!");} if (message.author.id === mention.id) {return message.reply("Wow...you must really have a big ego to wink at yourself...");} diff --git a/slash/userinfo.js.dev b/slash/userinfo.js.dev new file mode 100644 index 0000000..1e43ebb --- /dev/null +++ b/slash/userinfo.js.dev @@ -0,0 +1,56 @@ +const {SlashCommand} = require('../util/slash'); +const {SlashCommandBuilder} = require('@discordjs/builders'); +const Discord = require('discord.js'); + +const UserData = require("../models/user"); +const moment = require('moment'); + +module.exports = (client) => { + return new SlashCommand( + 'userinfo', client, + + new SlashCommandBuilder() + .setName("userinfo") + .setDescription("Get info about yourself or another user!") + .addUserOption(option => { + return option + .setName("user") + .setDescription("A user to get the info of"); + }) + .addBooleanOption(option => { + return option + .setName('send') + .setDescription("If you want me to send the response to this channel."); + }), + + async (client, interaction) => { + let person = interaction.options.getUser("user") ? interaction.options.getUser("user").id : interaction.user.id; + let name = interaction.guild ? person.displayName : person.username; + let tu = await UserData.findOne({uid: person.id}); + let now = new Date(); + let infoembed = new Discord.MessageEmbed() + .setTitle(`User Info for ${name}`) + .setDescription(`Requested by ${interaction.guild ? interaction.member.displayName : interaction.user.username}`) + .setThumbnail(client.users.cache.get(person.id).avatarURL({size: 2048})) + .addField("Account Created", moment(client.users.cache.get(person.id).createdAt).fromNow(), true) + .addField("Bot User?", client.users.cache.get(person.id).bot ? "Is a bot" : "Is not a bot", true) + .setColor('c375f0') + .setFooter('Natsuki', client.user.avatarURL()) + .setTimestamp(); + + if (interaction.guild) { + infoembed.addField('In Server Since', `${moment(person.joinedAt).fromNow()}${!moment(person.joinedAt).fromNow().includes('days') ? ` | ${Math.floor((new Date().getTime() - person.joinedAt.getTime()) / (60 * 60 * 24 * 1000))} days` : ''}\nMember for **${Math.round(((now.getTime() - new Date(interaction.member.joinedAt.getTime()).getTime()) / (new Date(interaction.guild.createdAt).getTime() - now.getTime())) * -100)}%** of server lifetime`, false) + .addField('Roles', `**${person.roles.cache.size}** roles | [${person.roles.cache.size}/${interaction.guild.roles.cache.size}] - ${Math.round((person.roles.cache.size / interaction.guild.roles.cache.size) * 100)}%\nHighest: ${person.roles.highest ? `<@&${person.roles.highest.id}>` : 'No roles!'}`, true) + if (interaction.guild.ownerId === person.id) {infoembed.addField("Extra", "User is the server's owner!");} + else if (person.permissions.has("ADMINISTRATOR")) {infoembed.addField("Extra", "User is an admin! Watch out :eyes:");} + } + + if (tu) { + infoembed.addField('Natsuki Commands Executed', tu.commands) + .addField('Donator?', tu.developer ? `Well, ${name} makes me work, so they're a supporter in my book!` : tu.donator ? 'Yes! They have donated or supported me in the past!' : 'No', true) + .addField('Natsuki Staff Level', tu.developer ? 'Developer' : tu.admin ? 'Admin; Audit access to the bot' : tu.staff ? 'Staff; Support but with maintenance permissions' : tu.support ? 'Support; Answers tickets and help queries' : 'Member; Does not have a staff rank.', true); + } + return interaction.reply({embeds: [infoembed]}); + } + ); +} \ No newline at end of file diff --git a/slashtemplate.js b/slashtemplate.js new file mode 100644 index 0000000..934e60c --- /dev/null +++ b/slashtemplate.js @@ -0,0 +1,2 @@ +const Discord = require('discord.js'); +