BUTTTOOOONNNNSSSS

This commit is contained in:
Christopher Cookman 2024-03-10 16:46:33 -06:00
parent 92dee4c72b
commit 8f0fcded62
Signed by: ChrisChrome
GPG key ID: A023A26E42C33A42

278
index.js
View file

@ -1,6 +1,6 @@
const config = require("./config.json");
const Discord = require("discord.js");
const client = new Discord.Client({intents: ["Guilds", "GuildMembers", "GuildMessages", "MessageContent", "GuildMessageReactions", "DirectMessageReactions"]})
const client = new Discord.Client({ intents: ["Guilds", "GuildMembers", "GuildMessages", "MessageContent", "GuildMessageReactions", "DirectMessageReactions"] })
const colors = require("colors")
var staffChannel;
client.on("ready", () => {
@ -11,11 +11,11 @@ client.on("ready", () => {
var activeTickets = {};
client.on("messageCreate", async (msg) => {
if( !msg.author.id === config.ticket_bot ) return;
if( !msg.content.includes(config.ticket_detect_phrase)) return;
if( !msg.channel.name.startsWith(config.ticket_channel_prefix) ) return;
if (!msg.author.id === config.ticket_bot) return;
if (!msg.content.includes(config.ticket_detect_phrase)) return;
if (!msg.channel.name.startsWith(config.ticket_channel_prefix)) return;
let user = msg.mentions.users.first();
if( !user ) return;
if (!user) return;
staffChannel.send({
content: `${config.staff_ping ? config.staff_ping : ""} Ticket ${msg.channel} created by ${user} (${user.tag})`,
components: [
@ -39,6 +39,24 @@ client.on("messageCreate", async (msg) => {
emoji: {
name: "❌"
}
},
{
type: 2,
label: "Question (0)",
style: 1,
custom_id: "question",
emoji: {
name: "❓"
}
},
{
type: 2,
label: "Coven (0)",
style: 2,
custom_id: "coven",
emoji: {
name: "🔮"
}
}
]
}
@ -47,40 +65,50 @@ client.on("messageCreate", async (msg) => {
activeTickets[m.id] = {
user: user,
adminMessage: m,
accepts: [],
denies: []
counts: {
accept: [],
deny: [],
question: [],
coven: []
},
}
});
})
client.on("interactionCreate", async (interaction) => {
// Check if its a button event
if( !interaction.isButton() ) return;
if (!interaction.isButton()) return;
// Check if the button is on an active ticket (if not, just ignore it, it should never happen)
if( !activeTickets[interaction.message.id] ) return interaction.reply({
if (!activeTickets[interaction.message.id]) return interaction.reply({
content: "Something went wrong, this ticket is not seen as active/monitored. Please revert to using reactions.",
ephemeral: true
});
// Check if the user is staff, Just check for admin perm, you can add more checks if you want
if( !interaction.member.permissions.has("ADMINISTRATOR") ) return;
if (!interaction.member.permissions.has("ADMINISTRATOR")) return;
msg = activeTickets[interaction.message.id].adminMessage;
switch (interaction.customId) {
case "accept":
// If the user is already in the array, tell them with ephemeral message
if( activeTickets[interaction.message.id].accepts.includes(interaction.user.id) ) {
if (activeTickets[interaction.message.id].counts.accept.includes(interaction.user.id)) {
return await interaction.reply({
content: "You already accepted this ticket!",
ephemeral: true
});
}
// Add the interaction user to the accepts array
activeTickets[interaction.message.id].accepts.push(interaction.user.id);
// If the user is in the deny array remove them
if( activeTickets[interaction.message.id].denies.includes(interaction.user.id) ) {
activeTickets[interaction.message.id].denies = activeTickets[interaction.message.id].denies.filter((id) => id !== interaction.user.id);
// Remove the other counts if the user is in them
if (activeTickets[interaction.message.id].counts.deny.includes(interaction.user.id)) {
activeTickets[interaction.message.id].counts.deny = activeTickets[interaction.message.id].counts.deny.filter((id) => id !== interaction.user.id);
}
if (activeTickets[interaction.message.id].counts.question.includes(interaction.user.id)) {
activeTickets[interaction.message.id].counts.question = activeTickets[interaction.message.id].counts.question.filter((id) => id !== interaction.user.id);
}
if (activeTickets[interaction.message.id].counts.coven.includes(interaction.user.id)) {
activeTickets[interaction.message.id].counts.coven = activeTickets[interaction.message.id].counts.coven.filter((id) => id !== interaction.user.id);
}
// Add the interaction user to the accepts array
activeTickets[interaction.message.id].counts.accept.push(interaction.user.id);
// if statement, check if that makes the accepts go over the threshold for auto accept
if( activeTickets[interaction.message.id].accepts.length >= config.auto_accept.threshold ) {
if (activeTickets[interaction.message.id].counts.accept.length >= config.auto_accept.threshold) {
// Remove roles from config.auto_accept.remove_roles array
config.auto_accept.remove_roles.forEach((role) => {
interaction.guild.members.cache.get(activeTickets[interaction.message.id].user.id).roles.remove(role);
@ -115,7 +143,7 @@ client.on("interactionCreate", async (interaction) => {
components: [
{
type: 2,
label: `Accept (${activeTickets[interaction.message.id].accepts.length})`,
label: `Accept (${activeTickets[interaction.message.id].counts.accept.length})`,
style: 3,
custom_id: "accept",
emoji: {
@ -124,12 +152,30 @@ client.on("interactionCreate", async (interaction) => {
},
{
type: 2,
label: `Deny (${activeTickets[interaction.message.id].denies.length})`,
label: `Deny (${activeTickets[interaction.message.id].counts.deny.length})`,
style: 4,
custom_id: "deny",
emoji: {
name: "❌"
}
},
{
type: 2,
label: `Question (${activeTickets[interaction.message.id].counts.question.length})`,
style: 1,
custom_id: "question",
emoji: {
name: "❓"
}
},
{
type: 2,
label: `Coven (${activeTickets[interaction.message.id].counts.coven.length})`,
style: 2,
custom_id: "coven",
emoji: {
name: "🔮"
}
}
]
}
@ -142,21 +188,28 @@ client.on("interactionCreate", async (interaction) => {
});
break;
case "deny": // This one doesnt automatically do anything, its just a counter
// If the user is already in the array, tell them with ephemeral message
if( activeTickets[interaction.message.id].denies.includes(interaction.user.id) ) {
if (activeTickets[interaction.message.id].counts.deny.includes(interaction.user.id)) {
return await interaction.reply({
content: "You already denied this ticket!",
ephemeral: true
});
}
// Add the interaction user to the denies array
activeTickets[interaction.message.id].denies.push(interaction.user.id);
// If the user is in the accept array remove them
if( activeTickets[interaction.message.id].accepts.includes(interaction.user.id) ) {
activeTickets[interaction.message.id].accepts = activeTickets[interaction.message.id].accepts.filter((id) => id !== interaction.user.id);
// Remove the other counts if the user is in them
if (activeTickets[interaction.message.id].counts.accept.includes(interaction.user.id)) {
activeTickets[interaction.message.id].counts.accept = activeTickets[interaction.message.id].counts.accept.filter((id) => id !== interaction.user.id);
}
if (activeTickets[interaction.message.id].counts.question.includes(interaction.user.id)) {
activeTickets[interaction.message.id].counts.question = activeTickets[interaction.message.id].counts.question.filter((id) => id !== interaction.user.id);
}
if (activeTickets[interaction.message.id].counts.coven.includes(interaction.user.id)) {
activeTickets[interaction.message.id].counts.coven = activeTickets[interaction.message.id].counts.coven.filter((id) => id !== interaction.user.id);
}
// Add the interaction user to the denies array
activeTickets[interaction.message.id].counts.deny.push(interaction.user.id);
// Update the message
msg.edit({
content: msg.content,
@ -166,7 +219,7 @@ client.on("interactionCreate", async (interaction) => {
components: [
{
type: 2,
label: `Accept (${activeTickets[interaction.message.id].accepts.length})`,
label: `Accept (${activeTickets[interaction.message.id].counts.accept.length})`,
style: 3,
custom_id: "accept",
emoji: {
@ -175,12 +228,30 @@ client.on("interactionCreate", async (interaction) => {
},
{
type: 2,
label: `Deny (${activeTickets[interaction.message.id].denies.length})`,
label: `Deny (${activeTickets[interaction.message.id].counts.deny.length})`,
style: 4,
custom_id: "deny",
emoji: {
name: "❌"
}
},
{
type: 2,
label: `Question (${activeTickets[interaction.message.id].counts.question.length})`,
style: 1,
custom_id: "question",
emoji: {
name: "❓"
}
},
{
type: 2,
label: `Coven (${activeTickets[interaction.message.id].counts.coven.length})`,
style: 2,
custom_id: "coven",
emoji: {
name: "🔮"
}
}
]
}
@ -192,6 +263,153 @@ client.on("interactionCreate", async (interaction) => {
})
});
break;
case "question": // This one doesnt automatically do anything, its just a counter
// If the user is already in the array, tell them with ephemeral message
if (activeTickets[interaction.message.id].counts.question.includes(interaction.user.id)) {
return await interaction.reply({
content: "You already questioned this ticket!",
ephemeral: true
});
}
// Remove the other counts if the user is in them
if (activeTickets[interaction.message.id].counts.accept.includes(interaction.user.id)) {
activeTickets[interaction.message.id].counts.accept = activeTickets[interaction.message.id].counts.accept.filter((id) => id !== interaction.user.id);
}
if (activeTickets[interaction.message.id].counts.deny.includes(interaction.user.id)) {
activeTickets[interaction.message.id].counts.deny = activeTickets[interaction.message.id].counts.deny.filter((id) => id !== interaction.user.id);
}
if (activeTickets[interaction.message.id].counts.coven.includes(interaction.user.id)) {
activeTickets[interaction.message.id].counts.coven = activeTickets[interaction.message.id].counts.coven.filter((id) => id !== interaction.user.id);
}
// Add the interaction user to the questions array
activeTickets[interaction.message.id].counts.question.push(interaction.user.id);
// Update the message
msg.edit({
content: msg.content,
components: [
{
type: 1,
components: [
{
type: 2,
label: `Accept (${activeTickets[interaction.message.id].counts.accept.length})`,
style: 3,
custom_id: "accept",
emoji: {
name: "✅"
}
},
{
type: 2,
label: `Deny (${activeTickets[interaction.message.id].counts.deny.length})`,
style: 4,
custom_id: "deny",
emoji: {
name: "❌"
}
},
{
type: 2,
label: `Question (${activeTickets[interaction.message.id].counts.question.length})`,
style: 1,
custom_id: "question",
emoji: {
name: "❓"
}
},
{
type: 2,
label: `Coven (${activeTickets[interaction.message.id].counts.coven.length})`,
style: 2,
custom_id: "coven",
emoji: {
name: "🔮"
}
}
]
}
]
}).then(() => {
interaction.reply({
content: "You have questioned the ticket",
ephemeral: true
})
});
break;
case "coven": // This one doesnt automatically do anything, its just a counter
// If the user is already in the array, tell them with ephemeral message
if (activeTickets[interaction.message.id].counts.coven.includes(interaction.user.id)) {
return await interaction.reply({
content: "You already coven'd this ticket!",
ephemeral: true
});
}
// Remove the other counts if the user is in them
if (activeTickets[interaction.message.id].counts.accept.includes(interaction.user.id)) {
activeTickets[interaction.message.id].counts.accept = activeTickets[interaction.message.id].counts.accept.filter((id) => id !== interaction.user.id);
}
if (activeTickets[interaction.message.id].counts.deny.includes(interaction.user.id)) {
activeTickets[interaction.message.id].counts.deny = activeTickets[interaction.message.id].counts.deny.filter((id) => id !== interaction.user.id);
}
if (activeTickets[interaction.message.id].counts.question.includes(interaction.user.id)) {
activeTickets[interaction.message.id].counts.question = activeTickets[interaction.message.id].counts.question.filter((id) => id !== interaction.user.id);
}
// Add the interaction user to the covens array
activeTickets[interaction.message.id].counts.coven.push(interaction.user.id);
// Update the message
msg.edit({
content: msg.content,
components: [
{
type: 1,
components: [
{
type: 2,
label: `Accept (${activeTickets[interaction.message.id].counts.accept.length})`,
style: 3,
custom_id: "accept",
emoji: {
name: "✅"
}
},
{
type: 2,
label: `Deny (${activeTickets[interaction.message.id].counts.deny.length})`,
style: 4,
custom_id: "deny",
emoji: {
name: "❌"
}
},
{
type: 2,
label: `Question (${activeTickets[interaction.message.id].counts.question.length})`,
style: 1,
custom_id: "question",
emoji: {
name: "❓"
}
},
{
type: 2,
label: `Coven (${activeTickets[interaction.message.id].counts.coven.length})`,
style: 2,
custom_id: "coven",
emoji: {
name: "🔮"
}
}
]
}
]
});
interaction.reply({
content: "You suggested to send this ticket to the coven",
ephemeral: true
});
break;
}
});
@ -199,7 +417,7 @@ client.on("interactionCreate", async (interaction) => {
// Lets actually handle exceptions now
process.on('unhandledRejection', (error) => {
// Log a full error with line number
sendLog(`${colors.red("[ERROR]")} ${error}`);
console.log(`${colors.red("[ERROR]")} ${error}`);
// If config.ntfyUrl is set, Send the exception to ntfy
if (config.ntfyUrl) fetch(config.ntfyUrl, {
method: 'POST', // PUT works too
@ -214,7 +432,7 @@ process.on('unhandledRejection', (error) => {
process.on('uncaughtException', (error) => {
// Log a full error with line number
sendLog(`${colors.red("[ERROR]")} ${error}`);
console.log(`${colors.red("[ERROR]")} ${error}`);
// If config.ntfyUrl is set, Send the exception to ntfy
if (config.ntfyUrl) fetch(config.ntfyUrl, {
method: 'POST', // PUT works too