diff --git a/src/commands/dev/sentry.js b/src/commands/dev/sentry.js index 5cd4349..b4a3a95 100644 --- a/src/commands/dev/sentry.js +++ b/src/commands/dev/sentry.js @@ -18,15 +18,8 @@ module.exports = { { type: 1, name: "register", - description: "[DEVELOPER ONLY] Register a Sentry project to capture issues.", + description: "[DEVELOPER ONLY] Register a Sentry capture URL to capture events.", options: [ - { - type: 3, - name: "project_id", - description: "The ID of the Sentry project.", - required: true - }, - { type: 7, name: "channel", @@ -96,13 +89,11 @@ module.exports = { if(interaction.options.getSubcommand() === "register") { const channel = interaction.options.getChannel("channel"); - const project = interaction.options.getString("project_id"); const id = require("crypto").randomUUID(); new sentrySchema({ _id: id, - project: project, channel: channel.id, registered: Date.now(), user: interaction.user.id @@ -110,14 +101,14 @@ module.exports = { const registered = new Discord.EmbedBuilder() .setColor(client.config_embeds.default) - .setDescription(`${emoji.successful} Sentry project \`${project}\` has been registered!`) + .setDescription(`${emoji.successful} A new capture URL has been registered!`) const actions = new Discord.ActionRowBuilder() .addComponents ( new Discord.ButtonBuilder() .setStyle(Discord.ButtonStyle.Secondary) .setCustomId(`capture-url-${id}`) - .setLabel("Get Capture URL") + .setLabel("Get URL") ) await interaction.editReply({ embeds: [registered], components: [actions] }); diff --git a/src/index.js b/src/index.js index ab3dbf6..8192d56 100644 --- a/src/index.js +++ b/src/index.js @@ -105,6 +105,4 @@ client.validPermissions = [ // Start Sentry API const sentryAPI = require("./sentry-api/index"); -sentryAPI(); - -module.exports = client; +sentryAPI(client); diff --git a/src/models/sentrySchema.js b/src/models/sentrySchema.js index fea594c..c9746f8 100644 --- a/src/models/sentrySchema.js +++ b/src/models/sentrySchema.js @@ -2,7 +2,6 @@ const mongoose = require("mongoose"); const schema = new mongoose.Schema({ _id: String, - project: String, channel: String, registered: String, user: String diff --git a/src/sentry-api/endpoints/index.js b/src/sentry-api/endpoints/index.js index 06b3a6f..3b43d3d 100644 --- a/src/sentry-api/endpoints/index.js +++ b/src/sentry-api/endpoints/index.js @@ -1,20 +1,20 @@ +const Discord = require("discord.js"); + const cap = require("../../util/cap"); +const getColor = require("../../util/sentry/color"); const parser = require("../../util/sentry/parser"); const schema = require("../../models/sentrySchema"); -module.exports = async (req, res, client, Discord) => { +module.exports = async (req, res, client) => { if(!await schema.exists({ _id: req.params.secret })) return res.status(401).json({ "message": "Invalid capture ID.", "code": "INVALID_ID" }); const data = await schema.findOne({ _id: req.params.secret }); - if(!req.body.project.id === data.project) return res.status(401).json({ "message": "Different project ID specified.", "code": "DIFFERENT_PROJECT" }); - const event = req.body; const embed = new Discord.EmbedBuilder() - .setColor(client.config_embeds.error) - .setAuthor({ name: `${req.body.project.name}` }) + .setAuthor({ name: `${event.project_name}` }) const projectName = parser.getProject(event); @@ -124,9 +124,8 @@ module.exports = async (req, res, client, Discord) => { const actions = new Discord.ActionRowBuilder() .addComponents ( new Discord.ButtonBuilder() - .setStyle(Discord.ButtonStyle.Secondary) + .setStyle(Discord.ButtonStyle.Success) .setCustomId(`sentry-resolve-${event.project.id}`) - .setEmoji("✅") .setLabel("Resolve") ) @@ -134,5 +133,5 @@ module.exports = async (req, res, client, Discord) => { channel.send({ embeds: [embed], components: [actions] }); - res.status(200); + res.status(200).json({ "message": "The event has been recieved.", "code": "EVENT_RECIEVED" }); } diff --git a/src/sentry-api/index.js b/src/sentry-api/index.js index ba73217..c6a367e 100644 --- a/src/sentry-api/index.js +++ b/src/sentry-api/index.js @@ -1,4 +1,4 @@ -module.exports = async () => { +module.exports = async (client) => { const express = require("express"); const app = express(); @@ -18,7 +18,6 @@ module.exports = async () => { tracesSampleRate: 1.0 }) - const router = require("./util/router"); const port = process.env.sentry_api_port; app.use(Sentry.Handlers.requestHandler()); @@ -28,7 +27,15 @@ module.exports = async () => { app.use(bodyParser.urlencoded({ extended: true })); app.use(express.json()); - app.use("/", router); + const routes = require("./util/routes"); + + app.get("/info/:secret", async (req, res) => { + routes.info(req, res); + }) + + app.post("/:secret", async (req, res) => { + routes.index(req, res, client); + }) app.use(Sentry.Handlers.errorHandler()); diff --git a/src/sentry-api/util/router.js b/src/sentry-api/util/router.js deleted file mode 100644 index 555e775..0000000 --- a/src/sentry-api/util/router.js +++ /dev/null @@ -1,17 +0,0 @@ -const { Router } = require("express"); - -const router = Router(); -const routes = require("./routes"); - -const client = require("../../index"); -const Discord = require("discord.js"); - -router.get("/info/:secret", async (req, res) => { - routes.info(req, res); -}) - -router.post("/:secret", async (req, res) => { - routes.index(req, res, client, Discord); -}) - -module.exports = router; diff --git a/src/util/database/cleanFilter.js b/src/util/database/cleanFilter.js index 503ac71..b0efa17 100644 --- a/src/util/database/cleanFilter.js +++ b/src/util/database/cleanFilter.js @@ -27,13 +27,13 @@ module.exports = async function cleanChannels() { await Promise.all(promises); - if(!autobanData.words.length) { + if(!autobanData.words.length && autobanData._id) { await autobanData.delete(); removedData.push("autoban"); } - if(!blockData.words.length) { + if(!blockData.words.length && blockData._id) { await blockData.delete(); removedData.push("block"); diff --git a/src/util/sentry/color.js b/src/util/sentry/color.js new file mode 100644 index 0000000..6f2bbf3 --- /dev/null +++ b/src/util/sentry/color.js @@ -0,0 +1,15 @@ +module.exports = function (level) { + switch (level) { + case "debug": + return parseInt("fbe14f", 16); + case "info": + return parseInt("2788ce", 16); + case "warning": + return parseInt("f18500", 16); + case "fatal": + return parseInt("d20f2a", 16); + case "error": + default: + return parseInt("e03e2f", 16); + } +}