From 7eb5dd3e4d165d2a654409262230108816122e45 Mon Sep 17 00:00:00 2001 From: Liam Skinner Date: Thu, 3 Jun 2021 23:17:18 +0100 Subject: [PATCH] v1.3.3 release --- .github/pull_request_template.md | 8 +++ .github/workflows/codeql-analysis.yml | 71 ++++++++++++++++++++++ .gitignore | 4 +- .npmignore | 4 +- README.md | 4 +- package-lock.json | 4 +- package.json | 4 +- src/features/{ghostping.js => detector.js} | 22 ++++++- src/index.js | 22 +------ src/util/embedValues.js | 10 +-- src/util/send.js | 15 +++-- 11 files changed, 124 insertions(+), 44 deletions(-) create mode 100644 .github/workflows/codeql-analysis.yml rename src/features/{ghostping.js => detector.js} (87%) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index e69de29..7c7bb31 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -0,0 +1,8 @@ +## Overview + +**Provide a general overview of this PR:** + +## General Information +1. **Does it solve a bug?** +2. **What changes have you made?** +3. **What alternatives have you tried?** \ No newline at end of file diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 0000000..490918b --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,71 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: [ main ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ main ] + schedule: + - cron: '39 10 * * 6' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'javascript' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] + # Learn more: + # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v1 + + # ℹī¸ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl + + # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language + + #- run: | + # make bootstrap + # make release + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v1 diff --git a/.gitignore b/.gitignore index ce5aa48..e5d286e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ node_modules/ -.git/ \ No newline at end of file +.git/ + +test/ \ No newline at end of file diff --git a/.npmignore b/.npmignore index 4019f9f..20e3c0e 100644 --- a/.npmignore +++ b/.npmignore @@ -3,4 +3,6 @@ node_modules/ .git/ .github/ -.gitignore \ No newline at end of file +.gitignore + +test/ \ No newline at end of file diff --git a/README.md b/README.md index 037f894..220065c 100644 --- a/README.md +++ b/README.md @@ -15,11 +15,11 @@ This package comes from the developer of verified bots: [**@Coin Flipper#1767**] - [x] Send Messages As the Bot ### Help -If you don't understand something in the documentation, you are experiencing problems, or you just need a gentle nudge in the right direction, please don't hesitate to join our [Discord Server](https://discord.gg/2je9aJynqt). +If you don't understand something in the [documentation](https://github.com/ThatsLiamS/discord.js-ghost-ping/wiki), you are experiencing problems, or you just need a gentle nudge in the right direction, please don't hesitate to join our [Discord Server](https://discord.gg/2je9aJynqt). # **Installation** To install, do this command in your shell or command prompt then you are good to go! -```js +``` npm install discord.js-ghost-ping /* or */ yarn add discord.js-ghost-ping diff --git a/package-lock.json b/package-lock.json index 71e345a..2fa0ae0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { "name": "discord.js-ghost-ping", - "version": "1.3.2", + "version": "1.3.3", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "1.3.2", + "version": "1.3.3", "license": "MIT", "dependencies": { "discord.js": "^12.5.3" diff --git a/package.json b/package.json index a611c49..e26f51d 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,10 @@ { "name": "discord.js-ghost-ping", - "version": "1.3.2", + "version": "1.3.3", "description": "Detect Ghost Pings inside of discord.js!", "main": "src/index.js", "scripts": { - "run": "node src/index.js" + "test": "node test/index.js" }, "keywords": [ "JavaScript", diff --git a/src/features/ghostping.js b/src/features/detector.js similarity index 87% rename from src/features/ghostping.js rename to src/features/detector.js index e8138c3..d9a7bc0 100644 --- a/src/features/ghostping.js +++ b/src/features/detector.js @@ -11,7 +11,6 @@ async function messageDelete(message, value){ let stringMentions = ""; - await message.mentions.members.forEach(member => { if(!member.user.bot && member.id != message.author.id){ stringMentions += `${member} ` @@ -73,7 +72,24 @@ async function messageUpdate(oldMessage, newMessage, value){ return send(value, newMessage, stringMentions) } + +function detector(EventType, ...args){ + + if(EventType){ + if(EventType == 'messageDelete'){ + return messageDelete(...args) + } + if(EventType == 'messageUpdate'){ + return messageUpdate(...args) + } + + throw ErrorMessages.unexpectedParameterError + + } + else{ + throw ErrorMessages.expectedParameterError + } +} module.exports = { - messageDelete, - messageUpdate + detector } \ No newline at end of file diff --git a/src/index.js b/src/index.js index 2f8145f..3dbb367 100644 --- a/src/index.js +++ b/src/index.js @@ -1,23 +1,5 @@ -const { messageDelete, messageUpdate } = require(`${__dirname}/features/ghostping`) -const { ErrorMessages } = require(`${__dirname}/util/errors`) - -function detector(EventType, ...args){ - - if(EventType){ - if(EventType == 'messageDelete'){ - return messageDelete(...args) - } - if(EventType == 'messageUpdate'){ - return messageUpdate(...args) - } - - throw ErrorMessages.unexpectedParameterError - - } else{ - throw ErrorMessages.expectedParameterError - } -} +const { detector } = require(`${__dirname}/features/detector`) module.exports = { detector -} +} \ No newline at end of file diff --git a/src/util/embedValues.js b/src/util/embedValues.js index 5843ff7..02815a4 100644 --- a/src/util/embedValues.js +++ b/src/util/embedValues.js @@ -1,5 +1,4 @@ const { ErrorMessages } = require(`${__dirname}/../util/errors`) -const Discord = require('discord.js') function embedValues(object, message){ @@ -15,16 +14,13 @@ function embedValues(object, message){ /* Does the user provide the argument and is it an object? */ if(!object || object && (typeof object !== 'object')){ return editedValues } - /* Change the values */ - if(object.title) editedValues.title = object.title + /* Changes the values */ + if(object.title && object.title.toString().length < 257 ) editedValues.title = object.title if(object.color) editedValues.color = object.color if(object.picture) editedValues.picture = object.picture - if(object.footer) editedValues.footer = object.footer + if(object.footer && object.footer.toString().length < 2049 ) editedValues.footer = object.footer if(object.channel) editedValues.channel = message.guild.channels.cache.get(object.channel) - /* Checks if the channel is a real channel */ - if (!editedValues.channel instanceof Discord.TextChannel){ throw ErrorMessages.unableToGetChannel } - /* Return the edited values to use in send() */ return editedValues } diff --git a/src/util/send.js b/src/util/send.js index 047749b..a40f943 100644 --- a/src/util/send.js +++ b/src/util/send.js @@ -2,21 +2,24 @@ const Discord = require('discord.js') const { embedValues } = require(`${__dirname}/embedValues`) async function send(value, message, mentions){ - const embedInfo = embedValues(value, message) + + const { title, color, picture, footer, channel } = embedValues(value, message) const embed = new Discord.MessageEmbed() - .setTitle(`${embedInfo.title}`) + .setTitle(`${title}`) .setAuthor(`${message.member.user.tag}`, `${message.member.user.displayAvatarURL()}`) - .setColor(`${embedInfo.color}`) - .setThumbnail(`${embedInfo.picture}`) + .setColor(`${color}`) + .setThumbnail(`${picture}`) .addFields( { name: `**Channel:**`, value: `${message.channel}`, inline: true }, { name: `**Mentions:**`, value: `${mentions}`, inline: true } ) - .setFooter(`${embedInfo.footer}`) + .setFooter(`${footer}`) .setTimestamp(); - embedInfo.channel.send({embed}).catch(() => { + if (!channel instanceof Discord.TextChannel && !channel instanceof Discord.NewsChannel){ throw ErrorMessages.unableToGetChannel } + + await channel.send({embed}).catch(() => { throw ErrorMessages.unableToSendMessage })