Pārlūkot izejas kodu

Fixed iterMessages; modified signature of some sendMessage like methods

* Fixed iterMessages; modified signature of some sendMessage like methods

* Revert changes to sendMessage and the like

* Remove unused imports

* Make booleans optional again
Chris Watson 3 gadi atpakaļ
vecāks
revīzija
9377e035fc
4 mainītis faili ar 49 papildinājumiem un 9117 dzēšanām
  1. 3 3
      gramjs/client/TelegramClient.ts
  2. 44 26
      gramjs/client/messages.ts
  3. 1 2
      gramjs/tl/custom/message.ts
  4. 1 9086
      package-lock.json

+ 3 - 3
gramjs/client/TelegramClient.ts

@@ -16,7 +16,7 @@ import type { ButtonLike, Entity, EntityLike, MessageIDLike } from "../define";
 import { Api } from "../tl";
 import { sanitizeParseMode } from "../Utils";
 import type { EventBuilder } from "../events/common";
-import { MTProtoSender, UpdateConnectionState } from "../network";
+import { MTProtoSender } from "../network";
 
 import { LAYER } from "../tl/AllTLObjects";
 import { betterConsoleLog, IS_NODE } from "../Helpers";
@@ -589,7 +589,7 @@ export class TelegramClient extends TelegramBaseClient {
      */
     iterMessages(
         entity: EntityLike | undefined,
-        iterParams: messageMethods.IterMessagesParams
+        iterParams: Partial<messageMethods.IterMessagesParams>
     ) {
         return messageMethods.iterMessages(this, entity, iterParams);
     }
@@ -618,7 +618,7 @@ export class TelegramClient extends TelegramBaseClient {
      */
     getMessages(
         entity: EntityLike | undefined,
-        getMessagesParams: messageMethods.IterMessagesParams
+        getMessagesParams: Partial<messageMethods.IterMessagesParams>
     ) {
         return messageMethods.getMessages(this, entity, getMessagesParams);
     }

+ 44 - 26
gramjs/client/messages.ts

@@ -412,13 +412,13 @@ export interface IterMessagesParams {
     /** Offset date (messages previous to this date will be retrieved). Exclusive. */
     offsetDate?: DateLike;
     /** Offset message ID (only messages previous to the given ID will be retrieved). Exclusive. */
-    offsetId?: number;
+    offsetId: number;
     /** All the messages with a higher (newer) ID or equal to this will be excluded. */
-    maxId?: number;
+    maxId: number;
     /** All the messages with a lower (older) ID or equal to this will be excluded. */
-    minId?: number;
+    minId: number;
     /** Additional message offset (all of the specified offsets + this offset = older messages). */
-    addOffset?: number;
+    addOffset: number;
     /** The string to be used as a search query. */
     search?: string;
     /** The filter to use when returning messages.<br/>
@@ -451,6 +451,27 @@ export interface IterMessagesParams {
      * When using this parameter, the filter and search parameters have no effect, since Telegram's API doesn't support searching messages in replies.
      */
     replyTo?: number;
+    /** If set to `true`, messages which are scheduled will be returned.
+     *  All other parameters will be ignored for this, except `entity`.
+     */
+    scheduled: boolean;
+}
+
+const IterMessagesDefaults: IterMessagesParams = {
+    limit: undefined,
+    offsetDate: undefined,
+    offsetId: 0,
+    maxId: 0,
+    minId: 0,
+    addOffset: 0,
+    search: undefined,
+    filter: undefined,
+    fromUser: undefined,
+    waitTime: undefined,
+    ids: undefined,
+    reverse: false,
+    replyTo: undefined,
+    scheduled: false,
 }
 
 /**
@@ -460,7 +481,7 @@ export interface SendMessageParams {
     /**  The message to be sent, or another message object to resend as a copy.<br/>
      * The maximum length for a message is 35,000 bytes or 4,096 characters.<br/>
      * Longer messages will not be sliced automatically, and you should slice them manually if the text to send is longer than said length. */
-    message: MessageLike;
+    message?: MessageLike;
     /** Whether to reply to a message or not. If an integer is provided, it should be the ID of the message that it should reply to. */
     replyTo?: number | Api.Message;
     /** Optional attributes that override the inferred ones, like DocumentAttributeFilename and so on. */
@@ -506,7 +527,7 @@ export interface SendMessageParams {
 /** interface used for forwarding messages */
 export interface ForwardMessagesParams {
     /** The message(s) to forward, or their integer IDs. */
-    messages: MessageIDLike[];
+    messages: MessageIDLike | MessageIDLike[];
     /** If the given messages are integer IDs and not instances of the Message class, this must be specified in order for the forward to work.<br/> */
     fromPeer: EntityLike;
     /** Whether the message should notify people with sound or not.<br/>
@@ -550,22 +571,12 @@ export interface EditMessageParams {
 export function iterMessages(
     client: TelegramClient,
     entity: EntityLike | undefined,
-    {
-        limit,
-        offsetDate,
-        offsetId,
-        maxId,
-        minId,
-        addOffset,
-        search,
-        filter,
-        fromUser,
-        waitTime,
-        ids,
-        reverse = false,
-        replyTo,
-    }: IterMessagesParams
+    options: Partial<IterMessagesParams>
 ) {
+    const {
+        limit, offsetDate, offsetId, maxId, minId, addOffset, search,
+        filter, fromUser, waitTime, ids, reverse, replyTo,
+    } = { ...IterMessagesDefaults, ...options };
     if (ids) {
         let idsArray;
         if (!isArrayLike(ids)) {
@@ -588,7 +599,7 @@ export function iterMessages(
     }
     return new _MessagesIter(
         client,
-        limit || 1,
+        limit,
         {
             waitTime: waitTime,
             reverse: reverse,
@@ -612,7 +623,7 @@ export function iterMessages(
 export async function getMessages(
     client: TelegramClient,
     entity: EntityLike | undefined,
-    params: IterMessagesParams
+    params: Partial<IterMessagesParams>
 ): Promise<TotalList<Api.Message>> {
     if (Object.keys(params).length == 1 && params.limit === undefined) {
         if (params.minId === undefined && params.maxId === undefined) {
@@ -637,7 +648,11 @@ export async function getMessages(
 /** @hidden */
 export async function sendMessage(
     client: TelegramClient,
+    /** To who will it be sent. */
     entity: EntityLike,
+    /**  The message to be sent, or another message object to resend as a copy.<br/>
+     * The maximum length for a message is 35,000 bytes or 4,096 characters.<br/>
+     * Longer messages will not be sliced automatically, and you should slice them manually if the text to send is longer than said length. */
     {
         message,
         replyTo,
@@ -653,7 +668,7 @@ export async function sendMessage(
         silent,
         supportStreaming,
         schedule,
-    }: SendMessageParams
+    }: SendMessageParams = {}
 ) {
     if (file) {
         return client.sendFile(entity, {
@@ -678,7 +693,7 @@ export async function sendMessage(
     }
     entity = await client.getInputEntity(entity);
     let markup, request;
-    if (message instanceof Api.Message) {
+    if (message && message instanceof Api.Message) {
         if (buttons == undefined) {
             markup = message.replyMarkup;
         } else {
@@ -720,7 +735,7 @@ export async function sendMessage(
         if (formattingEntities == undefined) {
             [message, formattingEntities] = await _parseMessageText(
                 client,
-                message,
+                message || '',
                 parseMode
             );
         }
@@ -766,6 +781,9 @@ export async function forwardMessages(
     entity: EntityLike,
     { messages, fromPeer, silent, schedule }: ForwardMessagesParams
 ) {
+    if (!isArrayLike(messages)) {
+        messages = [messages]
+    }
     entity = await client.getInputEntity(entity);
     let fromPeerId: number | undefined;
     if (fromPeer) {

+ 1 - 2
gramjs/tl/custom/message.ts

@@ -771,8 +771,7 @@ export class CustomMessage extends SenderGetter {
             const params = {
                 messages: [this.id],
                 fromPeer: (await this.getInputChat())!,
-            };
-
+            }
             return this._client.forwardMessages(entity, params);
         }
     }

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 1 - 9086
package-lock.json


Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels