diff --git a/README.md b/README.md index 5118e8f..6316c59 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ The version above is unstable so if you find bugs, please report them in the dis # open-ticket -[![discord](https://img.shields.io/badge/discord-join%20our%20server-5865F2.svg?style=flat-square&logo=discord)](https://discord.com/invite/26vT9wt3n3) [![version](https://img.shields.io/badge/version-1.4.0%20unstable-red.svg?style=flat-square)](https://github.com/DJj123dj/open-ticket/releases/tag/v1.4.0) [![npm](https://img.shields.io/badge/npm-external%20libraries%20needed-CB3837.svg?style=flat-square&logo=npm)](#packages) [![license](https://img.shields.io/badge/license-GPL%203.0-important.svg?style=flat-square)](https://github.com/DJj123dj/open-ticket/blob/main/LICENSE) +[![discord](https://img.shields.io/badge/discord-join%20our%20server-5865F2.svg?style=flat-square&logo=discord)](https://discord.com/invite/26vT9wt3n3) [![version](https://img.shields.io/badge/version-2.0.0%20unstable-red.svg?style=flat-square)](https://github.com/DJj123dj/open-ticket/releases/tag/v2.0.0) [![npm](https://img.shields.io/badge/npm-external%20libraries%20needed-CB3837.svg?style=flat-square&logo=npm)](#packages) [![license](https://img.shields.io/badge/license-GPL%203.0-important.svg?style=flat-square)](https://github.com/DJj123dj/open-ticket/blob/main/LICENSE) This is an open-source discord ticket bot, you can configure it and it comes with cool features like transcripts & custom options! @@ -62,7 +62,7 @@ You can also configure your own permissions ## information -_v1.4.0 unstable_ +_v2.0.0 unstable_ changelog: [click here](./TEMPDOCS.md) diff --git a/TEMPDOCS.md b/TEMPDOCS.md index 334fb38..4188c3e 100644 --- a/TEMPDOCS.md +++ b/TEMPDOCS.md @@ -1,5 +1,5 @@ # documentation The documentation is not available here, go to the [wiki](https://github.com/DJj123dj/open-ticket/wiki) instead. (the wiki isn't fully done yet!) -## 1.4.0 beta -There is currently no documentation available for open-ticket v1.4.0 beta. So if you want to test it, you need to figure it out on yourself at the moment! \ No newline at end of file +## 2.0.0 beta +There is currently no documentation available for open-ticket v2.0.0 beta. So if you want to test it, you need to figure it out on yourself at the moment! \ No newline at end of file diff --git a/config.json b/config.json index 705dfc9..ffc16d0 100644 --- a/config.json +++ b/config.json @@ -78,7 +78,7 @@ "name":"Choose Your Ticket", "description":"You can click one of the buttons below!\nYou can also customize all the embeds now!", "enableFooter":true, - "footer":"Open Ticket v1.4.0 beta - sneakpeak", + "footer":"Open Ticket v2.0.0 beta - sneakpeak", "enableThumbnail":false, "thumbnail":"https://www.example.com/catmemes/cat.png", "color":"#0075e9", diff --git a/core/dynamicdatabase/cleardata.js b/core/dynamicdatabase/cleardata.js index a883d5a..c63acfd 100644 --- a/core/dynamicdatabase/cleardata.js +++ b/core/dynamicdatabase/cleardata.js @@ -24,7 +24,7 @@ ask() const runClear = async () => { const chalk = await (await import("chalk")).default console.log(chalk.blue("You can get a node.js warning below, just ignore that, it's not important!")) - const dataPaths = ["./storage/tickets","./storage/transcripts","./storage/userTickets"] + const dataPaths = ["./storage/dynamicDB"] var index = 0 @@ -32,20 +32,20 @@ const runClear = async () => { try { fs.rmdirSync(path,{recursive:true,force:true}) }catch{ - console.log(path,"doesn't exist") + //console.log(path,"doesn't exist") } setTimeout(() => { try{ fs.mkdirSync(path) }catch{ - console.log(path,"already exists") + //console.log(path,"already exists") } index++ },500) }) setInterval(() => { - if (index >= 3){ + if (index >= 1){ console.log(chalk.bgGreen("All local data is cleared!")) process.exit(1) } diff --git a/core/dynamicdatabase/dynamicfiles/local.js b/core/dynamicdatabase/dynamicfiles/local.js new file mode 100644 index 0000000..fec0b6c --- /dev/null +++ b/core/dynamicdatabase/dynamicfiles/local.js @@ -0,0 +1,39 @@ +const localstorage = require("node-localstorage") + +const ls = new localstorage.LocalStorage("./storage/dynamicDB") + +/** + * + * @param {String} category + * @param {String} id + * @param {String} value + * @returns {Boolean} + */ +exports.set = (category,id,value) => { + ls.setItem(category+"--"+id,value.toString()) + return true +} + +/** + * + * @param {String} category + * @param {String} id + * @returns {String|false} + */ +exports.get = (category,id) => { + const result = ls.getItem(category+"--"+id) + if (!result) return false + + return result +} + +/** + * + * @param {String} category + * @param {String} id + * @returns {Boolean} + */ +exports.delete = (category,id) => { + ls.removeItem(category+"--"+id) + return true +} \ No newline at end of file diff --git a/core/dynamicdatabase/storage.js b/core/dynamicdatabase/storage.js index 1af2cff..7405466 100644 --- a/core/dynamicdatabase/storage.js +++ b/core/dynamicdatabase/storage.js @@ -1,3 +1,18 @@ +//Do not change this without knowing what you are doing!! +const databaseFile = "local" +//Do not change this without knowing what you are doing!! + + +try { + var db = require("./dynamicfiles/local") +}catch{ + console.log("I couldn't find the database file! (location: ./core/dynamicdatabase/storage.js:2)") + process.exit(1) +} + +module.exports = db + + /** ============================= ** NOT READY YET ** must be dynamic diff --git a/core/ticketCloser.js b/core/ticketCloser.js index fad6168..cce6df6 100644 --- a/core/ticketCloser.js +++ b/core/ticketCloser.js @@ -3,9 +3,7 @@ const bot = require('../index') const client = bot.client const config = bot.config -const ticketStorage = bot.TicketStorage -const userTicketStorage = bot.userTicketStorage -const transcriptStorage = bot.transcriptStorage +const storage = bot.storage /** * @@ -27,11 +25,17 @@ exports.closeTicket = async (interaction,prefix,mode) => { const ticketuserarray = interaction.channel.name const ticketusername = ticketuserarray.split(prefix)[1] - var getuserID = userTicketStorage.getItem(interaction.channel.id) - var getusernameStep1 = client.users.cache.find(u => u.id === getuserID) + var getuserID = storage.get("userTicketStorage",interaction.channel.id) + try { + var getusernameStep1 = client.users.cache.find(u => u.id === getuserID) + var isDatabaseError = false + }catch{ + var isDatabaseError = true + } if (!getusernameStep1){ console.log(chalk.red("[database error]"),"something went wrong when getting the data in the database.\nNo panic, this error fixes itself!") + var isDatabaseError = true } var enableTranscript = true @@ -40,10 +44,10 @@ exports.closeTicket = async (interaction,prefix,mode) => { interaction.channel.delete() if (config.logs){console.log("[system] deleted a ticket (name:"+interaction.channel.name+",user:"+interaction.user.username+")")} - ticketStorage.setItem(getuserID,Number(ticketStorage.getItem(getuserID)) - 1) + if (!isDatabaseError) storage.set("ticketStorage",getuserID,Number(storage.get("ticketStorage",getuserID)) - 1) }else if (mode == "close"){ var permissionArray = [] - permissionArray.push({ + if (!isDatabaseError) permissionArray.push({ id:getusernameStep1.id, type:"member", allow:["VIEW_CHANNEL"], @@ -86,7 +90,7 @@ exports.closeTicket = async (interaction,prefix,mode) => { interaction.channel.delete() if (config.logs){console.log("[system] deleted a ticket (name:"+interaction.channel.name+",user:"+interaction.user.username+")")} - ticketStorage.setItem(getuserID,Number(ticketStorage.getItem(getuserID)) - 1) + if (!isDatabaseError) storage.set("ticketStorage",getuserID,Number(storage.get("ticketStorage",getuserID)) - 1) } if (enableTranscript == true && mode != "deletenotranscript"){ @@ -96,12 +100,6 @@ exports.closeTicket = async (interaction,prefix,mode) => { if (fileattachment == false){console.log("[transcript] internal error: no transcript is created!");return} } - - if (getusernameStep1 == null || getusernameStep1 == undefined || getusernameStep1 == false || getusernameStep1 == ""){ - var getuserNAME = ":usernotfound:" - }else { - var getuserNAME = getusernameStep1.username - } if (config.system.enable_transcript){ const transcriptEmbed = new discord.MessageEmbed() @@ -124,7 +122,7 @@ exports.closeTicket = async (interaction,prefix,mode) => { .setDescription("You can find the transcript in the text file above!") .setFooter({text:"ticket: "+ticketuserarray}) - getusernameStep1.send({ + if (!isDatabaseError) getusernameStep1.send({ embeds:[transcriptEmbed], files:[fileattachment] }) diff --git a/core/ticketOpener.js b/core/ticketOpener.js index 6bfcc31..9cdb293 100644 --- a/core/ticketOpener.js +++ b/core/ticketOpener.js @@ -4,10 +4,7 @@ const client = bot.client const config = bot.config const getconfigoptions = require("./getoptions") - -const ticketStorage = bot.TicketStorage -const userTicketStorage = bot.userTicketStorage -const transcriptStorage = bot.transcriptStorage +const storage = bot.storage module.exports = () => { var closeButton = new discord.MessageActionRow() @@ -47,7 +44,7 @@ module.exports = () => { //ticketoptions from config const currentTicketOptions = getconfigoptions.getOptionsById(customId) - if (ticketStorage.getItem(interaction.member.id) == null || ticketStorage.getItem(interaction.member.id) == "false"|| Number(ticketStorage.getItem(interaction.member.id)) < config.system.max_allowed_tickets){ + if (storage.get("ticketStorage",interaction.member.id) == null || storage.get("ticketStorage",interaction.member.id) == "false"|| Number(storage.get("ticketStorage",interaction.member.id)) < config.system.max_allowed_tickets){ try{ if (config.system.enable_DM_Messages){ @@ -59,7 +56,7 @@ module.exports = () => { //update storage - ticketStorage.setItem(interaction.member.id,Number(ticketStorage.getItem(interaction.member.id))+1) + storage.set("ticketStorage",interaction.member.id,Number(storage.get("ticketStorage",interaction.member.id))+1) var ticketNumber = interaction.member.user.username //set ticketName @@ -139,7 +136,7 @@ module.exports = () => { permissionOverwrites:permissionsArray }).then((ticketChannel) => { - userTicketStorage.setItem(ticketChannel.id,interaction.member.id) + storage.set("userTicketStorage",ticketChannel.id,interaction.member.id) var ticketEmbed = new discord.MessageEmbed() .setColor(config.main_color) diff --git a/index.js b/index.js index c52ac69..f4f88f7 100644 --- a/index.js +++ b/index.js @@ -50,10 +50,7 @@ client.on('ready',async () => { if (process.argv[2] != "slash"){ var storage = require('./core/dynamicdatabase/storage') - exports.TicketStorage = storage.ticketStorage - exports.userTicketStorage = storage.userTicketStorage - exports.transcriptStorage = storage.transcriptStorage - exports.ticketNumberStorage = storage.ticketNumberStorage + exports.storage = storage //commands require('./commands/ticket')() diff --git a/package.json b/package.json index 7b11fa2..21b6826 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "open-ticket", - "version": "1.3.2", + "version": "2.0.0", "description": "This is an open-source discord ticket bot, you can configure it and it comes with cool features like a transcript.", "main": "index.js", "scripts": { diff --git a/storage/tickets/779742674932072469 b/storage/tickets/779742674932072469 deleted file mode 100644 index 56a6051..0000000 --- a/storage/tickets/779742674932072469 +++ /dev/null @@ -1 +0,0 @@ -1 \ No newline at end of file diff --git a/storage/userTickets/971449683379646526 b/storage/userTickets/971449683379646526 deleted file mode 100644 index 71d7104..0000000 --- a/storage/userTickets/971449683379646526 +++ /dev/null @@ -1 +0,0 @@ -779742674932072469 \ No newline at end of file diff --git a/storage/userTickets/971471181670662204 b/storage/userTickets/971471181670662204 deleted file mode 100644 index 71d7104..0000000 --- a/storage/userTickets/971471181670662204 +++ /dev/null @@ -1 +0,0 @@ -779742674932072469 \ No newline at end of file