mirror of
https://gitlab.com/simple-stock-bots/simple-discord-stock-bot.git
synced 2025-06-16 15:17:29 +00:00
updated bot with new features function code.
This commit is contained in:
parent
1a2cc312b2
commit
8511376005
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
.vscode/settings.json
|
||||||
|
__pycache__/functions.cpython-38.pyc
|
40
bot.py
40
bot.py
@ -1,7 +1,9 @@
|
|||||||
import discord
|
import discord
|
||||||
from functions import *
|
from functions import Symbol
|
||||||
|
import os
|
||||||
|
|
||||||
client = discord.Client()
|
client = discord.Client()
|
||||||
|
s = Symbol(os.environ["IEX"])
|
||||||
|
|
||||||
|
|
||||||
@client.event
|
@client.event
|
||||||
@ -16,37 +18,57 @@ async def on_message(message):
|
|||||||
|
|
||||||
# Check for dividend command
|
# Check for dividend command
|
||||||
if message.content.startswith("/dividend"):
|
if message.content.startswith("/dividend"):
|
||||||
replies = symbolDividend(getSymbols(message.content))
|
replies = s.dividend_reply(s.find_symbols(message.content))
|
||||||
if replies:
|
if replies:
|
||||||
for reply in replies.items():
|
for reply in replies.items():
|
||||||
await message.channel.send(reply[1])
|
await message.channel.send(reply[1])
|
||||||
else:
|
else:
|
||||||
await message.channel.send("No tickers found.")
|
|
||||||
|
await message.channel.send(
|
||||||
|
"Command requires a ticker. See /help for more information."
|
||||||
|
)
|
||||||
|
|
||||||
elif message.content.startswith("/news"):
|
elif message.content.startswith("/news"):
|
||||||
replies = symbolNews(getSymbols(message.content))
|
replies = s.news_reply(s.find_symbols(message.content))
|
||||||
if replies:
|
if replies:
|
||||||
for reply in replies.items():
|
for reply in replies.items():
|
||||||
await message.channel.send(reply[1])
|
await message.channel.send(reply[1])
|
||||||
else:
|
else:
|
||||||
await message.channel.send("No tickers found.")
|
await message.channel.send(
|
||||||
|
"Command requires a ticker. See /help for more information."
|
||||||
|
)
|
||||||
|
|
||||||
elif message.content.startswith("/info"):
|
elif message.content.startswith("/info"):
|
||||||
replies = symbolInfo(getSymbols(message.content))
|
replies = s.info_reply(s.find_symbols(message.content))
|
||||||
if replies:
|
if replies:
|
||||||
for reply in replies.items():
|
for reply in replies.items():
|
||||||
await message.channel.send(reply[1])
|
await message.channel.send(reply[1])
|
||||||
else:
|
else:
|
||||||
await message.channel.send("No tickers found.")
|
await message.channel.send(
|
||||||
|
"Command requires a ticker. See /help for more information."
|
||||||
|
)
|
||||||
|
|
||||||
|
elif message.content.startswith("/search"):
|
||||||
|
queries = s.search_symbols(message.content[7:])[:6]
|
||||||
|
if queries:
|
||||||
|
reply = "*Search Results:*\n`$ticker: Company Name`\n"
|
||||||
|
for query in queries:
|
||||||
|
reply += "`" + query[1] + "`\n"
|
||||||
|
await message.channel.send(reply)
|
||||||
|
|
||||||
|
else:
|
||||||
|
await message.channel.send(
|
||||||
|
"Command requires a ticker. See /help for more information."
|
||||||
|
)
|
||||||
|
|
||||||
elif message.content.startswith("/help"):
|
elif message.content.startswith("/help"):
|
||||||
"""Send link to docs when the command /help is issued."""
|
"""Send link to docs when the command /help is issued."""
|
||||||
reply = "[Please see the documentation for Bot information](https://simple-stock-bots.gitlab.io/site/discord/)"
|
reply = "[Please see the documentation for Bot information](https://simple-stock-bots.gitlab.io/site/discord/)"
|
||||||
await message.channel.send(message)
|
await message.channel.send(s.help_text)
|
||||||
|
|
||||||
# If no commands, check for any tickers.
|
# If no commands, check for any tickers.
|
||||||
else:
|
else:
|
||||||
replies = symbolDataReply(getSymbols(message.content))
|
replies = s.price_reply(s.find_symbols(message.content))
|
||||||
if replies:
|
if replies:
|
||||||
for reply in replies.items():
|
for reply in replies.items():
|
||||||
await message.channel.send(reply[1])
|
await message.channel.send(reply[1])
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import json
|
import json
|
||||||
import os
|
|
||||||
import re
|
import re
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
@ -27,13 +26,14 @@ Full documentation can be found [here.](https://simple-stock-bots.gitlab.io/site
|
|||||||
- /dividend `$[symbol]` will return dividend information for the symbol.
|
- /dividend `$[symbol]` will return dividend information for the symbol.
|
||||||
- /news `$[symbol]` will return news about the symbol.
|
- /news `$[symbol]` will return news about the symbol.
|
||||||
- /info `$[symbol]` will return general information about the symbol.
|
- /info `$[symbol]` will return general information about the symbol.
|
||||||
|
- /search `query` Takes a search string, whether a company name or ticker and returns a list of companies that are supported by the bot.
|
||||||
|
|
||||||
**Inline Features**
|
**Inline Features**
|
||||||
You can type @SimpleStockBot `[search]` in any chat or direct message to search for the stock bots full list of stock symbols and return the price of the ticker.
|
You can type @SimpleStockBot `[search]` in any chat or direct message to search for the stock bots full list of stock symbols and return the price of the ticker.
|
||||||
|
|
||||||
The bot also looks at every message in any chat it is in for stock symbols. Symbols start with a `$` followed by the stock symbol. For example: $tsla would return price information for Tesla Motors.
|
The bot also looks at every message in any chat it is in for stock symbols. Symbols start with a `$` followed by the stock symbol. For example: $tsla would return price information for Tesla Motors.
|
||||||
|
|
||||||
Market data is provided by [IEX Cloud](https://iexcloud.io)
|
`Market data is provided by [IEX Cloud](https://iexcloud.io)`
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, IEX_TOKEN: str):
|
def __init__(self, IEX_TOKEN: str):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user