mirror of
https://github.com/xCyanGrizzly/DragonsStash.git
synced 2026-05-11 06:11:15 +00:00
fix: resolve TypeScript null-check errors in bot tdlib client
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -66,10 +66,11 @@ export async function copyMessageToUser(
|
|||||||
toUserId: bigint
|
toUserId: bigint
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
if (!client) throw new Error("Bot client not initialized");
|
if (!client) throw new Error("Bot client not initialized");
|
||||||
|
const c = client;
|
||||||
|
|
||||||
await withFloodWait(
|
await withFloodWait(
|
||||||
() =>
|
() =>
|
||||||
client.invoke({
|
c.invoke({
|
||||||
_: "forwardMessages",
|
_: "forwardMessages",
|
||||||
chat_id: Number(toUserId),
|
chat_id: Number(toUserId),
|
||||||
from_chat_id: Number(fromChatId),
|
from_chat_id: Number(fromChatId),
|
||||||
@@ -90,11 +91,12 @@ export async function sendTextMessage(
|
|||||||
parseMode: "textParseModeMarkdown" | "textParseModeHTML" = "textParseModeMarkdown"
|
parseMode: "textParseModeMarkdown" | "textParseModeHTML" = "textParseModeMarkdown"
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
if (!client) throw new Error("Bot client not initialized");
|
if (!client) throw new Error("Bot client not initialized");
|
||||||
|
const c = client;
|
||||||
|
|
||||||
// Parse the text first
|
// Parse the text first
|
||||||
const parsed = await withFloodWait(
|
const parsed = await withFloodWait(
|
||||||
() =>
|
() =>
|
||||||
client.invoke({
|
c.invoke({
|
||||||
_: "parseTextEntities",
|
_: "parseTextEntities",
|
||||||
text,
|
text,
|
||||||
parse_mode: { _: parseMode, version: parseMode === "textParseModeMarkdown" ? 2 : 0 },
|
parse_mode: { _: parseMode, version: parseMode === "textParseModeMarkdown" ? 2 : 0 },
|
||||||
@@ -104,7 +106,7 @@ export async function sendTextMessage(
|
|||||||
|
|
||||||
await withFloodWait(
|
await withFloodWait(
|
||||||
() =>
|
() =>
|
||||||
client.invoke({
|
c.invoke({
|
||||||
_: "sendMessage",
|
_: "sendMessage",
|
||||||
chat_id: Number(chatId),
|
chat_id: Number(chatId),
|
||||||
input_message_content: {
|
input_message_content: {
|
||||||
@@ -125,6 +127,7 @@ export async function sendPhotoMessage(
|
|||||||
caption: string
|
caption: string
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
if (!client) throw new Error("Bot client not initialized");
|
if (!client) throw new Error("Bot client not initialized");
|
||||||
|
const c = client;
|
||||||
|
|
||||||
// Write the photo to a temp file
|
// Write the photo to a temp file
|
||||||
const { writeFile, unlink } = await import("fs/promises");
|
const { writeFile, unlink } = await import("fs/promises");
|
||||||
@@ -136,7 +139,7 @@ export async function sendPhotoMessage(
|
|||||||
|
|
||||||
const parsedCaption = await withFloodWait(
|
const parsedCaption = await withFloodWait(
|
||||||
() =>
|
() =>
|
||||||
client.invoke({
|
c.invoke({
|
||||||
_: "parseTextEntities",
|
_: "parseTextEntities",
|
||||||
text: caption,
|
text: caption,
|
||||||
parse_mode: { _: "textParseModeMarkdown", version: 2 },
|
parse_mode: { _: "textParseModeMarkdown", version: 2 },
|
||||||
@@ -146,7 +149,7 @@ export async function sendPhotoMessage(
|
|||||||
|
|
||||||
await withFloodWait(
|
await withFloodWait(
|
||||||
() =>
|
() =>
|
||||||
client.invoke({
|
c.invoke({
|
||||||
_: "sendMessage",
|
_: "sendMessage",
|
||||||
chat_id: Number(chatId),
|
chat_id: Number(chatId),
|
||||||
input_message_content: {
|
input_message_content: {
|
||||||
@@ -171,9 +174,10 @@ export async function getUser(
|
|||||||
userId: number
|
userId: number
|
||||||
): Promise<{ firstName: string; lastName?: string; username?: string }> {
|
): Promise<{ firstName: string; lastName?: string; username?: string }> {
|
||||||
if (!client) throw new Error("Bot client not initialized");
|
if (!client) throw new Error("Bot client not initialized");
|
||||||
|
const c = client;
|
||||||
const user = (await withFloodWait(
|
const user = (await withFloodWait(
|
||||||
() =>
|
() =>
|
||||||
client.invoke({
|
c.invoke({
|
||||||
_: "getUser",
|
_: "getUser",
|
||||||
user_id: userId,
|
user_id: userId,
|
||||||
}),
|
}),
|
||||||
|
|||||||
Reference in New Issue
Block a user