1
0
mirror of https://gitlab.com/simple-stock-bots/simple-discord-stock-bot.git synced 2025-06-16 07:16:41 +00:00

updated bot with new features function code.

This commit is contained in:
Anson 2020-06-10 23:23:01 -07:00
parent 1a2cc312b2
commit 8511376005
3 changed files with 35 additions and 11 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.vscode/settings.json
__pycache__/functions.cpython-38.pyc

40
bot.py
View File

@ -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])

View File

@ -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):