Update 'dogetipbot_telegram.py'

This commit is contained in:
nyanloutre 2023-06-13 16:50:51 +02:00
parent df4062f9e6
commit 9fa9fd3215
1 changed files with 17 additions and 23 deletions

View File

@ -1,4 +1,4 @@
from telegram.ext import Updater, CommandHandler, CallbackContext
from telegram.ext import Updater, CommandHandler, CallbackContext, Application
from telegram.constants import ParseMode
from telegram import Update, Bot
from pycoin.symbols.doge import network
@ -175,15 +175,14 @@ def transaction(sender, receiver, amount=None):
# Telegram functions
def start(bot, update):
bot.send_message(
chat_id=update.message.chat_id,
text="Bark ! Je suis un tipbot Dogecoin ! \n\n \
async def start(update: Update, context: CallbackContext):
await update.message.reply_text(
"Bark ! Je suis un tipbot Dogecoin ! \n\n \
Pour commencer envoyez moi /register",
)
def dogetip(update: Update, context: CallbackContext):
async def dogetip(update: Update, context: CallbackContext):
try:
montant = int(context.args[0])
unit = context.args[1]
@ -227,7 +226,7 @@ def dogetip(update: Update, context: CallbackContext):
)
def register(update: Update, context: CallbackContext):
async def register(update: Update, context: CallbackContext):
query = SESSION.query(User).filter_by(name=update.message.from_user.username)
if query.count() > 0:
update.message.reply_text("Vous avez déjà un compte")
@ -238,7 +237,7 @@ def register(update: Update, context: CallbackContext):
update.message.reply_text(get_user(update.message.from_user.username).address)
def infos(update: Update, context: CallbackContext):
async def infos(update: Update, context: CallbackContext):
try:
address = get_user(update.message.from_user.username).address
balance, unconfirmed_balance = get_user(
@ -262,7 +261,7 @@ def infos(update: Update, context: CallbackContext):
)
def withdraw(update: Update, context: CallbackContext):
async def withdraw(update: Update, context: CallbackContext):
try:
unit = context.args[1]
address = context.args[2]
@ -288,7 +287,7 @@ def withdraw(update: Update, context: CallbackContext):
)
def users(update: Update, context: CallbackContext):
async def users(update: Update, context: CallbackContext):
query = SESSION.query(User).all()
reply = ""
for user in query:
@ -300,31 +299,26 @@ def users(update: Update, context: CallbackContext):
# Telegram initialisation
myBot = Bot(TELEGRAM_API_KEY)
queue = asyncio.Queue()
updater = Updater(myBot, queue)
dispatcher = updater.dispatcher
application = Application.builder().token(TELEGRAM_API_KEY).build()
start_handler = CommandHandler("start", start)
dispatcher.add_handler(start_handler)
application.add_handler(start_handler)
dogetip_handler = CommandHandler("dogetip", dogetip)
dispatcher.add_handler(dogetip_handler)
application.add_handler(dogetip_handler)
register_handler = CommandHandler("register", register)
dispatcher.add_handler(register_handler)
application.add_handler(register_handler)
infos_handler = CommandHandler("infos", infos)
dispatcher.add_handler(infos_handler)
application.add_handler(infos_handler)
infos_handler = CommandHandler("users", users)
dispatcher.add_handler(infos_handler)
application.add_handler(infos_handler)
withdraw_handler = CommandHandler("withdraw", withdraw)
dispatcher.add_handler(withdraw_handler)
application.add_handler(withdraw_handler)
def main():
updater.start_polling()
updater.idle()
application.run_polling(1.0)