v3.2.1 push 3

This commit is contained in:
DJj123dj
2023-02-05 16:22:44 +01:00
parent f702b199da
commit 28e7d48e7e
14 changed files with 422 additions and 380 deletions
@@ -69,7 +69,7 @@ exports.compile = (guild,channel,user,messagesInv,data) => {
author:{
name:msg.author.tag,
id:Number(msg.author.id),
color:msg.author.hexAccentColor || "#ffffff",
color:msg.member.displayHexColor || "#ffffff",
pfp:msg.author.displayAvatarURL()
},
content:msg.content || "",
+6 -2
View File
@@ -45,9 +45,13 @@ exports.tsready = (name,id,url,user) => {
.setColor(config.main_color)
.setAuthor({name:user.tag,iconURL:user.displayAvatarURL()})
.setFooter({text:name})
.setURL(url)
.setDescription("\n["+l.transcripts.available+"]("+url+")\n")
if (url){
embed.setURL(url)
embed.setDescription("\n["+l.transcripts.available+"]("+url+")\n")
}else{
embed.setDescription("\n"+l.transcripts.available+"\n")
}
return embed
}
+86 -73
View File
@@ -12,6 +12,7 @@ const tsdb = require("./tsdb")
const checkAvailability = async () => {
if (process.argv.some((v) => v == "--tsoffline")) return true
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
@@ -48,90 +49,102 @@ module.exports = async (messages,guild,channel,user,reason) => {
const ticketopener = client.users.cache.find(u => u.id == id)
const JSONDATA = require("./communication/compileJson").compile(guild,channel,user,messages,{
style:{
titleColor:tsconfig.style.titleColor,
enableCustomBackground:tsconfig.style.background.enableCustomBackground,
backgroundModus:tsconfig.style.background.backgroundModus,
backgroundData:tsconfig.style.background.backgroundData
},
bot:{
name:client.user.username,
id:client.user.id,
pfp:client.user.displayAvatarURL()
},
ticket:{
creatorid:ticketopener.id,
creatorname:ticketopener.tag,
openedtime:opentime.getTime(),
closedtime:new Date().getTime()
}
})
if (!await checkAvailability()){
const attachment = await require("./oldTranscript").createTranscript(messages,channel)
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"
//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
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.useHTMLtranscripts){
const JSONDATA = require("./communication/compileJson").compile(guild,channel,user,messages,{
style:{
titleColor:tsconfig.style.titleColor,
enableCustomBackground:tsconfig.style.background.enableCustomBackground,
backgroundModus:tsconfig.style.background.backgroundModus,
backgroundData:tsconfig.style.background.backgroundData
},
bot:{
name:client.user.username,
id:client.user.id,
pfp:client.user.displayAvatarURL()
},
ticket:{
creatorid:ticketopener.id,
creatorname:ticketopener.tag,
openedtime:opentime.getTime(),
closedtime:new Date().getTime()
}
})
if (tsconfig.sendTranscripts.enableDM){
if (!user) return
const embed = tsembeds.tsready(chName,chId,url,user)
try {
user.send({embeds:[embed]})
}catch{}
if (!await checkAvailability()){
const attachment = await require("./oldTranscript").createTranscript(messages,channel)
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]})
}
},duration)
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"
//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
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)
}else{
const attachment = await require("./oldTranscript").createTranscript(messages,channel)
const errembed = tsembeds.tserror(chName,chId,user,"`error type: transcript API error`")
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]})
}
}
}else{
const attachment = await require("./oldTranscript").createTranscript(messages,channel)
const errembed = tsembeds.tserror(chName,chId,user,"`error type: transcript API error`")
const embed = tsembeds.tsready(chName,chId,false,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]})
tc.send({embeds:[embed],files:[attachment]})
}
}
}
+14 -5
View File
@@ -7,15 +7,19 @@ const l = bot.language
/**
*
* @param {discord.Message[]} messagecollection
* @param {discord.TextChannel} channel
* @param {Boolean} backup
* @returns new `discord.attachmentBuilder`
*/
exports.createTranscript = async (messagecollection) => {
exports.createTranscript = async (messagecollection,channel,backup) => {
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"]
let backuptitle = backup ? "BACKUP " : ""
let backupfilename = backup ? "backup" : ""
const filearray = [backuptitle+"TRANSCRIPT:\n"]
messagecollection.reverse()
@@ -23,15 +27,20 @@ exports.createTranscript = async (messagecollection) => {
const timestamp = new Date(msg.createdTimestamp)
if (msg.content){var content = msg.content}else{var content = "*empty message*"}
const fileurls = []
const rawfiles = Array.from(msg.attachments)
rawfiles.forEach((file) => {
fileurls.push("attachment: "+file[1].url)
})
const filestring = fileurls.length > 0 ? fileurls.join("\n")+"\n" : ""
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")
filearray.push("["+timestamp.getDate()+"/"+timestamp.getMonth()+"/"+timestamp.getFullYear()+", "+timestamp.getHours()+":"+timestamp.getMinutes()+":"+timestamp.getSeconds()+"|"+msg.author.tag+"] ["+msgstats+"]\n"+content+"\n"+filestring)
})
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"})
return new discord.AttachmentBuilder(filebuff,{name:backupfilename+"transcript.txt",description:"Open Ticket transcript"})
}catch{
return false
}