toowake

ptero.js

Sep 24th, 2023
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const ptero = require("pterodactyl.js");
  2. const { SlashCommandBuilder, EmbedBuilder, ButtonBuilder, ButtonStyle, ActionRowBuilder } = require("discord.js");
  3. const Schema = require("../../Modals/account");
  4. const preRegister = require("../../Modals/pre-register");
  5.  
  6. module.exports = {
  7.     data: new SlashCommandBuilder()
  8.     .setName("hosting")
  9.     .setDescription("Hosting manager")
  10.     .addSubcommandGroup(group => group
  11.         .setName("account")
  12.         .setDescription("Create/Delete an account")
  13.         .addSubcommand(command => command
  14.             .setName("create")
  15.             .setDescription("Create an pterodactyl account")
  16.             .addStringOption(option => option.setName("username").setDescription("Your username").setMinLength(7).setMaxLength(24).setRequired(true))
  17.             .addStringOption(option => option.setName("email").setDescription("Your email").setRequired(true))
  18.             .addStringOption(option => option.setName("password").setDescription("Your password").setRequired(true).setMinLength(8).setMaxLength(24))
  19.         )
  20.         .addSubcommand(command => command
  21.             .setName("delete")
  22.             .setDescription("Delete your pterodactyl account")
  23.             .addStringOption(option => option.setName("username").setDescription("Your username").setMaxLength(24).setMinLength(7).setRequired(true))
  24.             .addStringOption(option => option.setName("password").setDescription("Your password").setMaxLength(24).setMinLength(8).setRequired(true))
  25.         )
  26.     )
  27.     .addSubcommandGroup(group => group
  28.         .setName("server")
  29.         .addSubcommand(command => command
  30.             .setName("create")
  31.             .setDescription("Create a server")
  32.             .addStringOption(option => option.setName("name").setDescription("Your servers name").setMinLength(7).setMaxLength(24).setRequired(true))
  33.             .addStringOption(option => option
  34.                 .setName("type")
  35.                 .setDescription("The type you need")
  36.                 .setRequired(true)
  37.                 .addChoices(
  38.                     {name: "NodeJS", value: "NodeJS"},
  39.                     {name: "Python", value: "Python"},
  40.                     {name: "Java/JDA", value: "Java"}
  41.                 )
  42.             )
  43.         )
  44.         .addSubcommand(command => command
  45.             .setName("status")
  46.             .setDescription("get infos about your server")
  47.             .addStringOption(option => option.setName("server-id").setDescription("please fill in your server url (https://panel.nexus-hosting.com/server/your-id)").setRequired(true))
  48.         )
  49.         .addSubcommand(command => command
  50.             .setName("delete")
  51.             .setDescription("Delete a server")
  52.             .addStringOption(option => option.setName("server-id").setDescription("Delete a server with the id").setRequired(true))
  53.         )
  54.     ),
  55.  
  56.     async execute (interaction, client) {
  57.         const {user, member, options} = interaction;
  58.         const c = options.getSubcommand()
  59.         const g = options.getSubcommandGroup();
  60.         const registers = await preRegister.findOne({ID: "Testing"});
  61.  
  62.         function checkEmail (email) {
  63.             const types = [
  64.                 "@gmail.com",
  65.                 "@proton.me",
  66.                 "@gmx.de",
  67.                 "@gmx.net",
  68.                 "@gmx.ch",
  69.                 "@gmx.at",
  70.                 "@web.de",
  71.                 "@icloud.com",
  72.                 "@yahoo.com",
  73.                 "@jason-dev.tech",
  74.                 "@nexus-hosting.tech",
  75.             ]
  76.  
  77.             const isValidEmail = types.some(domain => email.endsWith(domain));
  78.  
  79.             return isValidEmail;
  80.         }
  81.  
  82.         function checkPassword(password) {
  83.             if (password.length >= 8 && password.length <= 24) {
  84.                 if (/[!@#$%^&*()-_=+[ \]{};:'",.<>?/\\|`~]/.test(password)) {
  85.                    if (/\d/.test(password)) {
  86.                        if (/[A-Z]/.test(password)) {
  87.                            return true;
  88.                        }
  89.                    }
  90.                }
  91.            }
  92.            
  93.            return false;
  94.        }
  95.        
  96.        switch (g) {
  97.            case "account":
  98.                switch (c) {
  99.                    case "create":
  100.                        const mail = options.getString("email");
  101.                        const username = options.getString("username");
  102.                        const password = options.getString("password");
  103.  
  104.                        if (!registers) {
  105.                            await registers.create({ID: "Testing", Count: 1});
  106.                        } else {
  107.                            let count = registers.Count;
  108.  
  109.                            if (count >= 10) {
  110.                                await interaction.reply({
  111.                                    content: "Sorry, but there is no more pre register place for you :(",
  112.                                    ephemeral: true
  113.                                })
  114.                            }
  115.                            
  116.                            count++;
  117.                            await registers.deleteOne({ID: "Testing"});
  118.                            await registers.create({
  119.                                Count: count,
  120.                                ID: "Testing"
  121.                            })
  122.                        }
  123.  
  124.                        const mailCheck = checkEmail(mail);
  125.                        const passCheck = checkPassword(password)
  126.  
  127.                        if (!mailCheck.isValidEmail) {
  128.                            await interaction.reply({
  129.                                content: `\`${mail}\` is not a valid email!`,
  130.                                ephemeral: true
  131.                            })
  132.                        }
  133.  
  134.                        if (!passCheck) {
  135.                            const embed = new EmbedBuilder()
  136.                            .setDescription("Please use at least: \n- 1 Number \n- 1 Special Letter \n- 1 Cap letter \n- Min. 8 placeholders \n- Max. 24 Placeholders")
  137.                            await interaction.reply({
  138.                                embeds: [embed],
  139.                                ephemeral: true
  140.                            })
  141.                        }
  142.  
  143.                        const data = await Schema.findOne({ UserID: user.id })
  144.                        const data2 = await Schema.findOne({ Username: username });
  145.                        const data3 = await Schema.findOne({ Email: mail })
  146.  
  147.                        if (data) {
  148.                            await interaction.reply({
  149.                                content: "You already have an account!",
  150.                                ephemeral: true
  151.                            })
  152.                        } else if (data2) {
  153.                            await interaction.reply({
  154.                                content: `An account with the name __***${username}***__ already exists!`
  155.                            })
  156.                        } else if (data3) {
  157.                            await interaction.reply({
  158.                                content: "Sorry, this email already has been used!",
  159.                                ephemeral: true
  160.                            })
  161.                        }
  162.  
  163.                        const embed = new EmbedBuilder()
  164.                        .setTitle("Account Created")
  165.                        .setColor("White")
  166.                        .addFields(
  167.                            {name: "Username:", value: `||${username}||`, inline: true},
  168.                            {name: "Email:", value: `||${mail}||`, inline: true},
  169.                            {name: "Password:", value: `||${password}||`, inline: true}
  170.                        )
  171.  
  172.                        try {
  173.                            await Schema.create({
  174.                                UserID: member.id,
  175.                                Username: username,
  176.                                Email: mail,
  177.                                Coins: 0,
  178.                                Password: password,
  179.                                ServerMax: 3,
  180.                                TwoFA: false,
  181.                                RamMax: "512 MB",
  182.                                CPUcoresMax: 2,
  183.                                CPUUsageMax: 50,
  184.                            })
  185.                            await interaction.reply({
  186.                                embeds: [embed],
  187.                                ephemeral: true
  188.                            })
  189.                            await user.send({
  190.                                embeds: [embed]
  191.                            })
  192.                        } catch (err) {
  193.                            console.log(err);
  194.                        }
  195.                    break;
  196.                    case "delete":
  197.                    break;
  198.                }
  199.            break;
  200.            case "server":
  201.                await interaction.reply({
  202.                    content: "Sorry, this is currently under development!"
  203.                })
  204.                switch (c) {
  205.                    case "create":
  206.                    break;
  207.                    case "status":
  208.                    break;
  209.                    case "delete":
  210.                    break;
  211.                }
  212.            break;
  213.        }
  214.    }
  215. }
Advertisement
Add Comment
Please, Sign In to add comment