Fixed loopAll() async errors

This commit is contained in:
DJj123dj
2024-10-03 20:46:01 +02:00
parent 7c76be8473
commit 56e1fb3939
14 changed files with 24 additions and 24 deletions
+1 -1
View File
@@ -882,7 +882,7 @@ const blacklistEmbeds = () => {
const {user} = params const {user} = params
const renderedUsers: string[] = [] const renderedUsers: string[] = []
openticket.blacklist.forEach((blacklist,id) => {renderedUsers.push(discord.userMention(id.value)+" - "+(blacklist.reason ? blacklist.reason : "/"))}) openticket.blacklist.loopAll((blacklist,id) => {renderedUsers.push(discord.userMention(id.value)+" - "+(blacklist.reason ? blacklist.reason : "/"))})
instance.setAuthor(user.displayName,user.displayAvatarURL()) instance.setAuthor(user.displayName,user.displayAvatarURL())
instance.setColor(generalConfig.data.mainColor) instance.setColor(generalConfig.data.mainColor)
+1 -1
View File
@@ -371,7 +371,7 @@ export class ODManager<DataType extends ODManagerData> extends ODManagerChangeHe
return this.#data.map((d) => d.id) return this.#data.map((d) => d.id)
} }
/**Run an iterator over all data in this manager. This method also supports async-await behaviour!*/ /**Run an iterator over all data in this manager. This method also supports async-await behaviour!*/
async forEach(cb:(data:DataType,id:ODId) => ODPromiseVoid): Promise<void> { async loopAll(cb:(data:DataType,id:ODId) => ODPromiseVoid): Promise<void> {
for (const data of this.getAll()){ for (const data of this.getAll()){
await cb(data,data.id) await cb(data,data.id)
} }
+1 -1
View File
@@ -65,7 +65,7 @@ export class ODCheckerManager extends ODManager<ODChecker> {
if (!res.valid) isValid = false if (!res.valid) isValid = false
}) })
this.functions.forEach((func) => { this.functions.loopAll((func) => {
const res = func.func(this,this.functions) const res = func.func(this,this.functions)
final.push(...res.messages) final.push(...res.messages)
+2 -2
View File
@@ -496,7 +496,7 @@ export class ODSlashCommandManager extends ODManager<ODSlashCommand> {
const existing: {cmd:ODSlashCommand, requiresUpdate:boolean}[] = [] const existing: {cmd:ODSlashCommand, requiresUpdate:boolean}[] = []
const nonExisting: ODSlashCommand[] = [] const nonExisting: ODSlashCommand[] = []
this.forEach((cmd) => { this.loopAll((cmd) => {
if (guildId && cmd.guildId != guildId) return if (guildId && cmd.guildId != guildId) return
const result = cmds.find((cmddata) => cmddata.name == cmd.name) const result = cmds.find((cmddata) => cmddata.name == cmd.name)
if (result){ if (result){
@@ -977,7 +977,7 @@ export class ODTextCommandManager extends ODManager<ODTextCommand> {
//filter commands for correct prefix //filter commands for correct prefix
const validPrefixCommands: {cmd:ODTextCommand,newContent:string}[] = [] const validPrefixCommands: {cmd:ODTextCommand,newContent:string}[] = []
this.forEach((cmd) => { this.loopAll((cmd) => {
if (msg.content.startsWith(cmd.builder.prefix)) validPrefixCommands.push({ if (msg.content.startsWith(cmd.builder.prefix)) validPrefixCommands.push({
cmd:cmd, cmd:cmd,
newContent:msg.content.substring(cmd.builder.prefix.length) newContent:msg.content.substring(cmd.builder.prefix.length)
+2 -2
View File
@@ -139,7 +139,7 @@ export class ODCounterCooldown extends ODCooldown<{value:number}> {
async init(){ async init(){
if (this.ready) return if (this.ready) return
setInterval(() => { setInterval(() => {
this.data.forEach((cooldown) => { this.data.loopAll((cooldown) => {
cooldown.data.value = cooldown.data.value - this.decrement cooldown.data.value = cooldown.data.value - this.decrement
if (cooldown.data.value <= this.cancelLimit){ if (cooldown.data.value <= this.cancelLimit){
cooldown.active = false cooldown.active = false
@@ -217,7 +217,7 @@ export class ODIncrementalCounterCooldown extends ODCooldown<{value:number}> {
async init(){ async init(){
if (this.ready) return if (this.ready) return
setInterval(() => { setInterval(() => {
this.data.forEach((cooldown) => { this.data.loopAll((cooldown) => {
cooldown.data.value = cooldown.data.value - this.decrement cooldown.data.value = cooldown.data.value - this.decrement
if (cooldown.data.value <= this.cancelLimit){ if (cooldown.data.value <= this.cancelLimit){
cooldown.active = false cooldown.active = false
+1 -1
View File
@@ -66,7 +66,7 @@ export class ODFlagManager extends ODManager<ODFlag> {
/**Set all flags to their `process.argv` value. */ /**Set all flags to their `process.argv` value. */
init(){ init(){
this.forEach((flag) => { this.loopAll((flag) => {
flag.detectProcessParams(false) flag.detectProcessParams(false)
}) })
} }
+4 -4
View File
@@ -42,9 +42,9 @@ const preloadMigrationContext = async () => {
const unloadMigrationContext = async () => { const unloadMigrationContext = async () => {
openticket.debug.visible = false openticket.debug.visible = false
openticket.databases.forEach((database,id) => {openticket.databases.remove(id)}) openticket.databases.loopAll((database,id) => {openticket.databases.remove(id)})
openticket.configs.forEach((config,id) => {openticket.configs.remove(id)}) openticket.configs.loopAll((config,id) => {openticket.configs.remove(id)})
openticket.flags.forEach((flag,id) => {openticket.flags.remove(id)}) openticket.flags.loopAll((flag,id) => {openticket.flags.remove(id)})
openticket.debug.debug("-- MIGRATION CONTEXT END --") openticket.debug.debug("-- MIGRATION CONTEXT END --")
} }
@@ -78,7 +78,7 @@ const loadAllVersionMigrations = async (lastVersion:api.ODVersion) => {
const saveAllVersionsToDatabase = async () => { const saveAllVersionsToDatabase = async () => {
const globalDatabase = openticket.databases.get("openticket:global") const globalDatabase = openticket.databases.get("openticket:global")
openticket.versions.forEach((version,id) => { openticket.versions.loopAll((version,id) => {
globalDatabase.set("openticket:last-version",id.value,version.toString()) globalDatabase.set("openticket:last-version",id.value,version.toString())
}) })
} }
+2 -2
View File
@@ -135,7 +135,7 @@ export const loadDatabaseCleanersCode = async () => {
//OPTION DATABASE CLEANER //OPTION DATABASE CLEANER
openticket.code.add(new api.ODCode("openticket:option-database-cleaner",10,() => { openticket.code.add(new api.ODCode("openticket:option-database-cleaner",10,() => {
//delete all unused options //delete all unused options
openticket.options.forEach((option,id) => { openticket.options.loopAll((option,id) => {
if (optionDatabase.exists("openticket:used-option",id.value) && !openticket.tickets.getAll().some((ticket) => ticket.id.value == id.value)){ if (optionDatabase.exists("openticket:used-option",id.value) && !openticket.tickets.getAll().some((ticket) => ticket.id.value == id.value)){
optionDatabase.delete("openticket:used-option",id.value) optionDatabase.delete("openticket:used-option",id.value)
} }
@@ -331,7 +331,7 @@ export const loadDatabaseSaversCode = async () => {
} }
//delete all unused options on ticket move //delete all unused options on ticket move
openticket.options.forEach((option,id) => { openticket.options.loopAll((option,id) => {
if (optionDatabase.exists("openticket:used-option",id.value) && !openticket.tickets.getAll().some((ticket) => ticket.id.value == id.value)){ if (optionDatabase.exists("openticket:used-option",id.value) && !openticket.tickets.getAll().some((ticket) => ticket.id.value == id.value)){
optionDatabase.delete("openticket:used-option",id.value) optionDatabase.delete("openticket:used-option",id.value)
} }
+1 -1
View File
@@ -1,7 +1,7 @@
import {openticket, api, utilities} from "../../index" import {openticket, api, utilities} from "../../index"
export const loadAllCooldowns = async () => { export const loadAllCooldowns = async () => {
openticket.options.forEach((option) => { openticket.options.loopAll((option) => {
if (!(option instanceof api.ODTicketOption)) return if (!(option instanceof api.ODTicketOption)) return
loadTicketOptionCooldown(option) loadTicketOptionCooldown(option)
}) })
+1 -1
View File
@@ -30,7 +30,7 @@ export const loadAllPermissions = async () => {
}) })
//TICKET ADMINS //TICKET ADMINS
openticket.tickets.forEach(async (ticket) => { openticket.tickets.loopAll(async (ticket) => {
try { try {
const channel = await openticket.client.fetchGuildTextChannel(mainServer,ticket.id.value) const channel = await openticket.client.fetchGuildTextChannel(mainServer,ticket.id.value)
if (!channel) return if (!channel) return
+4 -4
View File
@@ -19,8 +19,8 @@ export const loadAllOptions = async () => {
//update options on config reload //update options on config reload
optionConfig.onReload(async () => { optionConfig.onReload(async () => {
//clear previous options & suffixes //clear previous options & suffixes
openticket.options.forEach((data,id) => {openticket.options.remove(id)}) await openticket.options.loopAll((data,id) => {openticket.options.remove(id)})
openticket.options.suffix.forEach((data,id) => {openticket.options.suffix.remove(id)}) await openticket.options.suffix.loopAll((data,id) => {openticket.options.suffix.remove(id)})
//add new options //add new options
optionConfig.data.forEach((option) => { optionConfig.data.forEach((option) => {
@@ -36,7 +36,7 @@ export const loadAllOptions = async () => {
}) })
//update options in tickets //update options in tickets
openticket.tickets.forEach((ticket) => { await openticket.tickets.loopAll((ticket) => {
const optionId = ticket.option.id const optionId = ticket.option.id
const option = openticket.options.get(optionId) const option = openticket.options.get(optionId)
if (option && option instanceof api.ODTicketOption) ticket.option = option if (option && option instanceof api.ODTicketOption) ticket.option = option
@@ -49,7 +49,7 @@ export const loadAllOptions = async () => {
}) })
//update roles on config reload //update roles on config reload
openticket.roles.forEach((data,id) => {openticket.roles.remove(id)}) await openticket.roles.loopAll((data,id) => {openticket.roles.remove(id)})
await (await import("./roleLoader.js")).loadAllRoles() await (await import("./roleLoader.js")).loadAllRoles()
}) })
} }
+1 -1
View File
@@ -12,7 +12,7 @@ export const loadAllPanels = async () => {
//update panels on config reload //update panels on config reload
panelConfig.onReload(async () => { panelConfig.onReload(async () => {
//clear previous panels //clear previous panels
openticket.panels.forEach((data,id) => {openticket.panels.remove(id)}) await openticket.panels.loopAll((data,id) => {openticket.panels.remove(id)})
//add new panels //add new panels
panelConfig.data.forEach((panel) => { panelConfig.data.forEach((panel) => {
+2 -2
View File
@@ -13,9 +13,9 @@ export const loadAllQuestions = async () => {
}) })
//update questions on config reload //update questions on config reload
questionConfig.onReload(() => { questionConfig.onReload(async () => {
//clear previous questions //clear previous questions
openticket.questions.forEach((data,id) => {openticket.questions.remove(id)}) await openticket.questions.loopAll((data,id) => {openticket.questions.remove(id)})
//add new questions //add new questions
questionConfig.data.forEach((question) => { questionConfig.data.forEach((question) => {
+1 -1
View File
@@ -1,7 +1,7 @@
import {openticket, api, utilities} from "../../index" import {openticket, api, utilities} from "../../index"
export const loadAllRoles = async () => { export const loadAllRoles = async () => {
openticket.options.forEach((opt) => { openticket.options.loopAll((opt) => {
if (opt instanceof api.ODRoleOption){ if (opt instanceof api.ODRoleOption){
openticket.roles.add(loadRole(opt)) openticket.roles.add(loadRole(opt))
} }