mirror of
https://gitlab.com/simple-stock-bots/simple-discord-stock-bot.git
synced 2025-08-01 19:11:34 +00:00
updated bot for iex api 2.0 and python 3.6
This commit is contained in:
61
bot.py
61
bot.py
@@ -1,47 +1,36 @@
|
|||||||
# Work with Python 3.6
|
|
||||||
import discord
|
import discord
|
||||||
import re
|
import cred
|
||||||
import urllib.request
|
from functions import *
|
||||||
import json
|
|
||||||
import tickerInfo as ti
|
|
||||||
|
|
||||||
TOKEN = "Discord Token"
|
|
||||||
TICKER_REGEX = "[$]([a-zA-Z]{1,4})"
|
|
||||||
|
|
||||||
client = discord.Client()
|
client = discord.Client()
|
||||||
|
|
||||||
|
|
||||||
@client.event
|
@client.event
|
||||||
async def on_message(message):
|
async def on_ready():
|
||||||
"""
|
print("We have logged in as {0.user}".format(client))
|
||||||
This runs every time a message is detected.
|
|
||||||
"""
|
|
||||||
|
|
||||||
# Check that message wasnt the bot.
|
|
||||||
if message.author == client.user:
|
|
||||||
return
|
|
||||||
|
|
||||||
tickers = re.findall(TICKER_REGEX, message.content)
|
|
||||||
if tickers is not []:
|
|
||||||
print(tickers)
|
|
||||||
await client.send_typing(message.channel)
|
|
||||||
await client.send_message(message.channel, ti.tickerMessage(tickers))
|
|
||||||
return
|
|
||||||
|
|
||||||
# print(message.author.id)
|
|
||||||
|
|
||||||
# if message.content.startswith("!hello"):
|
|
||||||
# print(dir(message.author))
|
|
||||||
# msg = "Hello {0.author.mention}".format(message)
|
|
||||||
# await client.send_message(message.channel, msg)
|
|
||||||
|
|
||||||
|
|
||||||
@client.event
|
@client.event
|
||||||
async def on_ready():
|
async def on_message(message):
|
||||||
print("Logged in as")
|
if message.author == client.user:
|
||||||
print(client.user.name)
|
return
|
||||||
print(client.user.id)
|
|
||||||
print("------")
|
# Check for dividend command
|
||||||
|
if message.content.startswith("/dividend"):
|
||||||
|
replies = tickerDividend(getTickers(message.content))
|
||||||
|
if replies:
|
||||||
|
for tick, reply in replies.items():
|
||||||
|
await message.channel.send(reply)
|
||||||
|
else:
|
||||||
|
await message.channel.send("No tickers found.")
|
||||||
|
# If no commands, check for any tickers.
|
||||||
|
else:
|
||||||
|
replies = tickerDataReply(getTickers(message.content))
|
||||||
|
if replies:
|
||||||
|
for symbol, reply in replies.items():
|
||||||
|
await message.channel.send(reply)
|
||||||
|
else:
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
client.run(TOKEN)
|
client.run(os.environ["DISCORD"])
|
||||||
|
Reference in New Issue
Block a user