diff --git a/package.json b/package.json index ccb39b9..996a9ea 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "#opendiscord": "./dist/src/index.js", "#opendiscord-types": "./dist/src/core/api/api.js" }, - "funding":{ + "funding": { "type": "individual", "url": "https://github.com/sponsors/DJj123dj" } diff --git a/src/core/api/defaults/flag.ts b/src/core/api/defaults/flag.ts index bf2d5eb..218fae4 100644 --- a/src/core/api/defaults/flag.ts +++ b/src/core/api/defaults/flag.ts @@ -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` diff --git a/src/core/startup/manageMigration.ts b/src/core/startup/manageMigration.ts index 496de92..d08d833 100644 --- a/src/core/startup/manageMigration.ts +++ b/src/core/startup/manageMigration.ts @@ -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 { + 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 => { - 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()) - }) } \ No newline at end of file diff --git a/src/data/framework/flagLoader.ts b/src/data/framework/flagLoader.ts index 8c4e5bc..6a70f40 100644 --- a/src/data/framework/flagLoader.ts +++ b/src/data/framework/flagLoader.ts @@ -15,4 +15,5 @@ export const loadAllFlags = async () => { opendiscord.flags.add(new api.ODFlag("opendiscord:force-slash-update","Force Slash Update","Force update all slash commands.","--force-slash",["-fs"])) opendiscord.flags.add(new api.ODFlag("opendiscord:no-compile","No Compile","Disable compilation of plugins & bot before starting.","--no-compile",[])) opendiscord.flags.add(new api.ODFlag("opendiscord:compile-only","Compile Only","This description will never be shown because the bot wouldn't run when this flag is enabled :)","--compile-only",[])) + opendiscord.flags.add(new api.ODFlag("opendiscord:silent","Silent Mode","Run the bot without displaying logs. The startscreen will still be displayed.","--silent",[])) } \ No newline at end of file