Started working on --silent flag

This commit is contained in:
DJj123dj
2025-04-04 22:40:15 +02:00
parent 9414b96221
commit 376fa23288
4 changed files with 30 additions and 22 deletions
+1
View File
@@ -23,6 +23,7 @@ export interface ODFlagManagerIds_Default {
"opendiscord:force-slash-update":ODFlag,
"opendiscord:no-compile":ODFlag,
"opendiscord:compile-only":ODFlag,
"opendiscord:silent":ODFlag,
}
/**## ODFlagManager_Default `default_class`
+27 -21
View File
@@ -1,5 +1,24 @@
import {opendiscord, api, utilities} from "../../index"
/**Check if migration is required. Returns the last version used in the database. */
async function isMigrationRequired(): Promise<false|api.ODVersion> {
const rawVersion = await opendiscord.databases.get("opendiscord:global").get("opendiscord:last-version","opendiscord:version")
if (!rawVersion) return false
const version = api.ODVersion.fromString("opendiscord:last-version",rawVersion)
if (opendiscord.versions.get("opendiscord:version").compare(version) == "higher"){
return version
}else return false
}
/**Save all versions in `opendiscord.versions` to the global database. */
async function saveAllVersionsToDatabase(){
const globalDatabase = opendiscord.databases.get("opendiscord:global")
await opendiscord.versions.loopAll(async (version,id) => {
await globalDatabase.set("opendiscord:last-version",id.value,version.toString())
})
}
export const loadVersionMigrationSystem = async () => {
//ENTER MIGRATION CONTEXT
await preloadMigrationContext()
@@ -36,7 +55,8 @@ export const loadVersionMigrationSystem = async () => {
return lastVersion
}
const preloadMigrationContext = async () => {
/**Initialize the migration context by loading the built-in flags, configs & databases. */
async function preloadMigrationContext(){
opendiscord.debug.debug("-- MIGRATION CONTEXT START --")
await (await import("../../data/framework/flagLoader.js")).loadAllFlags()
await opendiscord.flags.init()
@@ -47,7 +67,8 @@ const preloadMigrationContext = async () => {
opendiscord.debug.visible = true
}
const unloadMigrationContext = async () => {
/**Unload the migration context to start the bot normally. */
async function unloadMigrationContext(){
opendiscord.debug.visible = false
await opendiscord.databases.loopAll((database,id) => {opendiscord.databases.remove(id)})
await opendiscord.configs.loopAll((config,id) => {opendiscord.configs.remove(id)})
@@ -55,16 +76,8 @@ const unloadMigrationContext = async () => {
opendiscord.debug.debug("-- MIGRATION CONTEXT END --")
}
const isMigrationRequired = async (): Promise<false|api.ODVersion> => {
const rawVersion = await opendiscord.databases.get("opendiscord:global").get("opendiscord:last-version","opendiscord:version")
if (!rawVersion) return false
const version = api.ODVersion.fromString("opendiscord:last-version",rawVersion)
if (opendiscord.versions.get("opendiscord:version").compare(version) == "higher"){
return version
}else return false
}
const loadAllVersionMigrations = async (lastVersion:api.ODVersion) => {
/**Execute all version migration functions which are handled in the restricted migration context. */
async function loadAllVersionMigrations(lastVersion:api.ODVersion){
const migrations = (await import("./migration.js")).migrations
migrations.sort((a,b) => {
const comparison = a.version.compare(b.version)
@@ -83,7 +96,8 @@ const loadAllVersionMigrations = async (lastVersion:api.ODVersion) => {
}
}
export const loadAllAfterInitVersionMigrations = async (lastVersion:api.ODVersion) => {
/**Execute all version migration functions which are handled in the normal startup sequence. */
export async function loadAllAfterInitVersionMigrations(lastVersion:api.ODVersion){
const migrations = (await import("./migration.js")).migrations
migrations.sort((a,b) => {
const comparison = a.version.compare(b.version)
@@ -100,12 +114,4 @@ export const loadAllAfterInitVersionMigrations = async (lastVersion:api.ODVersio
])
}
}
}
const saveAllVersionsToDatabase = async () => {
const globalDatabase = opendiscord.databases.get("opendiscord:global")
await opendiscord.versions.loopAll(async (version,id) => {
await globalDatabase.set("opendiscord:last-version",id.value,version.toString())
})
}