From 05aea043b6aecfdf2b207d20467d249218349ae1 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 27 Jan 2026 10:13:16 +0300 Subject: [PATCH] Added sql --- database.py => jokes-bot-v3.0/database.py | 0 jokes-bot-v3.0/debug_app.py | 75 ------------------ jokes-bot-v3.0/jokes.db | Bin 8192 -> 12288 bytes jokes-bot-v3.0/jokes.db-journal | Bin 0 -> 8720 bytes .../{starter_app.py => jokes_v1.py} | 0 jokes-bot-v3.0/{app.py => jokes_v2.py} | 0 jokes-bot-v3.0/jokes_v3.py | 33 ++++++++ .../sample_jokes.sql | 8 +- jokes-bot-v3.0/simple_test.py | 44 ---------- 9 files changed, 37 insertions(+), 123 deletions(-) rename database.py => jokes-bot-v3.0/database.py (100%) delete mode 100644 jokes-bot-v3.0/debug_app.py create mode 100644 jokes-bot-v3.0/jokes.db-journal rename jokes-bot-v3.0/{starter_app.py => jokes_v1.py} (100%) rename jokes-bot-v3.0/{app.py => jokes_v2.py} (100%) create mode 100644 jokes-bot-v3.0/jokes_v3.py rename sample_jokes.sql => jokes-bot-v3.0/sample_jokes.sql (92%) delete mode 100644 jokes-bot-v3.0/simple_test.py diff --git a/database.py b/jokes-bot-v3.0/database.py similarity index 100% rename from database.py rename to jokes-bot-v3.0/database.py diff --git a/jokes-bot-v3.0/debug_app.py b/jokes-bot-v3.0/debug_app.py deleted file mode 100644 index 8bebe7f..0000000 --- a/jokes-bot-v3.0/debug_app.py +++ /dev/null @@ -1,75 +0,0 @@ -# Debug version with logging -from telegram import Update -from telegram.ext import ApplicationBuilder, CommandHandler, ContextTypes -from database import JokeDatabase -import os -import logging - -# Enable detailed logging -logging.basicConfig( - format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', - level=logging.DEBUG # Changed to DEBUG -) -logger = logging.getLogger(__name__) - -BOT_TOKEN = "7864875699:AAEWf6ff1DYNzPvW6Dbn7D2W5aavg9KPhgY" -db = JokeDatabase() - -async def start(update: Update, context: ContextTypes.DEFAULT_TYPE): - logger.info(f"๐Ÿ“ฑ /start from user: {update.effective_user.username}") - await update.message.reply_text("๐Ÿค– Hi! I'm your Joke Bot!\nCommands: /joke, /addjoke") - -async def get_random_joke(update: Update, context: ContextTypes.DEFAULT_TYPE): - logger.info(f"๐ŸŽฒ /joke from user: {update.effective_user.username}") - joke = db.get_random_joke() - - if not joke: - await update.message.reply_text("No jokes yet! Use /addjoke to add one.") - return - - await update.message.reply_text(joke['joke_text']) - -async def add_new_joke(update: Update, context: ContextTypes.DEFAULT_TYPE): - logger.info(f"โž• /addjoke from user: {update.effective_user.username}") - logger.info(f" Args: {context.args}") - - if not context.args: - await update.message.reply_text("Usage: /addjoke [your joke]") - return - - joke_text = " ".join(context.args) - user = update.effective_user - - logger.info(f" User ID: {user.id}, Username: {user.username}") - logger.info(f" Joke text (first 50 chars): {joke_text[:50]}...") - - # Add to database - joke_id = db.add_joke(joke_text, user.id, user.username or user.first_name) - logger.info(f" Database returned joke_id: {joke_id}") - - await update.message.reply_text("โœ… Joke added to database!") - -def main(): - print("๐Ÿ” DEBUG MODE - Starting bot with detailed logs...") - print(f"๐Ÿ“Š Database: {os.path.abspath('jokes.db')}") - - app = ApplicationBuilder()\ - .token(BOT_TOKEN)\ - .read_timeout(30)\ - .write_timeout(30)\ - .connect_timeout(30)\ - .pool_timeout(30)\ - .build() - - app.add_handler(CommandHandler("start", start)) - app.add_handler(CommandHandler("joke", get_random_joke)) - app.add_handler(CommandHandler("addjoke", add_new_joke)) - - print("โœ… Debug bot is running! Check logs below...") - print("๐Ÿ“ฑ Test in Telegram with /addjoke test joke") - print("๐Ÿ›‘ Press Ctrl+C to stop") - - app.run_polling() - -if __name__ == "__main__": - main() diff --git a/jokes-bot-v3.0/jokes.db b/jokes-bot-v3.0/jokes.db index d267d9dbf2909c08a7d04df1c81bbc4b78094d34..a699084965678355b4b5bb2e0d968373a0ae1e30 100644 GIT binary patch delta 298 zcmZp0Xh@hK&C1BYz`#6F!CsJ&L9a`M7szAc`^CWT!}n`rVHaOa027C2^%`6XK#-ZD;OQ6Q>h2n(5D?_)>lhTN;O!cz;20X>@976L*VolALD literal 8192 zcmeI1L2uJA6vv&>f`+sODM%Hkz6zl-X{tmk&~C6o(Ga~9g5bizi=D(vVoy#2nx*orqWWA|7PuonP~v3=}&*f$p7 zq_jw=#FXe?PWbKE&m+uy*@dD!0`Emh%3+}?MJ#OT;2I9r1_!!z++Uu$2mGsl2gYXaQ z9j;jTEBq1;4_D#vrc2Ns5g-CYfCvx)B0vO)01+SpM1TkofgJ+tx3~L0zK^1hxzz9m z5?5(92I?d?ri7}4)GDb3@VbC2moG+hRYPT}aSa@uf(x7_rn=<1o50zX6TTW-pa7fm z3B~oXm%CsLx%Mj!O^&~`TP-aw;gZ|Z*a_an9VDDj*-dVjY`o-cmit7nlpH@hIhj43 zPG{5U+?;>t_t%m8m=1*Uu|BeGu$0!)Wiw!9l5?BM=P;KE$0{4}^n`1SkWi{ZLTB2^ zR@z~&cQlG(cW-Rmm+#wxTTbx0)w=UecnD9n1W5gC6p6G>MeRm6h;&!-XcT1^c~)da J{_oim{RIftt4II< diff --git a/jokes-bot-v3.0/jokes.db-journal b/jokes-bot-v3.0/jokes.db-journal new file mode 100644 index 0000000000000000000000000000000000000000..34c22e87d7e2979c71c1580cd47867f098da3dba GIT binary patch literal 8720 zcmeI$u?@f=3jq^;7=hg)TVcJJI>`~U;^yv2Y3Jg literal 0 HcmV?d00001 diff --git a/jokes-bot-v3.0/starter_app.py b/jokes-bot-v3.0/jokes_v1.py similarity index 100% rename from jokes-bot-v3.0/starter_app.py rename to jokes-bot-v3.0/jokes_v1.py diff --git a/jokes-bot-v3.0/app.py b/jokes-bot-v3.0/jokes_v2.py similarity index 100% rename from jokes-bot-v3.0/app.py rename to jokes-bot-v3.0/jokes_v2.py diff --git a/jokes-bot-v3.0/jokes_v3.py b/jokes-bot-v3.0/jokes_v3.py new file mode 100644 index 0000000..130706d --- /dev/null +++ b/jokes-bot-v3.0/jokes_v3.py @@ -0,0 +1,33 @@ +# simple_joke_menu.py +import sqlite3 +import random + +db = sqlite3.connect('jokes.db') + +while True: + print("\n1. Get joke") + print("2. Add joke") + print("3. Quit") + + choice = input("Your choice: ") + + if choice == "1": + joke = db.execute("SELECT joke FROM jokes ORDER BY RANDOM() LIMIT 1").fetchone() + if joke: + print(f"\n๐Ÿคฃ {joke[0]}") + else: + print("No jokes yet!") + + elif choice == "2": + new = input("Your joke: ") + if new: + name = input("Your name: ") or "Friend" + db.execute("INSERT INTO jokes (joke, contributor) VALUES (?, ?)", (new, name)) + db.commit() + print("Saved!") + + elif choice == "3": + break + +db.close() +print("Bye!") \ No newline at end of file diff --git a/sample_jokes.sql b/jokes-bot-v3.0/sample_jokes.sql similarity index 92% rename from sample_jokes.sql rename to jokes-bot-v3.0/sample_jokes.sql index 83d29a8..b1f9f4d 100644 --- a/sample_jokes.sql +++ b/jokes-bot-v3.0/sample_jokes.sql @@ -1,16 +1,16 @@ --- jokes_database.sql --- Create and populate jokes table +-- jokes_database_fixed.sql +-- Create and populate jokes table with column name 'joke' -- Step 1: Create the jokes table CREATE TABLE IF NOT EXISTS jokes ( id INTEGER PRIMARY KEY AUTOINCREMENT, - joke_text TEXT NOT NULL, + joke TEXT NOT NULL, -- CHANGED FROM 'joke_text' TO 'joke' contributor TEXT, published DATE DEFAULT CURRENT_DATE ); -- Step 2: Insert 25 sample jokes -INSERT INTO jokes (joke_text, contributor, published) VALUES +INSERT INTO jokes (joke, contributor, published) VALUES -- CHANGED COLUMN NAME HERE ('Why don''t scientists trust atoms? Because they make up everything!', 'Science Fan', '2024-01-15'), ('Why did the scarecrow win an award? He was outstanding in his field!', 'Farm Humor', '2024-01-16'), ('What do you call a fake noodle? An impasta!', 'Italian Chef', '2024-01-17'), diff --git a/jokes-bot-v3.0/simple_test.py b/jokes-bot-v3.0/simple_test.py deleted file mode 100644 index 65191e6..0000000 --- a/jokes-bot-v3.0/simple_test.py +++ /dev/null @@ -1,44 +0,0 @@ -import asyncio -import logging -from telegram import Update -from telegram.ext import ApplicationBuilder, CommandHandler, ContextTypes - -logging.basicConfig(level=logging.INFO) - -BOT_TOKEN = "7864875699:AAEWf6ff1DYNzPvW6Dbn7D2W5aavg9KPhgY" - -async def start(update: Update, context: ContextTypes.DEFAULT_TYPE): - await update.message.reply_text("โœ… Simple test works!") - -async def main(): - print("๐Ÿงช Testing Telegram connection...") - try: - app = ApplicationBuilder()\ - .token(BOT_TOKEN)\ - .read_timeout(30)\ - .write_timeout(30)\ - .connect_timeout(30)\ - .pool_timeout(30)\ - .build() - - app.add_handler(CommandHandler("start", start)) - - print("๐Ÿค– Starting bot...") - await app.initialize() - await app.start() - print("โœ… Bot started! Type /start in Telegram to test.") - print("โณ Running for 15 seconds...") - - # Run for 15 seconds - await asyncio.sleep(15) - - await app.stop() - await app.shutdown() - print("โœ… Test complete - no network errors!") - - except Exception as e: - print(f"โŒ Error: {e}") - print("\n๐Ÿ’ก Try: pip install python-telegram-bot==13.15") - -if __name__ == "__main__": - asyncio.run(main())