diff --git a/src/commands/panel.ts b/src/commands/panel.ts index 74b44e6..22218db 100644 --- a/src/commands/panel.ts +++ b/src/commands/panel.ts @@ -64,9 +64,12 @@ export const registerCommandResponders = async () => { await instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:panel-ready").build(source,{guild,channel,user,panel})) const panelMessage = await instance.channel.send((await opendiscord.builders.messages.getSafe("opendiscord:panel").build(source,{guild,channel,user,panel})).message) - //add panel to database on auto-update + //add panel to database (this way, the bot knows where all panels are located) + const globalDatabase = opendiscord.databases.get("opendiscord:global") + await globalDatabase.set("opendiscord:panel-message",panelMessage.channel.id+"_"+panelMessage.id,panel.id.value) + + //add panel to database for auto-update if (instance.options.getBoolean("auto-update",false)){ - const globalDatabase = opendiscord.databases.get("opendiscord:global") await globalDatabase.set("opendiscord:panel-update",panelMessage.channel.id+"_"+panelMessage.id,panel.id.value) } }), diff --git a/src/commands/ticket.ts b/src/commands/ticket.ts index 1265d79..faab16c 100644 --- a/src/commands/ticket.ts +++ b/src/commands/ticket.ts @@ -205,6 +205,14 @@ export const registerDropdownResponders = async () => { } if (generalConfig.data.system.replyOnTicketCreation) await instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:ticket-created").build("panel-dropdown",{guild,channel:res.channel,user,ticket:res.ticket})) } + + //update panel after dropdown usage (reset panel choice) + const globalDatabase = opendiscord.databases.get("opendiscord:global") + const rawPanelId = await globalDatabase.get("opendiscord:panel-message",instance.message.channel.id+"_"+instance.message.id) + if (rawPanelId){ + const panel = opendiscord.panels.get(rawPanelId) + if (panel) await instance.message.edit((await opendiscord.builders.messages.getSafe("opendiscord:panel").build("auto-update",{guild,channel,user,panel})).message) + } }) ) } diff --git a/src/core/api/defaults/database.ts b/src/core/api/defaults/database.ts index 9dd3bcc..8e73a10 100644 --- a/src/core/api/defaults/database.ts +++ b/src/core/api/defaults/database.ts @@ -52,6 +52,7 @@ export class ODDatabaseManager_Default extends ODDatabaseManager { * It's used to generate typescript declarations for this class. */ export interface ODFormattedJsonDatabaseIds_DefaultGlobal { + "opendiscord:panel-message":string, "opendiscord:panel-update":string, "opendiscord:option-suffix-counter":number, "opendiscord:option-suffix-history":string[], diff --git a/src/core/startup/manageMigration.ts b/src/core/startup/manageMigration.ts index 8ac3f1c..496de92 100644 --- a/src/core/startup/manageMigration.ts +++ b/src/core/startup/manageMigration.ts @@ -5,7 +5,10 @@ export const loadVersionMigrationSystem = async () => { await preloadMigrationContext() const lastVersion = await isMigrationRequired() + + //save last version to database (OR set to current version if no migration is required) opendiscord.versions.add(lastVersion ? lastVersion : api.ODVersion.fromString("opendiscord:last-version",opendiscord.versions.get("opendiscord:version").toString())) + if (lastVersion && !opendiscord.flags.get("opendiscord:no-migration").value){ //MIGRATION IS REQUIRED opendiscord.log("Detected old data!","info") diff --git a/src/core/startup/migration.ts b/src/core/startup/migration.ts index 75b3734..45db853 100644 --- a/src/core/startup/migration.ts +++ b/src/core/startup/migration.ts @@ -2,15 +2,16 @@ import {opendiscord, api, utilities} from "../../index" export const migrations = [ //MIGRATE TO v4.0.0 - new utilities.ODVersionMigration(api.ODVersion.fromString("opendiscord:version","v4.0.0"),async () => { - //MIGRATE BEFORE STARTUP + new utilities.ODVersionMigration(api.ODVersion.fromString("opendiscord:version","v4.0.0"),async () => {},async () => {}), + + //MIGRATE TO v4.0.1 + new utilities.ODVersionMigration(api.ODVersion.fromString("opendiscord:version","v4.0.1"),async () => {},async () => { + //AFTER INIT MIGRATION - //nothing needs to be transferred :) - },() => { - //MIGRATE AFTER INITIAL STARTUP (plugins, flags, config, database, language, ... => loaded) - - //nothing needs to be transferred :) - }), - //MIGRATE TO v4.0.1 (nothing) - new utilities.ODVersionMigration(api.ODVersion.fromString("opendiscord:version","v4.0.0"),async () => {},() => {}) + //add opendiscord:panel-message properties for all existing panels. + const globalDatabase = opendiscord.databases.get("opendiscord:global") + for (const panel of (await globalDatabase.getCategory("opendiscord:panel-update") ?? [])){ + globalDatabase.set("opendiscord:panel-message",panel.key,panel.value) + } + }) ] \ No newline at end of file diff --git a/src/data/framework/codeLoader.ts b/src/data/framework/codeLoader.ts index 8899c14..4d7051e 100644 --- a/src/data/framework/codeLoader.ts +++ b/src/data/framework/codeLoader.ts @@ -73,7 +73,7 @@ export const loadDatabaseCleanersCode = async () => { const validPanels: string[] = [] //check global database for valid panel embeds - for (const panel of (await globalDatabase.getCategory("opendiscord:panel-update") ?? [])){ + for (const panel of (await globalDatabase.getCategory("opendiscord:panel-message") ?? [])){ if (!validPanels.includes(panel.key)){ try{ const splittedId = panel.key.split("_") @@ -84,15 +84,17 @@ export const loadDatabaseCleanersCode = async () => { } //remove all unused panels - for (const panel of (await globalDatabase.getCategory("opendiscord:panel-update") ?? [])){ + for (const panel of (await globalDatabase.getCategory("opendiscord:panel-message") ?? [])){ if (!validPanels.includes(panel.key)){ + await globalDatabase.delete("opendiscord:panel-message",panel.key) await globalDatabase.delete("opendiscord:panel-update",panel.key) } } //delete panel from database on delete opendiscord.client.client.on("messageDelete",async (msg) => { - if (await globalDatabase.exists("opendiscord:panel-update",msg.channel.id+"_"+msg.id)){ + if (await globalDatabase.exists("opendiscord:panel-message",msg.channel.id+"_"+msg.id)){ + await globalDatabase.delete("opendiscord:panel-message",msg.channel.id+"_"+msg.id) await globalDatabase.delete("opendiscord:panel-update",msg.channel.id+"_"+msg.id) } })