From f02ab0d14b53495939d9f9b08e163c12087e2dd9 Mon Sep 17 00:00:00 2001 From: Anson Biggs Date: Sun, 31 Jan 2021 16:52:05 -0700 Subject: [PATCH] finished donation functinoality. --- bot.py | 33 ++++++++++++++++++++++++++++++--- commands | 8 ++++++++ functions.py | 4 +++- 3 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 commands diff --git a/bot.py b/bot.py index db31e89..706d406 100644 --- a/bot.py +++ b/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) diff --git a/commands b/commands new file mode 100644 index 0000000..d19d45d --- /dev/null +++ b/commands @@ -0,0 +1,8 @@ +donate - Donate to the bot đŸŽ—ī¸ +help - Get some help using the bot. 🆘 +info - $[symbol] General information about the symbol. â„šī¸ +news - $[symbol] News about the symbol. 📰 +stat - $[symbol] Key statistics about the symbol. đŸ”ĸ +dividend - $[symbol] Dividend info 📅 +intra - $[symbol] Plot since the last market open. 📈 +chart - $[chart] Plot of the past month. 📊 \ No newline at end of file diff --git a/functions.py b/functions.py index 836e078..81071c3 100644 --- a/functions.py +++ b/functions.py @@ -35,7 +35,7 @@ Keep up with the latest news for the bot in its Telegram Channel: https://t.me/s Full documentation on using and running your own stock bot can be found [here.](https://simple-stock-bots.gitlab.io/site) **Commands** - - /donate [amount in USD] to donate. đŸ’ĩ + - /donate [amount in USD] to donate. đŸŽ—ī¸ - /dividend $[symbol] will return dividend information for the symbol. 📅 - /intra $[symbol] Plot of the stocks movement since the last market open. 📈 - /chart $[symbol] Plot of the stocks movement for the past 1 month. 📊 @@ -62,6 +62,8 @@ Example: `/donate 2` would donate 2 USD. An alternative way to donate is through https://www.buymeacoffee.com/Anson, which accepts Paypal or Credit card. If you have any questions get in touch: @MisterBiggs or [anson@ansonbiggs.com](http://mailto:anson@ansonbiggs.com/) + +*Donations can only be made in a chat directly with @simplestockbot """ def __init__(self, IEX_TOKEN: str):