mirror of
https://github.com/the-draupnir-project/Draupnir.git
synced 2026-08-28 05:14:04 +00:00
Tests / Build & Lint (push) Failing after 2m30s
Tests / Unit tests (push) Successful in 2m58s
Tests / Integration tests (push) Failing after 14s
Tests / Application Service Integration tests (push) Failing after 16s
GHCR - Development Branches / ghcr-publish (push) Failing after 13m10s
Docker Hub - Develop / docker-latest (push) Failing after 14m5s
* Add Avatar Command to bot mode and AS mode * Add changesets * Move MXC URI validation to matrix basic types * Fix MediaID being mixed case when its exempt from usual case rules. * Update changeset * Integrate Gnuxie Review Feedback * Fix linting errors * Fix having forgotten to run prettier. * Integrate Gnuxie review feedback. * Fix version.txt.tmp files
52 lines
1.7 KiB
TypeScript
52 lines
1.7 KiB
TypeScript
// SPDX-FileCopyrightText: 2026 Catalan Lover <catalanlover@protonmail.com>
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import { isError, Ok, Result } from "@gnuxie/typescript-result";
|
|
import {
|
|
StringPresentationType,
|
|
describeCommand,
|
|
} from "@the-draupnir-project/interface-manager";
|
|
import { isStringMediaURI } from "@the-draupnir-project/matrix-basic-types";
|
|
import { Draupnir } from "../Draupnir";
|
|
import { DraupnirInterfaceAdaptor } from "./DraupnirCommandPrerequisites";
|
|
import { resultifyBotSDKRequestError } from "matrix-protection-suite-for-matrix-bot-sdk";
|
|
import { ActionError } from "matrix-protection-suite";
|
|
|
|
export const DraupnirAvatarCommand = describeCommand({
|
|
summary:
|
|
"Sets the avatar of the draupnir instance to the specified MXC URI in all rooms.",
|
|
parameters: [],
|
|
rest: {
|
|
name: "avatar url",
|
|
acceptor: StringPresentationType,
|
|
},
|
|
async executor(
|
|
draupnir: Draupnir,
|
|
_info,
|
|
_keywords,
|
|
avatarParts
|
|
): Promise<Result<void>> {
|
|
const avatarUrl = avatarParts.join(" ").trim();
|
|
if (!avatarUrl) {
|
|
return ActionError.Result("Avatar URL cannot be empty");
|
|
}
|
|
if (!isStringMediaURI(avatarUrl)) {
|
|
return ActionError.Result(
|
|
`Invalid MXC URI format. Expected format: mxc://server/media-id, got: ${avatarUrl}`
|
|
);
|
|
}
|
|
const setAvatarResult = await draupnir.client
|
|
.setAvatarUrl(avatarUrl)
|
|
.then((_) => Ok(undefined), resultifyBotSDKRequestError);
|
|
if (isError(setAvatarResult)) {
|
|
return setAvatarResult.elaborate(`Failed to set avatar to ${avatarUrl}`);
|
|
}
|
|
return setAvatarResult;
|
|
},
|
|
});
|
|
|
|
DraupnirInterfaceAdaptor.describeRenderer(DraupnirAvatarCommand, {
|
|
isAlwaysSupposedToUseDefaultRenderer: true,
|
|
});
|