mirror of
https://gitlab.com/simple-stock-bots/simple-discord-stock-bot.git
synced 2025-06-16 15:17:29 +00:00
added logging and small fixes
This commit is contained in:
parent
45f0ee0091
commit
5e90bf9eab
34
bot.py
34
bot.py
@ -1,24 +1,15 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import html
|
|
||||||
import io
|
import io
|
||||||
import json
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import random
|
|
||||||
import string
|
|
||||||
import traceback
|
|
||||||
from logging import critical, debug, error, info, warning
|
|
||||||
from uuid import uuid4
|
|
||||||
|
|
||||||
import mplfinance as mpf
|
|
||||||
|
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
|
import mplfinance as mpf
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
from discord.flags import Intents
|
||||||
|
|
||||||
from symbol_router import Router
|
|
||||||
from D_info import D_info
|
from D_info import D_info
|
||||||
|
from symbol_router import Router
|
||||||
|
|
||||||
DISCORD_TOKEN = os.environ["DISCORD"]
|
DISCORD_TOKEN = os.environ["DISCORD"]
|
||||||
|
|
||||||
@ -30,28 +21,31 @@ client = discord.Client()
|
|||||||
|
|
||||||
|
|
||||||
bot = commands.Bot(
|
bot = commands.Bot(
|
||||||
command_prefix="/",
|
command_prefix="/", description=d.help_text, intents=Intents.default()
|
||||||
description=d.help_text,
|
)
|
||||||
|
|
||||||
|
logger = logging.getLogger("discord")
|
||||||
|
logging.basicConfig(
|
||||||
|
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@bot.event
|
@bot.event
|
||||||
async def on_ready():
|
async def on_ready():
|
||||||
print("Starting Simple Stock Bot")
|
logging.info("Starting Simple Stock Bot")
|
||||||
print("Logged in as")
|
logging.info(f"Logged in as {bot.user.name} {bot.user.id}")
|
||||||
print(bot.user.name)
|
|
||||||
print(bot.user.id)
|
|
||||||
print("------")
|
|
||||||
|
|
||||||
|
|
||||||
@bot.command()
|
@bot.command()
|
||||||
async def status(ctx: commands):
|
async def status(ctx: commands):
|
||||||
"""Debug command for diagnosing if the bot is experiencing any issues."""
|
"""Debug command for diagnosing if the bot is experiencing any issues."""
|
||||||
|
logging.warning(f"Status command ran by {ctx.message.author}")
|
||||||
message = ""
|
message = ""
|
||||||
try:
|
try:
|
||||||
message = "Contact MisterBiggs#0465 if you need help.\n"
|
message = "Contact MisterBiggs#0465 if you need help.\n"
|
||||||
message += s.status("") + "\n"
|
message += s.status("") + "\n"
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
|
logging.critical(ex)
|
||||||
message += (
|
message += (
|
||||||
f"*\n\nERROR ENCOUNTERED:*\n{ex}\n\n"
|
f"*\n\nERROR ENCOUNTERED:*\n{ex}\n\n"
|
||||||
+ "*The bot encountered an error while attempting to find errors. Please contact the bot admin.*"
|
+ "*The bot encountered an error while attempting to find errors. Please contact the bot admin.*"
|
||||||
@ -216,6 +210,7 @@ async def chart(ctx: commands, sym: str):
|
|||||||
|
|
||||||
@bot.command()
|
@bot.command()
|
||||||
async def cap(ctx: commands, sym: str):
|
async def cap(ctx: commands, sym: str):
|
||||||
|
"""Get the market cap of a symbol"""
|
||||||
symbols = s.find_symbols(sym)
|
symbols = s.find_symbols(sym)
|
||||||
if symbols:
|
if symbols:
|
||||||
with ctx.channel.typing():
|
with ctx.channel.typing():
|
||||||
@ -225,6 +220,7 @@ async def cap(ctx: commands, sym: str):
|
|||||||
|
|
||||||
@bot.command()
|
@bot.command()
|
||||||
async def trending(ctx: commands):
|
async def trending(ctx: commands):
|
||||||
|
"""Get a list of Trending Stocks and Coins"""
|
||||||
with ctx.channel.typing():
|
with ctx.channel.typing():
|
||||||
await ctx.send(s.trending())
|
await ctx.send(s.trending())
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user