✨ Automatically set the bot's profile info
This commit is contained in:
@ -12,4 +12,7 @@ MATRIX_USER=
|
|||||||
# You can get the access token by for example logging into
|
# You can get the access token by for example logging into
|
||||||
# the bot's matrix account in element and copying the
|
# the bot's matrix account in element and copying the
|
||||||
# Access Token under Settings > Help & About > Advanced
|
# Access Token under Settings > Help & About > Advanced
|
||||||
MATRIX_TOKEN=
|
MATRIX_TOKEN=
|
||||||
|
|
||||||
|
# The bot set this as its display name (Default: Timetable V2)
|
||||||
|
MATRIX_DISPLAYNAME=
|
BIN
images/profile-picture.png
Normal file
BIN
images/profile-picture.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.7 KiB |
21
index.js
21
index.js
@ -1,6 +1,7 @@
|
|||||||
import * as sdk from "matrix-js-sdk";
|
import * as sdk from "matrix-js-sdk";
|
||||||
import fetch from "node-fetch";
|
import fetch from "node-fetch";
|
||||||
import process from "process";
|
import process from "process";
|
||||||
|
import fs from "fs";
|
||||||
import "dotenv/config";
|
import "dotenv/config";
|
||||||
import { JsonDB, Config } from "node-json-db";
|
import { JsonDB, Config } from "node-json-db";
|
||||||
import { TimetableClient } from "./timetable.js";
|
import { TimetableClient } from "./timetable.js";
|
||||||
@ -22,6 +23,24 @@ const client = sdk.createClient({
|
|||||||
fetchFn: fetch,
|
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) {
|
client.once("sync", function (state) {
|
||||||
if (state === "PREPARED") {
|
if (state === "PREPARED") {
|
||||||
console.log("sync finished");
|
console.log("sync finished");
|
||||||
@ -105,7 +124,7 @@ setInterval(async () => {
|
|||||||
client.sendHtmlMessage(roomId, plainText(message), message);
|
client.sendHtmlMessage(roomId, plainText(message), message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 1000 * 60);
|
}, 1000);
|
||||||
|
|
||||||
// Handle events
|
// Handle events
|
||||||
client.on("Room.timeline", async function (event, room) {
|
client.on("Room.timeline", async function (event, room) {
|
||||||
|
Reference in New Issue
Block a user