diff --git a/src/bot.ts b/src/bot.ts index 0e80cd5cd0c96f0082e1189eb783ae9b2d5ed81b..1649dd72406cdbfaa6b282567d6f17f63bdbf106 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -47,7 +47,7 @@ export class DiscordBot { new MessageProcessorOpts(this.config.bridge.domain, this), ); this.mxEventProcessor = new MatrixEventProcessor( - new MatrixEventProcessorOpts(this.config, this.msgProcessor, this.bridge), + new MatrixEventProcessorOpts(this.config, this.bridge), ); this.presenceHandler = new PresenceHandler(this); } @@ -64,7 +64,7 @@ export class DiscordBot { return this.bridge.getIntentFromLocalpart(`_discord_${member.id}`); } - public run (): Promise<null> { + public run (): Promise<void> { return this.clientFactory.init().then(() => { return this.clientFactory.getClient(); }).then((client: any) => { diff --git a/src/db/schema/dbschema.ts b/src/db/schema/dbschema.ts index 814e4a4c47007f4a362e1f6e6ab408603a51a41e..563aeae5ae1b0d9032635741fc2dfa897a1f4c5a 100644 --- a/src/db/schema/dbschema.ts +++ b/src/db/schema/dbschema.ts @@ -1,6 +1,6 @@ import { DiscordStore } from "../../store"; export interface IDbSchema { description: string; - run(store: DiscordStore): Promise<null>; - rollBack(store: DiscordStore): Promise<null>; + run(store: DiscordStore): Promise<null|void|Error|Error[]>; + rollBack(store: DiscordStore): Promise<null|void|Error|Error[]>; } diff --git a/src/db/schema/v1.ts b/src/db/schema/v1.ts index 32446f98d75155cc187dd3e70b42570f6519c6b1..1dcf17f9828b03d53113ed896a8a5e43953fd3ce 100644 --- a/src/db/schema/v1.ts +++ b/src/db/schema/v1.ts @@ -2,7 +2,7 @@ import {IDbSchema} from "./dbschema"; import {DiscordStore} from "../../store"; export class Schema implements IDbSchema { public description = "Schema, Client Auth Table"; - public run(store: DiscordStore): Promise<null> { + public run(store: DiscordStore): Promise<Error> { return store.create_table(` CREATE TABLE schema ( version INTEGER UNIQUE NOT NULL @@ -16,7 +16,7 @@ export class Schema implements IDbSchema { );`, "user_tokens"); }); } - public rollBack(store: DiscordStore): Promise<null> { + public rollBack(store: DiscordStore): Promise<Error> { return store.db.execAsync( `DROP TABLE IF EXISTS schema; DROP TABLE IF EXISTS user_tokens`, diff --git a/src/db/schema/v2.ts b/src/db/schema/v2.ts index be22b682d5399bfb4a6e1f1ef804136fd556edc9..26969a1058b19f0c16b55234de4c67850e44abe1 100644 --- a/src/db/schema/v2.ts +++ b/src/db/schema/v2.ts @@ -2,7 +2,7 @@ import {IDbSchema} from "./dbschema"; import {DiscordStore} from "../../store"; export class Schema implements IDbSchema { public description = "Create DM Table, User Options"; - public run(store: DiscordStore): Promise<null> { + public run(store: DiscordStore): Promise<Error[]> { return Promise.all([ store.create_table(` CREATE TABLE dm_rooms ( @@ -17,7 +17,7 @@ export class Schema implements IDbSchema { );`, "client_options", )]); } - public rollBack(store: DiscordStore): Promise<null> { + public rollBack(store: DiscordStore): Promise<Error> { return store.db.execAsync( `DROP TABLE IF EXISTS dm_rooms; DROP TABLE IF EXISTS client_options;`, diff --git a/src/db/schema/v3.ts b/src/db/schema/v3.ts index 88de6e9be802c524d7fd5a87fe49fb15587091fd..81b7f7386e0dfecba9ec3319d0179161267e0208 100644 --- a/src/db/schema/v3.ts +++ b/src/db/schema/v3.ts @@ -34,12 +34,14 @@ export class Schema implements IDbSchema { }); } - public rollBack(store: DiscordStore): Promise <null> { + public rollBack(store: DiscordStore): Promise <void> { return Promise.all([store.db.execAsync( `DROP TABLE IF EXISTS user_id_discord_id;`, ), store.db.execAsync( `DROP TABLE IF EXISTS discord_id_token;`, - )]); + )]).then(() => { + + }); } private async moveUserIds(store: DiscordStore): Promise <null> { diff --git a/src/db/schema/v4.ts b/src/db/schema/v4.ts index 4e097c8cde096df08352bcd8ccb5eb0e24fbf1f5..fa493e3423a615ce15906b9c532f1c6e29a8e27c 100644 --- a/src/db/schema/v4.ts +++ b/src/db/schema/v4.ts @@ -6,7 +6,7 @@ import * as Bluebird from "bluebird"; export class Schema implements IDbSchema { public description = "create guild emoji table"; - public run(store: DiscordStore): Promise<null> { + public run(store: DiscordStore): Promise<Error> { return store.create_table(` CREATE TABLE guild_emoji ( emoji_id TEXT NOT NULL, @@ -19,7 +19,7 @@ export class Schema implements IDbSchema { );`, "guild_emoji"); } - public rollBack(store: DiscordStore): Promise <null> { + public rollBack(store: DiscordStore): Promise <Error> { return store.db.execAsync( `DROP TABLE IF EXISTS guild_emoji;`, ); diff --git a/src/db/schema/v5.ts b/src/db/schema/v5.ts index 8d6320dd3413d1772b6268463db24951ec4f176b..e99eea4bd7f58a20eb428b4d3e2701af37049fd0 100644 --- a/src/db/schema/v5.ts +++ b/src/db/schema/v5.ts @@ -6,7 +6,7 @@ import * as Bluebird from "bluebird"; export class Schema implements IDbSchema { public description = "create event_store table"; - public run(store: DiscordStore): Promise<null> { + public run(store: DiscordStore): Promise<Error> { return store.create_table(` CREATE TABLE event_store ( matrix_id TEXT NOT NULL, @@ -15,7 +15,7 @@ export class Schema implements IDbSchema { );`, "event_store"); } - public rollBack(store: DiscordStore): Promise <null> { + public rollBack(store: DiscordStore): Promise <Error> { return store.db.execAsync( `DROP TABLE IF EXISTS event_store;`, ); diff --git a/src/store.ts b/src/store.ts index 37ffee124a9c220962f2fac3d63116eef9f2c54c..6ae5d09e3e25878207d4bfbdf5dc85adb948dc18 100644 --- a/src/store.ts +++ b/src/store.ts @@ -20,7 +20,7 @@ export class DiscordStore { this.filepath = filepath; } - public backup_database(): Promise<null> { + public backup_database(): Promise<void|{}> { if (this.filepath === ":memory:") { log.info("DiscordStore", "Can't backup a :memory: database."); return Promise.resolve(); @@ -37,7 +37,6 @@ export class DiscordStore { if (!result) { log.warn("DiscordStore", "NOT backing up database while a file already exists"); resolve(true); - return; } const rd = fs.createReadStream(this.filepath); rd.on("error", reject); @@ -52,7 +51,7 @@ export class DiscordStore { /** * Checks the database has all the tables needed. */ - public async init (overrideSchema: number = 0) { + public async init (overrideSchema: number = 0): Promise<void> { log.info("DiscordStore", "Starting DB Init"); await this.open_database(); let version = await this.getSchemaVersion(); @@ -95,7 +94,7 @@ export class DiscordStore { }); } - public add_user_token(userId: string, discordId: string, token: string): Promise<null> { + public add_user_token(userId: string, discordId: string, token: string): Promise<any> { log.silly("SQL", "add_user_token => %s", userId); return Promise.all([ this.db.runAsync( @@ -227,7 +226,7 @@ export class DiscordStore { }); } - public Get<T extends IDbData>(dbType: {new(): T; }, params: any): Promise<T> { + public Get<T extends IDbData>(dbType: {new(): T; }, params: any): Promise<T|null> { const dType = new dbType(); log.silly("DiscordStore", `get <${dType.constructor.name} with params ${params}>`); return dType.RunQuery(this, params).then(() => { @@ -235,20 +234,21 @@ export class DiscordStore { return dType; }).catch((ex) => { log.warn("DiscordStore", `get <${dType.constructor.name} with params ${params} FAILED with exception ${ex}>`); + return null; }); } - public Insert<T extends IDbData>(data: T): Promise<null> { + public Insert<T extends IDbData>(data: T): Promise<Error> { log.silly("DiscordStore", `insert <${data.constructor.name}>`); return data.Insert(this); } - public Update<T extends IDbData>(data: T): Promise<null> { + public Update<T extends IDbData>(data: T): Promise<Error> { log.silly("DiscordStore", `insert <${data.constructor.name}>`); return data.Update(this); } - public Delete<T extends IDbData>(data: T): Promise<null> { + public Delete<T extends IDbData>(data: T): Promise<Error> { log.silly("DiscordStore", `insert <${data.constructor.name}>`); return data.Delete(this); } diff --git a/test/mocks/discordclientfactory.ts b/test/mocks/discordclientfactory.ts index 9894f5e24d200d836464e2e7580c6173ce77cace..99bb5b2e47e6fd4ffc5becc86a9e5f1a6082cff6 100644 --- a/test/mocks/discordclientfactory.ts +++ b/test/mocks/discordclientfactory.ts @@ -5,7 +5,7 @@ export class DiscordClientFactory { ; } - public init(): Promise<null> { + public init(): Promise<void> { return Promise.resolve(); }