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
12 changes: 8 additions & 4 deletions src/middlewares/bot-membership-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,14 @@ export class BotMembershipHandler<C extends TelemetryContextFlavor<Context>> ext
constructor() {
super("bot_membership_handler")

void this.fillRedis()

// TEMP: this is for initial migration from previous bot
this.composer.fork().filter(predicate, async (ctx, next) => {
if (ctx.chat.type === "private") return next()

const redisCheck = await this.TEMP_redis.has(ctx.chat.id.toString())
if (redisCheck) {
const backendGroup = await api.tg.groups.getById.query({ telegramId: ctx.chat.id }).catch(() => null)
if (backendGroup !== null) return next()
}
if (redisCheck) return next()

const me = await ctx.getChatMember(ctx.me.id).catch(() => ({ status: "undefined" }))
if (me.status !== "administrator") {
Expand Down Expand Up @@ -93,6 +92,11 @@ export class BotMembershipHandler<C extends TelemetryContextFlavor<Context>> ext
})
}

private async fillRedis() {
const dbGroups = await api.tg.groups.getAll.query()
await Promise.all(dbGroups.map((g) => this.TEMP_redis.write(g.telegramId.toString(), g.telegramId)))
}

private static isJoin<C extends Context>(ctx: MemberContext<C>): boolean {
const oldStatusCheck = ["left", "kicked"].includes(ctx.myChatMember.old_chat_member.status)
const newStatusCheck = joinEvent[ctx.myChatMember.chat.type].includes(ctx.myChatMember.new_chat_member.status)
Expand Down
Loading