Skip to content

Commit

Permalink
chore: test
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyrxng committed Sep 11, 2024
1 parent a5318f4 commit 8d6b0fe
Showing 1 changed file with 17 additions and 23 deletions.
40 changes: 17 additions & 23 deletions src/bot/mtproto-api/workrooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export async function reopenChat(context: Context<"issues.reopened", SupportedEv
const { payload, adapters: { supabase: { chats } }, logger } = context;

let chatFull: Api.ChatFull;
let participants: Api.ChatParticipants;
let participants: Api.ChatParticipantsForbidden;
const mtProto = new MtProto(context);
await mtProto.initialize();

Expand All @@ -164,7 +164,7 @@ export async function reopenChat(context: Context<"issues.reopened", SupportedEv
}

chatFull = fetchChat.fullChat as Api.ChatFull
participants = chatFull.participants as Api.ChatParticipants;
participants = chatFull.participants as Api.ChatParticipantsForbidden;

console.log("Chat: ", chatFull);
console.log("Participants: ", participants);
Expand All @@ -178,16 +178,16 @@ export async function reopenChat(context: Context<"issues.reopened", SupportedEv
sendMedia: true,
sendStickers: true,
sendGifs: true,
sendGames: true,
sendGames: false,
sendInline: true,
embedLinks: true,
sendPolls: true,
changeInfo: true,
changeInfo: false,
inviteUsers: true,
pinMessages: true,
pinMessages: false,
untilDate: 0,
}),
peer: new mtProto.api.InputPeerChat({ chatId: chat.chatId }),
peer: fetchChat,
})
);

Expand All @@ -197,27 +197,21 @@ export async function reopenChat(context: Context<"issues.reopened", SupportedEv

} catch (er) {
console.error(`Error in reopening chat: ${er}`);

throw new Error("Failed to edit default ban rights");
}

try {
for (const participant of participants.participants) {
if (participant instanceof mtProto.api.ChatParticipant) {
await mtProto.client.invoke(
new mtProto.api.messages.AddChatUser({
chatId: chat.chatId,
userId: participant.userId,
fwdLimit: 50,
})
);
}
}

return { status: 200, reason: "chat_reopened" };
await mtProto.client.invoke(
new mtProto.api.messages.AddChatUser({
chatId: chat.chatId,
userId: participants.selfParticipant?.userId,
fwdLimit: 50,
})
);
} catch (er) {
console.log(er);
logger.error("Failed to reopen chat", { er });
return { status: 500, reason: "chat_reopen_failed", content: { error: er } };
console.error(`Error in reopening chat: ${er}`);
throw new Error("Failed to add user to chat");
}

return { status: 200, reason: "chat_reopened" };
}

0 comments on commit 8d6b0fe

Please sign in to comment.