Replies: 1 comment
-
Hi english only |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
from telegram.ext import Updater, CommandHandler
import os
import json
from queue import Queue
Charger les données de points depuis un fichier JSON
def load_points():
if os.path.exists("points.json"):
with open("points.json", "r") as file:
return json.load(file)
else:
return {}
Enregistrer les données de points dans un fichier JSON
def save_points(points):
with open("points.json", "w") as file:
json.dump(points, file)
Définir une fonction pour gérer la commande /bonus
def bonus(update, context):
user_id = str(update.effective_user.id)
points = load_points()
if user_id not in points:
points[user_id] = 0
points[user_id] += 1000 # Ajouter 1000 points à l'utilisateur
save_points(points)
update.message.reply_text("Vous avez reçu 1000 FCFA en bonus !")
Définir une fonction pour gérer la commande /points
def points(update, context):
user_id = str(update.effective_user.id)
points = load_points()
if user_id not in points:
update.message.reply_text("Vous n'avez pas encore de points.")
else:
update.message.reply_text(f"Votre nombre de points actuel est : {points[user_id]} FCFA")
Créer une file d'attente update_queue
update_queue = Queue()
Initialiser le bot avec votre token d'accès et la file d'attente
updater = Updater("7180191832:AAFe1h_x2WV5EVB5lmjS8gq67D8G16KbwS4", use_context=True, update_queue=update_queue)
Ajouter les gestionnaires de commande pour les commandes /bonus et /points
updater.dispatcher.add_handler(CommandHandler('bonus', bonus))
updater.dispatcher.add_handler(CommandHandler('points', points))
Démarrer le bot
updater.start_polling()
Beta Was this translation helpful? Give feedback.
All reactions