mirror of
https://gitlab.com/simple-stock-bots/simple-telegram-stock-bot.git
synced 2025-07-26 08:01:26 +00:00
finished donation functinoality.
This commit is contained in:
33
bot.py
33
bot.py
@@ -4,14 +4,19 @@ import io
|
||||
import logging
|
||||
import os
|
||||
import random
|
||||
|
||||
import mplfinance as mpf
|
||||
|
||||
import telegram
|
||||
from telegram import InlineQueryResultArticle, InputTextMessageContent, LabeledPrice
|
||||
from telegram import (
|
||||
InlineQueryResultArticle,
|
||||
InputTextMessageContent,
|
||||
LabeledPrice,
|
||||
)
|
||||
from telegram.ext import (
|
||||
CommandHandler,
|
||||
Filters,
|
||||
InlineQueryHandler,
|
||||
PreCheckoutQueryHandler,
|
||||
MessageHandler,
|
||||
Updater,
|
||||
)
|
||||
@@ -67,7 +72,7 @@ def donate(update, context):
|
||||
amount = update.message.text.replace("/donate", "").replace("$", "").strip()
|
||||
title = "Simple Stock Bot Donation"
|
||||
description = f"Simple Stock Bot Donation of ${amount}"
|
||||
payload = "Simple Telegram Stock Bot"
|
||||
payload = "simple-stock-bot"
|
||||
provider_token = STRIPE_TOKEN
|
||||
start_parameter = str(chat_id)
|
||||
|
||||
@@ -95,6 +100,20 @@ def donate(update, context):
|
||||
)
|
||||
|
||||
|
||||
def precheckout_callback(update, context):
|
||||
query = update.pre_checkout_query
|
||||
|
||||
if query.invoice_payload == "simple-stock-bot":
|
||||
# answer False pre_checkout_query
|
||||
query.answer(ok=True)
|
||||
else:
|
||||
query.answer(ok=False, error_message="Something went wrong...")
|
||||
|
||||
|
||||
def successful_payment_callback(update, context):
|
||||
update.message.reply_text("Thank you for your donation!")
|
||||
|
||||
|
||||
def symbol_detect(update, context):
|
||||
"""
|
||||
Runs on any message that doesn't have a command and searches for symbols, then returns the prices of any symbols found.
|
||||
@@ -377,6 +396,14 @@ def main():
|
||||
# Inline Bot commands
|
||||
dp.add_handler(InlineQueryHandler(inline_query))
|
||||
|
||||
# Pre-checkout handler to final check
|
||||
dp.add_handler(PreCheckoutQueryHandler(precheckout_callback))
|
||||
|
||||
# Payment success
|
||||
dp.add_handler(
|
||||
MessageHandler(Filters.successful_payment, successful_payment_callback)
|
||||
)
|
||||
|
||||
# log all errors
|
||||
dp.add_error_handler(error)
|
||||
|
||||
|
Reference in New Issue
Block a user