v3.2 push 2
This commit is contained in:
-105
@@ -1,105 +0,0 @@
|
||||
{
|
||||
"version": "1.0.0",
|
||||
"otversion": "3.1.0",
|
||||
"style": {
|
||||
"backgroundData": "https://pbs.twimg.com/media/EBjFBlVXsAAhvXl?format=jpg&name=4096x4096",
|
||||
"backgroundModus": "image",
|
||||
"enableCustomBackground": true,
|
||||
"titleColor": "#49c100"
|
||||
},
|
||||
"bot": {
|
||||
"name": "DJdj Test Bot",
|
||||
"id": 958290611331539000,
|
||||
"pfp": "https://cdn.discordapp.com/avatars/958290611331538975/7a989e8ce6cde2b3e3c7fc15001452a0.webp"
|
||||
},
|
||||
"ticket": {
|
||||
"name": "question-djj123dj",
|
||||
"id": 1064653735772565500,
|
||||
"guildname": "DJDJ bot test",
|
||||
"guildid": 935983011281903600,
|
||||
"creatorname": "DJj123dj#1706",
|
||||
"creatorid": 779742674932072400,
|
||||
"closedbyname": "DJj123dj#1706",
|
||||
"closedbyid": 779742674932072400,
|
||||
"closedtime": 1673903703543,
|
||||
"openedtime": 1673903631015,
|
||||
"messages": 4,
|
||||
"files": 0
|
||||
},
|
||||
"messages": [
|
||||
{
|
||||
"author": {
|
||||
"name": "DJdj Test Bot#7338",
|
||||
"id": 958290611331539000,
|
||||
"color": "#ffffff",
|
||||
"pfp": "https://cdn.discordapp.com/avatars/958290611331538975/7a989e8ce6cde2b3e3c7fc15001452a0.webp"
|
||||
},
|
||||
"content": "<@779742674932072469> @here",
|
||||
"timestamp": 1673903631356,
|
||||
"embeds": [
|
||||
{
|
||||
"title": "Question",
|
||||
"description": "The staff will help you soon!\n\n*Click on the button below to close the ticket!*",
|
||||
"authorimg": false,
|
||||
"authortext": false,
|
||||
"footerimg": false,
|
||||
"footertext": false,
|
||||
"color": "#49c100",
|
||||
"image": false,
|
||||
"thumbnail": false,
|
||||
"url": false
|
||||
}
|
||||
],
|
||||
"files": []
|
||||
},
|
||||
{
|
||||
"author": {
|
||||
"name": "DJdj Test Bot#7338",
|
||||
"id": 958290611331539000,
|
||||
"color": "#ffffff",
|
||||
"pfp": "https://cdn.discordapp.com/avatars/958290611331538975/7a989e8ce6cde2b3e3c7fc15001452a0.webp"
|
||||
},
|
||||
"content": "",
|
||||
"timestamp": 1673903631652,
|
||||
"embeds": [],
|
||||
"files": []
|
||||
},
|
||||
{
|
||||
"author": {
|
||||
"name": "DJj123dj#1706",
|
||||
"id": 779742674932072400,
|
||||
"color": "#ffffff",
|
||||
"pfp": "https://cdn.discordapp.com/avatars/779742674932072469/4588af0ccb6a18a66d66c77bddbdfc81.webp"
|
||||
},
|
||||
"content": "**test markdown (again)**\n__hi__\n~~hello!~~\n\n_nice_\n\n**___super text!__**",
|
||||
"timestamp": 1673903693407,
|
||||
"embeds": [],
|
||||
"files": []
|
||||
},
|
||||
{
|
||||
"author": {
|
||||
"name": "DJdj Test Bot#7338",
|
||||
"id": 958290611331539000,
|
||||
"color": "#ffffff",
|
||||
"pfp": "https://cdn.discordapp.com/avatars/958290611331538975/7a989e8ce6cde2b3e3c7fc15001452a0.webp"
|
||||
},
|
||||
"content": "",
|
||||
"timestamp": 1673903697253,
|
||||
"embeds": [
|
||||
{
|
||||
"title": "❌ Deleting this ticket...",
|
||||
"description": false,
|
||||
"authorimg": false,
|
||||
"authortext": false,
|
||||
"footerimg": "https://cdn.discordapp.com/avatars/779742674932072469/4588af0ccb6a18a66d66c77bddbdfc81.webp",
|
||||
"footertext": "DJj123dj#1706",
|
||||
"color": "#49c100",
|
||||
"image": false,
|
||||
"thumbnail": false,
|
||||
"url": false
|
||||
}
|
||||
],
|
||||
"files": []
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -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 = {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
Executable
+38
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user