mirror of
https://gitlab.com/simple-stock-bots/simple-telegram-stock-bot.git
synced 2025-06-16 15:06:53 +00:00
add donations to bot
This commit is contained in:
parent
11d64ab413
commit
71db661d72
44
bot.py
44
bot.py
@ -7,7 +7,7 @@ import random
|
|||||||
|
|
||||||
import mplfinance as mpf
|
import mplfinance as mpf
|
||||||
import telegram
|
import telegram
|
||||||
from telegram import InlineQueryResultArticle, InputTextMessageContent
|
from telegram import InlineQueryResultArticle, InputTextMessageContent, LabeledPrice
|
||||||
from telegram.ext import (
|
from telegram.ext import (
|
||||||
CommandHandler,
|
CommandHandler,
|
||||||
Filters,
|
Filters,
|
||||||
@ -20,6 +20,7 @@ from functions import Symbol
|
|||||||
|
|
||||||
TELEGRAM_TOKEN = os.environ["TELEGRAM"]
|
TELEGRAM_TOKEN = os.environ["TELEGRAM"]
|
||||||
IEX_TOKEN = os.environ["IEX"]
|
IEX_TOKEN = os.environ["IEX"]
|
||||||
|
STRIPE_TOKEN = os.environ["STRIPE"]
|
||||||
|
|
||||||
s = Symbol(IEX_TOKEN)
|
s = Symbol(IEX_TOKEN)
|
||||||
# Enable logging
|
# 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):
|
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.
|
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("chart", chart))
|
||||||
dp.add_handler(CommandHandler("crypto", crypto))
|
dp.add_handler(CommandHandler("crypto", crypto))
|
||||||
dp.add_handler(CommandHandler("random", rand_pick))
|
dp.add_handler(CommandHandler("random", rand_pick))
|
||||||
|
dp.add_handler(CommandHandler("donate", donate))
|
||||||
|
|
||||||
# on noncommand i.e message - echo the message on Telegram
|
# on noncommand i.e message - echo the message on Telegram
|
||||||
dp.add_handler(MessageHandler(Filters.text, symbol_detect))
|
dp.add_handler(MessageHandler(Filters.text, symbol_detect))
|
||||||
|
13
functions.py
13
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)
|
Full documentation on using and running your own stock bot can be found [here.](https://simple-stock-bots.gitlab.io/site)
|
||||||
|
|
||||||
**Commands**
|
**Commands**
|
||||||
|
- /donate [amount in USD] to donate. 💵
|
||||||
- /dividend $[symbol] will return dividend information for the symbol. 📅
|
- /dividend $[symbol] will return dividend information for the symbol. 📅
|
||||||
- /intra $[symbol] Plot of the stocks movement since the last market open. 📈
|
- /intra $[symbol] Plot of the stocks movement since the last market open. 📈
|
||||||
- /chart $[symbol] Plot of the stocks movement for the past 1 month. 📊
|
- /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)
|
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):
|
def __init__(self, IEX_TOKEN: str):
|
||||||
self.IEX_TOKEN = IEX_TOKEN
|
self.IEX_TOKEN = IEX_TOKEN
|
||||||
if IEX_TOKEN != "":
|
if IEX_TOKEN != "":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user