forked from 1inch/shieldy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEntryMessage.ts
32 lines (29 loc) · 948 Bytes
/
EntryMessage.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { report } from '@helpers/report'
import { deleteMessageSafeWithBot } from '@helpers/deleteMessageSafe'
import { getModelForClass, prop, index } from '@typegoose/typegoose'
@index({ createdAt: 1 }, { expireAfterSeconds: 60 * 60 })
export class EntryMessage {
@prop({ required: true, index: true })
message_id: number
@prop({ required: true, index: true })
from_id: number
@prop({ required: true, index: true })
chat_id: number
}
export const EntryMessageModel = getModelForClass(EntryMessage, {
schemaOptions: { timestamps: true },
})
export async function removeEntryMessages(chatId: number, fromId: number) {
const messages = await EntryMessageModel.find({
chat_id: chatId,
from_id: fromId,
})
messages.forEach(async (message) => {
await deleteMessageSafeWithBot(chatId, message.message_id)
try {
await message.remove()
} catch (err) {
report(err, 'removeEntryMessages')
}
})
}