v3.2 push 1 NOT WORKING YET!!!

This commit is contained in:
DJj123dj
2023-01-17 17:34:51 +01:00
parent fc50a8e83f
commit 7ed2d7bcc7
25 changed files with 687 additions and 184 deletions
@@ -0,0 +1,115 @@
const discord = require('discord.js')
const bot = require("../../../index")
const tsconfig = bot.tsconfig
const tsembeds = require("../embeds")
const tsdb = require("../tsdb")
const otversion = require("../../../package.json").version
const version = require("../info.json").version
/**@typedef {{style:{enableCustomBackground:Boolean, backgroundModus:"color"|"image", backgroundData:String, titleColor:String}, bot:{name:String, id:Number, pfp:String}, ticket:{creatorname:String, creatorid:Number, closedtime:Number, openedtime:Number}}} OThtsDataOption */
/**
*
* @param {discord.Guild} guild
* @param {discord.Channel} channel
* @param {discord.User} user
* @param {discord.Message[]} messagesInv
* @param {OThtsDataOption} data
*/
exports.compile = (guild,channel,user,messagesInv,data) => {
const messages = messagesInv.reverse()
const rawfiles = messages.filter((m) => Array.from(m.attachments).length > 0)
var fileAmount = 0
rawfiles.forEach((msg) => {
fileAmount = fileAmount + Array.from(msg.attachments).length
})
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
})
})
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)
})
})
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 = {
version,otversion,
style:{
backgroundData:data.style.backgroundData || "",
backgroundModus:data.style.backgroundModus || "",
enableCustomBackground:data.style.enableCustomBackground || false,
titleColor:data.style.titleColor || "#F8BA00"
},
bot:{
name:data.bot.name || "Open Ticket",
id:Number(data.bot.id) || 0,
pfp:data.bot.pfp || "dj-dj.be/wp-content/uploads/2022/07/profielfoto-blauw-wit.png?size=128"
},
ticket:{
name:channel.name,
id:Number(channel.id),
guildname:guild.name,
guildid:Number(guild.id),
creatorname:data.ticket.creatorname,
creatorid:Number(data.ticket.creatorid),
closedbyname:user.tag,
closedbyid:Number(user.id),
closedtime:data.ticket.closedtime,
openedtime:data.ticket.openedtime,
messages:Array.from(messages).length,
files:fileAmount
},
messages:messagesArray
}
return result
}
@@ -0,0 +1,28 @@
const axios = require("axios").default
const discord = require('discord.js')
const bot = require("../../../index")
const tsconfig = bot.tsconfig
const tsembeds = require("../embeds")
const tsdb = require("../tsdb")
/**@typedef {{status:"success"|"error", id:String, time:Number, estimated:{lastdump: Number, processtime:Number}, transcriptstatus:{value:2, data:{fetchedmsgs:true, uploaded:true, inqueue:true, processed:false, waiting:false, available:false}}}} OTuploadResponse */
/**
* @param {Object} json
* @returns {OTuploadResponse}
*/
exports.upload = async (json) => {
const data = encodeURIComponent(JSON.stringify(json))
try {
const res = await axios.get("https://api.transcripts.dj-dj.be/upload?auth=openticketTRANSCRIPT1234&version=1.0.0&data="+data)
if (res.status != 200) return false
return res.data
}catch{
console.log("failed transcript upload!")
return false
}
}
@@ -0,0 +1,67 @@
{
"version":"1.0.0",
"otversion":"3.2.0",
"style":{
"enableCustomBackground":false,
"backgroundModus":"color OR image",
"backgroundData":"#ffffff OR https://www.example.com/image.png",
"titleColor":"#ffffff"
},
"bot":{
"name":"DJdj Support Bot",
"id":12345678910,
"pfp":"https://www.example.com/image.png"
},
"ticket":{
"name":"support-DJj123dj",
"id":12345678910,
"guildname":"DJdj Development",
"guildid":12345678910,
"creatorname":"DJj123dj#1706",
"creatorid":12345678910,
"closedbyname":"DJj123dj#1706",
"closedbyid":12345678910,
"closedtime":12345678910,
"openedtime":12345678910,
"messages":1,
"files":1
},
"messages":[
{
"author":{
"name":"DJj123dj#1706",
"id":12345678910,
"color":"#ffffff",
"pfp":"https://www.example.com/image.png"
},
"content":"string or FALSE",
"timestamp":12345678910,
"embeds":[
{
"title":"string or FALSE",
"description":"string or FALSE",
"authorimg":"https://www.example.com/image.png or FALSE",
"authortext":"string or FALSE",
"footerimg":"https://www.example.com/image.png or FALSE",
"footertext":"string or FALSE",
"color":"#ffffff",
"image":"https://www.example.com/image.png or FALSE",
"thumbnail":"https://www.example.com/image.png or FALSE",
"url":"https://www.example.com/image.png or FALSE"
}
],
"files":[
{
"name":"image.png",
"type":"PNG",
"size":"1MB",
"url":"https://www.example.com/image.png"
}
]
}
]
}
+53
View File
@@ -0,0 +1,53 @@
const discord = require('discord.js')
const bot = require('../../index')
const client = bot.client
const config = bot.config
const log = bot.errorLog.log
const l = bot.language
const storage = bot.storage
const tsconfig = bot.tsconfig
/**
*
* @param {String} name
* @param {String} id
* @param {Number} rawprocesstime milliseconds
* @param {discord.User} user
*/
exports.beingprocessed = (name,id,rawprocesstime,user) => {
const newtime = new Date(new Date().getTime() + rawprocesstime)
const processtime = "<t:"+newtime.getTime().toString().substring(0,newtime.getTime().toString().length-3)+":R>"
const embed = new discord.EmbedBuilder()
.setTitle("🧾 Transcript")
.setColor(config.main_color)
.setAuthor({name:user.tag,iconURL:user.displayAvatarURL()})
.setFooter({text:name})
.setDescription("`This transcript is being processed...`\nPlease wait!\n\nEstimated time: "+processtime)
return embed
}
/**
*
* @param {String} name
* @param {String} id
* @param {String} url
* @param {discord.User} user
*/
exports.tsready = (name,id,url,user) => {
const embed = new discord.EmbedBuilder()
.setTitle("🧾 Transcript")
.setColor(config.main_color)
.setAuthor({name:user.tag,iconURL:user.displayAvatarURL()})
.setFooter({text:name})
.setURL(url)
.setDescription("The transcript is available [here]("+url+")")
return embed
}
+3
View File
@@ -0,0 +1,3 @@
{
"version":"1.0.0"
}
+92
View File
@@ -0,0 +1,92 @@
const discord = require('discord.js')
const bot = require('../../index')
const client = bot.client
const config = bot.config
const log = bot.errorLog.log
const l = bot.language
const storage = bot.storage
const tsconfig = bot.tsconfig
const tsembeds = require("./embeds")
const tsdb = require("./tsdb")
/**
*
* @param {discord.Message[]} messages
* @param {discord.Guild} guild
* @param {discord.TextChannel} channel
* @param {discord.User} user
* @param {String|false} reason
*/
module.exports = async (messages,guild,channel,user,reason) => {
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}
/**@param {discord.Collection<string, discord.Message<true>>} msglist*/
const asyncmanager = async (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
const opentime = new Date(Number(hiddendata.data.find(d => d.key == "createdms").value))
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()
}
})
require("fs").writeFileSync("./TESTJSON.json",JSON.stringify(JSONDATA,null,"\t"))
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)
}
if (tsconfig.sendTranscripts.enableDM){
if (!user) return
const embed = tsembeds.tsready(chName,chId,url,user)
try {
user.send({embeds:[embed]})
}catch{}
}
}
}
asyncmanager(msglist)
}
+71
View File
@@ -0,0 +1,71 @@
const fs = require("fs")
const location = "./storage/tsdatabase.json"
/**@returns {[{category:String, key:String, value:String}]}*/
function getData(){
if (fs.existsSync(location)){
return JSON.parse(fs.readFileSync(location).toString())
}else{
fs.writeFileSync(location,"[]")
return []
}
}
/**@param {[{category:String, key:String, value:String}]} data*/
function setData(data){
fs.writeFileSync(location,JSON.stringify(data,null,"\t"))
}
exports.set = (category,key,value) => {
const currentData = getData()
const exists = currentData.find((d) => (d.category == category) && (d.key == key)) ? true : false
var newData = []
if (exists){
currentData.forEach((d,i) => {
if (d.category == category && d.key == key){
newData.push({category,key,value})
}else{
newData.push(d)
}
})
}else{
currentData.push({category,key,value})
newData = currentData
}
setData(newData)
return exists
}
/**
* @param {String} category
* @param {String} key
* @returns {String|false}
*/
exports.get = (category,key) => {
const currentData = getData()
const tempresult = currentData.find((d) => (d.category == category) && (d.key == key))
const result = tempresult ? tempresult.value : false
return result
}
/**
* @param {String} category
* @param {String} key
* @param {String} value
*/
exports.delete = (category,key) => {
const currentData = getData()
const exists = currentData.find((d) => (d.category == category) && (d.key == key)) ? true : false
var newData = []
if (exists){
currentData.forEach((d,i) => {
if (!(d.category == category && d.key == key)){
newData.push(d)
}
})
}else{
newData = currentData
}
setData(newData)
return exists
}