updated cleardatabase with chalk

This commit is contained in:
DJj123dj
2022-05-02 14:54:52 +02:00
parent 07de112f32
commit f163769de4
6 changed files with 66 additions and 36 deletions
+2 -2
View File
@@ -67,7 +67,7 @@ module.exports = () => {
.setDisabled(false)
.setStyle("DANGER")
.setLabel("Delete Ticket")
.setEmoji("❌")
.setEmoji("✖️")
)
var closeRowClosed = new discord.MessageActionRow()
.addComponents(
@@ -76,7 +76,7 @@ module.exports = () => {
.setDisabled(false)
.setStyle("DANGER")
.setLabel("Delete Ticket")
.setEmoji("❌")
.setEmoji("✖️")
)
.addComponents(
new discord.MessageButton()
+50 -25
View File
@@ -1,28 +1,53 @@
const fs = require('fs')
const dataPaths = ["./storage/tickets","./storage/transcripts","./storage/userTickets"]
var index = 0
dataPaths.forEach((path) => {
try {
fs.rmdirSync(path,{recursive:true,force:true})
}catch{
console.log(path,"doesn't exist")
}
setTimeout(() => {
try{
fs.mkdirSync(path)
}catch{
console.log(path,"already exists")
}
index++
},500)
const readline = require("readline")
const rl = readline.createInterface({
input:process.stdin,
output:process.stdout,
terminal:true
})
setInterval(() => {
if (index >= 3){
console.log("All local data is cleared!")
process.exit(1)
}
},500)
const ask = async () => {
const chalk = await (await import("chalk")).default
rl.question(chalk.yellow("WARNING: are you sure that there are",chalk.red("no tickets open"),"at the moment? ")+chalk.green("(yes/no)")+"\n",(answer) => {
if (answer != "1" && !answer.toLowerCase().startsWith("yes")){
console.log(chalk.red("invalid answer"))
ask()
return
}
console.log(chalk.green("clearing data..."))
runClear()
rl.close()
})
}
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"]
var index = 0
dataPaths.forEach((path) => {
try {
fs.rmdirSync(path,{recursive:true,force:true})
}catch{
console.log(path,"doesn't exist")
}
setTimeout(() => {
try{
fs.mkdirSync(path)
}catch{
console.log(path,"already exists")
}
index++
},500)
})
setInterval(() => {
if (index >= 3){
console.log(chalk.bgGreen("All local data is cleared!"))
process.exit(1)
}
},500)
}
+6 -1
View File
@@ -14,6 +14,7 @@ const transcriptStorage = bot.transcriptStorage
* @param {"delete"|"close"|"deletenotranscript"} mode
*/
exports.closeTicket = async (interaction,prefix,mode) => {
const chalk = await (await import("chalk")).default
const channelmessages = await interaction.channel.messages.fetch()
channelmessages.sweep((msgSweep) => {
@@ -29,6 +30,10 @@ exports.closeTicket = async (interaction,prefix,mode) => {
var getuserID = userTicketStorage.getItem(interaction.channel.id)
var getusernameStep1 = client.users.cache.find(u => u.id === getuserID)
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 enableTranscript = true
if (mode == "delete"){
@@ -61,7 +66,7 @@ exports.closeTicket = async (interaction,prefix,mode) => {
.setDisabled(false)
.setStyle("DANGER")
.setLabel("Delete Ticket")
.setEmoji("❌")
.setEmoji("✖️")
)
.addComponents(
new discord.MessageButton()
+1 -1
View File
@@ -25,7 +25,7 @@ module.exports = () => {
.setDisabled(false)
.setStyle("DANGER")
.setLabel("Delete Ticket")
.setEmoji("❌")
.setEmoji("✖️")
)
//ticket button click / create ticket