diff --git a/bot.py b/bot.py index 89c2469..db31e89 100644 --- a/bot.py +++ b/bot.py @@ -7,7 +7,7 @@ import random import mplfinance as mpf import telegram -from telegram import InlineQueryResultArticle, InputTextMessageContent +from telegram import InlineQueryResultArticle, InputTextMessageContent, LabeledPrice from telegram.ext import ( CommandHandler, Filters, @@ -20,6 +20,7 @@ from functions import Symbol TELEGRAM_TOKEN = os.environ["TELEGRAM"] IEX_TOKEN = os.environ["IEX"] +STRIPE_TOKEN = os.environ["STRIPE"] s = Symbol(IEX_TOKEN) # Enable logging @@ -54,6 +55,46 @@ def license(update, context): ) +def donate(update, context): + chat_id = update.message.chat_id + + if update.message.text.strip() == "/donate": + update.message.reply_text( + text=s.donate_text, parse_mode=telegram.ParseMode.MARKDOWN + ) + return + else: + 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" + provider_token = STRIPE_TOKEN + start_parameter = str(chat_id) + + print(start_parameter) + currency = "USD" + + try: + price = int(float(amount) * 100) + except ValueError: + update.message.reply_text(f"{amount} is not a valid donation amount or number.") + return + print(price) + + prices = [LabeledPrice(f"Donation:", price)] + + context.bot.send_invoice( + chat_id, + title, + description, + payload, + provider_token, + start_parameter, + currency, + prices, + ) + + 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. @@ -328,6 +369,7 @@ def main(): dp.add_handler(CommandHandler("chart", chart)) dp.add_handler(CommandHandler("crypto", crypto)) dp.add_handler(CommandHandler("random", rand_pick)) + dp.add_handler(CommandHandler("donate", donate)) # on noncommand i.e message - echo the message on Telegram dp.add_handler(MessageHandler(Filters.text, symbol_detect)) diff --git a/functions.py b/functions.py index 29936cc..836e078 100644 --- a/functions.py +++ b/functions.py @@ -35,6 +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. 💵 - /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. 📊 @@ -51,6 +52,18 @@ The bot also looks at every message in any chat it is in for stock symbols. Symb Market data is provided by [IEX Cloud](https://iexcloud.io) """ + donate_text = """ +Simple Stock Bot is run entirely on donations[.](https://www.buymeacoffee.com/Anson) All donations go directly towards paying for servers, and market data is provided by [IEX Cloud](https://iexcloud.io/). + +The easiest way to donate is to run the `/donate [amount in USD]` command with US dollars you would like to donate. + +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/) + """ + def __init__(self, IEX_TOKEN: str): self.IEX_TOKEN = IEX_TOKEN if IEX_TOKEN != "":