(v4.2.0) Panel auto-update now uses message states

This commit is contained in:
DJj123dj
2026-05-23 14:32:22 +02:00
parent 4af9b9e17f
commit c442e50cb4
6 changed files with 123 additions and 74 deletions
+19
View File
@@ -12,6 +12,7 @@ import { ODTicketClearFilter } from "../api/ticket.js"
export interface ODStateManagerIdMappings extends api.ODStateManagerIdConstraint {
"opendiscord:interactive-message":ODInteractiveMessageState,
"opendiscord:clear-message":ODClearMessageState,
"opendiscord:panel-message":ODPanelMessageState,
}
/////////////////////////////
@@ -59,4 +60,22 @@ export class ODClearMessageState extends api.ODState<{
autodeleteOnRestart:true
})
}
}
/**## ODPanelMessageState `class
* A special class with state types for the Open Ticket panel message.
*/
export class ODPanelMessageState extends api.ODState<{
/**The method this message was generated with. */
messageOrigin:"slash"|"text"|"auto-update"|"other",
/**The Id of the panel associated with this message. */
panelId:string,
/**A list of options available in this panel. (buttons or dropdown) */
panelOptionIds:string[]
/**Should this panel be auto-updated on restart? */
panelAutoUpdate:boolean
},false,false> {
constructor(id:api.ODValidId,client:api.ODClientManager,database:api.ODDatabase){
super(id,client,database,{})
}
}
+31 -1
View File
@@ -339,9 +339,11 @@ export const migrations = [
}
//migrate database
const globalDatabase = opendiscord.databases.get("opendiscord:global")
const optionDatabase = opendiscord.databases.get("opendiscord:options")
const ticketDatabase = opendiscord.databases.get("opendiscord:tickets")
const stateDatabase = opendiscord.databases.get("opendiscord:message-states")
for (const option of (await optionDatabase.getCategory("opendiscord:used-option") ?? [])){
const optionData = option.value
optionData.data = optionData.data.filter((data) => (
@@ -359,6 +361,34 @@ export const migrations = [
ticketDatabase.set("opendiscord:ticket",ticket.key,ticketData)
}
//migrate old panel messages from global.json to the new message states
const migratedPanelStates: {channelId:string,messageId:string,panelId:string,autoUpdate:boolean}[] = []
opendiscord.events.get("afterClientReady").listen(async () => {
for (const panelMessage of (await globalDatabase.getCategory("opendiscord:panel-message") ?? [])){
const splittedId = panelMessage.key.split("_")
const channelId = splittedId[0]
const messageId = splittedId[1]
const message = await opendiscord.client.fetchChannelMessage(channelId,messageId)
const autoUpdate = typeof (await globalDatabase.get("opendiscord:panel-update",panelMessage.key)) == "string"
//if message still exists
if (message) migratedPanelStates.push({channelId,messageId,panelId:panelMessage.value,autoUpdate})
await globalDatabase.delete("opendiscord:panel-message",panelMessage.key)
await globalDatabase.delete("opendiscord:panel-update",panelMessage.key)
}
})
opendiscord.events.get("afterStatesInitiated").listen(async (states) => {
const panelMsgState = states.get("opendiscord:panel-message")
for (const {channelId,messageId,panelId,autoUpdate} of migratedPanelStates){
await panelMsgState.setMsgState({channel:channelId,message:messageId},{
messageOrigin:"auto-update",
panelId,
panelOptionIds:[],
panelAutoUpdate:autoUpdate
},false)
}
})
}
}),
]