@@ -14,13 +14,14 @@ See the License for the specific language governing permissions and
1414limitations under the License.
1515*/
1616
17- import { AppServiceRegistration , Bridge , Request , WeakEvent , BridgeContext , MatrixUser } from "matrix-appservice-bridge" ;
17+ import { AppServiceRegistration , Bridge , Request , WeakEvent , BridgeContext , MatrixUser , Logger } from "matrix-appservice-bridge" ;
1818import { MjolnirManager } from ".//MjolnirManager" ;
1919import { DataStore , PgDataStore } from ".//datastore" ;
2020import { Api } from "./Api" ;
2121import { IConfig } from "./config/config" ;
2222import { AccessControl } from "./AccessControl" ;
2323
24+ const log = new Logger ( "AppService" ) ;
2425/**
2526 * Responsible for setting up listeners and delegating functionality to a matrix-appservice-bridge `Bridge` for
2627 * the entrypoint of the application.
@@ -64,7 +65,7 @@ export class MjolnirAppService {
6465 } ,
6566 suppressEcho : false ,
6667 } ) ;
67- await bridge . initalise ( ) ;
68+ await bridge . initialise ( ) ;
6869 const accessControlListId = await bridge . getBot ( ) . getClient ( ) . resolveRoom ( config . accessControlList ) ;
6970 const accessControl = await AccessControl . setupAccessControl ( accessControlListId , bridge ) ;
7071 const mjolnirManager = await MjolnirManager . makeMjolnirManager ( dataStore , bridge , accessControl ) ;
@@ -89,6 +90,7 @@ export class MjolnirAppService {
8990 * @param registrationFilePath A path to their homeserver registration file.
9091 */
9192 public static async run ( port : number , config : IConfig , registrationFilePath : string ) : Promise < MjolnirAppService > {
93+ Logger . configure ( config . logging ?? { console : "debug" } ) ;
9294 const dataStore = new PgDataStore ( config . db . connectionString ) ;
9395 await dataStore . init ( ) ;
9496 const service = await MjolnirAppService . makeMjolnirAppService ( config , dataStore , registrationFilePath ) ;
@@ -114,11 +116,19 @@ export class MjolnirAppService {
114116 // Acts as an alternative to the web api provided for the widget.
115117 if ( 'm.room.member' === mxEvent . type ) {
116118 if ( 'invite' === mxEvent . content [ 'membership' ] && mxEvent . state_key === this . bridge . botUserId ) {
117- await this . mjolnirManager . provisionNewMjolnir ( mxEvent . sender ) ;
118- // reject the invite to keep the room clean and make sure the invetee doesn't get confused and think this is their mjolnir.
119- this . bridge . getBot ( ) . getClient ( ) . leaveRoom ( mxEvent . room_id ) . catch ( e => {
120- console . warn ( "Unable to reject an invite to a room" , e )
121- } ) ;
119+ log . info ( `${ mxEvent . sender } has sent an invitation to the appservice bot ${ this . bridge . botUserId } , attempting to provision them a mjolnir` ) ;
120+ try {
121+ await this . mjolnirManager . provisionNewMjolnir ( mxEvent . sender )
122+ } catch ( e : any ) {
123+ log . error ( `Failed to provision a mjolnir for ${ mxEvent . sender } after they invited ${ this . bridge . botUserId } :` , e ) ;
124+ // continue, we still want to reject this invitation.
125+ }
126+ try {
127+ // reject the invite to keep the room clean and make sure the invetee doesn't get confused and think this is their mjolnir.
128+ await this . bridge . getBot ( ) . getClient ( ) . leaveRoom ( mxEvent . room_id ) ;
129+ } catch ( e : any ) {
130+ log . warn ( "Unable to reject an invite to a room" , e ) ;
131+ }
122132 }
123133 }
124134 this . accessControl . handleEvent ( mxEvent [ 'room_id' ] , mxEvent ) ;
@@ -130,10 +140,10 @@ export class MjolnirAppService {
130140 * @param port The port that the appservice should listen on to receive transactions from the homeserver.
131141 */
132142 private async start ( port : number ) {
133- console . log ( "Starting MjolnirAppService, Matrix-side to listen on port %s " , port ) ;
143+ log . info ( "Starting MjolnirAppService, Matrix-side to listen on port" , port ) ;
134144 this . api . start ( this . config . webAPI . port ) ;
135145 await this . bridge . listen ( port ) ;
136- console . log ( "MjolnirAppService started successfully" ) ;
146+ log . info ( "MjolnirAppService started successfully" ) ;
137147 }
138148
139149 /**
0 commit comments