Merge branch 'dev' into dev-v4.1.0

This commit is contained in:
DJj123dj
2025-05-03 21:15:03 +02:00
45 changed files with 152 additions and 78 deletions
+1 -1
View File
@@ -130,7 +130,7 @@ export class ODMain {
constructor(){
this.versions = new ODVersionManager_Default()
this.versions.add(ODVersion.fromString("opendiscord:version","v4.0.4"))
this.versions.add(ODVersion.fromString("opendiscord:version","v4.0.5"))
this.versions.add(ODVersion.fromString("opendiscord:api","v1.0.0"))
this.versions.add(ODVersion.fromString("opendiscord:transcripts","v2.0.0"))
this.versions.add(ODVersion.fromString("opendiscord:livestatus","v2.0.0"))
+4 -4
View File
@@ -560,8 +560,8 @@ export class ODHTTPGetRequest {
this.throwOnError = throwOnError
const newConfig = config ?? {}
newConfig.method = "GET"
if (newConfig.headers) Object.assign(newConfig.headers,{"User-Agent":"OpenDiscordBots-OpenTicket/4.0.4"})
else newConfig.headers = {"User-Agent":"OpenDiscordBots-OpenTicket/4.0.4"}
if (newConfig.headers) Object.assign(newConfig.headers,{"User-Agent":"OpenDiscordBots-OpenTicket/4.0.5"})
else newConfig.headers = {"User-Agent":"OpenDiscordBots-OpenTicket/4.0.5"}
this.config = newConfig
}
@@ -615,8 +615,8 @@ export class ODHTTPPostRequest {
this.throwOnError = throwOnError
const newConfig = config ?? {}
newConfig.method = "POST"
if (newConfig.headers) Object.assign(newConfig.headers,{"User-Agent":"OpenDiscordBots-OpenTicket/4.0.4"})
else newConfig.headers = {"User-Agent":"OpenDiscordBots-OpenTicket/4.0.4"}
if (newConfig.headers) Object.assign(newConfig.headers,{"User-Agent":"OpenDiscordBots-OpenTicket/4.0.5"})
else newConfig.headers = {"User-Agent":"OpenDiscordBots-OpenTicket/4.0.5"}
this.config = newConfig
}
+22 -17
View File
@@ -257,7 +257,7 @@ export class ODQuickButton {
/**The id of this button. */
id: ODId
/**The current data of this button */
data: ODButtonData = {
data: Partial<ODButtonData> = {
customId:"",
mode:"button",
url:null,
@@ -267,7 +267,7 @@ export class ODQuickButton {
disabled:false
}
constructor(id:ODValidId,data:ODButtonData){
constructor(id:ODValidId,data:Partial<ODButtonData>){
this.id = new ODId(id)
this.data = data
}
@@ -277,7 +277,7 @@ export class ODQuickButton {
try {
//create the discord.js button
const button = new discord.ButtonBuilder()
if (this.data.mode == "button") button.setCustomId(this.data.customId)
if (this.data.mode == "button") button.setCustomId(this.data.customId ?? "od:unknown-button")
if (this.data.mode == "url") button.setStyle(discord.ButtonStyle.Link)
else if (this.data.color == "gray") button.setStyle(discord.ButtonStyle.Secondary)
else if (this.data.color == "blue") button.setStyle(discord.ButtonStyle.Primary)
@@ -287,7 +287,7 @@ export class ODQuickButton {
if (this.data.label) button.setLabel(this.data.label)
if (this.data.emoji) button.setEmoji(this.data.emoji)
if (this.data.disabled) button.setDisabled(this.data.disabled)
if (!this.data.emoji && !this.data.label) button.setLabel(this.data.customId)
if (!this.data.emoji && !this.data.label) button.setLabel(this.data.customId ?? "od:unknown-button")
return {id:this.id,component:button}
}catch(err){
@@ -564,7 +564,7 @@ export class ODQuickDropdown {
/**The id of this dropdown. */
id: ODId
/**The current data of this dropdown */
data: ODDropdownData = {
data: Partial<ODDropdownData> = {
customId:"",
type:"string",
placeholder:null,
@@ -580,7 +580,7 @@ export class ODQuickDropdown {
mentionables:[]
}
constructor(id:ODValidId,data:ODDropdownData){
constructor(id:ODValidId,data:Partial<ODDropdownData>){
this.id = new ODId(id)
this.data = data
}
@@ -590,8 +590,9 @@ export class ODQuickDropdown {
try{
//create the discord.js dropdown
if (this.data.type == "string"){
if (!this.data.options) throw new ODSystemError("ODQuickDropdown:build(): "+this.id.value+" => Dropdown requires at least 1 option to be present.")
const dropdown = new discord.StringSelectMenuBuilder()
dropdown.setCustomId(this.data.customId)
dropdown.setCustomId(this.data.customId ?? "od:unknown-dropdown")
dropdown.setOptions(...this.data.options)
if (this.data.placeholder) dropdown.setPlaceholder(this.data.placeholder)
if (this.data.minValues) dropdown.setMinValues(this.data.minValues)
@@ -601,8 +602,9 @@ export class ODQuickDropdown {
return {id:this.id,component:dropdown}
}else if (this.data.type == "user"){
if (!this.data.users) throw new ODSystemError("ODQuickDropdown:build(): "+this.id.value+" => Dropdown requires at least 1 user option to be present.")
const dropdown = new discord.UserSelectMenuBuilder()
dropdown.setCustomId(this.data.customId)
dropdown.setCustomId(this.data.customId ?? "od:unknown-dropdown")
if (this.data.users.length > 0) dropdown.setDefaultUsers(...this.data.users.map((u) => u.id))
if (this.data.placeholder) dropdown.setPlaceholder(this.data.placeholder)
if (this.data.minValues) dropdown.setMinValues(this.data.minValues)
@@ -612,8 +614,9 @@ export class ODQuickDropdown {
return {id:this.id,component:dropdown}
}else if (this.data.type == "role"){
if (!this.data.roles) throw new ODSystemError("ODQuickDropdown:build(): "+this.id.value+" => Dropdown requires at least 1 role option to be present.")
const dropdown = new discord.RoleSelectMenuBuilder()
dropdown.setCustomId(this.data.customId)
dropdown.setCustomId(this.data.customId ?? "od:unknown-dropdown")
if (this.data.roles.length > 0) dropdown.setDefaultRoles(...this.data.roles.map((r) => r.id))
if (this.data.placeholder) dropdown.setPlaceholder(this.data.placeholder)
if (this.data.minValues) dropdown.setMinValues(this.data.minValues)
@@ -623,8 +626,9 @@ export class ODQuickDropdown {
return {id:this.id,component:dropdown}
}else if (this.data.type == "channel"){
if (!this.data.channels) throw new ODSystemError("ODQuickDropdown:build(): "+this.id.value+" => Dropdown requires at least 1 channel option to be present.")
const dropdown = new discord.ChannelSelectMenuBuilder()
dropdown.setCustomId(this.data.customId)
dropdown.setCustomId(this.data.customId ?? "od:unknown-dropdown")
if (this.data.channels.length > 0) dropdown.setDefaultChannels(...this.data.channels.map((c) => c.id))
if (this.data.placeholder) dropdown.setPlaceholder(this.data.placeholder)
if (this.data.minValues) dropdown.setMinValues(this.data.minValues)
@@ -634,6 +638,7 @@ export class ODQuickDropdown {
return {id:this.id,component:dropdown}
}else if (this.data.type == "mentionable"){
if (!this.data.mentionables) throw new ODSystemError("ODQuickDropdown:build(): "+this.id.value+" => Dropdown requires at least 1 mentionable option to be present.")
const dropdown = new discord.MentionableSelectMenuBuilder()
const values: ({type:discord.SelectMenuDefaultValueType.User,id:string}|{type:discord.SelectMenuDefaultValueType.Role,id:string})[] = []
@@ -645,7 +650,7 @@ export class ODQuickDropdown {
}
})
dropdown.setCustomId(this.data.customId)
dropdown.setCustomId(this.data.customId ?? "od:unknown-dropdown")
if (this.data.mentionables.length > 0) dropdown.setDefaultValues(...values)
if (this.data.placeholder) dropdown.setPlaceholder(this.data.placeholder)
if (this.data.minValues) dropdown.setMinValues(this.data.minValues)
@@ -799,14 +804,14 @@ export class ODQuickFile {
/**The id of this file. */
id: ODId
/**The current data of this file */
data: ODFileData = {
data: Partial<ODFileData> = {
file:"",
name:"file.txt",
description:null,
spoiler:false
}
constructor(id:ODValidId,data:ODFileData){
constructor(id:ODValidId,data:Partial<ODFileData>){
this.id = new ODId(id)
this.data = data
}
@@ -815,7 +820,7 @@ export class ODQuickFile {
async build(): Promise<ODFileBuildResult> {
try{
//create the discord.js attachment
const file = new discord.AttachmentBuilder(this.data.file)
const file = new discord.AttachmentBuilder(this.data.file ?? "<empty-file>")
file.setName(this.data.name ? this.data.name : "file.txt")
if (this.data.description) file.setDescription(this.data.description)
if (this.data.spoiler) file.setSpoiler(this.data.spoiler)
@@ -1055,7 +1060,7 @@ export class ODQuickEmbed {
/**The id of this embed. */
id: ODId
/**The current data of this embed */
data: ODEmbedData = {
data: Partial<ODEmbedData> = {
title:null,
color:null,
url:null,
@@ -1071,7 +1076,7 @@ export class ODQuickEmbed {
timestamp:null
}
constructor(id:ODValidId,data:ODEmbedData){
constructor(id:ODValidId,data:Partial<ODEmbedData>){
this.id = new ODId(id)
this.data = data
}
@@ -1097,7 +1102,7 @@ export class ODQuickEmbed {
if (this.data.image) embed.setImage(this.data.image)
if (this.data.thumbnail) embed.setThumbnail(this.data.thumbnail)
if (this.data.timestamp) embed.setTimestamp(this.data.timestamp)
if (this.data.fields.length > 0) embed.setFields(this.data.fields)
if (this.data.fields && this.data.fields.length > 0) embed.setFields(this.data.fields)
return {id:this.id,embed}
}catch(err){
+17 -17
View File
@@ -350,10 +350,10 @@ export class ODOptionSuffixManager extends ODManager<ODOptionSuffix> {
}
/**Instantly get the suffix from an `ODTicketOption`. */
getSuffixFromOption(option:ODTicketOption,user:discord.User): string|null {
async getSuffixFromOption(option:ODTicketOption,user:discord.User): Promise<string|null> {
const suffix = this.getAll().find((suffix) => suffix.option.id.value == option.id.value)
if (!suffix) return null
return suffix.getSuffix(user)
return await suffix.getSuffix(user)
}
}
@@ -374,7 +374,7 @@ export class ODOptionSuffix extends ODManagerData {
}
/**Get the suffix for a new ticket. */
getSuffix(user:discord.User): string {
async getSuffix(user:discord.User): Promise<string> {
throw new ODSystemError("Tried to use an unimplemented ODOptionSuffix!")
}
}
@@ -387,7 +387,7 @@ export class ODOptionSuffix extends ODManagerData {
* Use `getSuffix()` to get the new suffix!
*/
export class ODOptionUserNameSuffix extends ODOptionSuffix {
getSuffix(user:discord.User): string {
async getSuffix(user:discord.User): Promise<string> {
return user.username
}
}
@@ -400,7 +400,7 @@ export class ODOptionUserNameSuffix extends ODOptionSuffix {
* Use `getSuffix()` to get the new suffix!
*/
export class ODOptionUserIdSuffix extends ODOptionSuffix {
getSuffix(user:discord.User): string {
async getSuffix(user:discord.User): Promise<string> {
return user.id
}
}
@@ -426,11 +426,11 @@ export class ODOptionCounterDynamicSuffix extends ODOptionSuffix {
async #init(){
if (!await this.database.exists("opendiscord:option-suffix-counter",this.option.id.value)) await this.database.set("opendiscord:option-suffix-counter",this.option.id.value,0)
}
getSuffix(user:discord.User): string {
const rawCurrentValue = this.database.get("opendiscord:option-suffix-counter",this.option.id.value)
async getSuffix(user:discord.User): Promise<string> {
const rawCurrentValue = await this.database.get("opendiscord:option-suffix-counter",this.option.id.value)
const currentValue = (typeof rawCurrentValue != "number") ? 0 : rawCurrentValue
const newValue = currentValue+1
this.database.set("opendiscord:option-suffix-counter",this.option.id.value,newValue)
await this.database.set("opendiscord:option-suffix-counter",this.option.id.value,newValue)
return newValue.toString()
}
}
@@ -456,12 +456,12 @@ export class ODOptionCounterFixedSuffix extends ODOptionSuffix {
async #init(){
if (!await this.database.exists("opendiscord:option-suffix-counter",this.option.id.value)) await this.database.set("opendiscord:option-suffix-counter",this.option.id.value,0)
}
getSuffix(user:discord.User): string {
const rawCurrentValue = this.database.get("opendiscord:option-suffix-counter",this.option.id.value)
async getSuffix(user:discord.User): Promise<string> {
const rawCurrentValue = await this.database.get("opendiscord:option-suffix-counter",this.option.id.value)
const currentValue = (typeof rawCurrentValue != "number") ? 0 : rawCurrentValue
const newValue = (currentValue >= 9999) ? 0 : currentValue+1
this.database.set("opendiscord:option-suffix-counter",this.option.id.value,newValue)
await this.database.set("opendiscord:option-suffix-counter",this.option.id.value,newValue)
if (newValue.toString().length == 1) return "000"+newValue.toString()
else if (newValue.toString().length == 2) return "00"+newValue.toString()
else if (newValue.toString().length == 3) return "0"+newValue.toString()
@@ -501,13 +501,13 @@ export class ODOptionRandomNumberSuffix extends ODOptionSuffix {
if (history.includes(number)) return this.#generateUniqueValue(history)
else return number
}
getSuffix(user:discord.User): string {
const rawCurrentValues = this.database.get("opendiscord:option-suffix-history",this.option.id.value)
async getSuffix(user:discord.User): Promise<string> {
const rawCurrentValues = await this.database.get("opendiscord:option-suffix-history",this.option.id.value)
const currentValues = ((Array.isArray(rawCurrentValues)) ? rawCurrentValues : []) as string[]
const newValue = this.#generateUniqueValue(currentValues)
currentValues.push(newValue)
if (currentValues.length > 50) currentValues.shift()
this.database.set("opendiscord:option-suffix-history",this.option.id.value,currentValues)
await this.database.set("opendiscord:option-suffix-history",this.option.id.value,currentValues)
return newValue
}
}
@@ -539,13 +539,13 @@ export class ODOptionRandomHexSuffix extends ODOptionSuffix {
if (history.includes(hex)) return this.#generateUniqueValue(history)
else return hex
}
getSuffix(user:discord.User): string {
const rawCurrentValues = this.database.get("opendiscord:option-suffix-history",this.option.id.value)
async getSuffix(user:discord.User): Promise<string> {
const rawCurrentValues = await this.database.get("opendiscord:option-suffix-history",this.option.id.value)
const currentValues = ((Array.isArray(rawCurrentValues)) ? rawCurrentValues : []) as string[]
const newValue = this.#generateUniqueValue(currentValues)
currentValues.push(newValue)
if (currentValues.length > 50) currentValues.shift()
this.database.set("opendiscord:option-suffix-history",this.option.id.value,currentValues)
await this.database.set("opendiscord:option-suffix-history",this.option.id.value,currentValues)
return newValue
}
}