Make function async
This commit is contained in:
parent
3f6f2bcbb3
commit
88410a1b29
1 changed files with 21 additions and 19 deletions
|
@ -452,7 +452,9 @@ function setBotOptions(event: MessageEvent<any>, roomId: string, userId: string)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function setBotPower(event: MessageEvent<any>, roomId: string, userId: string, level: number, ignoreIfGreater?: boolean): void {
|
async function setBotPower(
|
||||||
|
event: MessageEvent<any>, roomId: string, userId: string, level: number, ignoreIfGreater?: boolean,
|
||||||
|
): Promise<void> {
|
||||||
if (!(Number.isInteger(level) && level >= 0)) {
|
if (!(Number.isInteger(level) && level >= 0)) {
|
||||||
sendError(event, _t('Power level must be positive integer.'));
|
sendError(event, _t('Power level must be positive integer.'));
|
||||||
return;
|
return;
|
||||||
|
@ -465,34 +467,34 @@ function setBotPower(event: MessageEvent<any>, roomId: string, userId: string, l
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
client.getStateEvent(roomId, "m.room.power_levels", "").then((powerLevels) => {
|
try {
|
||||||
const powerEvent = new MatrixEvent(
|
const powerLevels = await client.getStateEvent(roomId, "m.room.power_levels", "");
|
||||||
{
|
|
||||||
type: "m.room.power_levels",
|
|
||||||
content: powerLevels,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
// If the PL is equal to or greater than the requested PL, ignore.
|
// If the PL is equal to or greater than the requested PL, ignore.
|
||||||
if (ignoreIfGreater) {
|
if (ignoreIfGreater === true) {
|
||||||
// As per https://matrix.org/docs/spec/client_server/r0.6.0#m-room-power-levels
|
// As per https://matrix.org/docs/spec/client_server/r0.6.0#m-room-power-levels
|
||||||
const currentPl = (powerLevels.content.users && powerLevels.content.users[userId]) || powerLevels.content.users_default || 0;
|
const currentPl = (
|
||||||
|
powerLevels.content.users && powerLevels.content.users[userId]
|
||||||
|
) || powerLevels.content.users_default || 0;
|
||||||
|
|
||||||
if (currentPl >= level) {
|
if (currentPl >= level) {
|
||||||
sendResponse(event, {
|
return sendResponse(event, {
|
||||||
success: true,
|
success: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
await client.setPowerLevel(roomId, userId, level, new MatrixEvent(
|
||||||
client.setPowerLevel(roomId, userId, level, powerEvent).then(() => {
|
{
|
||||||
sendResponse(event, {
|
type: "m.room.power_levels",
|
||||||
success: true,
|
content: powerLevels,
|
||||||
});
|
},
|
||||||
}, (err) => {
|
));
|
||||||
sendError(event, err.message ? err.message : _t('Failed to send request.'), err);
|
return sendResponse(event, {
|
||||||
|
success: true,
|
||||||
});
|
});
|
||||||
});
|
} catch (err) {
|
||||||
|
sendError(event, err.message ? err.message : _t('Failed to send request.'), err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMembershipState(event: MessageEvent<any>, roomId: string, userId: string): void {
|
function getMembershipState(event: MessageEvent<any>, roomId: string, userId: string): void {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue