Created
June 22, 2021 13:11
-
-
Save teidesu/a3cc27004ebe19c3be1b10635e7fc7ea to your computer and use it in GitHub Desktop.
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
| /* | |
| * Script for checking whether the Telegram username is occupied. | |
| * Uses t.me (or its mirrors, configurable as a second parameter), so there are no | |
| * flood limits. | |
| * Usage: | |
| * const checkUsername = require('./tg-username-checker') | |
| * // ... | |
| * await checkUsername('someone') | |
| * await checkUsername('someone', 'telesco.pe') | |
| * Alternatively, can be used as an interactive CLI when ran directly. | |
| * | |
| * (c) 2019 teidesu. This script is licensed under GPLv3 | |
| */ | |
| const axios = require('axios') | |
| async function check(domain, tme = 't.me') { | |
| const { data } = await axios.get(`https://${tme}/${domain}`) | |
| const match = data.match(/<div[^>]* class="tgme_page_extra"[^>]*>(.+?)<\/div>/s) | |
| if (!match) { | |
| return false | |
| } | |
| const text = match[1].trim() | |
| return text.indexOf('members') > -1 || text === '@' + domain | |
| } | |
| module.exports = check | |
| // vvv THE FOLLOWING IS NOT NEEDED FOR CHECKING, UI/TEST STUFF ONLY. MAY BE FREELY REMOVED WHEN USED AS A LIBRARY vvv // | |
| const readline = require('readline') | |
| const CRED = '\33[91m' | |
| const CGREEN = '\33[92m' | |
| const CEND = '\33[0m' | |
| const CYELLOW = '\33[33m' | |
| function prompt(text) { | |
| return new Promise(resolve => { | |
| const rl = readline.createInterface({ | |
| input: process.stdin, | |
| output: process.stdout | |
| }) | |
| rl.question(text, (val) => { | |
| rl.close() | |
| resolve(val) | |
| }) | |
| }) | |
| } | |
| async function test() { | |
| proms = [] | |
| // tggdesu, desubot, ksaxbot, tggblog should return true, others -- false. | |
| for (let i of ['tggdesu', 'desubot', 'ksaxbot', 'tggblog', 'djsdhasjkdhsak', 'fjhdhfdjhfdjbot', 'foo', 's']) { | |
| proms.push(check(i).then(res => console.log(i, res))) | |
| } | |
| return Promise.all(proms) | |
| } | |
| async function main() { | |
| for (;;) { | |
| const d = await prompt(CYELLOW + 'Domain > ' + CEND) | |
| if (d === 'q') { | |
| break | |
| } | |
| process.stdout.write(CYELLOW + 'Checking...' + CEND + '\r') | |
| const res = await check(d) | |
| console.log((!res ? CGREEN + 'Available!' : CRED + 'Occupied!') + CEND + ' ') | |
| } | |
| } | |
| if (require.main === module) { | |
| main().catch(console.error) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment