BUTTTOOOONNNNSSSS
This commit is contained in:
parent
92dee4c72b
commit
8f0fcded62
278
index.js
278
index.js
|
@ -1,6 +1,6 @@
|
||||||
const config = require("./config.json");
|
const config = require("./config.json");
|
||||||
const Discord = require("discord.js");
|
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")
|
const colors = require("colors")
|
||||||
var staffChannel;
|
var staffChannel;
|
||||||
client.on("ready", () => {
|
client.on("ready", () => {
|
||||||
|
@ -11,11 +11,11 @@ client.on("ready", () => {
|
||||||
var activeTickets = {};
|
var activeTickets = {};
|
||||||
|
|
||||||
client.on("messageCreate", async (msg) => {
|
client.on("messageCreate", async (msg) => {
|
||||||
if( !msg.author.id === config.ticket_bot ) return;
|
if (!msg.author.id === config.ticket_bot) return;
|
||||||
if( !msg.content.includes(config.ticket_detect_phrase)) return;
|
if (!msg.content.includes(config.ticket_detect_phrase)) return;
|
||||||
if( !msg.channel.name.startsWith(config.ticket_channel_prefix) ) return;
|
if (!msg.channel.name.startsWith(config.ticket_channel_prefix)) return;
|
||||||
let user = msg.mentions.users.first();
|
let user = msg.mentions.users.first();
|
||||||
if( !user ) return;
|
if (!user) return;
|
||||||
staffChannel.send({
|
staffChannel.send({
|
||||||
content: `${config.staff_ping ? config.staff_ping : ""} Ticket ${msg.channel} created by ${user} (${user.tag})`,
|
content: `${config.staff_ping ? config.staff_ping : ""} Ticket ${msg.channel} created by ${user} (${user.tag})`,
|
||||||
components: [
|
components: [
|
||||||
|
@ -39,6 +39,24 @@ client.on("messageCreate", async (msg) => {
|
||||||
emoji: {
|
emoji: {
|
||||||
name: "❌"
|
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] = {
|
activeTickets[m.id] = {
|
||||||
user: user,
|
user: user,
|
||||||
adminMessage: m,
|
adminMessage: m,
|
||||||
accepts: [],
|
counts: {
|
||||||
denies: []
|
accept: [],
|
||||||
|
deny: [],
|
||||||
|
question: [],
|
||||||
|
coven: []
|
||||||
|
},
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
client.on("interactionCreate", async (interaction) => {
|
client.on("interactionCreate", async (interaction) => {
|
||||||
// Check if its a button event
|
// 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)
|
// 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.",
|
content: "Something went wrong, this ticket is not seen as active/monitored. Please revert to using reactions.",
|
||||||
ephemeral: true
|
ephemeral: true
|
||||||
});
|
});
|
||||||
// Check if the user is staff, Just check for admin perm, you can add more checks if you want
|
// 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;
|
msg = activeTickets[interaction.message.id].adminMessage;
|
||||||
switch (interaction.customId) {
|
switch (interaction.customId) {
|
||||||
case "accept":
|
case "accept":
|
||||||
// If the user is already in the array, tell them with ephemeral message
|
// 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({
|
return await interaction.reply({
|
||||||
content: "You already accepted this ticket!",
|
content: "You already accepted this ticket!",
|
||||||
ephemeral: true
|
ephemeral: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// Add the interaction user to the accepts array
|
// Remove the other counts if the user is in them
|
||||||
activeTickets[interaction.message.id].accepts.push(interaction.user.id);
|
if (activeTickets[interaction.message.id].counts.deny.includes(interaction.user.id)) {
|
||||||
// If the user is in the deny array remove them
|
activeTickets[interaction.message.id].counts.deny = activeTickets[interaction.message.id].counts.deny.filter((id) => id !== interaction.user.id);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
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 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
|
// Remove roles from config.auto_accept.remove_roles array
|
||||||
config.auto_accept.remove_roles.forEach((role) => {
|
config.auto_accept.remove_roles.forEach((role) => {
|
||||||
interaction.guild.members.cache.get(activeTickets[interaction.message.id].user.id).roles.remove(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: [
|
components: [
|
||||||
{
|
{
|
||||||
type: 2,
|
type: 2,
|
||||||
label: `Accept (${activeTickets[interaction.message.id].accepts.length})`,
|
label: `Accept (${activeTickets[interaction.message.id].counts.accept.length})`,
|
||||||
style: 3,
|
style: 3,
|
||||||
custom_id: "accept",
|
custom_id: "accept",
|
||||||
emoji: {
|
emoji: {
|
||||||
|
@ -124,12 +152,30 @@ client.on("interactionCreate", async (interaction) => {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 2,
|
type: 2,
|
||||||
label: `Deny (${activeTickets[interaction.message.id].denies.length})`,
|
label: `Deny (${activeTickets[interaction.message.id].counts.deny.length})`,
|
||||||
style: 4,
|
style: 4,
|
||||||
custom_id: "deny",
|
custom_id: "deny",
|
||||||
emoji: {
|
emoji: {
|
||||||
name: "❌"
|
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;
|
break;
|
||||||
|
|
||||||
case "deny": // This one doesnt automatically do anything, its just a counter
|
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 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({
|
return await interaction.reply({
|
||||||
content: "You already denied this ticket!",
|
content: "You already denied this ticket!",
|
||||||
ephemeral: true
|
ephemeral: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// Add the interaction user to the denies array
|
// Remove the other counts if the user is in them
|
||||||
activeTickets[interaction.message.id].denies.push(interaction.user.id);
|
if (activeTickets[interaction.message.id].counts.accept.includes(interaction.user.id)) {
|
||||||
// If the user is in the accept array remove them
|
activeTickets[interaction.message.id].counts.accept = activeTickets[interaction.message.id].counts.accept.filter((id) => id !== interaction.user.id);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
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
|
// Update the message
|
||||||
msg.edit({
|
msg.edit({
|
||||||
content: msg.content,
|
content: msg.content,
|
||||||
|
@ -166,7 +219,7 @@ client.on("interactionCreate", async (interaction) => {
|
||||||
components: [
|
components: [
|
||||||
{
|
{
|
||||||
type: 2,
|
type: 2,
|
||||||
label: `Accept (${activeTickets[interaction.message.id].accepts.length})`,
|
label: `Accept (${activeTickets[interaction.message.id].counts.accept.length})`,
|
||||||
style: 3,
|
style: 3,
|
||||||
custom_id: "accept",
|
custom_id: "accept",
|
||||||
emoji: {
|
emoji: {
|
||||||
|
@ -175,12 +228,30 @@ client.on("interactionCreate", async (interaction) => {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 2,
|
type: 2,
|
||||||
label: `Deny (${activeTickets[interaction.message.id].denies.length})`,
|
label: `Deny (${activeTickets[interaction.message.id].counts.deny.length})`,
|
||||||
style: 4,
|
style: 4,
|
||||||
custom_id: "deny",
|
custom_id: "deny",
|
||||||
emoji: {
|
emoji: {
|
||||||
name: "❌"
|
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;
|
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
|
// Lets actually handle exceptions now
|
||||||
process.on('unhandledRejection', (error) => {
|
process.on('unhandledRejection', (error) => {
|
||||||
// Log a full error with line number
|
// 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 is set, Send the exception to ntfy
|
||||||
if (config.ntfyUrl) fetch(config.ntfyUrl, {
|
if (config.ntfyUrl) fetch(config.ntfyUrl, {
|
||||||
method: 'POST', // PUT works too
|
method: 'POST', // PUT works too
|
||||||
|
@ -214,7 +432,7 @@ process.on('unhandledRejection', (error) => {
|
||||||
|
|
||||||
process.on('uncaughtException', (error) => {
|
process.on('uncaughtException', (error) => {
|
||||||
// Log a full error with line number
|
// 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 is set, Send the exception to ntfy
|
||||||
if (config.ntfyUrl) fetch(config.ntfyUrl, {
|
if (config.ntfyUrl) fetch(config.ntfyUrl, {
|
||||||
method: 'POST', // PUT works too
|
method: 'POST', // PUT works too
|
||||||
|
|
Loading…
Reference in a new issue