#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}))
|
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)
|
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)){
|
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)
|
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}))
|
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.
|
* It's used to generate typescript declarations for this class.
|
||||||
*/
|
*/
|
||||||
export interface ODFormattedJsonDatabaseIds_DefaultGlobal {
|
export interface ODFormattedJsonDatabaseIds_DefaultGlobal {
|
||||||
|
"opendiscord:panel-message":string,
|
||||||
"opendiscord:panel-update":string,
|
"opendiscord:panel-update":string,
|
||||||
"opendiscord:option-suffix-counter":number,
|
"opendiscord:option-suffix-counter":number,
|
||||||
"opendiscord:option-suffix-history":string[],
|
"opendiscord:option-suffix-history":string[],
|
||||||
|
|||||||
@@ -5,7 +5,10 @@ export const loadVersionMigrationSystem = async () => {
|
|||||||
await preloadMigrationContext()
|
await preloadMigrationContext()
|
||||||
|
|
||||||
const lastVersion = await isMigrationRequired()
|
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()))
|
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){
|
if (lastVersion && !opendiscord.flags.get("opendiscord:no-migration").value){
|
||||||
//MIGRATION IS REQUIRED
|
//MIGRATION IS REQUIRED
|
||||||
opendiscord.log("Detected old data!","info")
|
opendiscord.log("Detected old data!","info")
|
||||||
|
|||||||
@@ -2,15 +2,16 @@ import {opendiscord, api, utilities} from "../../index"
|
|||||||
|
|
||||||
export const migrations = [
|
export const migrations = [
|
||||||
//MIGRATE TO v4.0.0
|
//MIGRATE TO v4.0.0
|
||||||
new utilities.ODVersionMigration(api.ODVersion.fromString("opendiscord:version","v4.0.0"),async () => {
|
new utilities.ODVersionMigration(api.ODVersion.fromString("opendiscord:version","v4.0.0"),async () => {},async () => {}),
|
||||||
//MIGRATE BEFORE STARTUP
|
|
||||||
|
|
||||||
//nothing needs to be transferred :)
|
//MIGRATE TO v4.0.1
|
||||||
},() => {
|
new utilities.ODVersionMigration(api.ODVersion.fromString("opendiscord:version","v4.0.1"),async () => {},async () => {
|
||||||
//MIGRATE AFTER INITIAL STARTUP (plugins, flags, config, database, language, ... => loaded)
|
//AFTER INIT MIGRATION
|
||||||
|
|
||||||
//nothing needs to be transferred :)
|
//add opendiscord:panel-message properties for all existing panels.
|
||||||
}),
|
const globalDatabase = opendiscord.databases.get("opendiscord:global")
|
||||||
//MIGRATE TO v4.0.1 (nothing)
|
for (const panel of (await globalDatabase.getCategory("opendiscord:panel-update") ?? [])){
|
||||||
new utilities.ODVersionMigration(api.ODVersion.fromString("opendiscord:version","v4.0.0"),async () => {},() => {})
|
globalDatabase.set("opendiscord:panel-message",panel.key,panel.value)
|
||||||
|
}
|
||||||
|
})
|
||||||
]
|
]
|
||||||
@@ -73,7 +73,7 @@ export const loadDatabaseCleanersCode = async () => {
|
|||||||
const validPanels: string[] = []
|
const validPanels: string[] = []
|
||||||
|
|
||||||
//check global database for valid panel embeds
|
//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)){
|
if (!validPanels.includes(panel.key)){
|
||||||
try{
|
try{
|
||||||
const splittedId = panel.key.split("_")
|
const splittedId = panel.key.split("_")
|
||||||
@@ -84,15 +84,17 @@ export const loadDatabaseCleanersCode = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//remove all unused panels
|
//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)){
|
if (!validPanels.includes(panel.key)){
|
||||||
|
await globalDatabase.delete("opendiscord:panel-message",panel.key)
|
||||||
await globalDatabase.delete("opendiscord:panel-update",panel.key)
|
await globalDatabase.delete("opendiscord:panel-update",panel.key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//delete panel from database on delete
|
//delete panel from database on delete
|
||||||
opendiscord.client.client.on("messageDelete",async (msg) => {
|
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)
|
await globalDatabase.delete("opendiscord:panel-update",msg.channel.id+"_"+msg.id)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user