From 26cceb310384f625459c5719b916c5de39ced420 Mon Sep 17 00:00:00 2001 From: StephanAkkerman Date: Thu, 29 Aug 2024 20:15:43 +0200 Subject: [PATCH] Fixed IDE errors for discord option close #648 --- src/cogs/commands/analyze.py | 10 +++--- src/cogs/commands/earnings.py | 12 +++---- src/cogs/commands/help.py | 8 ++--- src/cogs/commands/portfolio.py | 40 +++++++++++------------ src/cogs/commands/sentiment.py | 6 ++-- src/cogs/commands/stock.py | 59 +++++++++++++++++++++------------- 6 files changed, 73 insertions(+), 62 deletions(-) diff --git a/src/cogs/commands/analyze.py b/src/cogs/commands/analyze.py index e0aca48..b6da54e 100644 --- a/src/cogs/commands/analyze.py +++ b/src/cogs/commands/analyze.py @@ -1,7 +1,6 @@ import datetime import discord -from discord.commands import Option from discord.commands.context import ApplicationContext from discord.ext import commands @@ -23,13 +22,12 @@ def __init__(self, bot: commands.Bot) -> None: @commands.slash_command( description="Request the current analysis for a stock ticker." ) + @discord.option( + "stock", type=str, description="Stock ticker, e.g. AAPL.", required=True + ) @log_command_usage @conditional_role_decorator(config["COMMANDS"]["ANALYZE"]["ROLE"]) - async def analyze( - self, - ctx: ApplicationContext, - stock: Option(str, description="Stock ticker, e.g. AAPL.", required=True), - ) -> None: + async def analyze(self, ctx: ApplicationContext, stock: str) -> None: """ The analyze command is used to get the current analyst ratings for a stock ticker from benzinga.com. diff --git a/src/cogs/commands/earnings.py b/src/cogs/commands/earnings.py index e55b0d3..5032b8d 100644 --- a/src/cogs/commands/earnings.py +++ b/src/cogs/commands/earnings.py @@ -1,18 +1,13 @@ -##> Imports from datetime import datetime +import discord import pandas as pd import pytz - -# > 3rd Party Dependencies import yfinance -from discord.commands import Option from discord.commands.context import ApplicationContext from discord.ext import commands from constants.logger import logger - -# Local dependencies from util.confirm_stock import confirm_stock from util.disc import log_command_usage @@ -29,11 +24,14 @@ def __init__(self, bot: commands.Bot): @commands.slash_command( name="earnings", description="Gets next earnings date for a given stock." ) + @discord.option( + "stock", type=str, description="Stock ticker, e.g. AAPL.", required=True + ) @log_command_usage async def earnings( self, ctx: ApplicationContext, - stock: Option(str, description="Stock ticker, e.g. AAPL.", required=True), + stock: str, ): """ Gets next earnings date for a given stock. diff --git a/src/cogs/commands/help.py b/src/cogs/commands/help.py index e37bb27..d317c55 100644 --- a/src/cogs/commands/help.py +++ b/src/cogs/commands/help.py @@ -1,7 +1,4 @@ -##> Imports -# > Discord dependencies import discord -from discord.commands import Option from discord.commands.context import ApplicationContext from discord.ext import commands @@ -19,11 +16,14 @@ def __init__(self, bot): self.guild = None @commands.slash_command(description="Receive information about a command.") + @discord.option( + "command", str, description="Command to get help for.", required=False + ) @log_command_usage async def help( self, ctx: ApplicationContext, - command: Option(str, description="Command to get help for.", required=False), + command: str = None, ): """ Receive information about a command or channel diff --git a/src/cogs/commands/portfolio.py b/src/cogs/commands/portfolio.py index 60b7a5d..c5ed873 100644 --- a/src/cogs/commands/portfolio.py +++ b/src/cogs/commands/portfolio.py @@ -4,7 +4,7 @@ import discord import pandas as pd from discord import Interaction, SelectOption -from discord.commands import Option, SlashCommandGroup +from discord.commands import SlashCommandGroup from discord.commands.context import ApplicationContext from discord.ext import commands from discord.ui import Select, View @@ -39,30 +39,28 @@ def update_portfolio_db(self, new_db): @portfolios.command( name="add", description="Add a cryptocurrency portfolio to the database." ) + @discord.option( + "exchange", + type=str, + description="The name of your crypto exchange.", + required=True, + ) + @discord.option("key", type=str, description="Your API key.", required=True) + @discord.option("secret", type=str, description="Your API secret.", required=True) + @discord.option( + "passphrase", + type=str, + description="Your API passphrase (only used for Kucoin).", + required=False, + ) @log_command_usage async def add( self, ctx: ApplicationContext, - exchange: Option( - str, - description="Provide the name of your crypto exchange.", - required=True, - ), - key: Option( - str, - description="Provide your API key.", - required=True, - ), - secret: Option( - str, - description="Provide your API secret.", - required=True, - ), - passphrase: Option( - str, - description="Provide your API passphrase (only used for Kucoin).", - required=False, - ), + exchange: str, + key: str, + secret: str, + passphrase: str, ) -> None: """ Adds your portfolio to the database. diff --git a/src/cogs/commands/sentiment.py b/src/cogs/commands/sentiment.py index a6fe8d4..0d8b709 100644 --- a/src/cogs/commands/sentiment.py +++ b/src/cogs/commands/sentiment.py @@ -5,7 +5,6 @@ import discord import nltk import pandas as pd -from discord.commands import Option from discord.commands.context import ApplicationContext from discord.ext import commands from nltk.sentiment.vader import SentimentIntensityAnalyzer @@ -66,11 +65,14 @@ def __init__(self, bot: commands.Bot) -> None: @commands.slash_command( description="Request the current sentiment for a stock ticker." ) + @discord.option( + "stock", type=str, description="Stock ticker, e.g. AAPL.", required=True + ) @log_command_usage async def sentiment( self, ctx: ApplicationContext, - stock: Option(str, description="Stock ticker, i.e. AAPL.", required=True), + stock: str, ) -> None: """ This method is used to handle the sentiment command. diff --git a/src/cogs/commands/stock.py b/src/cogs/commands/stock.py index 7b5416d..ff7043e 100644 --- a/src/cogs/commands/stock.py +++ b/src/cogs/commands/stock.py @@ -1,5 +1,6 @@ +import discord import pandas as pd -from discord.commands import Option, SlashCommandGroup +from discord.commands import SlashCommandGroup from discord.commands.context import ApplicationContext from discord.ext import commands @@ -47,23 +48,31 @@ def update_assets_db(self, new_db): update_db(new_db, "assets") @stocks.command(name="add", description="Add a stock to your portfolio.") + @discord.option( + "ticker", + type=str, + description="The ticker of the stock e.g., AAPL.", + required=True, + ) + @discord.option( + "buying_price", + type=str, + description="The price of the stock when you bought it, e.g., 106.40", + required=True, + ) + @discord.option( + "amount", + type=str, + description="The amount of stocks that you own at this price, e.g., 2", + required=True, + ) @log_command_usage async def add( self, ctx: ApplicationContext, - ticker: Option( - str, description="The ticker of the stock e.g., AAPL", required=True - ), - buying_price: Option( - str, - description="The price of the stock when you bought it, e.g., 106.40", - required=True, - ), - amount: Option( - str, - description="The amount of stocks that you own at this price, e.g., 2", - required=True, - ), + ticker: str, + buying_price: str, + amount: str, ) -> None: """ Add stocks to your portfolio. @@ -188,18 +197,24 @@ async def add( @stocks.command( name="remove", description="Remove a specific stock from your portfolio." ) + @discord.option( + "ticker", + type=str, + description="The ticker of the stock e.g., AAPL.", + required=True, + ) + @discord.option( + "amount", + type=str, + description="The amount of stocks that you want to delete, e.g., 2", + required=False, + ) @log_command_usage async def remove( self, ctx: ApplicationContext, - ticker: Option( - str, description="The ticker of the stock e.g., AAPL", required=True - ), - amount: Option( - str, - description="The amount of stocks that you want to delete, e.g., 2", - required=False, - ), + ticker: str, + amount: str, ) -> None: """ Usage: