diff --git a/.env.sample b/.env.sample index edea89e..348d121 100644 --- a/.env.sample +++ b/.env.sample @@ -12,4 +12,7 @@ MATRIX_USER= # You can get the access token by for example logging into # the bot's matrix account in element and copying the # Access Token under Settings > Help & About > Advanced -MATRIX_TOKEN= \ No newline at end of file +MATRIX_TOKEN= + +# The bot set this as its display name (Default: Timetable V2) +MATRIX_DISPLAYNAME= \ No newline at end of file diff --git a/images/profile-picture.png b/images/profile-picture.png new file mode 100644 index 0000000..9002b8b Binary files /dev/null and b/images/profile-picture.png differ diff --git a/index.js b/index.js index 911cf28..5578ee0 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,7 @@ import * as sdk from "matrix-js-sdk"; import fetch from "node-fetch"; import process from "process"; +import fs from "fs"; import "dotenv/config"; import { JsonDB, Config } from "node-json-db"; import { TimetableClient } from "./timetable.js"; @@ -22,6 +23,24 @@ const client = sdk.createClient({ fetchFn: fetch, }); +const displayName = process.env.MATRIX_DISPLAYNAME || "Timetable V2"; +(async () => { + const profileInfo = await client.getProfileInfo(userId); + if (profileInfo.displayname != displayName) { + await client.setProfileInfo("displayname", { + displayname: displayName, + }); + const file = fs.readFileSync("./images/profile-picture.png"); + const content = await client.uploadContent(file, { + name: "profile-picture.png", + type: "image/png", + }); + await client.setProfileInfo("avatar_url", { + avatar_url: content.content_uri, + }); + } +})(); + client.once("sync", function (state) { if (state === "PREPARED") { console.log("sync finished"); @@ -105,7 +124,7 @@ setInterval(async () => { client.sendHtmlMessage(roomId, plainText(message), message); } } -}, 1000 * 60); +}, 1000); // Handle events client.on("Room.timeline", async function (event, room) {