Code cleanup & bugfixes

This commit is contained in:
DJj123dj
2026-05-14 23:13:38 +02:00
parent 1a530aae4c
commit e6f6aa1af4
20 changed files with 282 additions and 522 deletions
+15 -27
View File
@@ -3,6 +3,7 @@
///////////////////////////////////////
import {opendiscord, api, utilities} from "../index.js"
import * as discord from "discord.js"
import * as actionUtils from "../actions/utilities.js"
const generalConfig = opendiscord.configs.get("opendiscord:general")
@@ -12,34 +13,21 @@ export async function registerCommandResponders(){
opendiscord.responders.commands.get("opendiscord:transfer").workers.add([
new api.ODWorker("opendiscord:transfer",0,async (instance,params,origin,cancel) => {
const {user,member,channel,guild} = instance
//check permissions
const permsResult = await opendiscord.permissions.checkCommandPerms(generalConfig.data.system.permissions.transfer,"support",user,member,channel,guild)
if (!permsResult.hasPerms){
if (permsResult.reason == "not-in-server") await instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
else await instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-no-permissions").build(origin,{guild,channel,user,permissions:["support"]}))
return cancel()
}
//check is in guild/Server
if (!guild){
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
return cancel()
}
//check if ticket exists
const ticket = opendiscord.tickets.get(channel.id)
if (!ticket || channel.isDMBased()){
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-unknown").build("button",{guild,channel,user}))
return cancel()
}
//return when busy
if (ticket.get("opendiscord:busy").value){
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-busy").build("button",{guild,channel,user}))
return cancel()
}
//responder checks
const hasPerms = await actionUtils.replyHasPermissions(instance,origin,"transfer")
if (!hasPerms) return cancel()
const isInGuild = await actionUtils.replyIsInGuild(instance,origin)
if (!isInGuild || !guild || channel.isDMBased()) return cancel()
const ticket = await actionUtils.replyIsTicket(instance,origin)
if (!ticket) return cancel()
const isAvailable = await actionUtils.replyTicketIsAvailable(instance,origin,ticket)
if (!isAvailable) return cancel()
//fetch data
const oldCreator = await opendiscord.tickets.getTicketUser(ticket,"creator") ?? opendiscord.client.client.user
const newCreator = instance.options.getUser("user",true)
const reason = instance.options.getString("reason",false)