Skip to content
This repository has been archived by the owner on Jul 15, 2024. It is now read-only.

Commit

Permalink
fix: sentry api + filter when empty
Browse files Browse the repository at this point in the history
  • Loading branch information
wdhdev committed Jul 1, 2023
1 parent 5396d4a commit 0ecaa38
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 46 deletions.
15 changes: 3 additions & 12 deletions src/commands/dev/sentry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -96,28 +89,26 @@ 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
}).save()

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] });
Expand Down
4 changes: 1 addition & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,4 @@ client.validPermissions = [

// Start Sentry API
const sentryAPI = require("./sentry-api/index");
sentryAPI();

module.exports = client;
sentryAPI(client);
1 change: 0 additions & 1 deletion src/models/sentrySchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const mongoose = require("mongoose");

const schema = new mongoose.Schema({
_id: String,
project: String,
channel: String,
registered: String,
user: String
Expand Down
15 changes: 7 additions & 8 deletions src/sentry-api/endpoints/index.js
Original file line number Diff line number Diff line change
@@ -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);

Expand Down Expand Up @@ -124,15 +124,14 @@ 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")
)

const channel = client.channels.cache.get(data.channel);

channel.send({ embeds: [embed], components: [actions] });

res.status(200);
res.status(200).json({ "message": "The event has been recieved.", "code": "EVENT_RECIEVED" });
}
13 changes: 10 additions & 3 deletions src/sentry-api/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = async () => {
module.exports = async (client) => {
const express = require("express");
const app = express();

Expand All @@ -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());
Expand All @@ -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());

Expand Down
17 changes: 0 additions & 17 deletions src/sentry-api/util/router.js

This file was deleted.

4 changes: 2 additions & 2 deletions src/util/database/cleanFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
15 changes: 15 additions & 0 deletions src/util/sentry/color.js
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 0ecaa38

Please sign in to comment.