You are on page 1of 14

/* Coinmarketcap new listings sniper bot that uses

telegram notifications from this telegram channel


https://t.me/joinchat/b17jE6EbQX5kNWY8 use this link and subscribe
*/
const { TelegramClient } = require("telegram"); //npm install telegram
const { Api } = require("telegram/tl");
const Web3 = require("web3");
const axios = require("axios");
const { StringSession } = require("telegram/sessions");
const input = require("input"); // npm install input
// const open = require('open'); //npm install open
const { NewMessage } = require("telegram/events");
const ethers = require("ethers"); // npm install ethers
const fs = require('fs');
const path = require('path');
//let channelId = JSON.parse(fs.readFileSync(path.resolve(__dirname,
'channels.json')));
//let channelUser = JSON.parse(fs.readFileSync(path.resolve(__dirname,
'channeluser.json')));
let channelObj = JSON.parse(fs.readFileSync(path.resolve(__dirname,
'channelObj.json')));
const apiId = 12883476;
const apiHash = "328ecf6c7a77ccf43e9d0fc7fcb7b1eb";

let tokens_to_sell = 1;

const session = new


StringSession("1BAAOMTQ5LjE1NC4xNjcuOTEAUEn53tpk8N0gaEvAzB9B1zqHvkDOPG/
v6ukzKeRogMfqL8zEMld5fxiYHsW+HWhSacT/+YIeP4haEJkL3oguQTcS/
g14D6tmg22tCp3+uKuB80kn0+6D+S/uqypvF7Syw3pdTQWEC02Xtpz974ed2d0wtEl5DnSJC/
YTfvtXEBC8OeLTBdl2LxOpRqBxGmAp/
M3SggYnxTesROxTcCIcnuPDDcan7RxOFFI5ffDiF4+SklnG4QGPjAjT1JMBAEBUXCDeQvioUMul9QS6HZPd
sbz8CYgw8ycDzgM8zHI12WJ3KFEJquL6gaOxRCRPUUXGnK3prpN8gnuSoRIEExi8vno="); // You
should put your string session here
const addresses = {
WBNB: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",
pancakeRouter: "0x10ED43C718714eb63d5aA57B78B54704E256024E",
recipient: "0xC30C98fc8CE9FF6DCb0C0286575F8324aae660c1", // Your wallet address
contractAddress: '',
};
const mnemonic =
"wide reduce ride peace north always excite panel breeze scout essence sorry"; //
Your wallet seed phrase
const investmentAmount = "0.0"; // The amount you want to buy in BNB
const myGasPrice = ethers.utils.parseUnits("7", "gwei"); // Adjust your gas here,
the higher the better
const myGasLimit = 500000; // Gas limit

const node = "https://bsc-dataseed1.binance.org/";


const wallet = new ethers.Wallet.fromMnemonic(mnemonic);
const wsProvider = new ethers.providers.JsonRpcProvider(node);
const account = wallet.connect(wsProvider);
let tokenIn, tokenOut;
tokenIn = addresses.WBNB;
const amountIn = ethers.utils.parseUnits(investmentAmount, "ether");
var count = 0;
// ÚJ RÉSZ
const profitXAmount = 1.2; //5 times profit
const sellXamount = 1; // sell all
const myGasPriceForApproval = ethers.utils.parseUnits('5', 'gwei');
const amountOutMin = ethers.utils.parseUnits('0', '0');
var sellCount = 0;
// ÚJ RÉSZ
let pancakeAbi = [{ inputs: [{ internalType: "address", name: "_factory", type:
"address" }, { internalType: "address", name: "_WETH", type: "address" },],
stateMutability: "nonpayable", type: "constructor", }, { inputs: [], name: "WETH",
outputs: [{ internalType: "address", name: "", type: "address" }], stateMutability:
"view", type: "function", }, { inputs: [{ internalType: "address", name: "tokenA",
type: "address" }, { internalType: "address", name: "tokenB", type: "address" },
{ internalType: "uint256", name: "amountADesired", type: "uint256" },
{ internalType: "uint256", name: "amountBDesired", type: "uint256" },
{ internalType: "uint256", name: "amountAMin", type: "uint256" }, { internalType:
"uint256", name: "amountBMin", type: "uint256" }, { internalType: "address", name:
"to", type: "address" }, { internalType: "uint256", name: "deadline", type:
"uint256" },], name: "addLiquidity", outputs: [{ internalType: "uint256", name:
"amountA", type: "uint256" }, { internalType: "uint256", name: "amountB", type:
"uint256" }, { internalType: "uint256", name: "liquidity", type: "uint256" },],
stateMutability: "nonpayable", type: "function", }, { inputs: [{ internalType:
"address", name: "token", type: "address" }, { internalType: "uint256", name:
"amountTokenDesired", type: "uint256" }, { internalType: "uint256", name:
"amountTokenMin", type: "uint256" }, { internalType: "uint256", name:
"amountETHMin", type: "uint256" }, { internalType: "address", name: "to", type:
"address" }, { internalType: "uint256", name: "deadline", type: "uint256" },],
name: "addLiquidityETH", outputs: [{ internalType: "uint256", name: "amountToken",
type: "uint256" }, { internalType: "uint256", name: "amountETH", type: "uint256" },
{ internalType: "uint256", name: "liquidity", type: "uint256" },], stateMutability:
"payable", type: "function", }, { inputs: [], name: "factory", outputs:
[{ internalType: "address", name: "", type: "address" }], stateMutability: "view",
type: "function", }, { inputs: [{ internalType: "uint256", name: "amountOut", type:
"uint256" }, { internalType: "uint256", name: "reserveIn", type: "uint256" },
{ internalType: "uint256", name: "reserveOut", type: "uint256" },], name:
"getAmountIn", outputs: [{ internalType: "uint256", name: "amountIn", type:
"uint256" }], stateMutability: "pure", type: "function", }, { inputs:
[{ internalType: "uint256", name: "amountIn", type: "uint256" }, { internalType:
"uint256", name: "reserveIn", type: "uint256" }, { internalType: "uint256", name:
"reserveOut", type: "uint256" },], name: "getAmountOut", outputs: [{ internalType:
"uint256", name: "amountOut", type: "uint256" }], stateMutability: "pure", type:
"function", }, { inputs: [{ internalType: "uint256", name: "amountOut", type:
"uint256" }, { internalType: "address[]", name: "path", type: "address[]" },],
name: "getAmountsIn", outputs: [{ internalType: "uint256[]", name: "amounts", type:
"uint256[]" },], stateMutability: "view", type: "function", }, { inputs:
[{ internalType: "uint256", name: "amountIn", type: "uint256" }, { internalType:
"address[]", name: "path", type: "address[]" },], name: "getAmountsOut", outputs:
[{ internalType: "uint256[]", name: "amounts", type: "uint256[]" },],
stateMutability: "view", type: "function", }, { inputs: [{ internalType: "uint256",
name: "amountA", type: "uint256" }, { internalType: "uint256", name: "reserveA",
type: "uint256" }, { internalType: "uint256", name: "reserveB", type:
"uint256" },], name: "quote", outputs: [{ internalType: "uint256", name: "amountB",
type: "uint256" }], stateMutability: "pure", type: "function", }, { inputs:
[{ internalType: "address", name: "tokenA", type: "address" }, { internalType:
"address", name: "tokenB", type: "address" }, { internalType: "uint256", name:
"liquidity", type: "uint256" }, { internalType: "uint256", name: "amountAMin",
type: "uint256" }, { internalType: "uint256", name: "amountBMin", type:
"uint256" }, { internalType: "address", name: "to", type: "address" },
{ internalType: "uint256", name: "deadline", type: "uint256" },], name:
"removeLiquidity", outputs: [{ internalType: "uint256", name: "amountA", type:
"uint256" }, { internalType: "uint256", name: "amountB", type: "uint256" },],
stateMutability: "nonpayable", type: "function", }, { inputs: [{ internalType:
"address", name: "token", type: "address" }, { internalType: "uint256", name:
"liquidity", type: "uint256" }, { internalType: "uint256", name: "amountTokenMin",
type: "uint256" }, { internalType: "uint256", name: "amountETHMin", type: "uint256"
}, { internalType: "address", name: "to", type: "address" }, { internalType:
"uint256", name: "deadline", type: "uint256" },], name: "removeLiquidityETH",
outputs: [{ internalType: "uint256", name: "amountToken", type: "uint256" },
{ internalType: "uint256", name: "amountETH", type: "uint256" },], stateMutability:
"nonpayable", type: "function", }, { inputs: [{ internalType: "address", name:
"token", type: "address" }, { internalType: "uint256", name: "liquidity", type:
"uint256" }, { internalType: "uint256", name: "amountTokenMin", type: "uint256" },
{ internalType: "uint256", name: "amountETHMin", type: "uint256" }, { internalType:
"address", name: "to", type: "address" }, { internalType: "uint256", name:
"deadline", type: "uint256" },], name:
"removeLiquidityETHSupportingFeeOnTransferTokens", outputs: [{ internalType:
"uint256", name: "amountETH", type: "uint256" }], stateMutability: "nonpayable",
type: "function", }, { inputs: [{ internalType: "address", name: "token", type:
"address" }, { internalType: "uint256", name: "liquidity", type: "uint256" },
{ internalType: "uint256", name: "amountTokenMin", type: "uint256" },
{ internalType: "uint256", name: "amountETHMin", type: "uint256" }, { internalType:
"address", name: "to", type: "address" }, { internalType: "uint256", name:
"deadline", type: "uint256" }, { internalType: "bool", name: "approveMax", type:
"bool" }, { internalType: "uint8", name: "v", type: "uint8" }, { internalType:
"bytes32", name: "r", type: "bytes32" }, { internalType: "bytes32", name: "s",
type: "bytes32" },], name: "removeLiquidityETHWithPermit", outputs:
[{ internalType: "uint256", name: "amountToken", type: "uint256" }, { internalType:
"uint256", name: "amountETH", type: "uint256" },], stateMutability: "nonpayable",
type: "function", }, { inputs: [{ internalType: "address", name: "token", type:
"address" }, { internalType: "uint256", name: "liquidity", type: "uint256" },
{ internalType: "uint256", name: "amountTokenMin", type: "uint256" },
{ internalType: "uint256", name: "amountETHMin", type: "uint256" }, { internalType:
"address", name: "to", type: "address" }, { internalType: "uint256", name:
"deadline", type: "uint256" }, { internalType: "bool", name: "approveMax", type:
"bool" }, { internalType: "uint8", name: "v", type: "uint8" }, { internalType:
"bytes32", name: "r", type: "bytes32" }, { internalType: "bytes32", name: "s",
type: "bytes32" },], name:
"removeLiquidityETHWithPermitSupportingFeeOnTransferTokens", outputs:
[{ internalType: "uint256", name: "amountETH", type: "uint256" }], stateMutability:
"nonpayable", type: "function", }, { inputs: [{ internalType: "address", name:
"tokenA", type: "address" }, { internalType: "address", name: "tokenB", type:
"address" }, { internalType: "uint256", name: "liquidity", type: "uint256" },
{ internalType: "uint256", name: "amountAMin", type: "uint256" }, { internalType:
"uint256", name: "amountBMin", type: "uint256" }, { internalType: "address", name:
"to", type: "address" }, { internalType: "uint256", name: "deadline", type:
"uint256" }, { internalType: "bool", name: "approveMax", type: "bool" },
{ internalType: "uint8", name: "v", type: "uint8" }, { internalType: "bytes32",
name: "r", type: "bytes32" }, { internalType: "bytes32", name: "s", type: "bytes32"
},], name: "removeLiquidityWithPermit", outputs: [{ internalType: "uint256", name:
"amountA", type: "uint256" }, { internalType: "uint256", name: "amountB", type:
"uint256" },], stateMutability: "nonpayable", type: "function", }, { inputs:
[{ internalType: "uint256", name: "amountOut", type: "uint256" }, { internalType:
"address[]", name: "path", type: "address[]" }, { internalType: "address", name:
"to", type: "address" }, { internalType: "uint256", name: "deadline", type:
"uint256" },], name: "swapETHForExactTokens", outputs: [{ internalType:
"uint256[]", name: "amounts", type: "uint256[]" },], stateMutability: "payable",
type: "function", }, { inputs: [{ internalType: "uint256", name: "amountOutMin",
type: "uint256" }, { internalType: "address[]", name: "path", type: "address[]" },
{ internalType: "address", name: "to", type: "address" }, { internalType:
"uint256", name: "deadline", type: "uint256" },], name: "swapExactETHForTokens",
outputs: [{ internalType: "uint256[]", name: "amounts", type: "uint256[]" },],
stateMutability: "payable", type: "function", }, { inputs: [{ internalType:
"uint256", name: "amountOutMin", type: "uint256" }, { internalType: "address[]",
name: "path", type: "address[]" }, { internalType: "address", name: "to", type:
"address" }, { internalType: "uint256", name: "deadline", type: "uint256" },],
name: "swapExactETHForTokensSupportingFeeOnTransferTokens", outputs: [],
stateMutability: "payable", type: "function", }, { inputs: [{ internalType:
"uint256", name: "amountIn", type: "uint256" }, { internalType: "uint256", name:
"amountOutMin", type: "uint256" }, { internalType: "address[]", name: "path", type:
"address[]" }, { internalType: "address", name: "to", type: "address" },
{ internalType: "uint256", name: "deadline", type: "uint256" },], name:
"swapExactTokensForETH", outputs: [{ internalType: "uint256[]", name: "amounts",
type: "uint256[]" },], stateMutability: "nonpayable", type: "function", },
{ inputs: [{ internalType: "uint256", name: "amountIn", type: "uint256" },
{ internalType:
"uint256", name: "amountOutMin", type: "uint256" }, { internalType: "address[]",
name: "path", type: "address[]" }, { internalType: "address", name: "to", type:
"address" }, { internalType: "uint256", name: "deadline", type: "uint256" },],
name: "swapExactTokensForETHSupportingFeeOnTransferTokens", outputs: [],
stateMutability: "nonpayable", type: "function", }, { inputs: [{ internalType:
"uint256", name: "amountIn", type: "uint256" }, { internalType: "uint256", name:
"amountOutMin", type: "uint256" }, { internalType: "address[]", name: "path", type:
"address[]" }, { internalType: "address", name: "to", type: "address" },
{ internalType: "uint256", name: "deadline", type: "uint256" },], name:
"swapExactTokensForTokens", outputs: [{ internalType: "uint256[]", name: "amounts",
type: "uint256[]" },], stateMutability: "nonpayable", type: "function", },
{ inputs: [{ internalType: "uint256", name: "amountIn", type: "uint256" },
{ internalType: "uint256", name: "amountOutMin", type: "uint256" }, { internalType:
"address[]", name: "path", type: "address[]" }, { internalType: "address", name:
"to", type: "address" }, { internalType: "uint256", name: "deadline", type:
"uint256" },], name: "swapExactTokensForTokensSupportingFeeOnTransferTokens",
outputs: [], stateMutability: "nonpayable", type: "function", }, { inputs:
[{ internalType: "uint256", name: "amountOut", type: "uint256" }, { internalType:
"uint256", name: "amountInMax", type: "uint256" }, { internalType: "address[]",
name: "path", type: "address[]" }, { internalType: "address", name: "to", type:
"address" }, { internalType: "uint256", name: "deadline", type: "uint256" },],
name: "swapTokensForExactETH", outputs: [{ internalType: "uint256[]", name:
"amounts", type: "uint256[]" },], stateMutability: "nonpayable", type:
"function", }, { inputs: [{ internalType: "uint256", name: "amountOut", type:
"uint256" }, { internalType: "uint256", name: "amountInMax", type: "uint256" },
{ internalType: "address[]", name: "path", type: "address[]" }, { internalType:
"address", name: "to", type: "address" }, { internalType: "uint256", name:
"deadline", type: "uint256" },], name: "swapTokensForExactTokens", outputs:
[{ internalType: "uint256[]", name: "amounts", type: "uint256[]" },],
stateMutability: "nonpayable", type: "function", }, { stateMutability: "payable",
type: "receive" },];
let tokenAbi = [{ inputs: [{ internalType: "string", name: "_name", type:
"string" }, { internalType: "string", name: "_symbol", type: "string" },
{ internalType: "uint256", name: "_decimals", type: "uint256" }, { internalType:
"uint256", name: "_supply", type: "uint256" }, { internalType: "uint256", name:
"_txFee", type: "uint256" }, { internalType: "uint256", name: "_burnFee", type:
"uint256" }, { internalType: "uint256", name: "_charityFee", type: "uint256" },
{ internalType: "address", name: "_FeeAddress", type: "address" }, { internalType:
"address", name: "tokenOwner", type: "address" },], stateMutability: "nonpayable",
type: "constructor", }, { anonymous: false, inputs: [{ indexed: true, internalType:
"address", name: "owner", type: "address", }, { indexed: true, internalType:
"address", name: "spender", type: "address", }, { indexed: false, internalType:
"uint256", name: "value", type: "uint256", },], name: "Approval", type: "event", },
{ anonymous: false, inputs: [{ indexed: true, internalType: "address", name:
"previousOwner", type: "address", }, { indexed: true, internalType: "address",
name: "newOwner", type: "address", },], name: "OwnershipTransferred", type:
"event", }, { anonymous: false, inputs: [{ indexed: true, internalType: "address",
name: "from", type: "address" }, { indexed: true, internalType: "address", name:
"to", type: "address" }, { indexed: false, internalType: "uint256", name: "value",
type: "uint256", },], name: "Transfer", type: "event", }, { inputs: [], name:
"FeeAddress", outputs: [{ internalType: "address", name: "", type: "address" }],
stateMutability: "view", type: "function", }, { inputs: [], name: "_BURN_FEE",
outputs: [{ internalType: "uint256", name: "", type: "uint256" }], stateMutability:
"view", type: "function", }, { inputs: [], name: "_CHARITY_FEE", outputs:
[{ internalType: "uint256", name: "", type: "uint256" }], stateMutability: "view",
type: "function", }, { inputs: [], name: "_TAX_FEE", outputs: [{ internalType:
"uint256", name: "", type: "uint256" }], stateMutability: "view", type: "function",
}, { inputs: [], name: "_owner", outputs: [{ internalType: "address", name: "",
type: "address" }], stateMutability: "view", type: "function", }, { inputs:
[{ internalType: "address", name: "owner", type: "address" }, { internalType:
"address", name: "spender", type: "address" },], name: "allowance", outputs:
[{ internalType: "uint256", name: "", type: "uint256" }], stateMutability: "view",
type: "function", }, { inputs: [{ internalType: "address", name: "spender", type:
"address" }, { internalType: "uint256", name: "amount", type: "uint256" },], name:
"approve", outputs: [{ internalType: "bool", name: "", type: "bool" }],
stateMutability: "nonpayable", type: "function", }, { inputs: [{ internalType:
"address", name: "account", type: "address" }], name: "balanceOf", outputs:
[{ internalType: "uint256", name: "", type: "uint256" }], stateMutability: "view",
type: "function", }, { inputs: [{ internalType: "uint256", name: "_value", type:
"uint256" }], name: "burn", outputs: [], stateMutability: "nonpayable", type:
"function", }, { inputs: [], name: "decimals", outputs: [{ internalType: "uint256",
name: "", type: "uint256" }], stateMutability: "view", type: "function", },
{ inputs: [{ internalType: "address", name: "spender", type: "address" },
{ internalType: "uint256", name: "subtractedValue", type: "uint256" },], name:
"decreaseAllowance", outputs: [{ internalType: "bool", name: "", type: "bool" }],
stateMutability: "nonpayable", type: "function", }, { inputs: [{ internalType:
"uint256", name: "tAmount", type: "uint256" }], name: "deliver", outputs: [],
stateMutability: "nonpayable", type: "function", }, { inputs: [{ internalType:
"address", name: "account", type: "address" }], name: "excludeAccount", outputs:
[], stateMutability: "nonpayable", type: "function", }, { inputs: [{ internalType:
"address", name: "account", type: "address" }], name: "includeAccount", outputs:
[], stateMutability: "nonpayable", type: "function", }, { inputs: [{ internalType:
"address", name: "spender", type: "address" }, { internalType: "uint256", name:
"addedValue", type: "uint256" },], name: "increaseAllowance", outputs:
[{ internalType: "bool", name: "", type: "bool" }], stateMutability: "nonpayable",
type: "function", }, { inputs: [{ internalType: "address", name: "account", type:
"address" }], name: "isCharity", outputs: [{ internalType: "bool", name: "", type:
"bool" }], stateMutability: "view", type: "function", }, { inputs: [{ internalType:
"address", name: "account", type: "address" }], name: "isExcluded", outputs:
[{ internalType: "bool", name: "", type: "bool" }], stateMutability: "view", type:
"function", }, { inputs: [{ internalType: "address", name: "account", type:
"address" }, { internalType: "uint256", name: "amount", type: "uint256" },], name:
"mint", outputs: [], stateMutability: "nonpayable", type: "function", }, { inputs:
[], name: "name", outputs: [{ internalType: "string", name: "", type: "string" }],
stateMutability: "view", type: "function", }, { inputs: [], name: "owner", outputs:
[{ internalType: "address", name: "", type: "address" }], stateMutability: "view",
type: "function", }, { inputs: [{ internalType: "uint256", name: "tAmount", type:
"uint256" }, { internalType: "bool", name: "deductTransferFee", type: "bool" },],
name: "reflectionFromToken", outputs: [{ internalType: "uint256", name: "", type:
"uint256" }], stateMutability: "view", type: "function", }, { inputs: [], name:
"renounceOwnership", outputs: [], stateMutability: "nonpayable", type:
"function", }, { inputs: [{ internalType: "address", name: "account", type:
"address" }], name: "setAsCharityAccount", outputs: [], stateMutability:
"nonpayable", type: "function", }, { inputs: [], name: "symbol", outputs:
[{ internalType: "string", name: "", type: "string" }], stateMutability: "view",
type: "function", }, { inputs: [{ internalType: "uint256", name: "rAmount", type:
"uint256" }], name: "tokenFromReflection", outputs: [{ internalType: "uint256",
name: "", type: "uint256" }], stateMutability: "view", type: "function", },
{ inputs: [], name: "totalBurn", outputs: [{ internalType: "uint256", name: "",
type: "uint256" }], stateMutability: "view", type: "function", }, { inputs: [],
name: "totalCharity", outputs: [{ internalType: "uint256", name: "", type:
"uint256" }], stateMutability: "view", type: "function", }, { inputs: [], name:
"totalFees", outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
stateMutability: "view", type: "function", }, { inputs: [], name: "totalSupply",
outputs: [{ internalType: "uint256", name: "", type: "uint256" }], stateMutability:
"view", type: "function", }, { inputs: [{ internalType: "address", name:
"recipient", type: "address" }, { internalType: "uint256", name: "amount", type:
"uint256" },], name: "transfer", outputs: [{ internalType: "bool", name: "", type:
"bool" }], stateMutability: "nonpayable", type: "function", }, { inputs:
[{ internalType: "address", name: "sender", type: "address" }, { internalType:
"address", name: "recipient", type: "address" }, { internalType: "uint256", name:
"amount", type: "uint256" },], name: "transferFrom", outputs: [{ internalType:
"bool", name: "", type: "bool" }], stateMutability: "nonpayable", type: "function",
}, { inputs: [{ internalType: "address", name: "newOwner", type: "address" }],
name: "transferOwnership", outputs: [], stateMutability: "nonpayable", type:
"function", }, { inputs: [{ internalType: "uint256", name: "_txFee", type:
"uint256" }, { internalType: "uint256", name: "_burnFee", type: "uint256" },
{ internalType: "uint256", name: "_charityFee", type: "uint256" },], name:
"updateFee", outputs: [], stateMutability: "nonpayable", type: "function", },];
let tokenAbi2 = ['function approve(address spender, uint amount) public
returns(bool)', 'function balanceOf(address account) external view returns
(uint256)', 'function decimals() external view returns (uint8)', 'event
Transfer(address indexed from, address indexed to, uint amount)', 'function
transfer(address to, uint amount) returns (bool)'];
const pancakeRouter = new ethers.Contract(
addresses.pancakeRouter,
pancakeAbi,
account
);

const client = new TelegramClient(session, apiId, apiHash, {});

const web3 = new Web3(new Web3.providers.HttpProvider(node));

let contract;

(async () => {
await client.start({
phoneNumber: async () => await "+36301953442", // SAJÁT TELEFONSZÁM
password: async () => await "almafa2", //SAJÁT TELEGRAMOS JELSZÓ
phoneCode: async () => await input.text("Code?"),
onError: (err) => console.log(err),
});
console.log("You should now be connected.");
console.log(client.session.save()); // Save this string to avoid logging in again
client.addEventHandler(onNewMessage, new NewMessage({}));

async function onNewMessage(event) {


const message = event.message;
let tokenBought = false;
let badToken = false;
// const regex = /0x+[\w]{40}/g;

// console.log((message.peerId.channelId.value).toString());

if (channelId.includes(message.peerId.channelId.value.toString())) {

let date = new Date(message.date * 1000);


date = `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()} $
{date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`;

const regex = /0x+[\w]{40}/g;


const tg = /t.me\/(.*)|@(.*)/gmi;

if (regex.test(message.message)) {

const regexMessage = message.message.match(regex);


let address = regexMessage[0];
const regexMessage1 = (event.message.message.match(tg))
tg1 = regexMessage1[0];

if ((await onCheckMessCount(address))) {

let tg2 = new Array(tg1)

function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}

await sleep(1000);

tg2.push()

console.log(tg2)

tg2.forEach(tg3 => {

run(tg3);

});
async function run(tg3) {
try {

const result = await client.invoke(


new Api.channels.JoinChannel({
channel: tg3,
})
);

} catch (err) {
console.error(err.message);

console.log(tg3); // prints the result

return
}

try {

(async function run() {


//for (let i = 0; i < result.chats.length; i++) {
const result = await client.invoke(
new Api.messages.Search({
peer: tg3,
q: "",
filter: new Api.InputMessagesFilterPinned({}),
minDate: 0,
maxDate: 0,
offsetId: 0,
addOffset: 0,
limit: 100,
})
);

//let array2 = [];


result.chats.shift();
result.chats.forEach(chat => {
let newId = chat.id.value.toString().replace(/n/gmi, "");
console.log(typeof chat.username);
console.log(chat.broadcast)

if (!channelId.includes(newId) && typeof chat.username ==


'string' && chat.broadcast == true && chat.username !== 'HiddenSender') {
// channelId.push(newId);
//channelUser.push(chat.username);

channelObj.push({'id':newId,'name':chat.username});
/*
for (let i = 0; i < result.chats.length ; i++) {
if(result.chats[i].length != 0)
{
array2.push(result.chats[i].username);
}
let array3 = (result.chats[i].id.value)

array3 =array3.toString().replace(/n/gmi, "");


*/

//let array4 = new Array(array3)

//let filtered = array2.filter(function(e){return e});


//console.log(filtered);

//console.log(xd);

//array4.push()
//array2.push()
//console.log(array4)
//console.log(array2)

run(chat.username);
/*
array2.forEach(channel => {
run(channel);
});
*/

async function run(channel) {


(async function run() {

const result = await client.invoke(


new Api.channels.JoinChannel({
channel: channel,
})

);
// console.log(result); // prints the result
})();
}
}

})
/*
console.log(path.resolve(__dirname, 'channels.json'), channelId);
fs.writeFile(path.resolve(__dirname, 'channels.json'),
JSON.stringify(channelId), (err) => {
if (err)
console.log(err);
else {
console.log("ID File written successfully\n");
}
});

console.log(path.resolve(__dirname, 'channeluser.json'),
channelUser);
fs.writeFile(path.resolve(__dirname, 'channeluser.json'),
JSON.stringify(channelUser), (err) => {
if (err)
console.log(err);
else {
console.log("USER File written successfully\n");
}
});
*/

console.log(path.resolve(__dirname, 'channeluser.json'),
channelUser);
fs.writeFile(path.resolve(__dirname, 'channeluser.json'),
JSON.stringify(channelUser), (err) => {
if (err)
console.log(err);
else {
console.log("USER File written successfully\n");
}
});

(async function run() {


const result = await client.invoke(
new Api.channels.LeaveChannel({
channel: tg3
}));
//console.log(result); // prints the result

channelObj.forEach(peer => {
console.log(peer)
run(peer.name);
});

const nowtimeStamp = Math.ceil(new Date().getTime() / 1000);

console.log("ido most:", nowtimeStamp)

async function run(peer) {

const result = await client.invoke(


new Api.messages.Search({
peer: peer,
q: "",
filter: new Api.InputMessagesFilterEmpty({}),
minDate: 0,
maxDate: 0,
offsetId: 0,
addOffset: 0,
limit: 100,
})
);
console.log(result.messages[0].date); // prints the result
let messagedate = result.messages[0].date;

console.log(nowtimeStamp - messagedate)

if (nowtimeStamp - messagedate > 518400) {

(async function run() {


const result = await client.invoke(
new Api.channels.LeaveChannel({
channel: peer
}));
//console.log(result); // prints the result

/*
chanellObj.filter((item)=>{
if(item.name == peer)
{

}
})
*/

})();

};
})();

})();

} catch (err) {
console.error(err.message);

console.log(tg3); // prints the result

try {

let tokenPrice = await calc(address)


.catch(() => badToken = true);
let tokenRouter = await new web3.eth.Contract(tokenAbi, address);
let totalSupply = await tokenRouter.methods.totalSupply().call();
let decimals = await tokenRouter.methods.decimals().call();
decimals = String(1).padEnd(Number(decimals) + 1, "0");

let marketCap = (totalSupply / Number(decimals)) * tokenPrice;

console.log(address);

addresses.contractAddress = address;
tokenOut = address;
contract = new ethers.Contract(addresses.contractAddress, tokenAbi2,
account);

let tokenBought = false;


await axios.get(`http://localhost:8008/channels/${address}`)
.then(() => tokenBought = true)
.catch(() => tokenBought = false);

if ((!isNaN(marketCap) && marketCap > 0) && !badToken && !


tokenBought) {
if ((await
makeGetRequest(message.peerId.channelId.value.toString())).length === 0) {
const request = {
newTokenCounter: 1,
contractAddress: address,
marketCap: marketCap,
date: date,
firstPrice: tokenPrice,
highestPrice: tokenPrice,
currentPrice: tokenPrice,
maxX: 0,
firstCall: (await onCheckMessCount(address)) === 1,
channel: message.peerId.channelId.value.toString(),
id: address
};
console.log(request);
await axios
.post("http://localhost:8008/channels", request)
.then((res) => {
// console.log(`statusCode: ${res.status}`);
// console.log(res);
})
.catch(() => {
console.error('Duplikált id');
});

// const data = await


makeGetRequest(message.peerId.channelId.value);
// if (data[0]["0"].child.filter((child) => child.contractAddress
=== address).length === 0) {
// data[0]["0"].child.push({
// contractAddress: address,
// marketCap: marketCap,
// date: date,
// firstPrice: tokenPrice,
// highestPrice: tokenPrice,
// maxX: 0,
// firstLiqAdd: firstLiqAdd,
// firstCall: (await onCheckMessCount(address)) === 1,
// });
// }
// console.log(JSON.stringify(await data, null, 2));
// await axios.put(`http://localhost:8008/channels/$
{message.peerId.channelId.value}`, data[0]);
};

} catch (err) {
console.error(err.message);

console.log(tg3); // prints the result

}
}
}
}
}
})();

async function makeGetRequest(id) {


let res = await axios.get(`http://localhost:8008/channels?id=${id}`);

let data = res.data;


return data;
}

async function onCheckMessCount(message) {


const result = await client.invoke(
new Api.messages.SearchGlobal({
q: message,
filter: new Api.InputMessagesFilterEmpty({}),
minDate: 43,
maxDate: 43,
offsetRate: 43,
offsetPeer: "username",
offsetId: 43,
limit: 100,
})
);
return result.count;
}

let pancakeSwapContract =
"0x10ED43C718714eb63d5aA57B78B54704E256024E".toLowerCase();

async function calcSell(tokensToSell, tokenAddres) {


const BNBTokenAddress = "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"; //BNB

let tokenRouter = await new web3.eth.Contract(tokenAbi, tokenAddres);


let tokenDecimals = await tokenRouter.methods.decimals().call();

tokensToSell = setDecimals(tokensToSell, tokenDecimals);


let amountOut;
try {
let router = await new web3.eth.Contract(pancakeAbi, pancakeSwapContract);
amountOut = await router.methods
.getAmountsOut(tokensToSell, [tokenAddres, BNBTokenAddress])
.call();
amountOut = await web3.utils.fromWei(amountOut[1]);
} catch (error) { }

if (!amountOut) return 0;
return amountOut;
}

async function calcBNBPrice() {


const BNBTokenAddress = "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"; //BNB
const USDTokenAddress = "0x55d398326f99059fF775485246999027B3197955"; //USDT
let bnbToSell = await web3.utils.toWei("1", "ether");
let amountOut;
try {
let router = await new web3.eth.Contract(pancakeAbi, pancakeSwapContract);
amountOut = await router.methods
.getAmountsOut(bnbToSell, [BNBTokenAddress, USDTokenAddress])
.call();
amountOut = await web3.utils.fromWei(amountOut[1]);
} catch (error) { }
if (!amountOut) return 0;
return amountOut;
}

function setDecimals(number, decimals) {


number = number.toString();
let numberAbs = number.split(".")[0];
let numberDecimals = number.split(".")[1] ? number.split(".")[1] : "";
while (numberDecimals.length < decimals) {
numberDecimals += "0";
}
return numberAbs + numberDecimals;
}

async function calc(tokenAddres) {


let bnbPrice = await calcBNBPrice();
let priceInBnb = (await calcSell(tokens_to_sell, tokenAddres)) / tokens_to_sell;
return priceInBnb * bnbPrice;
}

You might also like