Skip to content

Commit

Permalink
Merge pull request #345 from discordextremelist/report-feature
Browse files Browse the repository at this point in the history
Add a report feature for bots, server and templates
  • Loading branch information
carolinaisslaying authored Mar 2, 2025
2 parents c2344e9 + c5b14ad commit ab384ae
Show file tree
Hide file tree
Showing 11 changed files with 624 additions and 28 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@
"prepare": "pnpm run snyk-protect",
"pretty": "npx prettier --write src/",
"sentry:build": "rm -rf dist/ && tsc",
"sentry:sourcemaps": "sentry-cli sourcemaps inject --org=delly --project=website --release=$npm_package_version ./dist && sentry-cli sourcemaps upload --org=delly --project=website --release=$npm_package_version ./dist"
"sentry:sourcemaps": "sentry-cli sourcemaps inject --org=delly --project=website --release=$npm_package_version ./dist && sentry-cli sourcemaps upload --org=delly --project=website --release=$npm_package_version ./dist",
"i18n:reinstall": "pnpm remove del-i18n && pnpm i discordextremelist/i18n --save"
},
"repository": {
"type": "git",
Expand Down
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion settings.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
"error": "‼️",
"notification": "🔔",
"warn": "⚠️",
"info": "ℹ️"
"info": "ℹ️",
"report": "<:warning_red:1345359504316960779>"
}
}
59 changes: 59 additions & 0 deletions src/Routes/bots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2014,6 +2014,65 @@ router.get(
}
);

router.post(
"/:id/report",
variables,
permission.auth,
async (req: Request, res: Response) => {
const bot = await botCache.getBot(req.params.id);

if (!bot)
return res.status(404).json({
error: true,
status: 404,
message: res.__("common.error.bot.404")
});

if (bot.owner.id === req.user.id)
return res.status(403).json({
error: true,
status: 403,
message: res.__("common.error.report.self")
});

try {
const embed = new Discord.EmbedBuilder();
embed.setColor(0x2f3136);
embed.setTitle("Bot Report");
embed.setURL(`${settings.website.url}/bots/${bot._id}`);
embed.addFields(
{ name: "Reason", value: req.body.reason ? req.body.reason : "None provided." },
{ name: "Additional information", value: req.body.additionalInfo ? req.body.additionalInfo : "None provided." },
);


await discord.channels.alerts
.send({
content: `${settings.emoji.report} **${functions.escapeFormatting(
req.user.db.fullUsername
)}** \`(${
req.user.id
})\` reported bot **${functions.escapeFormatting(
bot.name
)}** \`(${bot._id})\``,
embeds: [embed]
})

return res.status(200).json({
error: false,
status: 200,
message: res.__("common.report.done")
});
} catch (e) {
return res.status(500).json({
error: true,
status: 500,
message: res.__("common.error.report")
});
}
}
);

router.get(
"/:id/upvote",
variables,
Expand Down
59 changes: 59 additions & 0 deletions src/Routes/servers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,65 @@ router.get(
}
);

router.post(
"/:id/report",
variables,
permission.auth,
async (req: Request, res: Response) => {
const server = await serverCache.getServer(req.params.id);

if (!server)
return res.status(404).json({
error: true,
status: 404,
message: res.__("common.error.bot.404")
});

if (server.owner.id === req.user.id)
return res.status(403).json({
error: true,
status: 403,
message: res.__("common.error.report.self")
});

try {
const embed = new EmbedBuilder();
embed.setColor(0x2f3136);
embed.setTitle("Server Report");
embed.setURL(`${settings.website.url}/bots/${server._id}`);
embed.addFields(
{ name: "Reason", value: req.body.reason ? req.body.reason : "None provided." },
{ name: "Additional information", value: req.body.additionalInfo ? req.body.additionalInfo : "None provided." },
);


await discord.channels.alerts
.send({
content: `${settings.emoji.report} **${functions.escapeFormatting(
req.user.db.fullUsername
)}** \`(${
req.user.id
})\` reported server **${functions.escapeFormatting(
server.name
)}** \`(${server._id})\``,
embeds: [embed]
})

return res.status(200).json({
error: false,
status: 200,
message: res.__("common.report.done")
});
} catch (e) {
return res.status(500).json({
error: true,
status: 500,
message: res.__("common.error.report")
});
}
}
);

router.get(
"/:id/edit",
variables,
Expand Down
61 changes: 61 additions & 0 deletions src/Routes/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,67 @@ router.get(
}
);



router.post(
"/:id/report",
variables,
permission.auth,
async (req: Request, res: Response) => {
const template = await templateCache.getTemplate(req.params.id);

if (!template)
return res.status(404).json({
error: true,
status: 404,
message: res.__("common.error.bot.404")
});

if (template.owner.id === req.user.id)
return res.status(403).json({
error: true,
status: 403,
message: res.__("common.error.report.self")
});

try {
const embed = new EmbedBuilder();
embed.setColor(0x2f3136);
embed.setTitle("Template Report");
embed.setURL(`${settings.website.url}/bots/${template._id}`);
embed.addFields(
{ name: "Reason", value: req.body.reason ? req.body.reason : "None provided." },
{ name: "Additional information", value: req.body.additionalInfo ? req.body.additionalInfo : "None provided." },
);


await discord.channels.alerts
.send({
content: `${settings.emoji.report} **${functions.escapeFormatting(
req.user.db.fullUsername
)}** \`(${
req.user.id
})\` reported template **${functions.escapeFormatting(
template.name
)}** \`(${template._id})\``,
embeds: [embed]
})

return res.status(200).json({
error: false,
status: 200,
message: res.__("common.report.done")
});
} catch (e) {
return res.status(500).json({
error: true,
status: 500,
message: res.__("common.error.report")
});
}
}
);

router.get(
"/:id/edit",
variables,
Expand Down
65 changes: 65 additions & 0 deletions views/partials/cards/reportModalCard.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<header class="modal-card-head">
<p class="modal-card-title" id="reportModalTitle"><%= __("common.report.thing", name) %></p>
</header>
<section class="modal-card-body">
<div id="reportModalInner">
<p><%= __("common.report.note") %></p>
<br />
<div class="buttons">
<button class="button is-default is-fullwidth" onclick="reportFlow('<%= __("common.report.reason.nsfw") %>', 'NSFW Content');">
<span class="icon">
<i aria-hidden="true" class="fad fa-user-secret"></i>
</span>
<span><%= __("common.report.reason.nsfw") %></span>
</button>
<button class="button is-default is-fullwidth" onclick="reportFlow('<%= __("common.report.reason.scam") %>', 'Scam or Fraud');">
<span class="icon">
<i aria-hidden="true" class="fad fa-hand-holding-dollar"></i>
</span>
<span><%= __("common.report.reason.scam") %></span>
</button>
<button class="button is-default is-fullwidth" onclick="reportFlow('<%= __("common.report.reason.spam") %>', 'Spam');">
<span class="icon">
<i aria-hidden="true" class="fad fa-envelope-open-text"></i>
</span>
<span><%= __("common.report.reason.spam") %></span>
</button>
<% if (isBot) { %>
<button class="button is-default is-fullwidth" onclick="reportFlow('<%= __("page.bots.report.reason.apiAbuse") %>', 'API Abuse');">
<span class="icon">
<i aria-hidden="true" class="fad fa-code"></i>
</span>
<span><%= __("page.bots.report.reason.apiAbuse") %></span>
</button>
<button class="button is-default is-fullwidth" onclick="reportFlow('<%= __("page.bots.report.reason.clone") %>', 'Copycat / Clone');">
<span class="icon">
<i aria-hidden="true" class="fad fa-clone"></i>
</span>
<span><%= __("page.bots.report.reason.clone") %></span>
</button>
<button class="button is-default is-fullwidth" onclick="reportFlow('<%= __("page.bots.report.reason.unknownApplication") %>', 'Unknown Application on Invite');">
<span class="icon">
<i aria-hidden="true" class="fad fa-question-circle"></i>
</span>
<span><%= __("page.bots.report.reason.unknownApplication") %></span>
</button>
<% } else { %>
<button class="button is-default is-fullwidth" onclick="reportFlow('<%= __("common.report.reason.brokenLink") %>', 'Unknown Server or Template on Join');">
<span class="icon">
<i aria-hidden="true" class="fad fa-question-circle"></i>
</span>
<span><%= __("common.report.reason.brokenLink") %></span>
</button>
<% } %>
<button class="button is-default is-fullwidth" onclick="reportFlow('<%= __("common.report.reason.other") %>', 'Other');">
<span class="icon">
<i aria-hidden="true" class="fad fa-ellipsis"></i>
</span>
<span><%= __("common.report.reason.other") %></span>
</button>
</div>
</div>
</section>
<footer class="modal-card-foot" id="reportModalFooter">
<%= __("common.report.warning") %>
</footer>
4 changes: 1 addition & 3 deletions views/templates/bots/submit.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -587,8 +587,6 @@ function doSubmit() {
return response.json();
}
let modNotes = document.getElementById("modNotes").value;
fetchPOST("<%= linkPrefix %>/bots/submit", {
bot: document.getElementById("bot").checked,
Expand All @@ -615,7 +613,7 @@ function doSubmit() {
shortDescription: document.getElementById("form_shortDescription").value,
longDescription: document.getElementById("longDesc").value,
modNotes: modNotes,
modNotes: document.getElementById("modNotes").value,
supportServer: document.getElementById("form_supportServer").value,
website: document.getElementById("form_website").value,
Expand Down
Loading

0 comments on commit ab384ae

Please sign in to comment.