Skip to content

Commit

Permalink
Merge pull request #28 from ubq-testing/tweaks
Browse files Browse the repository at this point in the history
chore: edit workroom desc, no error comment on chat_not_found
  • Loading branch information
Keyrxng authored Oct 30, 2024
2 parents 103bd38 + 6945b2e commit c3e1e20
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/bot/mtproto-api/workrooms/close-chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export async function closeChat(context: Context<"issues.closed", SupportedEvent
const dbChat = await storage.retrieveChatByTaskNodeId(payload.issue.node_id);

if (!dbChat) {
return { status: 500, reason: "chat_not_found" };
logger.error("Chat not found in database", { chatName: payload.issue.title });
return { status: 200, reason: "chat_not_found" };
}

logger.info("Chat found: ", { dbChat });
Expand Down
33 changes: 23 additions & 10 deletions src/bot/mtproto-api/workrooms/create-chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,31 @@ export async function createChat(context: Context<"issues.assigned", SupportedEv
} else {
throw new Error(logger.error(`Failed to create chat invite link for the workroom: ${chatName}`).logMessage.raw);
}
}

const isBotPromotedToAdmin = await mtProto.client.invoke(
new mtProto.api.messages.EditChatAdmin({
chatId: chatIdBigInt,
isAdmin: true,
userId: botIdString,
})
);
// edit chat description
try {
await mtProto.client.invoke(
new mtProto.api.messages.EditChatAbout({
peer: new mtProto.api.InputPeerChat({ chatId: chatIdBigInt }),
about: `${payload.issue.html_url}`,
})
);
} catch (er) {
logger.error("Error in editing chat description: ", { er });
return { status: 500, reason: "chat_create_failed", content: { error: er } };
}

if (!isBotPromotedToAdmin) {
throw new Error("Failed to promote bot to admin");
const isBotPromotedToAdmin = await mtProto.client.invoke(
new mtProto.api.messages.EditChatAdmin({
chatId: chatIdBigInt,
isAdmin: true,
userId: botIdString,
})
);

if (!isBotPromotedToAdmin) {
throw new Error("Failed to promote bot to admin");
}
}
} catch (er) {
logger.error("Error in creating chat: ", { er });
Expand Down
5 changes: 4 additions & 1 deletion src/bot/mtproto-api/workrooms/reopen-chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ export async function reopenChat(context: Context<"issues.reopened", SupportedEv
const dbChat = await storage.retrieveChatByTaskNodeId(payload.issue.node_id);

if (!dbChat) {
return { status: 500, reason: "chat_not_found" };
logger.error("Chat not found in database", { chatName: payload.issue.title });
// no need to create one if it doesn't exist, this really only affects backwards compatibility
return { status: 200, reason: "chat_not_found" };
}

const chatIdBigInt = bigInt(dbChat.chat_id);

const fetchedChat = await mtProto.client.invoke(
Expand Down

0 comments on commit c3e1e20

Please sign in to comment.