@open-discord-bots/framework 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/api/main.js CHANGED
@@ -44,7 +44,7 @@ export class ODMain {
44
44
  constructor(managers, project) {
45
45
  this.project = project;
46
46
  this.versions = managers.versions;
47
- this.versions.add(ODVersion.fromString("opendiscord:api", "v0.4.0"));
47
+ this.versions.add(ODVersion.fromString("opendiscord:api", "v0.4.1"));
48
48
  this.versions.add(ODVersion.fromString("opendiscord:livestatus", "v2.0.0"));
49
49
  this.debugfile = managers.debugfile;
50
50
  this.console = managers.console;
@@ -243,6 +243,14 @@ export declare class ODVersion extends ODManagerData {
243
243
  /**Check if this version is matches the minor version (`vX.X.X`) of the provided `requirement`. */
244
244
  minor(requirement: string | ODVersion): boolean;
245
245
  }
246
+ export interface ODVersionMigrationFunctions {
247
+ /**The migration to run before any part of the bot is started (pure node.js). */
248
+ beforeStartupMigrate?: () => void | Promise<void>;
249
+ /**The migration to run in the Open Discord migration context (incl. flags, configs, database). */
250
+ contextMigrate?: () => void | Promise<void>;
251
+ /**The migration to run when the bot starts like normal (incl. plugins) */
252
+ afterStartupMigrate?: () => void | Promise<void>;
253
+ }
246
254
  /**## ODVersionMigration `class`
247
255
  * This class is used to manage data migration between Open Ticket versions.
248
256
  *
@@ -251,15 +259,15 @@ export declare class ODVersion extends ODManagerData {
251
259
  export declare class ODVersionMigration {
252
260
  /**The version to migrate data to */
253
261
  version: ODVersion;
254
- /**The migration function */
255
- private migrateFunc;
256
- /**The migration function */
257
- private migrateAfterInitFunc;
258
- constructor(version: ODVersion, migrateFunc: () => void | Promise<void>, migrateAfterInitFunc: () => void | Promise<void>);
259
- /**Run this version migration as a plugin. Returns `false` when something goes wrong. */
260
- migrate(): Promise<boolean>;
261
- /**Run this version migration as a plugin (after other plugins have loaded). Returns `false` when something goes wrong. */
262
- migrateAfterInit(): Promise<boolean>;
262
+ /**The migration functions */
263
+ private functions;
264
+ constructor(version: ODVersion, functions: ODVersionMigrationFunctions);
265
+ /**Run this migration before any other part of the bot is started (pure node.js). */
266
+ migrateBeforeStartup(): Promise<boolean>;
267
+ /**Run this migration in the Open Discord migration context (incl. flags, configs, database). */
268
+ migrateInContext(): Promise<boolean>;
269
+ /**Run this migration when the bot starts like normal (incl. plugins) */
270
+ migrateAfterStartup(): Promise<boolean>;
263
271
  }
264
272
  /**## ODHTTPGetRequest `class`
265
273
  * This is a class that can help you with creating simple HTTP GET requests.
@@ -505,19 +505,17 @@ export class ODVersion extends ODManagerData {
505
505
  export class ODVersionMigration {
506
506
  /**The version to migrate data to */
507
507
  version;
508
- /**The migration function */
509
- migrateFunc;
510
- /**The migration function */
511
- migrateAfterInitFunc;
512
- constructor(version, migrateFunc, migrateAfterInitFunc) {
508
+ /**The migration functions */
509
+ functions;
510
+ constructor(version, functions) {
513
511
  this.version = version;
514
- this.migrateFunc = migrateFunc;
515
- this.migrateAfterInitFunc = migrateAfterInitFunc;
512
+ this.functions = functions;
516
513
  }
517
- /**Run this version migration as a plugin. Returns `false` when something goes wrong. */
518
- async migrate() {
514
+ /**Run this migration before any other part of the bot is started (pure node.js). */
515
+ async migrateBeforeStartup() {
519
516
  try {
520
- await this.migrateFunc();
517
+ if (this.functions.beforeStartupMigrate)
518
+ await this.functions.beforeStartupMigrate();
521
519
  return true;
522
520
  }
523
521
  catch (err) {
@@ -525,10 +523,23 @@ export class ODVersionMigration {
525
523
  return false;
526
524
  }
527
525
  }
528
- /**Run this version migration as a plugin (after other plugins have loaded). Returns `false` when something goes wrong. */
529
- async migrateAfterInit() {
526
+ /**Run this migration in the Open Discord migration context (incl. flags, configs, database). */
527
+ async migrateInContext() {
530
528
  try {
531
- await this.migrateAfterInitFunc();
529
+ if (this.functions.contextMigrate)
530
+ await this.functions.contextMigrate();
531
+ return true;
532
+ }
533
+ catch (err) {
534
+ process.emit("uncaughtException", err);
535
+ return false;
536
+ }
537
+ }
538
+ /**Run this migration when the bot starts like normal (incl. plugins) */
539
+ async migrateAfterStartup() {
540
+ try {
541
+ if (this.functions.afterStartupMigrate)
542
+ await this.functions.afterStartupMigrate();
532
543
  return true;
533
544
  }
534
545
  catch (err) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@open-discord-bots/framework",
3
3
  "author": "DJj123dj",
4
- "version": "0.4.0",
4
+ "version": "0.4.1",
5
5
  "description": "The core framework of the popular open-source discord bots: Open Ticket & Open Moderation.",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",