Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/lib/group-management/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,17 @@ async function errorBackend(chat: ChatFullInfo, type: "CREATE" | "UPDATE", fatal
type GroupDB = Parameters<TRPCClient<AppRouter>["tg"]["groups"]["create"]["mutate"]>[0][0]
export const GroupManagement = {
async create(chatId: number, addedBy: User): Promise<Result<GroupDB, string>> {
const { status } = await modules.shared.api
.getChatMember(chatId, modules.shared.botInfo.id)
.catch(() => ({ status: null }))
if (status !== "administrator") {
const reason = "The bot is not an administrator"
logger.error({ chatId, reason }, "[GroupManagement] Cannot CREATE group")
return err(reason)
}

const chat = await modules.shared.api.getChat(chatId).catch(() => null)

if (!chat) {
const reason = "The bot cannot retrieve chat info, probably it is not an administrator"
logger.error({ chatId, reason }, "[GroupManagement] Cannot CREATE group")
Expand Down Expand Up @@ -79,6 +89,15 @@ export const GroupManagement = {
},

async update(chatId: number, requestedBy: User): Promise<Result<GroupDB, string>> {
const { status } = await modules.shared.api
.getChatMember(chatId, modules.shared.botInfo.id)
.catch(() => ({ status: null }))
if (status !== "administrator") {
const reason = "The bot is not an administrator"
logger.error({ chatId, reason }, "[GroupManagement] Cannot UPDATE group")
return err(reason)
}
Comment thread
lorenzocorallo marked this conversation as resolved.

const chat = await modules.shared.api.getChat(chatId).catch(() => null)
if (!chat) {
const reason = "The bot is not in this group or is not an administrator"
Expand Down
Loading