Created
April 4, 2025 13:58
-
-
Save iwconfig/f9014db1cff90d26ac51b44b98524348 to your computer and use it in GitHub Desktop.
Create telegram bots automatically (from your browser's dev console)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Create telegram bots automatically (from your browser's dev console) | |
1. Go to https://web.telegram.org/a/ | |
2. Open dev console | |
3. Copy paste this code | |
4. Adjust the number of bots and sleep settings to your liking (`addBots` and `sleep`) | |
5. Execute | |
6. Collect token, wait and repeat this step | |
NOTE: Make sure the tab doesn't get discarded automatically (memory saving feature) | |
NOTE: Max 20 bots per non-premium account: https://limits.tginfo.me/en/Bots%20number | |
*/ | |
// Create empty list for newly added bot tokens | |
if (typeof newBotTokens === 'undefined') { | |
var newBotTokens = []; | |
} | |
// Select the input field in the Telegram web client | |
var inputField = document.querySelector('div[contenteditable="true"]'); | |
// Returns a random float between min (inclusive) and max (exclusive) | |
function randomFloat(min, max) { | |
return Math.random() * (max - min) + min; | |
} | |
// A utility function to return a random element of an array. | |
function randomElement(arr) { | |
return arr[Math.floor(Math.random() * arr.length)]; | |
} | |
// Converts seconds into a human-friendly string format | |
function formatDuration(totalSeconds) { | |
const days = Math.floor(totalSeconds / (3600 * 24)); | |
totalSeconds %= 3600 * 24; | |
const hours = Math.floor(totalSeconds / 3600); | |
totalSeconds %= 3600; | |
const minutes = Math.floor(totalSeconds / 60); | |
const seconds = totalSeconds % 60; | |
const parts = []; | |
if (days) parts.push(`${days} day${days !== 1 ? 's' : ''}`); | |
if (hours) parts.push(`${hours} hour${hours !== 1 ? 's' : ''}`); | |
if (minutes) parts.push(`${minutes} minute${minutes !== 1 ? 's' : ''}`); | |
if (seconds || parts.length === 0) parts.push(`${seconds} second${seconds !== 1 ? 's' : ''}`); | |
return parts.join(', '); | |
} | |
// Pauses execution for the specified seconds | |
function sleep(seconds) { | |
console.log(`Sleeping for ${formatDuration(seconds)}...`); | |
return new Promise(resolve => setTimeout(resolve, seconds * 1000)); | |
} | |
// Function to generate a username with a surname ending in "bot" | |
function generateUsername() { | |
// List of example first names. Add or remove items as desired. | |
const firstNames = [ | |
"Nathaniel", "Olivia", "Benjamin", "Charlotte", "William", | |
"Amelia", "Alexander", "Sophia", "Henry", "Isabella", | |
"Daniel", "Evelyn", "Michael", "Abigail", "Christopher", | |
"Emily", "Joseph", "Madison", "Samuel", "Harper", | |
"David", "Ella", "Andrew", "Avery", "Elijah", | |
"Scarlett", "Lucas", "Victoria", "Mason", "Grace", | |
"Logan", "Chloe", "Jackson", "Lily", "Ethan", | |
"Zoey", "Gabriel", "Nora", "Anthony", "Elizabeth", | |
"Dylan", "Aria", "Ryan", "Audrey", "Isaac", | |
"Penelope", "Caleb", "Hailey", "Christian", "Sofia", | |
"Jonathan", "Stella", "Aaron", "Charles", "Lucy", | |
"Joshua", "Alice", "Savannah", "Adrian", "Bella", | |
"Thomas", "Mia", "Nicholas", "Lillian", "Patrick", | |
"Ruby", "Robert", "Clara", "Mark", "Eva", | |
"Stephen", "Leah", "Edward", "Gabriella", "Kevin", | |
"Isla", "Brian", "Julia", "Jason", "Aurora", | |
"Timothy", "Samantha", "Jeffrey", "Hazel", "Scott", | |
"Violet", "Kenneth", "Madeline", "Sean", "Martin", | |
"Katherine", "Raymond", "Elise", "Douglas", "Miriam", | |
"Bruce", "Daisy", "Warren", "Josephine", "Harold", | |
"Lawrence", "Iris", "Philip", "Cora", "Gerald", | |
"Matilda", "Frank", "Beatrice", "Wayne", "Curtis" | |
]; | |
// List of surname bases. They transform into surnames ending with "bot" | |
// For instance, "Ember" will become "Emberbot" | |
// You can also include the string "Bot" to sometimes have it exactly. | |
const surnameBases = [ | |
"Ember", "Rose", "Ash", "Elm", "Iron", | |
"Silver", "Oak", "Maple", "Stone", "Pearl", | |
"River", "Cloud", "Cedar", "Quartz", "Forest", | |
"Meadow", "Rivers", "Frost", "Wind", "Rock", | |
"Sun", "Storm", "Ice", "Moon", "Dawn", | |
"Tide", "Grove", "Rain", "Star", "Field", | |
"Sea", "Glacier", "Valley", "Hill", "Lake", | |
"Dusk", "Blaze", "Silk", "Seed", "Flame", | |
"Brook", "Bay", "Summit", "Mist", "Sol", | |
"Vine", "Cloud", "Reef", "Harbor", "Wood", | |
"Dart", "Wraith", "Corn", "Fern", "Dust", | |
"Stream", "Night", "Peak", "Gale", "Hollow", | |
"Bright", "Vale", "Crest", "Ice", "Boulder", | |
"Forest", "Snow", "Quick", "Breach", "Leaf" | |
]; | |
// Option to sometimes simply use "Bot" as the surname | |
const usePlainBot = Math.random() < 0.1; // 10% chance | |
const surname = usePlainBot ? "Bot" : randomElement(surnameBases) + "bot"; | |
// Remove spaces from first name if any (not really needed since first names have no spaces) | |
const firstName = randomElement(firstNames); | |
// Combine to form the username. | |
const username = firstName + surname; | |
return username; | |
} | |
function getNextBotName() { | |
const elements = document.querySelectorAll('.text-content.clearfix.with-meta.with-outgoing-icon'); | |
// Get the text content of the last matching element's bot name (e.g. "bot16") | |
const lastBotName = Array.from(elements[elements.length - 1].childNodes).find( | |
node => node.nodeType === Node.TEXT_NODE && /^bot\d+$/i.test(node.textContent) | |
).textContent; | |
// Increment the numeric part of the bot name | |
return lastBotName.replace(/(\d+)/, m => parseInt(m, 10) + 1); | |
} | |
function getLatestToken() { | |
var xpath = '//text()[contains(., "Use this token to access the HTTP API:")]/following-sibling::br[1]/following-sibling::code[1]'; | |
var results = document.evaluate( | |
xpath, | |
document, | |
null, | |
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, | |
null | |
); | |
if (results.snapshotLength > 0) { | |
var lastCodeElement = results.snapshotItem(results.snapshotLength - 1); | |
return lastCodeElement.textContent; | |
} else { | |
return null; | |
} | |
} | |
function sendMsg(msg) { | |
if (inputField) { | |
// Focus on the input field | |
inputField.focus(); | |
// Set the value of the input field | |
document.execCommand('insertText', false, msg); | |
// Create and dispatch the Enter key event | |
const enterEvent = new KeyboardEvent('keydown', { | |
key: 'Enter', | |
code: 'Enter', | |
keyCode: 13, | |
charCode: 13, | |
bubbles: true | |
}); | |
inputField.dispatchEvent(enterEvent); | |
} else { | |
console.log('Input field not found'); | |
} | |
} | |
async function addNewBot(botName, botUsername) { | |
sendMsg('/newbot'); | |
await sleep(randomFloat(5, 30)); | |
sendMsg(botName); | |
await sleep(randomFloat(5, 30)); | |
sendMsg(botUsername); | |
await sleep(randomFloat(5, 30)); | |
const token = getLatestToken(); | |
newBotTokens.push(token); | |
console.log(token); | |
} | |
async function addBots(n) { | |
for (let i = n; i <= n; i++) { | |
await addNewBot(getNextBotName(), generateUsername()) | |
await sleep(randomFloat(3600.0, 4500.0)); // 1 hour + random minutes from 0 to ~15 | |
} | |
} | |
addBots(5) | |
.then(() => { | |
console.log("All bots added."); | |
console.log("Tokens: " + newBotTokens); | |
}) | |
.catch(error => console.error("Error adding bots:", error)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment