v3.2 last push

This commit is contained in:
DJj123dj
2023-01-18 21:44:56 +01:00
parent b698c89a89
commit 1b8468330e
16 changed files with 306 additions and 62 deletions
+1
View File
@@ -17,3 +17,4 @@ storage/.DS_Store
.vscode/
livestatus.json
test.js
testtsconfig.json
+101
View File
@@ -0,0 +1,101 @@
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 permsChecker = require("../core/utils/permisssionChecker")
const APIEvents = require("../core/api/modules/events")
const DISABLE = require("../core/api/api.json").disable
module.exports = () => {
bot.errorLog.log("debug","COMMANDS: loaded change.js")
if (!DISABLE.commands.text.change) client.on("messageCreate",msg => {
if (!msg.content.startsWith(config.prefix+"change")) return
if (!msg.guild) return
if (!permsChecker.command(msg.author.id,msg.guild.id)){
permsChecker.sendUserNoPerms(msg.author)
return
}
msg.channel.messages.fetchPinned().then(msglist => {
var firstmsg = msglist.last()
if (firstmsg == undefined || firstmsg.author.id != client.user.id) return msg.channel.send({embeds:[bot.errorLog.notInATicket]})
const hiddendata = bot.hiddenData.readHiddenData(firstmsg.embeds[0].description)
const ticketId = hiddendata.data.find(d => d.key == "type").value
var newtype = msg.content.split(config.prefix+"change")[1].substring(1)
if (!newtype) return msg.channel.send({embeds:[bot.errorLog.invalidArgsMessage(l.errors.missingArgsDescription+" `<type>`:\n`"+config.prefix+"change <type>`")]})
const newTicket = require("../core/utils/configParser").getTicketById(newtype)
const list = []
config.options.forEach((o) => list.push(o.id))
if (!newTicket) return bot.errorLog.invalidIdChooseFromList(list)
/**@type {String} */
var chName = msg.channel.name
const splitted = chName.split("-")
const prefix = splitted.shift()
const name = (splitted.length > 0) ? splitted.join("-") : prefix
msg.channel.setName(newTicket.channelprefix+name)
msg.channel.send({embeds:[bot.embeds.commands.changeEmbed(msg.author,newtype)]})
log("command","someone used the 'change' command",[{key:"user",value:msg.author.tag}])
log("system","ticket type changed",[{key:"user",value:msg.author.tag},{key:"ticket",value:name},{key:"newtype",value:newtype}])
APIEvents.onCommand("change",permsChecker.command(msg.author.id,msg.guild.id),msg.author,msg.channel,msg.guild,new Date())
})
})
if (!DISABLE.commands.slash.change) client.on("interactionCreate",(interaction) => {
if (!interaction.isChatInputCommand()) return
if (interaction.commandName != "change") return
if (!interaction.guild) return
if (!permsChecker.command(interaction.user.id,interaction.guild.id)){
permsChecker.sendUserNoPerms(interaction.user)
return
}
//interaction.deferReply()
interaction.channel.messages.fetchPinned().then(msglist => {
var firstmsg = msglist.last()
if (firstmsg == undefined || firstmsg.author.id != client.user.id) return interaction.reply({embeds:[bot.errorLog.notInATicket]})
const hiddendata = bot.hiddenData.readHiddenData(firstmsg.embeds[0].description)
const ticketId = hiddendata.data.find(d => d.key == "type").value
console.log("HELLO WORLD!! 1")
var newtype = interaction.options.getString("type",true)
if (!newtype) return interaction.reply({embeds:[bot.errorLog.invalidArgsMessage(l.errors.missingArgsDescription+" `<type>`:\n`"+config.prefix+"change <type>`")]})
console.log("HELLO WORLD!! 2")
const newTicket = require("../core/utils/configParser").getTicketById(newtype,true)
const list = []
config.options.forEach((o) => list.push(o.id))
if (!newTicket) return bot.errorLog.invalidIdChooseFromList(list)
console.log("HELLO WORLD!! 3")
/**@type {String} */
var chName = interaction.channel.name
const splitted = chName.split("-")
const prefix = splitted.shift()
const name = (splitted.length > 0) ? splitted.join("-") : prefix
console.log("HELLO WORLD!! 4")
interaction.channel.setName(newTicket.channelprefix+name)
interaction.reply({embeds:[bot.embeds.commands.changeEmbed(interaction.user,newtype)]})
console.log("HELLO WORLD!! 5")
log("command","someone used the 'change' command",[{key:"user",value:interaction.user.tag}])
log("system","ticket type changed",[{key:"user",value:interaction.user.tag},{key:"ticket",value:name},{key:"newtype",value:newtype}])
APIEvents.onCommand("change",permsChecker.command(interaction.user.id,interaction.guild.id),interaction.user,interaction.channel,interaction.guild,new Date())
})
})
}
+4 -2
View File
@@ -29,7 +29,8 @@
"remove":false,
"rename":false,
"claim":false,
"unclaim":false
"unclaim":false,
"change":false
},
"slash":{
"help":false,
@@ -42,7 +43,8 @@
"remove":false,
"rename":false,
"claim":false,
"unclaim":false
"unclaim":false,
"change":false
}
},
"checkerjs":{
+93 -1
View File
@@ -17,6 +17,10 @@ const ticketReopenListeners = []
const ticketAddListeners = []
const ticketRemoveListeners = []
const ticketClaimListeners = []
const ticketUnclaimListeners = []
const ticketChangeListeners = []
const transcriptCreationListeners = []
const commandListeners = []
@@ -146,6 +150,66 @@ exports.onTicketRemove = (user,editeduser,channel,guild,date,ticketdata) => {
}
/**
*
* @param {discord.User} user
* @param {discord.TextChannel} channel
* @param {discord.Guild} guild
* @param {Date} date
* @param {{name:String,status:"open"|"closed"|"deleted"|"reopened",ticketOptions:configParser.OTTicketOptions}} ticketdata
*/
exports.onTicketClaim = (user,channel,guild,date,ticketdata) => {
//system
bot.errorLog.log("api","user claimed a ticket",[{key:"userid",value:user.id},{key:"channelid",value:channel.id},{key:"guildid",value:guild.id},{key:"ticketdata",value:JSON.stringify(ticketdata)}])
ticketClaimListeners.forEach((func) => {
try {
func(user,channel,guild,date,ticketdata)
}catch{}
})
}
/**
*
* @param {discord.User} user
* @param {discord.TextChannel} channel
* @param {discord.Guild} guild
* @param {Date} date
* @param {{name:String,status:"open"|"closed"|"deleted"|"reopened",ticketOptions:configParser.OTTicketOptions}} ticketdata
*/
exports.onTicketUnclaim = (user,channel,guild,date,ticketdata) => {
//system
bot.errorLog.log("api","user unclaimed a ticket",[{key:"userid",value:user.id},{key:"channelid",value:channel.id},{key:"guildid",value:guild.id},{key:"ticketdata",value:JSON.stringify(ticketdata)}])
ticketUnclaimListeners.forEach((func) => {
try {
func(user,channel,guild,date,ticketdata)
}catch{}
})
}
/**
* @param {String} newtype
* @param {discord.User} user
* @param {discord.TextChannel} channel
* @param {discord.Guild} guild
* @param {Date} date
* @param {{name:String,status:"open"|"closed"|"deleted"|"reopened",ticketOptions:configParser.OTTicketOptions}} ticketdata
*/
exports.onTicketChange = (newtype,user,channel,guild,date,ticketdata) => {
//system
bot.errorLog.log("api","user changed ticket type",[{key:"newtype",value:newtype},{key:"userid",value:user.id},{key:"channelid",value:channel.id},{key:"guildid",value:guild.id},{key:"ticketdata",value:JSON.stringify(ticketdata)}])
ticketChangeListeners.forEach((func) => {
try {
func(newtype,user,channel,guild,date,ticketdata)
}catch{}
})
}
/**
*
* @param {discord.Message[]} messages
@@ -165,7 +229,7 @@ exports.onTranscriptCreation = (messages,channel,guild,date) => {
}
/**@typedef {"help"|"message"|"close"|"delete"|"reopen"|"rename"|"add"|"remove"} OTCommandType */
/**@typedef {"help"|"message"|"close"|"delete"|"reopen"|"rename"|"add"|"remove"|"claim"|"unclaim"|"change"} OTCommandType */
/**
*
@@ -269,6 +333,16 @@ exports.onCommand = (type,hasPerms,user,channel,guild,date) => {
* @param {{name:String,status:"open"|"closed"|"deleted"|"reopened",ticketOptions:configParser.OTTicketOptions}} ticketdata
*/
/**
* @callback TicketTypeChangeEvent
* @param {String} newtype
* @param {discord.User} user
* @param {discord.TextChannel} channel
* @param {discord.Guild} guild
* @param {Date} date
* @param {{name:String,status:"open"|"closed"|"deleted"|"reopened",ticketOptions:configParser.OTTicketOptions}} ticketdata
*/
/**
* @callback CommandEvent
* @param {OTCommandType} type
@@ -328,6 +402,21 @@ const onTicketRemove = (callback) => {
ticketRemoveListeners.push(callback)
}
/**@param {TicketActionEvent} callback */
const onTicketClaim = (callback) => {
ticketClaimListeners.push(callback)
}
/**@param {TicketActionEvent} callback */
const onTicketUnclaim = (callback) => {
ticketUnclaimListeners.push(callback)
}
/**@param {TicketTypeChangeEvent} callback */
const onTicketChange = (callback) => {
ticketChangeListeners.push(callback)
}
/**@param {TranscriptCreationEvent} callback */
const onTranscriptCreation = (callback) => {
transcriptCreationListeners.push(callback)
@@ -355,6 +444,9 @@ exports.events = {
onTicketReopen,
onTicketAdd,
onTicketRemove,
onTicketClaim,
onTicketUnclaim,
onTicketChange,
onTranscriptCreation,
onCommand,
onReactionRole,
@@ -137,3 +137,16 @@ exports.renameEmbed = (renamer,newname) => {
.setFooter({text:author.tag,iconURL:author.displayAvatarURL()})
}
}
/**
*
* @param {discord.User} changer
* @param {String} newtype
* @returns {discord.EmbedBuilder}
*/
exports.changeEmbed = (changer,newtype) => {
return new embed()
.setTitle("🔄 "+l.commands.changeTitle.replace("{0}",newtype))
.setColor(mc)
.setFooter({text:changer.tag,iconURL:changer.displayAvatarURL()})
}
+21 -2
View File
@@ -32,8 +32,8 @@ module.exports = async () => {
//process.stdout.write("[status] there are "+chalk.blue("0 out of 10")+" commands ready! (this can take up to 40 seconds)")
setInterval(() => {
process.stdout.cursorTo(0)
process.stdout.write("[status] there are "+chalk.blue(readystats+" out of 12")+" commands ready! (this can take up to 40 seconds)")
if (readystats >= 12){
process.stdout.write("[status] there are "+chalk.blue(readystats+" out of 13")+" commands ready! (this can take up to 40 seconds)")
if (readystats >= 13){
const fs = require("fs")
fs.writeFileSync("./storage/slashcmdEnabled.txt","true")
console.log(chalk.green("\nready!"))
@@ -245,4 +245,23 @@ module.exports = async () => {
readystats++
})
//category
client.application.commands.create({
name:"change",
description:"Change ticket type.",
defaultPermission:true,
type:act.ChatInput,
options:[
{
type:acot.String,
name:"type",
description:"The new ticket type.",
required:true,
choices:choices
}
]
},sid).then(() => {
readystats++
})
}
-12
View File
@@ -88,12 +88,6 @@ exports.NEWcloseTicket = async (member,channel,prefix,mode,reason,nomessage) =>
if (!id) return false
try{
if (config.system.enable_DM_Messages){
member.send({embeds:[bot.errorLog.custom(l.messages.deletedTicketDmTitle,l.messages.deletedTicketDmDescription,":ticket:",config.main_color)]})
}
}
catch{log("system","can't send DM to member, member doesn't allow dm's")}
})
}else if (mode == "close"){
@@ -229,12 +223,6 @@ exports.NEWcloseTicket = async (member,channel,prefix,mode,reason,nomessage) =>
if (!id) return false
try{
if (config.system.enable_DM_Messages){
member.send({embeds:[bot.errorLog.custom(l.messages.closedTicketDmTitle,l.messages.closedTicketDmDescription+"\n\n**reason:** "+newReason,":ticket:",config.main_color)]})
}
}
catch{log("system","can't send DM to member, member doesn't allow dm's")}
})
+1 -1
View File
@@ -66,7 +66,7 @@ module.exports = () => {
if (storage.get("ticketStorage",interaction.member.id) == null || storage.get("ticketStorage",interaction.member.id) == "false"|| Number(storage.get("ticketStorage",interaction.member.id)) < config.system.max_allowed_tickets){
try{
if (config.system.enable_DM_Messages){
if (currentTicketOptions.enableDmOnOpen){
interaction.member.send({embeds:[bot.errorLog.custom(l.messages.newTicketDmTitle,currentTicketOptions.message,":ticket:",config.main_color)]})
}
}
@@ -21,6 +21,7 @@ const version = require("../info.json").version
*/
exports.compile = (guild,channel,user,messagesInv,data) => {
const messages = messagesInv.reverse()
var invisibleMessages = 0
const rawfiles = messages.filter((m) => Array.from(m.attachments).length > 0)
var fileAmount = 0
@@ -30,8 +31,6 @@ exports.compile = (guild,channel,user,messagesInv,data) => {
const messagesArray = []
messages.forEach((msg) => {
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 = []
@@ -78,7 +77,7 @@ exports.compile = (guild,channel,user,messagesInv,data) => {
embeds:embedArray,
files:fileArray
})
}
}else {invisibleMessages++}
})
const result = {
@@ -109,7 +108,7 @@ exports.compile = (guild,channel,user,messagesInv,data) => {
closedtime:data.ticket.closedtime,
openedtime:data.ticket.openedtime,
messages:Array.from(messages).length,
messages:Array.from(messages).length-invisibleMessages,
files:fileAmount
},
messages:messagesArray
+6 -5
View File
@@ -10,19 +10,20 @@ const tsdb = require("../tsdb")
/**
* @param {Object} json
* @returns {OTuploadResponse}
* @returns {Promise<OTuploadResponse|false>}
*/
exports.upload = async (json) => {
return new Promise(async (resolve,reject) => {
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
if (res.status != 200) resolve(false)
return res.data
resolve(res.data)
}catch{
console.log("failed transcript upload!")
return false
resolve(false)
}
})
}
+5 -2
View File
@@ -57,15 +57,18 @@ exports.tsready = (name,id,url,user) => {
* @param {String} name
* @param {String} id
* @param {discord.User} user
* @param {undefined|String} err
*/
exports.tserror = (name,id,user) => {
exports.tserror = (name,id,user,err) => {
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)")
const errDesc = (typeof err == "string") ? "\n"+err : ""
embed.setDescription("Something went wrong while creating the HTML transcript.\n\n[possible reasons](https://docs.openticket.dj-dj.be/the-system/transcripts/transcript-errors)"+errDesc)
return embed
}
+13 -1
View File
@@ -70,7 +70,7 @@ module.exports = async (messages,guild,channel,user,reason) => {
})
if (!await checkAvailability()){
const attachment = await require("./oldTranscript").createTranscript(messages,ch)
const attachment = await require("./oldTranscript").createTranscript(messages,channel)
const errembed = tsembeds.tserror(chName,chId,user)
if (tsconfig.sendTranscripts.enableChannel){
@@ -85,6 +85,7 @@ module.exports = async (messages,guild,channel,user,reason) => {
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"
@@ -121,6 +122,17 @@ module.exports = async (messages,guild,channel,user,reason) => {
}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]})
}
}
}
asyncmanager(msglist)
+1
View File
@@ -216,6 +216,7 @@ if (process.argv[2] && process.argv[2].startsWith("slash")){
require("./commands/reopen")()
require("./commands/claim")()
require("./commands/unclaim")()
require("./commands/change")()
this.errorLog.log("debug","LOADING CORE")
//core
+1
View File
@@ -27,6 +27,7 @@
"reopenTitle":"Re-Opened this ticket!",
"claimTitle":"This ticket is now claimed to {0}",
"unclaimTitle":"This ticket isn't claimed anymore!",
"changeTitle":"Changed ticket type to {0}!",
"ticketWarning":"The embed is in the message below!",
"maxTicketWarning":"**Warning:** _You can only create {0} ticket(s) at a time!_"
+17 -6
View File
@@ -114,9 +114,9 @@
"it":"Rinomina il canale di un ticket."
},
"claim":{
"en-GB":"",
"en-US":"",
"nl":"",
"en-GB":"Claim a ticket.",
"en-US":"Claim a ticket.",
"nl":"Claim een ticket.",
"ro":" ",
"de":" ",
"cs":" ",
@@ -125,9 +125,20 @@
"it":" "
},
"unclaim":{
"en-GB":"",
"en-US":"",
"nl":"",
"en-GB":"Un-claim a ticket.",
"en-US":"Un-claim a ticket.",
"nl":"Ontclaim een ticket.",
"ro":" ",
"de":" ",
"cs":" ",
"fr":" ",
"es-ES":" ",
"it":" "
},
"category":{
"en-GB":"Change ticket type.",
"en-US":"Change ticket type.",
"nl":"Verander ticket type.",
"ro":" ",
"de":" ",
"cs":" ",
+7 -7
View File
@@ -1,16 +1,16 @@
{
"sendTranscripts":{
"enableChannel":true,
"channel":"968899606912061490",
"enableChannel":false,
"channel":"transcript channel id",
"enableDM":true
"enableDM":false
},
"style":{
"titleColor":"#49c100",
"titleColor":"#F8BA00",
"background":{
"enableCustomBackground":true,
"backgroundModus":"image",
"backgroundData":"https://pbs.twimg.com/media/EBjFBlVXsAAhvXl?format=jpg&name=4096x4096"
"enableCustomBackground":false,
"backgroundModus":"color OR image",
"backgroundData":"#abc123 OR https://www.example.com/image.png"
}
}