diff --git a/API/server.js b/API/server.js index 49205e1..48913ea 100644 --- a/API/server.js +++ b/API/server.js @@ -649,8 +649,11 @@ h1{font-size:1.25rem}a{color:#a78bfa}
return res.status(404).json({ success: false, error: 'No connected Discord server found.' }); } - const deptKey = department || supportbot.Ticket?.DepartmentSystem?.DefaultDepartment || 'general'; - const deptConfig = supportbot.Ticket?.DepartmentSystem?.Departments?.[deptKey]; + const supportbot = configStore.supportbot; + const cmdconfig = configStore.commands; + + const deptKey = department || supportbot?.Ticket?.DepartmentSystem?.DefaultDepartment || 'general'; + const deptConfig = supportbot?.Ticket?.DepartmentSystem?.Departments?.[deptKey]; if (deptConfig && deptConfig.Enabled === false) { return res.status(400).json({ success: false, error: `Ticket department '${deptKey}' is currently disabled.` }); } @@ -661,19 +664,28 @@ h1{font-size:1.25rem}a{color:#a78bfa} targetUser = this.client.user; } - const openCmd = this.client.commands.get(cmdconfig.OpenTicket?.Command || "new"); + const openCmd = this.client.commands.get(cmdconfig?.OpenTicket?.Command || "new"); if (!openCmd) { return res.status(500).json({ success: false, error: 'Open ticket command not found in bot.' }); } const fakeInteraction = { + client: this.client, guild, user: targetUser, member: await guild.members.fetch(targetUser.id).catch(() => null), channel: guild.channels.cache.first(), department: deptKey, reason: subject || reason || "Opened via Web Dashboard", - priority: deptConfig?.DefaultPriority || supportbot.Ticket?.PrioritySystem?.DefaultPriority || "medium", + priority: deptConfig?.DefaultPriority || supportbot?.Ticket?.PrioritySystem?.DefaultPriority || "medium", + options: { + getString: (name) => { + if (name === "department") return deptKey; + if (name === "reason") return subject || reason || "Opened via Web Dashboard"; + if (name === "priority") return deptConfig?.DefaultPriority || supportbot?.Ticket?.PrioritySystem?.DefaultPriority || "medium"; + return null; + } + }, isCommand: () => false, isChatInputCommand: () => false, isButton: () => false, diff --git a/Structures/Database.js b/Structures/Database.js index 381f970..20576fa 100644 --- a/Structures/Database.js +++ b/Structures/Database.js @@ -355,6 +355,13 @@ function initMySQL() { } } catch (err) { console.error("[Database] Error initializing MySQL tables or state:", err.message); + console.warn("[Database] Falling back to SQLite database."); + mysqlReady = false; + if (mysqlPool) { + try { mysqlPool.end(); } catch (e) {} + mysqlPool = null; + } + initSQLite(); } })(); } @@ -449,7 +456,7 @@ function persistTicket(ticketId) { const t = state.tickets[ticketId]; if (!t) return; - if (isMySQL && mysqlPool) { + if (isMySQL && mysqlReady && mysqlPool) { const sql = ` INSERT INTO tickets ( ticket_id, user_id, subject, description, department, priority, status, @@ -526,7 +533,7 @@ function persistTicket(ticketId) { } function persistPanel(panelRow) { - if (isMySQL && mysqlPool) { + if (isMySQL && mysqlReady && mysqlPool) { mysqlPool.query( "INSERT INTO ticket_panels (id, message_id, channel_id, created_at) VALUES (?, ?, ?, ?)", [panelRow.id, panelRow.message_id, panelRow.channel_id, panelRow.created_at], @@ -542,7 +549,7 @@ function persistPanel(panelRow) { function persistTicketUser(ticketId, userId, action = "add") { if (action === "add") { - if (isMySQL && mysqlPool) { + if (isMySQL && mysqlReady && mysqlPool) { mysqlPool.query("INSERT IGNORE INTO ticket_users (ticket_id, user_id) VALUES (?, ?)", [ticketId, userId], (err) => { if (err) console.error("[Database] MySQL persistTicketUser error:", err.message); }); @@ -550,7 +557,7 @@ function persistTicketUser(ticketId, userId, action = "add") { sqliteDb.prepare("INSERT OR IGNORE INTO ticket_users (ticket_id, user_id) VALUES (?, ?)").run(ticketId, userId); } } else { - if (isMySQL && mysqlPool) { + if (isMySQL && mysqlReady && mysqlPool) { mysqlPool.query("DELETE FROM ticket_users WHERE ticket_id = ? AND user_id = ?", [ticketId, userId], (err) => { if (err) console.error("[Database] MySQL deleteTicketUser error:", err.message); }); @@ -564,7 +571,7 @@ function persistProfile(userId) { const p = state.profiles[userId]; if (!p) return; - if (isMySQL && mysqlPool) { + if (isMySQL && mysqlReady && mysqlPool) { const sql = ` INSERT INTO profiles (user_id, bio, timezone, clocked_in) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE bio=VALUES(bio), timezone=VALUES(timezone), clocked_in=VALUES(clocked_in); @@ -600,13 +607,13 @@ function persistSettings() { } function persistBlacklistedUser(userId, action = "add") { - if (isMySQL && !mysqlReady) { + if (isMySQL && mysqlReady && !mysqlPool) { mysqlWriteQueue.push(() => persistBlacklistedUser(userId, action)); return; } const b = state.blacklisted_users[userId]; if (action === "add" && b) { - if (isMySQL && mysqlPool) { + if (isMySQL && mysqlReady && mysqlPool) { const sql = ` INSERT INTO blacklisted_users (user_id, reason, added_by, created_at) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE reason=VALUES(reason), added_by=VALUES(added_by), created_at=VALUES(created_at); @@ -622,7 +629,7 @@ function persistBlacklistedUser(userId, action = "add") { stmt.run(b.user_id, b.reason || "", b.added_by || "", b.created_at || Date.now()); } } else { - if (isMySQL && mysqlPool) { + if (isMySQL && mysqlReady && mysqlPool) { mysqlPool.query("DELETE FROM blacklisted_users WHERE user_id = ?", [userId], (err) => { if (err) console.error("[Database] MySQL removeBlacklistedUser error:", err.message); }); diff --git a/public/dashboard/assets/index-xYh1zX07.js b/public/dashboard/assets/index-CzmlDpil.js similarity index 52% rename from public/dashboard/assets/index-xYh1zX07.js rename to public/dashboard/assets/index-CzmlDpil.js index 88ecbca..69799bc 100644 --- a/public/dashboard/assets/index-xYh1zX07.js +++ b/public/dashboard/assets/index-CzmlDpil.js @@ -1,4 +1,4 @@ -var w3=Object.defineProperty;var xy=t=>{throw TypeError(t)};var j3=(t,n,a)=>n in t?w3(t,n,{enumerable:!0,configurable:!0,writable:!0,value:a}):t[n]=a;var vy=(t,n,a)=>j3(t,typeof n!="symbol"?n+"":n,a),by=(t,n,a)=>n.has(t)||xy("Cannot "+a);var pn=(t,n,a)=>(by(t,n,"read from private field"),a?a.call(t):n.get(t)),yy=(t,n,a)=>n.has(t)?xy("Cannot add the same private member more than once"):n instanceof WeakSet?n.add(t):n.set(t,a),dp=(t,n,a,o)=>(by(t,n,"write to private field"),o?o.call(t,a):n.set(t,a),a);function C3(t,n){for(var a=0;are?(P.sortIndex=ae,n(g,P),a(p)===null&&P===a(g)&&(S?(N(L),L=-1):S=!0,se(_,ae-re))):(P.sortIndex=V,n(p,P),C||y||(C=!0,R||(R=!0,Y()))),P},t.unstable_shouldYield=I,t.unstable_wrapCallback=function(P){var Z=w;return function(){var ae=w;w=Z;try{return P.apply(this,arguments)}finally{w=ae}}}})(gp)),gp}var Ey;function T3(){return Ey||(Ey=1,hp.exports=k3()),hp.exports}var xp={exports:{}},hn={};/**
+ */var Ny;function k3(){return Ny||(Ny=1,(function(t){function n(P,W){var oe=P.length;P.push(W);e:for(;0 ae?(P.sortIndex=oe,n(g,P),a(p)===null&&P===a(g)&&(S?(T(L),L=-1):S=!0,se(_,oe-ae))):(P.sortIndex=G,n(p,P),C||y||(C=!0,R||(R=!0,q()))),P},t.unstable_shouldYield=I,t.unstable_wrapCallback=function(P){var W=w;return function(){var oe=w;w=W;try{return P.apply(this,arguments)}finally{w=oe}}}})(gp)),gp}var Ey;function T3(){return Ey||(Ey=1,hp.exports=k3()),hp.exports}var xp={exports:{}},hn={};/**
* @license React
* react-dom.production.js
*
@@ -30,7 +30,7 @@ var w3=Object.defineProperty;var xy=t=>{throw TypeError(t)};var j3=(t,n,a)=>n in
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
- */var ky;function M3(){if(ky)return hn;ky=1;var t=Xh();function n(p){var g="https://react.dev/errors/"+p;if(1