diff --git a/src/actions/claimTicket.ts b/src/actions/claimTicket.ts index e3b6aa5..6ce25a3 100644 --- a/src/actions/claimTicket.ts +++ b/src/actions/claimTicket.ts @@ -22,8 +22,8 @@ export const registerActions = async () => { ticket.get("openticket:busy").value = true //update stats - openticket.stats.get("openticket:global").setStat("openticket:tickets-claimed",1,"increase") - openticket.stats.get("openticket:user").setStat("openticket:tickets-claimed",user.id,1,"increase") + await openticket.stats.get("openticket:global").setStat("openticket:tickets-claimed",1,"increase") + await openticket.stats.get("openticket:user").setStat("openticket:tickets-claimed",user.id,1,"increase") //update category const rawClaimCategory = ticket.option.get("openticket:channel-categories-claimed").value.find((c) => c.user == user.id) diff --git a/src/actions/closeTicket.ts b/src/actions/closeTicket.ts index 4e87dcd..d8374d3 100644 --- a/src/actions/closeTicket.ts +++ b/src/actions/closeTicket.ts @@ -24,8 +24,8 @@ export const registerActions = async () => { ticket.get("openticket:busy").value = true //update stats - openticket.stats.get("openticket:global").setStat("openticket:tickets-closed",1,"increase") - openticket.stats.get("openticket:user").setStat("openticket:tickets-closed",user.id,1,"increase") + await openticket.stats.get("openticket:global").setStat("openticket:tickets-closed",1,"increase") + await openticket.stats.get("openticket:user").setStat("openticket:tickets-closed",user.id,1,"increase") //update category const closeCategory = ticket.option.get("openticket:channel-category-closed").value diff --git a/src/actions/createTicket.ts b/src/actions/createTicket.ts index adca753..7174a9d 100644 --- a/src/actions/createTicket.ts +++ b/src/actions/createTicket.ts @@ -159,8 +159,8 @@ export const registerActions = async () => { ]) //manage stats - openticket.stats.get("openticket:global").setStat("openticket:tickets-created",1,"increase") - openticket.stats.get("openticket:user").setStat("openticket:tickets-created",user.id,1,"increase") + await openticket.stats.get("openticket:global").setStat("openticket:tickets-created",1,"increase") + await openticket.stats.get("openticket:user").setStat("openticket:tickets-created",user.id,1,"increase") //manage bot permissions await openticket.events.get("onTicketPermissionsCreated").emit([option,openticket.permissions,channel,user]) @@ -187,7 +187,7 @@ export const registerActions = async () => { ticket.get("openticket:ticket-message").value = msg.id //manage stats - openticket.stats.get("openticket:ticket").setStat("openticket:messages-sent",ticket.id.value,1,"increase") + await openticket.stats.get("openticket:ticket").setStat("openticket:messages-sent",ticket.id.value,1,"increase") await openticket.events.get("afterTicketMainMessageCreated").emit([ticket,msg,channel,user]) }catch(err){ diff --git a/src/actions/createTranscript.ts b/src/actions/createTranscript.ts index 88d9b1c..10fab95 100644 --- a/src/actions/createTranscript.ts +++ b/src/actions/createTranscript.ts @@ -145,8 +145,8 @@ export const registerActions = async () => { }) //update stats - openticket.stats.get("openticket:global").setStat("openticket:transcripts-created",1,"increase") - openticket.stats.get("openticket:user").setStat("openticket:transcripts-created",params.user.id,1,"increase") + await openticket.stats.get("openticket:global").setStat("openticket:transcripts-created",1,"increase") + await openticket.stats.get("openticket:user").setStat("openticket:transcripts-created",params.user.id,1,"increase") await openticket.events.get("afterTranscriptCreated").emit([openticket.transcripts,instance.result.ticket,instance.result.channel,instance.result.user]) }), new api.ODWorker("openticket:logs",0,(instance,params,source,cancel) => { diff --git a/src/actions/deleteTicket.ts b/src/actions/deleteTicket.ts index a50b043..e6f8367 100644 --- a/src/actions/deleteTicket.ts +++ b/src/actions/deleteTicket.ts @@ -56,8 +56,8 @@ export const registerActions = async () => { } //update stats - openticket.stats.get("openticket:global").setStat("openticket:tickets-deleted",1,"increase") - openticket.stats.get("openticket:user").setStat("openticket:tickets-deleted",user.id,1,"increase") + await openticket.stats.get("openticket:global").setStat("openticket:tickets-deleted",1,"increase") + await openticket.stats.get("openticket:user").setStat("openticket:tickets-deleted",user.id,1,"increase") //delete ticket from manager openticket.tickets.remove(ticket.id) diff --git a/src/actions/moveTicket.ts b/src/actions/moveTicket.ts index 7d95b82..dfcd7ba 100644 --- a/src/actions/moveTicket.ts +++ b/src/actions/moveTicket.ts @@ -17,8 +17,8 @@ export const registerActions = async () => { ticket.option = data //update stats - openticket.stats.get("openticket:global").setStat("openticket:tickets-moved",1,"increase") - openticket.stats.get("openticket:user").setStat("openticket:tickets-moved",user.id,1,"increase") + await openticket.stats.get("openticket:global").setStat("openticket:tickets-moved",1,"increase") + await openticket.stats.get("openticket:user").setStat("openticket:tickets-moved",user.id,1,"increase") //get new channel properties const channelPrefix = ticket.option.get("openticket:channel-prefix").value diff --git a/src/actions/pinTicket.ts b/src/actions/pinTicket.ts index 3f06af4..c0dfb32 100644 --- a/src/actions/pinTicket.ts +++ b/src/actions/pinTicket.ts @@ -22,8 +22,8 @@ export const registerActions = async () => { ticket.get("openticket:busy").value = true //update stats - openticket.stats.get("openticket:global").setStat("openticket:tickets-pinned",1,"increase") - openticket.stats.get("openticket:user").setStat("openticket:tickets-pinned",user.id,1,"increase") + await openticket.stats.get("openticket:global").setStat("openticket:tickets-pinned",1,"increase") + await openticket.stats.get("openticket:user").setStat("openticket:tickets-pinned",user.id,1,"increase") //move to top of category if (channel.parent){ diff --git a/src/actions/reopenTicket.ts b/src/actions/reopenTicket.ts index 4d992b6..dccf05c 100644 --- a/src/actions/reopenTicket.ts +++ b/src/actions/reopenTicket.ts @@ -24,8 +24,8 @@ export const registerActions = async () => { ticket.get("openticket:busy").value = true //update stats - openticket.stats.get("openticket:global").setStat("openticket:tickets-reopened",1,"increase") - openticket.stats.get("openticket:user").setStat("openticket:tickets-reopened",user.id,1,"increase") + await openticket.stats.get("openticket:global").setStat("openticket:tickets-reopened",1,"increase") + await openticket.stats.get("openticket:user").setStat("openticket:tickets-reopened",user.id,1,"increase") //update category const channelCategory = ticket.option.get("openticket:channel-category").value diff --git a/src/commands/blacklist.ts b/src/commands/blacklist.ts index f0d3a6e..d7448d4 100644 --- a/src/commands/blacklist.ts +++ b/src/commands/blacklist.ts @@ -74,8 +74,8 @@ export const registerCommandResponders = async () => { ]) //manage stats - openticket.stats.get("openticket:global").setStat("openticket:users-blacklisted",1,"increase") - openticket.stats.get("openticket:user").setStat("openticket:users-blacklisted",user.id,1,"increase") + await openticket.stats.get("openticket:global").setStat("openticket:users-blacklisted",1,"increase") + await openticket.stats.get("openticket:user").setStat("openticket:users-blacklisted",user.id,1,"increase") await instance.reply(await openticket.builders.messages.getSafe("openticket:blacklist-add").build(source,{guild,channel,user,data,reason})) diff --git a/src/core/api/defaults/stat.ts b/src/core/api/defaults/stat.ts index 3366d7d..d4ea1e9 100644 --- a/src/core/api/defaults/stat.ts +++ b/src/core/api/defaults/stat.ts @@ -92,24 +92,24 @@ export class ODStatGlobalScope_DefaultGlobal extends ODStatGlobalScope { return super.exists(id) } - getStat(id:StatsId): ODValidStatValue|null - getStat(id:ODValidId): ODValidStatValue|null + getStat(id:StatsId): Promise + getStat(id:ODValidId): Promise - getStat(id:ODValidId): ODValidStatValue|null { + getStat(id:ODValidId): Promise { return super.getStat(id) } - setStat(id:StatsId, value:ODValidStatValue, mode:ODStatScopeSetMode): boolean - setStat(id:ODValidId, value:ODValidStatValue, mode:ODStatScopeSetMode): boolean + setStat(id:StatsId, value:ODValidStatValue, mode:ODStatScopeSetMode): Promise + setStat(id:ODValidId, value:ODValidStatValue, mode:ODStatScopeSetMode): Promise - setStat(id:ODValidId, value:ODValidStatValue, mode:ODStatScopeSetMode): boolean { + setStat(id:ODValidId, value:ODValidStatValue, mode:ODStatScopeSetMode): Promise { return super.setStat(id,value,mode) } - resetStat(id:ODValidId): ODValidStatValue|null - resetStat(id:ODValidId): ODValidStatValue|null + resetStat(id:ODValidId): Promise + resetStat(id:ODValidId): Promise - resetStat(id:ODValidId): ODValidStatValue|null { + resetStat(id:ODValidId): Promise { return super.resetStat(id) } } @@ -151,24 +151,24 @@ export class ODStatGlobalScope_DefaultSystem extends ODStatGlobalScope { return super.exists(id) } - getStat(id:StatsId): ODValidStatValue|null - getStat(id:ODValidId): ODValidStatValue|null + getStat(id:StatsId): Promise + getStat(id:ODValidId): Promise - getStat(id:ODValidId): ODValidStatValue|null { + getStat(id:ODValidId): Promise { return super.getStat(id) } - setStat(id:StatsId, value:ODValidStatValue, mode:ODStatScopeSetMode): boolean - setStat(id:ODValidId, value:ODValidStatValue, mode:ODStatScopeSetMode): boolean + setStat(id:StatsId, value:ODValidStatValue, mode:ODStatScopeSetMode): Promise + setStat(id:ODValidId, value:ODValidStatValue, mode:ODStatScopeSetMode): Promise - setStat(id:ODValidId, value:ODValidStatValue, mode:ODStatScopeSetMode): boolean { + setStat(id:ODValidId, value:ODValidStatValue, mode:ODStatScopeSetMode): Promise { return super.setStat(id,value,mode) } - resetStat(id:ODValidId): ODValidStatValue|null - resetStat(id:ODValidId): ODValidStatValue|null + resetStat(id:ODValidId): Promise + resetStat(id:ODValidId): Promise - resetStat(id:ODValidId): ODValidStatValue|null { + resetStat(id:ODValidId): Promise { return super.resetStat(id) } } @@ -219,24 +219,24 @@ export class ODStatScope_DefaultUser extends ODStatScope { return super.exists(id) } - getStat(id:StatsId, scopeId:string): ODValidStatValue|null - getStat(id:ODValidId, scopeId:string): ODValidStatValue|null + getStat(id:StatsId, scopeId:string): Promise + getStat(id:ODValidId, scopeId:string): Promise - getStat(id:ODValidId, scopeId:string): ODValidStatValue|null { + getStat(id:ODValidId, scopeId:string): Promise { return super.getStat(id,scopeId) } - setStat(id:StatsId, scopeId:string, value:ODValidStatValue, mode:ODStatScopeSetMode): boolean - setStat(id:ODValidId, scopeId:string, value:ODValidStatValue, mode:ODStatScopeSetMode): boolean + setStat(id:StatsId, scopeId:string, value:ODValidStatValue, mode:ODStatScopeSetMode): Promise + setStat(id:ODValidId, scopeId:string, value:ODValidStatValue, mode:ODStatScopeSetMode): Promise - setStat(id:ODValidId, scopeId:string, value:ODValidStatValue, mode:ODStatScopeSetMode): boolean { + setStat(id:ODValidId, scopeId:string, value:ODValidStatValue, mode:ODStatScopeSetMode): Promise { return super.setStat(id,scopeId,value,mode) } - resetStat(id:ODValidId, scopeId:string): ODValidStatValue|null - resetStat(id:ODValidId, scopeId:string): ODValidStatValue|null + resetStat(id:ODValidId, scopeId:string): Promise + resetStat(id:ODValidId, scopeId:string): Promise - resetStat(id:ODValidId, scopeId:string): ODValidStatValue|null { + resetStat(id:ODValidId, scopeId:string): Promise { return super.resetStat(id,scopeId) } } @@ -282,24 +282,24 @@ export class ODStatScope_DefaultTicket extends ODStatScope { return super.exists(id) } - getStat(id:StatsId, scopeId:string): ODValidStatValue|null - getStat(id:ODValidId, scopeId:string): ODValidStatValue|null + getStat(id:StatsId, scopeId:string): Promise + getStat(id:ODValidId, scopeId:string): Promise - getStat(id:ODValidId, scopeId:string): ODValidStatValue|null { + getStat(id:ODValidId, scopeId:string): Promise { return super.getStat(id,scopeId) } - setStat(id:StatsId, scopeId:string, value:ODValidStatValue, mode:ODStatScopeSetMode): boolean - setStat(id:ODValidId, scopeId:string, value:ODValidStatValue, mode:ODStatScopeSetMode): boolean + setStat(id:StatsId, scopeId:string, value:ODValidStatValue, mode:ODStatScopeSetMode): Promise + setStat(id:ODValidId, scopeId:string, value:ODValidStatValue, mode:ODStatScopeSetMode): Promise - setStat(id:ODValidId, scopeId:string, value:ODValidStatValue, mode:ODStatScopeSetMode): boolean { + setStat(id:ODValidId, scopeId:string, value:ODValidStatValue, mode:ODStatScopeSetMode): Promise { return super.setStat(id,scopeId,value,mode) } - resetStat(id:ODValidId, scopeId:string): ODValidStatValue|null - resetStat(id:ODValidId, scopeId:string): ODValidStatValue|null + resetStat(id:ODValidId, scopeId:string): Promise + resetStat(id:ODValidId, scopeId:string): Promise - resetStat(id:ODValidId, scopeId:string): ODValidStatValue|null { + resetStat(id:ODValidId, scopeId:string): Promise { return super.resetStat(id,scopeId) } } @@ -340,24 +340,24 @@ export class ODStatScope_DefaultParticipants extends ODStatScope { return super.exists(id) } - getStat(id:StatsId, scopeId:string): ODValidStatValue|null - getStat(id:ODValidId, scopeId:string): ODValidStatValue|null + getStat(id:StatsId, scopeId:string): Promise + getStat(id:ODValidId, scopeId:string): Promise - getStat(id:ODValidId, scopeId:string): ODValidStatValue|null { + getStat(id:ODValidId, scopeId:string): Promise { return super.getStat(id,scopeId) } - setStat(id:StatsId, scopeId:string, value:ODValidStatValue, mode:ODStatScopeSetMode): boolean - setStat(id:ODValidId, scopeId:string, value:ODValidStatValue, mode:ODStatScopeSetMode): boolean + setStat(id:StatsId, scopeId:string, value:ODValidStatValue, mode:ODStatScopeSetMode): Promise + setStat(id:ODValidId, scopeId:string, value:ODValidStatValue, mode:ODStatScopeSetMode): Promise - setStat(id:ODValidId, scopeId:string, value:ODValidStatValue, mode:ODStatScopeSetMode): boolean { + setStat(id:ODValidId, scopeId:string, value:ODValidStatValue, mode:ODStatScopeSetMode): Promise { return super.setStat(id,scopeId,value,mode) } - resetStat(id:ODValidId, scopeId:string): ODValidStatValue|null - resetStat(id:ODValidId, scopeId:string): ODValidStatValue|null + resetStat(id:ODValidId, scopeId:string): Promise + resetStat(id:ODValidId, scopeId:string): Promise - resetStat(id:ODValidId, scopeId:string): ODValidStatValue|null { + resetStat(id:ODValidId, scopeId:string): Promise { return super.resetStat(id,scopeId) } } \ No newline at end of file diff --git a/src/core/api/modules/stat.ts b/src/core/api/modules/stat.ts index baff800..0c1fe37 100644 --- a/src/core/api/modules/stat.ts +++ b/src/core/api/modules/stat.ts @@ -53,18 +53,18 @@ export class ODStatsManager extends ODManager { } //delete all deletable stats - deletableStats.forEach((data) => { + for (const data of deletableStats){ if (!this.database) return - this.database.delete(data.category,data.key) - }) + await this.database.delete(data.category,data.key) + } } async reset(){ if (!this.database) return const data = await this.database.getAll() - data.forEach((data) => { + for (const d of data){ if (!this.database) return - this.database.delete(data.category,data.key) - }) + await this.database.delete(d.category,d.key) + } } onInit(callback:ODStatsManagerInitCallback){ this.#initListeners.push(callback) @@ -90,10 +90,10 @@ export class ODStatScope extends ODManager { useDatabase(database:ODDatabase){ this.database = database } - getStat(id:ODValidId, scopeId:string): ODValidStatValue|null { + async getStat(id:ODValidId, scopeId:string): Promise { if (!this.database) return null const newId = new ODId(id) - const data = this.database.get(this.id.value+"_"+newId.value,scopeId) + const data = await this.database.get(this.id.value+"_"+newId.value,scopeId) if (typeof data == "undefined"){ //set stats to default value & return @@ -105,28 +105,28 @@ export class ODStatScope extends ODManager { //return null on error return null } - setStat(id:ODValidId, scopeId:string, value:ODValidStatValue, mode:ODStatScopeSetMode): boolean { + async setStat(id:ODValidId, scopeId:string, value:ODValidStatValue, mode:ODStatScopeSetMode): Promise { if (!this.database) return false const stat = this.get(id) if (!stat) return false if (mode == "set" || typeof value != "number"){ - this.database.set(this.id.value+"_"+stat.id.value,scopeId,value) + await this.database.set(this.id.value+"_"+stat.id.value,scopeId,value) }else if (mode == "increase"){ const currentValue = this.getStat(id,scopeId) - if (typeof currentValue != "number") this.database.set(this.id.value+"_"+stat.id.value,scopeId,0) - else this.database.set(this.id.value+"_"+stat.id.value,scopeId,currentValue+value) + if (typeof currentValue != "number") await this.database.set(this.id.value+"_"+stat.id.value,scopeId,0) + else await this.database.set(this.id.value+"_"+stat.id.value,scopeId,currentValue+value) }else if (mode == "decrease"){ const currentValue = this.getStat(id,scopeId) - if (typeof currentValue != "number") this.database.set(this.id.value+"_"+stat.id.value,scopeId,0) - else this.database.set(this.id.value+"_"+stat.id.value,scopeId,currentValue-value) + if (typeof currentValue != "number") await this.database.set(this.id.value+"_"+stat.id.value,scopeId,0) + else await this.database.set(this.id.value+"_"+stat.id.value,scopeId,currentValue-value) } return true } - resetStat(id:ODValidId, scopeId:string): ODValidStatValue|null { + async resetStat(id:ODValidId, scopeId:string): Promise { if (!this.database) return null const stat = this.get(id) if (!stat) return null - if (stat.value != null) this.database.set(this.id.value+"_"+stat.id.value,scopeId,stat.value) + if (stat.value != null) await this.database.set(this.id.value+"_"+stat.id.value,scopeId,stat.value) return stat.value } init(): string[] { @@ -149,7 +149,7 @@ export class ODStatScope extends ODManager { result.push(await stat.render("",scopeId,guild,channel,user)) }else{ //normal render (with value) - const value = this.getStat(stat.id,scopeId) + const value = await this.getStat(stat.id,scopeId) if (value != null) result.push(await stat.render(value,scopeId,guild,channel,user)) } @@ -163,13 +163,13 @@ export class ODStatScope extends ODManager { } export class ODStatGlobalScope extends ODStatScope { - getStat(id:ODValidId): ODValidStatValue|null { + getStat(id:ODValidId): Promise { return super.getStat(id,"GLOBAL") } - setStat(id:ODValidId, value:ODValidStatValue, mode:ODStatScopeSetMode): boolean { + setStat(id:ODValidId, value:ODValidStatValue, mode:ODStatScopeSetMode): Promise { return super.setStat(id,"GLOBAL",value,mode) } - resetStat(id:ODValidId): ODValidStatValue|null { + resetStat(id:ODValidId): Promise { return super.resetStat(id,"GLOBAL") } render(scopeId:"GLOBAL", guild:discord.Guild, channel:discord.TextBasedChannel, user: discord.User): Promise { diff --git a/src/data/framework/codeLoader.ts b/src/data/framework/codeLoader.ts index aee5ce3..b5e2d29 100644 --- a/src/data/framework/codeLoader.ts +++ b/src/data/framework/codeLoader.ts @@ -394,7 +394,7 @@ const loadAutoCode = () => { await openticket.actions.get("openticket:close-ticket").run("autoclose",{guild:channel.guild,channel,user:openticket.client.client.user,ticket,reason:"Autoclose",sendMessage:false}) await channel.send((await openticket.builders.messages.getSafe("openticket:autoclose-message").build("timeout",{guild:channel.guild,channel,user:openticket.client.client.user,ticket})).message) count++ - openticket.stats.get("openticket:global").setStat("openticket:tickets-autoclosed",1,"increase") + await openticket.stats.get("openticket:global").setStat("openticket:tickets-autoclosed",1,"increase") } } } @@ -420,7 +420,7 @@ const loadAutoCode = () => { //autoclose ticket await openticket.actions.get("openticket:close-ticket").run("autoclose",{guild:channel.guild,channel,user:openticket.client.client.user,ticket,reason:"Autoclose",sendMessage:false}) await channel.send((await openticket.builders.messages.getSafe("openticket:autoclose-message").build("leave",{guild:channel.guild,channel,user:openticket.client.client.user,ticket})).message) - openticket.stats.get("openticket:global").setStat("openticket:tickets-autoclosed",1,"increase") + await openticket.stats.get("openticket:global").setStat("openticket:tickets-autoclosed",1,"increase") } } } @@ -447,7 +447,7 @@ const loadAutoCode = () => { await channel.send((await openticket.builders.messages.getSafe("openticket:autodelete-message").build("timeout",{guild:channel.guild,channel,user:openticket.client.client.user,ticket})).message) await openticket.actions.get("openticket:delete-ticket").run("autodelete",{guild:channel.guild,channel,user:openticket.client.client.user,ticket,reason:"Autodelete",sendMessage:false,withoutTranscript:false}) count++ - openticket.stats.get("openticket:global").setStat("openticket:tickets-autodeleted",1,"increase") + await openticket.stats.get("openticket:global").setStat("openticket:tickets-autodeleted",1,"increase") } } } @@ -473,7 +473,7 @@ const loadAutoCode = () => { //autodelete ticket await channel.send((await openticket.builders.messages.getSafe("openticket:autodelete-message").build("leave",{guild:channel.guild,channel,user:openticket.client.client.user,ticket})).message) await openticket.actions.get("openticket:delete-ticket").run("autodelete",{guild:channel.guild,channel,user:openticket.client.client.user,ticket,reason:"Autodelete",sendMessage:false,withoutTranscript:false}) - openticket.stats.get("openticket:global").setStat("openticket:tickets-autodeleted",1,"increase") + await openticket.stats.get("openticket:global").setStat("openticket:tickets-autodeleted",1,"increase") } } }