v3.2 push 2

This commit is contained in:
DJj123dj
2023-01-17 22:25:20 +01:00
parent 7ed2d7bcc7
commit b698c89a89
6 changed files with 159 additions and 243 deletions
-75
View File
@@ -1,75 +0,0 @@
const discord = require('discord.js')
const bot = require('../index')
const client = bot.client
const config = bot.config
const l = bot.language
/** @param {discord.TextBasedChannel} channel @returns {Promise<{ticketname:String,ticketopener:{discordjsuser:discord.User,name:String,id:String}>} */
const getUserInfo = (channel) => {
return new Promise((promiseresolve,reject) => {
//getID
var result = {
ticketopener:{
discordjsuser:"",
id:"/",
name:"/"
},
ticketname:"/"
}
channel.messages.fetchPinned().then(msglist => {
var firstmsg = msglist.last()
if (firstmsg == undefined || firstmsg.author.id != client.user.id) return false
const hiddendata = bot.hiddenData.readHiddenData(firstmsg.embeds[0].description)
const ticketId = hiddendata.data.find(d => d.key == "type")
const id = hiddendata.data.find(d => d.key == "openerid").value
result.ticketopener.id = id
const ticketopener = client.users.cache.find(u => u.id == id)
const name = ticketopener.tag
const channelname = channel.name
promiseresolve({ticketname:channelname,ticketopener:{discordjsuser:ticketopener,name:name,id:id}})
})
})
}
/**
*
* @param {discord.Message[]} messagecollection
* @param {discord.Channel} channel
* @returns new `discord.attachmentBuilder`
*/
exports.createTranscript = async (messagecollection,channel) => {
const ticketuserdata = await getUserInfo(channel)
require("./api/modules/events").onTranscriptCreation(messagecollection,channel,channel.guild,new Date())
try {
const cd = new Date()
const months = ["January","February","March","April","May","June","July","August","September","October","November","December"]
const dateString = cd.getDate()+" "+months[cd.getMonth()-1]+" "+cd.getFullYear()+" - "+cd.getHours()+":"+cd.getMinutes()+":"+cd.getSeconds()
const filearray = ["open ticket transcript:\ntranscript creation: "+dateString+"\nticket name: "+ticketuserdata.ticketname+"\nticket opener: "+ticketuserdata.ticketopener.name,"\nTRANSCRIPT START:"]
messagecollection.reverse()
messagecollection.forEach((msg) => {
const timestamp = new Date(msg.createdTimestamp)
if (msg.content){var content = msg.content}else{var content = "*empty message*"}
const msgstats = "files: "+msg.attachments.size+", embeds: "+msg.embeds.length
filearray.push("["+timestamp.getDate()+"/"+timestamp.getMonth()+"/"+timestamp.getFullYear()+", "+timestamp.getHours()+":"+timestamp.getMinutes()+":"+timestamp.getSeconds()+"|"+msg.author.tag+"] ["+msgstats+"]\n"+content+"\n")
})
if (filearray.length < 2) filearray.push("transcript is empty")
const filestring = filearray.join("\n")
const filebuff = Buffer.from(filestring,"utf-8")
return new discord.AttachmentBuilder(filebuff,{name:"transcript_"+ticketuserdata.ticketname+".txt",description:"An Open Ticket transcript"})
}catch(err){
console.log("[error] "+err)
return false
}
}
@@ -30,50 +30,55 @@ exports.compile = (guild,channel,user,messagesInv,data) => {
const messagesArray = []
messages.forEach((msg) => {
const embedArray = []
const fileArray = []
msg.attachments.forEach((file) => {
fileArray.push({
name:file.name,
type:file.contentType,
size:file.size.toString()+" bytes",
url:file.url
console.log("'"+msg.content+"'",msg.embeds.length,msg.attachments.toJSON().length)
if (msg.content || msg.embeds.length > 0 || msg.attachments.toJSON().length > 0){
const embedArray = []
const fileArray = []
msg.attachments.forEach((file) => {
fileArray.push({
name:file.name,
type:file.contentType,
size:file.size.toString()+" bytes",
url:file.url
})
})
})
msg.embeds.forEach((embed) => {
if (embed.description){
var desc = bot.hiddenData.removeHiddenData(embed.description).description
}else{var desc = false}
msg.embeds.forEach((embed) => {
if (embed.description){
var desc = bot.hiddenData.removeHiddenData(embed.description).description
}else{var desc = false}
embedArray.push({
title:embed.title || false,
description:desc,
authorimg:((embed.author && embed.author.iconURL) ? embed.author.iconURL : false),
authortext:(embed.author ? embed.author.name : false),
footerimg:((embed.footer && embed.footer.iconURL) ? embed.footer.iconURL : false),
footertext:(embed.footer ? embed.footer.text : false),
color:embed.hexColor,
image:((embed.image && embed.image.url) ? embed.image.url : false),
thumbnail:((embed.thumbnail && embed.thumbnail.url) ? embed.thumbnail.url : false),
url:(embed.url ? embed.url : false)
embedArray.push({
title:embed.title || false,
description:desc,
authorimg:((embed.author && embed.author.iconURL) ? embed.author.iconURL : false),
authortext:(embed.author ? embed.author.name : false),
footerimg:((embed.footer && embed.footer.iconURL) ? embed.footer.iconURL : false),
footertext:(embed.footer ? embed.footer.text : false),
color:embed.hexColor,
image:((embed.image && embed.image.url) ? embed.image.url : false),
thumbnail:((embed.thumbnail && embed.thumbnail.url) ? embed.thumbnail.url : false),
url:(embed.url ? embed.url : false)
})
})
})
messagesArray.push({
author:{
name:msg.author.tag,
id:Number(msg.author.id),
color:msg.author.hexAccentColor || "#ffffff",
pfp:msg.author.displayAvatarURL()
},
content:msg.content || "",
timestamp:msg.createdTimestamp,
embeds:embedArray,
files:fileArray
})
messagesArray.push({
author:{
name:msg.author.tag,
id:Number(msg.author.id),
color:msg.author.hexAccentColor || "#ffffff",
pfp:msg.author.displayAvatarURL()
},
content:msg.content || "",
timestamp:msg.createdTimestamp,
embeds:embedArray,
files:fileArray
})
}
})
const result = {
+21 -3
View File
@@ -16,7 +16,7 @@ const tsconfig = bot.tsconfig
*/
exports.beingprocessed = (name,id,rawprocesstime,user) => {
const newtime = new Date(new Date().getTime() + rawprocesstime)
const newtime = rawprocesstime
const processtime = "<t:"+newtime.getTime().toString().substring(0,newtime.getTime().toString().length-3)+":R>"
@@ -47,7 +47,25 @@ exports.tsready = (name,id,url,user) => {
.setFooter({text:name})
.setURL(url)
.setDescription("The transcript is available [here]("+url+")")
.setDescription("\nThe transcript is available [here]("+url+")\n")
return embed
}
}
/**
*
* @param {String} name
* @param {String} id
* @param {discord.User} user
*/
exports.tserror = (name,id,user) => {
const embed = new discord.EmbedBuilder()
.setTitle("❌ Transcript")
.setColor(discord.Colors.Red)
.setAuthor({name:user.tag,iconURL:user.displayAvatarURL()})
.setFooter({text:name})
.setDescription("Something went wrong while creating the HTML transcript.\n\n[possible reasons](https://docs.openticket.dj-dj.be/the-system/transcripts/transcript-errors)")
return embed
}
+58 -23
View File
@@ -10,6 +10,16 @@ const tsconfig = bot.tsconfig
const tsembeds = require("./embeds")
const tsdb = require("./tsdb")
const checkAvailability = async () => {
const axios = require("axios").default
const res = await axios.get("https://transcripts.dj-dj.be/status.txt")
if (!res || !(res.status == 200) || !res.data) return false
if ((res.data == "online") || (res.data == "1") || (res.data == "true")) return true
else return false
}
/**
*
* @param {discord.Message[]} messages
@@ -19,19 +29,11 @@ const tsdb = require("./tsdb")
* @param {String|false} reason
*/
module.exports = async (messages,guild,channel,user,reason) => {
require("../api/modules/events").onTranscriptCreation(messages,channel,guild,new Date())
const msglist = await channel.messages.fetchPinned()
const chName = channel.id
const chId = channel.name
if (tsconfig.sendTranscripts.enableChannel){
/**@type {discord.TextChannel|undefined} */
const tc = guild.channels.cache.find((c) => c.id == tsconfig.sendTranscripts.channel)
if (!tc) return
const embed = tsembeds.beingprocessed(chName,chId,60000,user)
var msg = await tc.send({embeds:[embed]})
}else {var msg = false}
const chName = channel.name
const chId = channel.id
/**@param {discord.Collection<string, discord.Message<true>>} msglist*/
const asyncmanager = async (msglist) => {
@@ -67,25 +69,58 @@ module.exports = async (messages,guild,channel,user,reason) => {
}
})
require("fs").writeFileSync("./TESTJSON.json",JSON.stringify(JSONDATA,null,"\t"))
if (!await checkAvailability()){
const attachment = await require("./oldTranscript").createTranscript(messages,ch)
const errembed = tsembeds.tserror(chName,chId,user)
if (tsconfig.sendTranscripts.enableChannel){
/**@type {discord.TextChannel|undefined} */
const tc = guild.channels.cache.find((c) => c.id == tsconfig.sendTranscripts.channel)
if (!tc) return
tc.send({embeds:[errembed],files:[attachment]})
}
return
}
const TSdata = await require("./communication/index").upload(JSONDATA)
if (!TSdata) return false
if (TSdata.status == "success"){
const url = "https://transcripts.dj-dj.be/t/"+TSdata.time+"_"+TSdata.id+".html"
if (msg){
msg.edit(tsembeds.tsready(chName,chId,url,user))
console.log("URL:",url)
}
//calculate estimated time
const lastDumpTime = (new Date(TSdata.estimated.lastdump).getTime())
const dumpLoopTime = 15000
const nextDump = new Date(lastDumpTime+dumpLoopTime)
const processtime = TSdata.estimated.processtime+6000 //6sec extra time for overflow
if (tsconfig.sendTranscripts.enableDM){
if (!user) return
const embed = tsembeds.tsready(chName,chId,url,user)
try {
user.send({embeds:[embed]})
}catch{}
}
const finaltime = new Date(nextDump.getTime()+processtime)
const duration = finaltime.getTime()-new Date().getTime()
//waiting
if (tsconfig.sendTranscripts.enableChannel){
/**@type {discord.TextChannel|undefined} */
const tc = guild.channels.cache.find((c) => c.id == tsconfig.sendTranscripts.channel)
if (!tc) return
const embed = tsembeds.beingprocessed(chName,chId,finaltime,user)
var msg = await tc.send({embeds:[embed]})
}else {var msg = false}
//ready
setTimeout(() => {
if (msg){
msg.edit({embeds:[tsembeds.tsready(chName,chId,url,user)]})
}
if (tsconfig.sendTranscripts.enableDM){
if (!user) return
const embed = tsembeds.tsready(chName,chId,url,user)
try {
user.send({embeds:[embed]})
}catch{}
}
},duration)
}
}
asyncmanager(msglist)
+38
View File
@@ -0,0 +1,38 @@
const discord = require('discord.js')
const bot = require('../../index')
const client = bot.client
const config = bot.config
const l = bot.language
/**
*
* @param {discord.Message[]} messagecollection
* @returns new `discord.attachmentBuilder`
*/
exports.createTranscript = async (messagecollection) => {
try {
const cd = new Date()
const months = ["January","February","March","April","May","June","July","August","September","October","November","December"]
const dateString = cd.getDate()+" "+months[cd.getMonth()-1]+" "+cd.getFullYear()+" - "+cd.getHours()+":"+cd.getMinutes()+":"+cd.getSeconds()
const filearray = ["BACKUP TRANSCRIPT:\n"]
messagecollection.reverse()
messagecollection.forEach((msg) => {
const timestamp = new Date(msg.createdTimestamp)
if (msg.content){var content = msg.content}else{var content = "*empty message*"}
const msgstats = "files: "+msg.attachments.size+", embeds: "+msg.embeds.length
filearray.push("["+timestamp.getDate()+"/"+timestamp.getMonth()+"/"+timestamp.getFullYear()+", "+timestamp.getHours()+":"+timestamp.getMinutes()+":"+timestamp.getSeconds()+"|"+msg.author.tag+"] ["+msgstats+"]\n"+content+"\n")
})
if (filearray.length < 2) filearray.push("transcript is empty")
const filestring = filearray.join("\n")
const filebuff = Buffer.from(filestring,"utf-8")
return new discord.AttachmentBuilder(filebuff,{name:"backuptranscript.txt",description:"Open Ticket transcript"})
}catch{
return false
}
}