Skip to content

Commit

Permalink
chore: test
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyrxng committed Sep 8, 2024
1 parent da47c39 commit 7e90f30
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions src/bot/mtproto-api/workrooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Context, SupportedEvents } from "#root/types/context";
import { CallbackResult } from "#root/types/proxy.js";
import bigInt from "big-integer";
import { MtProto } from "./bot/mtproto";
import { Api } from "telegram";

function isPriceLabelChange(label: string): boolean {
return label.toLowerCase().includes("price");
Expand Down Expand Up @@ -75,36 +76,32 @@ export async function closeChat(context: Context<"issues.closed", SupportedEvent
})
);

let chatParticipants;

if ("participants" in fetchChat.fullChat) {
chatParticipants = fetchChat.fullChat.participants;
} else {
throw new Error("Failed to fetch chat participants");
if (!fetchChat) {
throw new Error("Failed to fetch chat");
}

if (chatParticipants.className === "ChatParticipantsForbidden") {
console.log("ChatParticipantsForbidden");
}
const chatFull = fetchChat.fullChat as Api.ChatFull
const participants = chatFull.participants as Api.ChatParticipants;

if (chatParticipants.className === "ChatParticipants") {
const userIDs = chatParticipants.participants.map((participant) => {
return participant.userId;
});

for (let i = 0; i < userIDs.length; i++) {
if (userIDs[i].toJSNumber() === context.config.botId) {
continue;
}
for (const participant of participants.participants) {
if (participant instanceof mtProto.api.ChatParticipant) {
await mtProto.client.invoke(
new mtProto.api.messages.DeleteChatUser({
chatId: chat.chatId,
userId: userIDs[i],
userId: participant.userId,
})
);
}
}

// delete all users from chat
await mtProto.client.invoke(
new mtProto.api.messages.DeleteChatUser({
chatId: chat.chatId,
userId: bigInt(0),
})
);

await mtProto.client.invoke(
new mtProto.api.messages.SendMessage({
message: "This task has been closed and this chat has been archived.",
Expand Down

0 comments on commit 7e90f30

Please sign in to comment.