Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/gram-js/gramjs
Browse files Browse the repository at this point in the history
  • Loading branch information
painor committed Sep 21, 2024
2 parents 097d1b3 + 5581af2 commit dc59ce3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 22 deletions.
6 changes: 3 additions & 3 deletions gramjs/client/TelegramClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1298,11 +1298,11 @@ export class TelegramClient extends TelegramBaseClient {
* @example
* ```ts
* const me = await client.getEntity("me");
* console.log("My name is",utils.getDisplayName(me));
* console.log("My name is", utils.getDisplayName(me));
*
* const chat = await client.getInputEntity("username");
* for await (const message of client.iterMessages(chat){
* console.log("Message text is",message.text);
* for await (const message of client.iterMessages(chat)) {
* console.log("Message text is", message.text);
* }
*
* // Note that you could have used the username directly, but it's
Expand Down
6 changes: 3 additions & 3 deletions gramjs/client/telegramBaseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,11 @@ export abstract class TelegramBaseClient {
}
this._connection = clientParams.connection;
let initProxy;
if (this._proxy?.MTProxy) {
if (this._proxy && 'MTProxy' in this._proxy) {
this._connection = ConnectionTCPMTProxyAbridged;
initProxy = new Api.InputClientProxy({
address: this._proxy!.ip,
port: this._proxy!.port,
address: this._proxy.ip,
port: this._proxy.port,
});
}
this._initRequest = new Api.InitConnection({
Expand Down
17 changes: 7 additions & 10 deletions gramjs/extensions/PromisedNetSockets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as net from "./net";
import { SocksClient } from "./socks";

import { Mutex } from "async-mutex";
import { ProxyInterface } from "../network/connection/TCPMTProxy";
import { ProxyInterface, SocksProxyType } from "../network/connection/TCPMTProxy";

const mutex = new Mutex();

Expand All @@ -14,22 +14,22 @@ export class PromisedNetSockets {
private stream: Buffer;
private canRead?: boolean | Promise<boolean>;
private resolveRead: ((value?: any) => void) | undefined;
private proxy?: ProxyInterface;
private proxy?: SocksProxyType;

constructor(proxy?: ProxyInterface) {
this.client = undefined;
this.closed = true;
this.stream = Buffer.alloc(0);
if (!proxy?.MTProxy) {
if (proxy) {
// we only want to use this when it's not an MTProto proxy.
if (proxy) {
if (!('MTProxy' in proxy)) {
if (!proxy.ip || !proxy.port || !proxy.socksType) {
throw new Error(
`Invalid sockets params. ${proxy.ip}, ${proxy.port}, ${proxy.socksType}`
`Invalid sockets params: ip=${proxy.ip}, port=${proxy.port}, socksType=${proxy.socksType}`
);
}
this.proxy = proxy;
}
this.proxy = proxy;
}
}

Expand Down Expand Up @@ -90,10 +90,7 @@ export class PromisedNetSockets {
proxy: {
host: this.proxy.ip,
port: this.proxy.port,
type:
this.proxy.socksType != undefined
? this.proxy.socksType
: 5, // Proxy version (4 or 5)
type: this.proxy.socksType,
userId: this.proxy.username,
password: this.proxy.password,
},
Expand Down
2 changes: 1 addition & 1 deletion gramjs/extensions/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class MarkdownParser {
foundIndex - tempEntities[foundDelim].offset;
entities.push(tempEntities[foundDelim]);
}
message = message.replace(foundDelim, "");
message = message.toString().replace(foundDelim, "");
i = foundIndex;
}
return [message, entities];
Expand Down
16 changes: 11 additions & 5 deletions gramjs/network/connection/TCPMTProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,22 @@ import {
} from "../../extensions";
import { CTR } from "../../crypto/CTR";

export interface ProxyInterface {
socksType?: 4 | 5;
interface BasicProxyInterface {
ip: string;
port: number;
secret?: string;
MTProxy?: boolean;
timeout?: number;
username?: string;
password?: string;
}
export type MTProxyType = BasicProxyInterface & {
secret: string;
MTProxy: true;
}
export type SocksProxyType = BasicProxyInterface & {
socksType: 4 | 5;
}

export type ProxyInterface = MTProxyType | SocksProxyType;

class MTProxyIO {
header?: Buffer = undefined;
Expand Down Expand Up @@ -154,7 +160,7 @@ export class TCPMTProxy extends ObfuscatedConnection {
proxy: proxy,
testServers: testServers,
});
if (!proxy.MTProxy) {
if (!('MTProxy' in proxy)) {
throw new Error("This connection only supports MPTProxies");
}
if (!proxy.secret) {
Expand Down

0 comments on commit dc59ce3

Please sign in to comment.