toowake

Affiliate Detecter

Jun 30th, 2023
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { SlashCommandBuilder, EmbedBuilder } = require("discord.js");
  2.  
  3. module.exports = {
  4.     data: new SlashCommandBuilder()
  5.     .setName("affiliate-check")
  6.     .setDescription("Check if a Link is affiliate")
  7.     .addStringOption(option => option
  8.         .setName("url")
  9.         .setDescription("The URL")
  10.         .setRequired(true)
  11.     ),
  12.  
  13.     async execute (interaction) {
  14.         var URL = interaction.options.getString("url");
  15.  
  16.         function isAffiliateLink(url) {
  17.             var affiliateParams = ['ref', 'affiliate', 'tag', 'tracking'];
  18.             for (var i = 0; i < affiliateParams.length; i++) {
  19.               if (url.indexOf(affiliateParams[i] + '=') !== -1) {
  20.                 return true;
  21.               }
  22.             }
  23.             if (
  24.               url.indexOf('://amzn.to/') !== -1 ||  
  25.               url.indexOf('://rstyle.me/') !== -1 ||
  26.               url.indexOf('://go.redirectingat.com/') !== -1
  27.             ) {
  28.               return true;
  29.             }
  30.             return false;
  31.           }
  32.          
  33.           const result  = isAffiliateLink(URL);
  34.          
  35.           let yn = " ";
  36.  
  37.           if (result === true) {
  38.             yn = "Affilite detected!"
  39.           } else {
  40.             yn = "Clear"
  41.           }
  42.  
  43.           const embed = new EmbedBuilder()
  44.           .setTitle("Affiliate Link check")
  45.           .addFields(
  46.             {name: "URL:", value: `${URL}`, inline: false},
  47.             {name: "Affiliate:", value: `${result}`, inline: false},
  48.           )
  49.           .setColor("Purple")
  50.           .setTimestamp()
  51.           .setAuthor({ name: "Affiliate Check"})
  52.           .setFooter({ text: `${yn}` })
  53.  
  54.           return await interaction.reply({ embeds: [embed], ephemeral: true});
  55.          
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment