From 5a8ce0b215e0346201a8baeeabbbca07670d1cde Mon Sep 17 00:00:00 2001 From: sky Date: Wed, 27 Mar 2024 23:10:54 -0400 Subject: [PATCH] byod --- commands/fun/dice.js | 1 + commands/selenite/createBYOD.js | 17 ++++++ index.js | 49 +++++++++--------- package-lock.json | 91 +++++++++++++++++++++++++++++++++ package.json | 1 + utils.js | 50 +++++++++++++++++- 6 files changed, 182 insertions(+), 27 deletions(-) create mode 100644 commands/selenite/createBYOD.js diff --git a/commands/fun/dice.js b/commands/fun/dice.js index 95400fd..261ec8c 100644 --- a/commands/fun/dice.js +++ b/commands/fun/dice.js @@ -1,5 +1,6 @@ const { EmbedBuilder } = require("discord.js"); const { SlashCommandBuilder } = require("discord.js"); +const { runAI } = require("../../utils") module.exports = { data: new SlashCommandBuilder() diff --git a/commands/selenite/createBYOD.js b/commands/selenite/createBYOD.js new file mode 100644 index 0000000..444ddbd --- /dev/null +++ b/commands/selenite/createBYOD.js @@ -0,0 +1,17 @@ +const { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder, SlashCommandBuilder, PermissionsBitField } = require("discord.js"); + +module.exports = { + data: new SlashCommandBuilder().setName("createbyodembed").setDescription("dev command"), + async execute(interaction) { + if (interaction.isChatInputCommand() && interaction.channel.permissionsFor(interaction.user).has(PermissionsBitField.Flags.ManageGuild)) { + let byodEmbed = new EmbedBuilder().setTitle("Bring Your Own Domain").setDescription("Do you wish you could just create your own domain without the hassle of hosting it yourself?\n\nBring Your Own Domain allows you to simply create a domain using any service, point it to us, and we'll host it for you!"); + const link = new ButtonBuilder().setCustomId('byodA').setLabel('Click here to start!').setStyle(ButtonStyle.Primary); + const button = new ActionRowBuilder().addComponents(link); + await interaction.channel.send( + { embeds: [byodEmbed], + components: [button], + } + ); + } + }, +}; diff --git a/index.js b/index.js index 673a660..313acb3 100644 --- a/index.js +++ b/index.js @@ -4,6 +4,7 @@ const { Client, Collection, GatewayIntentBits, Events, EmbedBuilder } = require( const { token, widgets, logs_channel, links, dispenser_logs } = require("./config.json"); const client = new Client({ intents: ["Guilds", "GuildMessages", "GuildMembers", "MessageContent"], allowedMentions: { everyone: [false], roles: [false] } }); const Sequelize = require("sequelize"); +const { byod } = require("./utils"); const level = new Sequelize("database", "user", "password", { host: "localhost", dialect: "sqlite", @@ -104,39 +105,32 @@ client.login(token); client.on("messageDelete", (message) => { const logsChannel = client.channels.cache.get(logs_channel.toString()); - const delEmbed = new EmbedBuilder() - delEmbed.setColor("#db3c30") - delEmbed.setTitle("🗑️ message deleted") - delEmbed.setDescription( - `> **author:** <@${message.author.id}> \n> **channel:** <#${message.channel.id}> \n> **timestamp:** ` - ); + const delEmbed = new EmbedBuilder(); + delEmbed.setColor("#db3c30"); + delEmbed.setTitle("🗑️ message deleted"); + delEmbed.setDescription(`> **author:** <@${message.author.id}> \n> **channel:** <#${message.channel.id}> \n> **timestamp:** `); - if (message.content) { - delEmbed.addFields({name: 'message:', value: message.content}); - } + if (message.content) { + delEmbed.addFields({ name: "message:", value: message.content }); + } - // extra thing here to check if message has attachments - if (message.attachments.size > 0) { - const attachments = message.attachments.map((attachment) => attachment.url); - delEmbed.addFields({name: "attached:", value: attachments.join("\n")}); - } + // extra thing here to check if message has attachments + if (message.attachments.size > 0) { + const attachments = message.attachments.map((attachment) => attachment.url); + delEmbed.addFields({ name: "attached:", value: attachments.join("\n") }); + } - logsChannel.send({ embeds: [delEmbed] }); + logsChannel.send({ embeds: [delEmbed] }); }); client.on("messageUpdate", (oldm, newm) => { const logsChannel = client.channels.cache.get(logs_channel.toString()); if (oldm !== newm) { - const ediEmbed = new EmbedBuilder() - ediEmbed.setColor("#e2e833") - ediEmbed.setTitle("✍️ message edited") - ediEmbed.setDescription( - `> **author:** <@${oldm.author.id}> \n> **channel:** <#${oldm.channel.id}> \n> **timestamp:** ` - ); + const ediEmbed = new EmbedBuilder(); + ediEmbed.setColor("#e2e833"); + ediEmbed.setTitle("✍️ message edited"); + ediEmbed.setDescription(`> **author:** <@${oldm.author.id}> \n> **channel:** <#${oldm.channel.id}> \n> **timestamp:** `); - ediEmbed.addFields( - {name: 'before:', value: `${oldm}`, inline: true}, - {name: 'after:', value: `${newm}`, inline: true}, - ); + ediEmbed.addFields({ name: "before:", value: `${oldm}`, inline: true }, { name: "after:", value: `${newm}`, inline: true }); logsChannel.send({ embeds: [ediEmbed] }); } @@ -172,5 +166,10 @@ client.on("interactionCreate", async (interaction) => { return; } } + if(interaction.customId.includes("byod")) { + byod(interaction); + } + } else if (interaction.isModalSubmit()) { + byod(interaction); } }); diff --git a/package-lock.json b/package-lock.json index c1f5d7e..135c514 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "dependencies": { "@2toad/profanity": "^2.2.0", "@google/generative-ai": "^0.3.0", + "axios": "^1.6.8", "bad-words-next": "^2.2.1", "discord.js": "^14.12.1", "sequelize": "^6.34.0", @@ -323,6 +324,21 @@ "node": "^12.13.0 || ^14.15.0 || >=16.0.0" } }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" + }, + "node_modules/axios": { + "version": "1.6.8", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.8.tgz", + "integrity": "sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==", + "dependencies": { + "follow-redirects": "^1.15.6", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, "node_modules/bad-words-next": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/bad-words-next/-/bad-words-next-2.2.1.tgz", @@ -463,6 +479,17 @@ "color-support": "bin.js" } }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -522,6 +549,14 @@ "node": ">=4.0.0" } }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/delegates": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", @@ -631,6 +666,38 @@ "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==" }, + "node_modules/follow-redirects": { + "version": "1.15.6", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", + "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, + "node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/fs-constants": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz", @@ -919,6 +986,25 @@ "resolved": "https://registry.npmjs.org/micro-memoize/-/micro-memoize-4.1.2.tgz", "integrity": "sha512-+HzcV2H+rbSJzApgkj0NdTakkC+bnyeiUxgT6/m7mjcz1CmM22KYFKp+EVj1sWe4UYcnriJr5uqHQD/gMHLD+g==" }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, "node_modules/mimic-response": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-3.1.0.tgz", @@ -1252,6 +1338,11 @@ "node": ">=10" } }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + }, "node_modules/pump": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz", diff --git a/package.json b/package.json index 85841af..a515302 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "dependencies": { "@2toad/profanity": "^2.2.0", "@google/generative-ai": "^0.3.0", + "axios": "^1.6.8", "bad-words-next": "^2.2.1", "discord.js": "^14.12.1", "sequelize": "^6.34.0", diff --git a/utils.js b/utils.js index 7286e55..e14541a 100644 --- a/utils.js +++ b/utils.js @@ -1,6 +1,7 @@ -const { EmbedBuilder } = require("discord.js"); +const { EmbedBuilder, ModalBuilder, TextInputBuilder, TextInputStyle, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require("discord.js"); const { ai_key, logs_channel } = require("./config.json"); const { GoogleGenerativeAI } = require("@google/generative-ai"); +const axios = require("axios"); async function runAI(interaction, freaky) { try { @@ -35,4 +36,49 @@ async function runAI(interaction, freaky) { } -module.exports = { runAI } \ No newline at end of file + +async function byod(interaction) { + if(interaction.isModalSubmit()) { + if(interaction.fields.getTextInputValue("byodB_Input")) { + await interaction.reply({ content: 'Thank you! We are currently checking to see if it is valid.', ephemeral: true }); + const url = 'http://localhost:5674/add'; + const data = { domain: interaction.fields.getTextInputValue("byodB_Input") }; + try { + const response = await axios.post(url, data, { + headers: { + 'Content-Type': 'application/json' + } + }); + reason = "**Congrats!**\nYou have successfully created your own link.\nYou may post it to community links if you'd like, or just continue."; + } catch (error) { + if (error.response) { + reason = error.response.data; + } else if (error.request) { + reason = 'No response received\nmajor fuck up, should never happen. dm @skysthelimit.dev'; + } else { + reason = 'no response\nis the api down? dm @skysthelimit.dev' + } + } + await interaction.followUp({content: reason, ephemeral: true}); + } + } + if (interaction.customId === "byodA") { + let byodEmbed = new EmbedBuilder().setTitle("Bring Your Own Domain").setDescription("Before we begin, let's make sure you have a domain set up!\nThis may vary across whatever you're using.\n\n").addFields({ name: "FreeDNS", value: "This assumes that you've already found a link that you like.\nOnce you are on the link creating page, make sure the type is A, and that you set the destination to \"5.161.118.69\". After you're done, click Continue.", inline: true }, { name: "Cloudflare", value: 'This assumes you already have already bought a domain.\nGo into the DNS settings, and add a new record. If you want it on the top level (for example, selenite.cc), then set Name to @, but if you want it to be on a subdomain (for example, selenite.skys.day), then set Name to the subdomain you want (if my domain is skys.day and I wanted to have Selenite on selenite.skys.day, set name to selenite). Set the IPv4 address to "5.161.118.69", and make sure Proxy status is set to DNS Only, and **NOT** Proxied. Click Save.', inline: true }, { name: "\n", value: "**Once you're done, then wait a few minutes to make sure everything is saved and working, and click Continue.**\n**To submit a domain, please type it without any slashes or anything other than the domain. If you created a link such as \"https://selenite.cc/projects.html\", please only type \"selenite.cc\".**" }); + const link = new ButtonBuilder().setCustomId("byodB").setLabel("Continue").setStyle(ButtonStyle.Primary); + const button = new ActionRowBuilder().addComponents(link); + await interaction.reply({ embeds: [byodEmbed], components: [button], ephemeral: true }); + } else if (interaction.customId === "byodB") { + const modal = new ModalBuilder().setCustomId("byodModal").setTitle("Bring Your Own Domain"); + + const byodInput = new TextInputBuilder() + .setCustomId("byodB_Input") + .setMaxLength(70) + .setMinLength(5) + .setLabel("Insert your link below") + .setStyle(TextInputStyle.Short); + const firstActionRow = new ActionRowBuilder().addComponents(byodInput); + modal.addComponents(firstActionRow); + await interaction.showModal(modal); + } +} +module.exports = { runAI, byod } \ No newline at end of file