| 91 | }; |
| 92 | |
| 93 | const getRepliedMessageId = async (msg: Api.Message): Promise<number | undefined> => { |
| 94 | try { |
| 95 | const typedMsg = msg as Api.Message & { |
| 96 | replyTo?: { replyToMsgId?: number; replyToTopId?: number; replyToMsg?: { id?: number } }; |
| 97 | replyToMsgId?: number; |
| 98 | }; |
| 99 | const id = |
| 100 | typedMsg.replyTo?.replyToTopId ?? |
| 101 | typedMsg.replyTo?.replyToMsgId ?? |
| 102 | typedMsg.replyToMsgId ?? |
| 103 | typedMsg.replyTo?.replyToMsg?.id; |
| 104 | |
| 105 | if (typeof id === "number") return id; |
| 106 | |
| 107 | const getter = (msg as any).getReplyMessage; |
| 108 | if (typeof getter === "function") { |
| 109 | const replied = await getter.call(msg); |
| 110 | const typedReply = replied as Api.Message & { |
| 111 | replyTo?: { replyToTopId?: number }; |
| 112 | }; |
| 113 | const rid = typedReply.replyTo?.replyToTopId ?? typedReply.id; |
| 114 | if (typeof rid === "number") return rid; |
| 115 | } |
| 116 | } catch {} |
| 117 | |
| 118 | return undefined; |
| 119 | }; |
| 120 | |
| 121 | class UserError extends Error { |
| 122 | constructor(message: string) { |