diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..be952f7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.vscode/settings.json +__pycache__/functions.cpython-38.pyc diff --git a/bot.py b/bot.py index f46fb53..aefd2c0 100644 --- a/bot.py +++ b/bot.py @@ -1,7 +1,9 @@ import discord -from functions import * +from functions import Symbol +import os client = discord.Client() +s = Symbol(os.environ["IEX"]) @client.event @@ -16,37 +18,57 @@ async def on_message(message): # Check for dividend command if message.content.startswith("/dividend"): - replies = symbolDividend(getSymbols(message.content)) + replies = s.dividend_reply(s.find_symbols(message.content)) if replies: for reply in replies.items(): await message.channel.send(reply[1]) 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"): - replies = symbolNews(getSymbols(message.content)) + replies = s.news_reply(s.find_symbols(message.content)) if replies: for reply in replies.items(): await message.channel.send(reply[1]) 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"): - replies = symbolInfo(getSymbols(message.content)) + replies = s.info_reply(s.find_symbols(message.content)) if replies: for reply in replies.items(): await message.channel.send(reply[1]) 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"): """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/)" - await message.channel.send(message) + await message.channel.send(s.help_text) # If no commands, check for any tickers. else: - replies = symbolDataReply(getSymbols(message.content)) + replies = s.price_reply(s.find_symbols(message.content)) if replies: for reply in replies.items(): await message.channel.send(reply[1]) diff --git a/functions.py b/functions.py index 6c9e432..30cf834 100644 --- a/functions.py +++ b/functions.py @@ -1,5 +1,4 @@ import json -import os import re 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. - /news `$[symbol]` will return news 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** 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. -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):