mirror of
https://gitlab.com/simple-stock-bots/simple-discord-stock-bot.git
synced 2025-06-16 15:17:29 +00:00
added super snazzy embeds
This commit is contained in:
parent
074692c77a
commit
9fd50e6c62
36
stockBot.py
36
stockBot.py
@ -5,6 +5,7 @@ import discord
|
|||||||
import re
|
import re
|
||||||
import urllib.request
|
import urllib.request
|
||||||
import credentials
|
import credentials
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
# Make sure to update credentials.py with your secrets
|
# Make sure to update credentials.py with your secrets
|
||||||
TOKEN = credentials.secrets['TOKEN']
|
TOKEN = credentials.secrets['TOKEN']
|
||||||
@ -30,6 +31,7 @@ async def on_message(message):
|
|||||||
content = message.content
|
content = message.content
|
||||||
channel = message.channel
|
channel = message.channel
|
||||||
|
|
||||||
|
try:
|
||||||
# regex to find tickers in messages
|
# regex to find tickers in messages
|
||||||
tickers = re.findall('[$](\w{1,4})', content)
|
tickers = re.findall('[$](\w{1,4})', content)
|
||||||
|
|
||||||
@ -44,10 +46,42 @@ async def on_message(message):
|
|||||||
try: # checks if data is a valid ticker, if it is not tells the user
|
try: # checks if data is a valid ticker, if it is not tells the user
|
||||||
nameTicker = data[ticker.upper()]['name']
|
nameTicker = data[ticker.upper()]['name']
|
||||||
priceTicker = data[ticker.upper()]['price']
|
priceTicker = data[ticker.upper()]['price']
|
||||||
await client.send_message(channel, 'The current stock price of ' + nameTicker + ' is $' + str(priceTicker))
|
if message.content.startswith('!news'):
|
||||||
|
embed = displayembed(ticker, nameTicker, priceTicker)
|
||||||
|
await client.send_message(channel, embed=embed)
|
||||||
|
else:
|
||||||
|
await client.send_message(channel, 'The current stock price of ' + nameTicker + ' is $**' + str(priceTicker) + '**')
|
||||||
except KeyError:
|
except KeyError:
|
||||||
await client.send_message(channel, ticker.upper() + ' does not exist.')
|
await client.send_message(channel, ticker.upper() + ' does not exist.')
|
||||||
pass
|
pass
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def displayembed(ticker, nameTicker, priceTicker):
|
||||||
|
|
||||||
|
embed = discord.Embed(
|
||||||
|
title='News for ' + nameTicker,
|
||||||
|
description='The current stock price of ' +
|
||||||
|
nameTicker + ' is $**' + str(priceTicker) + '**',
|
||||||
|
color=0x50bdfe
|
||||||
|
)
|
||||||
|
|
||||||
|
embed.set_thumbnail(
|
||||||
|
url='https://g.foolcdn.com/art/companylogos/mark/' + ticker + '.png')
|
||||||
|
embed.add_field(name='Seeking Alpha',
|
||||||
|
value='https://seekingalpha.com/symbol/' + ticker, inline=True)
|
||||||
|
embed.add_field(
|
||||||
|
name='MSN Money', value='https://www.msn.com/en-us/money/stockdetails?symbol=' + ticker, inline=False)
|
||||||
|
embed.add_field(name='Yahoo Finance',
|
||||||
|
value='https://finance.yahoo.com/quote/' + ticker, inline=False)
|
||||||
|
embed.add_field(name='Wall Street Journal',
|
||||||
|
value='https://quotes.wsj.com/' + ticker, inline=False)
|
||||||
|
embed.add_field(
|
||||||
|
name='The Street', value='https://www.thestreet.com/quote/' + ticker + '.html', inline=False)
|
||||||
|
embed.add_field(
|
||||||
|
name='Zacks', value='https://www.zacks.com/stock/quote/' + ticker, inline=False)
|
||||||
|
return embed
|
||||||
|
|
||||||
|
|
||||||
async def list_servers():
|
async def list_servers():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user