from telegram import Update
from telegram.ext import Application, CommandHandler, MessageHandler, filters, CallbackContext import requests
TOKEN = “6827724397:AAHAnz_77_IYZRZTT8VULEhyal1oJBe_Muw”
# API Endpoints
JOKE_API = “https://v2.jokeapi.dev/joke/Any”
IMAGE_API = “https://source.unsplash.com/600×400/?”
FACT_API = “https://uselessfacts.jsph.pl/random.json?language=en”
# Start Command
async def start(update: Update, context: CallbackContext) -> None:
await update.message.reply_text(“👋 Hey, I’m DadBOT! Ask me for a joke, image, or fun fact!”)
# Joke Function
async def joke(update: Update, context: CallbackContext) -> None: response = requests.get(JOKE_API).json()
joke_text = response.get(“setup”, “”) + “\n” + response.get(“delivery”, response.get(“joke”, “Couldn’t fetch a joke!”)) await update.message.reply_text(joke_text)
# Image Function
async def image(update: Update, context: CallbackContext) -> None: query = ” “.join(context.args) if context.args else “random”
await update.message.reply_text(f”Here’s an image for ‘{query}’:\n{IMAGE_API}{query}”)
# Fun Fact Function
async def fact(update: Update, context: CallbackContext) -> None: response = requests.get(FACT_API).json()
await update.message.reply_text(f”💡 Fun Fact: {response.get(‘text’, ‘Couldn’t fetch a fact!’)}”)
# Main Function
def main():
app = Application.builder().token(TOKEN).build()
app.add_handler(CommandHandler(“start”, start))
app.add_handler(CommandHandler(“joke”, joke))
app.add_handler(CommandHandler(“image”, image))
app.add_handler(CommandHandler(“fact”, fact))
print(“DadBOT is running…”)
app.run_polling()
if __name__ == “__main__”:
main()