generated from technolyceum/ai6-m3
Initial commit
This commit is contained in:
BIN
jokes-bot-v3.0/.DS_Store
vendored
Normal file
BIN
jokes-bot-v3.0/.DS_Store
vendored
Normal file
Binary file not shown.
45
jokes-bot-v3.0/README.md
Normal file
45
jokes-bot-v3.0/README.md
Normal file
@@ -0,0 +1,45 @@
|
||||
# Telegram Joke Bot
|
||||
|
||||
A simple Telegram bot that tells jokes when you send it the `/joke` command.
|
||||
|
||||
## Setup Instructions
|
||||
|
||||
1. **Install required packages**
|
||||
```bash
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
2. **Get a bot token**
|
||||
- Talk to [@BotFather](https://t.me/BotFather) on Telegram
|
||||
- Create a new bot with `/newbot`
|
||||
- Copy the token provided by BotFather
|
||||
|
||||
3. **Set your bot token**
|
||||
You can set your bot token in two ways:
|
||||
|
||||
Option A: Set as environment variable
|
||||
```bash
|
||||
export BOT_TOKEN="your_token_here"
|
||||
```
|
||||
|
||||
Option B: Replace "YOUR_BOT_TOKEN_HERE" in jokes.py with your actual token
|
||||
|
||||
4. **Run the bot**
|
||||
```bash
|
||||
python jokes.py
|
||||
```
|
||||
|
||||
## Bot Commands
|
||||
|
||||
- `/start` - Start the bot and get welcome message
|
||||
- `/joke` - Get a random joke
|
||||
- `/help` - Show help message
|
||||
|
||||
## Features
|
||||
|
||||
- Sends random jokes from a predefined list
|
||||
- Easy to add more jokes to the collection
|
||||
- Simple and lightweight implementation
|
||||
|
||||
|
||||
|
||||
35
jokes-bot-v3.0/app.py
Normal file
35
jokes-bot-v3.0/app.py
Normal file
@@ -0,0 +1,35 @@
|
||||
# app.py — Teacher-Only Telegram Joke Bot
|
||||
from telegram import Update
|
||||
from telegram.ext import ApplicationBuilder, CommandHandler, ContextTypes
|
||||
import random
|
||||
|
||||
# 🔑 REPLACE WITH REAL TOKEN FROM @BotFather
|
||||
BOT_TOKEN = ""
|
||||
|
||||
# --- COPY STUDENT JOKES HERE BEFORE CLASS ---
|
||||
JOKE_LIST = [
|
||||
"Why did the robot go to school? To recharge his brain! 🔋",
|
||||
"Knock knock!\\nWho's there?\\nBoo!\\nBoo who?\\nDon't cry! 😂",
|
||||
"Why don't eggs tell jokes? They'd crack each other up! 🥚",
|
||||
"What do you call a penguin in the desert? Lost! 🐧",
|
||||
# Add student jokes here
|
||||
]
|
||||
|
||||
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
await update.message.reply_text("🤖 Hi! I'm your Joke Bot!\nType /joke for a funny joke in English! 😄")
|
||||
|
||||
async def send_joke(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
joke = random.choice(JOKE_LIST)
|
||||
await update.message.reply_text(joke)
|
||||
|
||||
|
||||
def main():
|
||||
print("🚀 Starting Joke Bot...")
|
||||
app = ApplicationBuilder().token(BOT_TOKEN).build()
|
||||
app.add_handler(CommandHandler("start", start))
|
||||
app.add_handler(CommandHandler("joke", send_joke))
|
||||
print("✅ Bot is running! Press Ctrl+C to stop.")
|
||||
app.run_polling()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
1
jokes-bot-v3.0/requirements.txt
Normal file
1
jokes-bot-v3.0/requirements.txt
Normal file
@@ -0,0 +1 @@
|
||||
python-telegram-bot
|
||||
Reference in New Issue
Block a user