KAILASHSINGH9 / Davaldogs

1 stars 0 forks source link

import telegram #5

Closed KAILASHSINGH9 closed 1 week ago

KAILASHSINGH9 commented 1 week ago

import telegram from telegram.ext import Updater, CommandHandler, MessageHandler, Filters import random from datetime import datetime

Telegram Bot Token

TOKEN = '8149744153:AAG1Yn5h03IJh0DDbs48y4hUY4R1xuOVyTw'

updater = Updater(token=TOKEN, use_context=True) dispatcher = updater.dispatcher

Data Storage

user_wallet = {} # Store user coins user_tasks = {} # Store user tasks and completion status referrals = {} # Store user referrals

Levels

levels = { 1: {"name": "Silver", "coins": 0}, 2: {"name": "Gold", "coins": 1000}, 3: {"name": "Platinum", "coins": 5000}, 4: {"name": "Diamond", "coins": 15000}, 5: {"name": "Master", "coins": 50000}, 6: {"name": "Grandmaster", "coins": 100000}, 7: {"name": "Davaldogs", "coins": 500000}, 8: {"name": "Luck Davaldog", "coins": 1000000}, 9: {"name": "Davaldogs Master", "coins": 5000000}, 10: {"name": "King Dogs", "coins": 10000000} }

Start Command

def start(update, context): user = update.message.from_user update.message.reply_text(f"Hello {user.first_name}, welcome to Daval Dogs! Type /help for instructions.")

Help Command

def help(update, context): update.message.reply_text("Use /daily to get daily tasks, /balance to check your wallet, /leaderboard to see top players, /level to check your level, /tap to earn coins by tapping, /referral to earn coins for referring others.")

Daily Task Command

def daily_task(update, context): user_id = update.message.from_user.id today = datetime.today().date()

# Check if user has completed today's task
if user_tasks.get(user_id, {}).get("date") == today:
    update.message.reply_text("You have already completed today's task!")
else:
    # Assign a random task and reward
    task = f"Complete this task: Tap 5 times"
    reward = random.randint(10, 100)  # Random coins reward

    user_tasks[user_id] = {"date": today, "task": task, "reward": reward}
    update.message.reply_text(f"Today's task: {task}\nReward: {reward} coins")

Wallet Command

def check_balance(update, context): user_id = update.message.from_user.id balance = user_wallet.get(user_id, 0) # Default balance is 0 update.message.reply_text(f"Your current balance is: {balance} coins")

Update user balance

def update_balance(user_id, coins): if user_id in user_wallet: user_wallet[user_id] += coins else: user_wallet[user_id] = coins

Tap Command (Earn coins)

def tap(update, context): user_id = update.message.from_user.id coins_earned = 1 # 1 coin per tap update_balance(user_id, coins_earned) update.message.reply_text(f"You earned {coins_earned} coin by tapping!")

Referral Command

def referral(update, context): user_id = update.message.from_user.id if user_id not in referrals: referrals[user_id] = 0 # No referrals initially

# Reward for referral
referral_reward = 1000
referrals[user_id] += referral_reward
update_balance(user_id, referral_reward)

update.message.reply_text(f"Congratulations! You earned {referral_reward} coins for referring!")

Level Command (Check user's level based on coins)

def check_level(user_id): balance = user_wallet.get(user_id, 0) for level, data in levels.items(): if balance >= data["coins"]: level_name = data["name"] required_coins = data["coins"] return f"Your level: {level_name}, required coins: {required_coins}"

def level(update, context): user_id = update.message.from_user.id level_info = check_level(user_id) update.message.reply_text(level_info)

Leaderboard Command (Top Players)

def leaderboard(update, context): sorted_users = sorted(user_wallet.items(), key=lambda x: x[1], reverse=True) leaderboard_message = "Top Players:\n" for idx, (user_id, coins) in enumerate(sorted_users[:10], 1): leaderboard_message += f"{idx}. User ID {user_id}: {coins} coins\n" update.message.reply_text(leaderboard_message)

Home Screen Command (Black Background)

def home(update, context): update.message.reply_text("Welcome to Daval Dogs! The home screen is now black.")

Add Commands to Dispatcher

dispatcher.add_handler(CommandHandler("start", start)) dispatcher.add_handler(CommandHandler("help", help)) dispatcher.add_handler(CommandHandler("daily", daily_task)) dispatcher.add_handler(CommandHandler("balance", check_balance)) dispatcher.add_handler(CommandHandler("tap", tap)) dispatcher.add_handler(CommandHandler("referral", referral)) dispatcher.add_handler(CommandHandler("level", level)) dispatcher.add_handler(CommandHandler("leaderboard", leaderboard)) dispatcher.add_handler(CommandHandler("home", home))

Start Polling

updater.start_polling()

Originally posted by @KAILASHSINGH9 in https://github.com/KAILASHSINGH9/Davaldogs/issues/4#issuecomment-2461262742