If you want to create Fancy name generator bot using python then follow this steps
Step 1
Go to the telegram and search botfather and create bot
botfather will give you api key
First, you need to install the python-telegram-bot
library, which provides a convenient interface for interacting with the Telegram Bot API. Open your terminal or command prompt and run the following command:
1 |
pip install python-telegram-bot |
Step 2
To modify the bot to generate fancy names, you can update the auto_reply
function in the previous code. Here’s an updated version of the code that generates multiple fancy names based on the user’s input:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
import logging import random from telegram.ext import Updater, MessageHandler, Filters # Enable logging logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO) # Telegram bot API token (replace 'YOUR_API_TOKEN' with your actual token) TOKEN = 'YOUR_API_TOKEN' # Define the auto-reply function def auto_reply(update, context): message = update.message # Retrieve the text from the incoming message text = message.text # Generate fancy names fancy_names = generate_fancy_names(text) # Send the fancy names as multiple replies for name in fancy_names: context.bot.send_message(chat_id=message.chat_id, text=name) def generate_fancy_names(text): # Define a dictionary of fancy characters fancy_characters = { 'A': '♪ Δ几ᵠ', 'B': '⛵ Ⲃ', 'C': '☹ Ⓒ', 'D': ' Ⓓ', 'E': '⚡ ', 'F': '⚓ ', 'G': '⭐ ', 'H': '✨ ℍ', 'I': ' ', 'J': ' ', 'K': ' ', 'L': ' ', 'M': ' ', 'N': '✿ ℕ', 'O': ' ', 'P': ' ℙ', 'Q': '❄ ', 'R': ' ℝ', 'S': ' ', 'T': ' ', 'U': ' ', 'V': ' ', 'W': ' ', 'X': ' ', 'Y': ' ', 'Z': ' ℤ', } # Convert the text to uppercase text = text.upper() # Generate fancy names based on the characters in the text fancy_names = [] for char in text: if char in fancy_characters: fancy_name = fancy_characters[char] fancy_names.append(fancy_name) return fancy_names def main(): # Create an updater object updater = Updater(token=TOKEN, use_context=True) # Get the dispatcher to register handlers dispatcher = updater.dispatcher # Register the auto_reply function as a message handler dispatcher.add_handler(MessageHandler(Filters.text & ~Filters.command, auto_reply)) # Start the bot updater.start_polling() # Run the bot until you press Ctrl-C updater.idle() if __name__ == '__main__': main() |