-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from djmaze/add-admin-room
Setup admin room and log diagnostic and error output there
- Loading branch information
Showing
5 changed files
with
98 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
HOMESERVER_URL=https://matrix.org | ||
ACCESS_TOKEN=foobar123 | ||
INTERVAL_MINUTES=10 | ||
INTERVAL_MINUTES=10 | ||
#FEEDBACK_ROOM= | ||
#ADMIN_ROOM_ID= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import AdminRoom from "./admin_room" | ||
|
||
export default class AdminLogger { | ||
adminRoom?: AdminRoom | ||
|
||
constructor(adminRoom?: AdminRoom) { | ||
this.adminRoom = adminRoom | ||
} | ||
|
||
info(message: string) : void { | ||
if (this.adminRoom) | ||
this.adminRoom.logInfo(message) | ||
console.info(message) | ||
} | ||
|
||
error(message: string) : void { | ||
if (this.adminRoom) | ||
this.adminRoom.logError(message) | ||
console.error(message) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { MatrixClient } from "matrix-bot-sdk" | ||
|
||
export default class AdminRoom { | ||
client: MatrixClient | ||
roomId: string | ||
|
||
constructor(client: MatrixClient, roomId: string) { | ||
this.client = client | ||
this.roomId = roomId | ||
} | ||
|
||
async join() : Promise<void> { | ||
await this.client.joinRoom(this.roomId) | ||
} | ||
|
||
async listen() : Promise<void> { | ||
const userId = await this.client.getUserId() | ||
|
||
this.client.on("room.event", async (roomId, event) => { | ||
if (roomId !== this.roomId) return | ||
|
||
if (event.type === "m.room.member" && event.content.membership === "join" && event.sender === userId) { | ||
console.debug("admin room just entered, sending welcome message", roomId) | ||
await this.showHelp() | ||
} | ||
}) | ||
} | ||
|
||
async showHelp() : Promise<void> { | ||
const text = "<p>Willkommen im Admin-Raum des MINA-Bots!" | ||
|
||
await this.client.sendHtmlText(this.roomId, text) | ||
} | ||
|
||
async logError(message: string) : Promise<void> { | ||
await this.client.sendHtmlText(this.roomId, `⚠️ ${message}`) | ||
} | ||
|
||
async logInfo(message: string) : Promise<void> { | ||
await this.client.sendText(this.roomId, `🏁 ${message}`) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters