├── .env.sample ├── .gitignore ├── README.md ├── requirements.txt └── userGen.py /.env.sample: -------------------------------------------------------------------------------- 1 | BOT_TOKEN= -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .env 2 | bot.session -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Random User Generator Bot 2 | 3 | Can be found on telegram as [@RandomUserGenBot](https://t.me/RandomUserGenBot). 4 | 5 | ## Deploying 6 | 7 | Only necessary variable is `BOT_TOKEN`. 8 | Deploying is upto you, don't ask me. 9 | 10 | ## Credits 11 | - [@BotzHub](https://t.me/BotzHub) -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | python-decouple 2 | telethon 3 | requests -------------------------------------------------------------------------------- /userGen.py: -------------------------------------------------------------------------------- 1 | # < (c) @xditya > 2 | # This file is a part of RandomUserGenerator < https://github.com/xditya/RandomUserGenerator > 3 | import logging 4 | from telethon import TelegramClient, events, Button 5 | from decouple import config 6 | from requests import get 7 | 8 | logging.basicConfig( 9 | format="[%(levelname) 5s/%(asctime)s] %(name)s: %(message)s", level=logging.INFO 10 | ) 11 | 12 | bottoken = None 13 | # start the bot 14 | print("Starting...") 15 | apiid = 6 16 | apihash = "eb06d4abfb49dc3eeb1aeb98ae0f581e" 17 | try: 18 | bottoken = config("BOT_TOKEN") 19 | except: 20 | print("Environment vars are missing! Kindly recheck.") 21 | print("Bot is quiting...") 22 | exit() 23 | 24 | if bottoken != None: 25 | try: 26 | BotzHub = TelegramClient("bot", apiid, apihash).start(bot_token=bottoken) 27 | except Exception as e: 28 | print(f"ERROR!\n{str(e)}") 29 | print("Bot is quiting...") 30 | exit() 31 | else: 32 | print("Environment vars are missing! Kindly recheck.") 33 | print("Bot is quiting...") 34 | exit() 35 | 36 | base_url = "https://randomuser.me/api/" 37 | t_pic = "https://telegra.ph/file/e4383958aae2091dfd2ac.jpg" 38 | 39 | 40 | @BotzHub.on(events.NewMessage(incoming=True, pattern="^/start")) 41 | async def msgg(event): 42 | await send_start(event, "msg") 43 | 44 | 45 | @BotzHub.on(events.callbackquery.CallbackQuery(data="gen")) 46 | async def _gen_data(event): 47 | msg, pic = get_data() 48 | await event.edit( 49 | msg, 50 | file=pic, 51 | buttons=[ 52 | [Button.inline("♻️ Another ♻️", data="gen")], 53 | [Button.inline("◀️ Back", data="bck")], 54 | ], 55 | ) 56 | 57 | 58 | @BotzHub.on(events.callbackquery.CallbackQuery(data="bck")) 59 | async def bk(event): 60 | await send_start(event, "") 61 | 62 | 63 | def get_data(): 64 | d = get(base_url).json() 65 | data_ = d["results"][0] 66 | _g = data_["gender"] 67 | gender = "🤵" if _g == "male" else "👩‍🦰" 68 | name = data_["name"] 69 | loc = data_["location"] 70 | dob = data_["dob"] 71 | msg = """ 72 | {} **Name:** {}.{} {} 73 | 74 | **Street:** {} {} 75 | **City:** {} 76 | **State:** {} 77 | **Country:** {} 78 | **Postal Code:** {} 79 | 80 | **Email:** {} 81 | **Phone:** {} 82 | 83 | **Birthday:** {} 84 | """.format( 85 | gender, 86 | name["title"], 87 | name["first"], 88 | name["last"], 89 | loc["street"]["number"], 90 | loc["street"]["name"], 91 | loc["city"], 92 | loc["state"], 93 | loc["country"], 94 | loc["postcode"], 95 | data_["email"], 96 | data_["phone"], 97 | dob["date"], 98 | ) 99 | pic = data_["picture"]["large"] 100 | return msg, pic 101 | 102 | 103 | async def send_start(event, mode): 104 | user_ = await BotzHub.get_entity(event.sender_id) 105 | if mode == "msg": 106 | await event.reply( 107 | f'Hi {user_.first_name}.\n\nI am a random user info generator bot!\n\nClick "Generate" to generate a random data.', 108 | file=t_pic, 109 | buttons=[ 110 | [Button.inline("Generate", data="gen")], 111 | [ 112 | Button.url("Channel", url="https://t.me/BotzHub"), 113 | Button.url( 114 | "Source", url="https://github.com/xditya/RandomUserGenerator" 115 | ), 116 | ], 117 | ], 118 | ) 119 | else: 120 | await event.edit( 121 | f'Hi {user_.first_name}.\n\nI am a random user info generator bot!\n\nClick "Generate" to generate a random data.', 122 | file=t_pic, 123 | buttons=[ 124 | [Button.inline("Generate", data="gen")], 125 | [ 126 | Button.url("Channel", url="https://t.me/BotzHub"), 127 | Button.url( 128 | "Source", url="https://github.com/xditya/RandomUserGenerator" 129 | ), 130 | ], 131 | ], 132 | ) 133 | 134 | 135 | print("Bot has started.") 136 | print("Do visit @BotzHub..") 137 | BotzHub.run_until_disconnected() 138 | --------------------------------------------------------------------------------