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 -1
View File
@@ -42,7 +42,7 @@
"#opendiscord": "./dist/src/index.js", "#opendiscord": "./dist/src/index.js",
"#opendiscord-types": "./dist/src/core/api/api.js" "#opendiscord-types": "./dist/src/core/api/api.js"
}, },
"funding":{ "funding": {
"type": "individual", "type": "individual",
"url": "https://github.com/sponsors/DJj123dj" "url": "https://github.com/sponsors/DJj123dj"
} }
+1
View File
@@ -23,6 +23,7 @@ export interface ODFlagManagerIds_Default {
"opendiscord:force-slash-update":ODFlag, "opendiscord:force-slash-update":ODFlag,
"opendiscord:no-compile":ODFlag, "opendiscord:no-compile":ODFlag,
"opendiscord:compile-only":ODFlag, "opendiscord:compile-only":ODFlag,
"opendiscord:silent":ODFlag,
} }
/**## ODFlagManager_Default `default_class` /**## ODFlagManager_Default `default_class`
+27 -21
View File
@@ -1,5 +1,24 @@
import {opendiscord, api, utilities} from "../../index" 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 () => { export const loadVersionMigrationSystem = async () => {
//ENTER MIGRATION CONTEXT //ENTER MIGRATION CONTEXT
await preloadMigrationContext() await preloadMigrationContext()
@@ -36,7 +55,8 @@ export const loadVersionMigrationSystem = async () => {
return lastVersion 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 --") opendiscord.debug.debug("-- MIGRATION CONTEXT START --")
await (await import("../../data/framework/flagLoader.js")).loadAllFlags() await (await import("../../data/framework/flagLoader.js")).loadAllFlags()
await opendiscord.flags.init() await opendiscord.flags.init()
@@ -47,7 +67,8 @@ const preloadMigrationContext = async () => {
opendiscord.debug.visible = true opendiscord.debug.visible = true
} }
const unloadMigrationContext = async () => { /**Unload the migration context to start the bot normally. */
async function unloadMigrationContext(){
opendiscord.debug.visible = false opendiscord.debug.visible = false
await opendiscord.databases.loopAll((database,id) => {opendiscord.databases.remove(id)}) await opendiscord.databases.loopAll((database,id) => {opendiscord.databases.remove(id)})
await opendiscord.configs.loopAll((config,id) => {opendiscord.configs.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 --") opendiscord.debug.debug("-- MIGRATION CONTEXT END --")
} }
const isMigrationRequired = async (): Promise<false|api.ODVersion> => { /**Execute all version migration functions which are handled in the restricted migration context. */
const rawVersion = await opendiscord.databases.get("opendiscord:global").get("opendiscord:last-version","opendiscord:version") async function loadAllVersionMigrations(lastVersion:api.ODVersion){
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) => {
const migrations = (await import("./migration.js")).migrations const migrations = (await import("./migration.js")).migrations
migrations.sort((a,b) => { migrations.sort((a,b) => {
const comparison = a.version.compare(b.version) 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 const migrations = (await import("./migration.js")).migrations
migrations.sort((a,b) => { migrations.sort((a,b) => {
const comparison = a.version.compare(b.version) 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())
})
} }
+1
View File
@@ -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: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: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: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",[]))
} }