#143 : Panels now edit after using dropdown
From now on, all panels will update/edit themselfs after a dropdown has been used. This will reset the dropdown selection in the user client which results in a smoother user experience.
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}),
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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[],
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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 () => {}),
|
||||
|
||||
//nothing needs to be transferred :)
|
||||
},() => {
|
||||
//MIGRATE AFTER INITIAL STARTUP (plugins, flags, config, database, language, ... => loaded)
|
||||
//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 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)
|
||||
}
|
||||
})
|
||||
]
|
||||
@@ -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)
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user