Update 'dogetipbot_telegram.py'
This commit is contained in:
parent
df4062f9e6
commit
9fa9fd3215
@ -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.constants import ParseMode
|
||||||
from telegram import Update, Bot
|
from telegram import Update, Bot
|
||||||
from pycoin.symbols.doge import network
|
from pycoin.symbols.doge import network
|
||||||
@ -175,15 +175,14 @@ def transaction(sender, receiver, amount=None):
|
|||||||
# Telegram functions
|
# Telegram functions
|
||||||
|
|
||||||
|
|
||||||
def start(bot, update):
|
async def start(update: Update, context: CallbackContext):
|
||||||
bot.send_message(
|
await update.message.reply_text(
|
||||||
chat_id=update.message.chat_id,
|
"Bark ! Je suis un tipbot Dogecoin ! \n\n \
|
||||||
text="Bark ! Je suis un tipbot Dogecoin ! \n\n \
|
|
||||||
Pour commencer envoyez moi /register",
|
Pour commencer envoyez moi /register",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def dogetip(update: Update, context: CallbackContext):
|
async def dogetip(update: Update, context: CallbackContext):
|
||||||
try:
|
try:
|
||||||
montant = int(context.args[0])
|
montant = int(context.args[0])
|
||||||
unit = context.args[1]
|
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)
|
query = SESSION.query(User).filter_by(name=update.message.from_user.username)
|
||||||
if query.count() > 0:
|
if query.count() > 0:
|
||||||
update.message.reply_text("Vous avez déjà un compte")
|
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)
|
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:
|
try:
|
||||||
address = get_user(update.message.from_user.username).address
|
address = get_user(update.message.from_user.username).address
|
||||||
balance, unconfirmed_balance = get_user(
|
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:
|
try:
|
||||||
unit = context.args[1]
|
unit = context.args[1]
|
||||||
address = context.args[2]
|
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()
|
query = SESSION.query(User).all()
|
||||||
reply = ""
|
reply = ""
|
||||||
for user in query:
|
for user in query:
|
||||||
@ -300,31 +299,26 @@ def users(update: Update, context: CallbackContext):
|
|||||||
|
|
||||||
# Telegram initialisation
|
# Telegram initialisation
|
||||||
|
|
||||||
myBot = Bot(TELEGRAM_API_KEY)
|
application = Application.builder().token(TELEGRAM_API_KEY).build()
|
||||||
queue = asyncio.Queue()
|
|
||||||
updater = Updater(myBot, queue)
|
|
||||||
|
|
||||||
dispatcher = updater.dispatcher
|
|
||||||
|
|
||||||
start_handler = CommandHandler("start", start)
|
start_handler = CommandHandler("start", start)
|
||||||
dispatcher.add_handler(start_handler)
|
application.add_handler(start_handler)
|
||||||
|
|
||||||
dogetip_handler = CommandHandler("dogetip", dogetip)
|
dogetip_handler = CommandHandler("dogetip", dogetip)
|
||||||
dispatcher.add_handler(dogetip_handler)
|
application.add_handler(dogetip_handler)
|
||||||
|
|
||||||
register_handler = CommandHandler("register", register)
|
register_handler = CommandHandler("register", register)
|
||||||
dispatcher.add_handler(register_handler)
|
application.add_handler(register_handler)
|
||||||
|
|
||||||
infos_handler = CommandHandler("infos", infos)
|
infos_handler = CommandHandler("infos", infos)
|
||||||
dispatcher.add_handler(infos_handler)
|
application.add_handler(infos_handler)
|
||||||
|
|
||||||
infos_handler = CommandHandler("users", users)
|
infos_handler = CommandHandler("users", users)
|
||||||
dispatcher.add_handler(infos_handler)
|
application.add_handler(infos_handler)
|
||||||
|
|
||||||
withdraw_handler = CommandHandler("withdraw", withdraw)
|
withdraw_handler = CommandHandler("withdraw", withdraw)
|
||||||
dispatcher.add_handler(withdraw_handler)
|
application.add_handler(withdraw_handler)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
updater.start_polling()
|
application.run_polling(1.0)
|
||||||
updater.idle()
|
|
||||||
|
Loading…
Reference in New Issue
Block a user