aboutsummaryrefslogtreecommitdiffstats
path: root/bot/exts/evergreen/space.py
diff options
context:
space:
mode:
Diffstat (limited to 'bot/exts/evergreen/space.py')
-rw-r--r--bot/exts/evergreen/space.py34
1 files changed, 10 insertions, 24 deletions
diff --git a/bot/exts/evergreen/space.py b/bot/exts/evergreen/space.py
index 323ff659..6c991d26 100644
--- a/bot/exts/evergreen/space.py
+++ b/bot/exts/evergreen/space.py
@@ -1,15 +1,16 @@
import logging
import random
from datetime import date, datetime
-from typing import Any, Dict, Optional, Union
+from typing import Any, Dict, Optional
from urllib.parse import urlencode
from discord import Embed
from discord.ext import tasks
-from discord.ext.commands import BadArgument, Cog, Context, Converter, group
+from discord.ext.commands import Cog, Context, group
from bot.bot import Bot
from bot.constants import Tokens
+from bot.utils.converters import DateConverter
from bot.utils.extensions import invoke_help_command
logger = logging.getLogger(__name__)
@@ -21,25 +22,10 @@ NASA_EPIC_BASE_URL = "https://epic.gsfc.nasa.gov"
APOD_MIN_DATE = date(1995, 6, 16)
-class DateConverter(Converter):
- """Parse SOL or earth date (in format YYYY-MM-DD) into `int` or `datetime`. When invalid input, raise error."""
-
- async def convert(self, ctx: Context, argument: str) -> Union[int, datetime]:
- """Parse date (SOL or earth) into `datetime` or `int`. When invalid value, raise error."""
- if argument.isdigit():
- return int(argument)
- try:
- date = datetime.strptime(argument, "%Y-%m-%d")
- except ValueError:
- raise BadArgument(f"Can't convert `{argument}` to `datetime` in format `YYYY-MM-DD` or `int` in SOL.")
- return date
-
-
class Space(Cog):
"""Space Cog contains commands, that show images, facts or other information about space."""
def __init__(self, bot: Bot):
- self.bot = bot
self.http_session = bot.http_session
self.rovers = {}
@@ -67,7 +53,7 @@ class Space(Cog):
await invoke_help_command(ctx)
@space.command(name="apod")
- async def apod(self, ctx: Context, date: Optional[str] = None) -> None:
+ async def apod(self, ctx: Context, date: Optional[str]) -> None:
"""
Get Astronomy Picture of Day from NASA API. Date is optional parameter, what formatting is YYYY-MM-DD.
@@ -100,7 +86,7 @@ class Space(Cog):
)
@space.command(name="nasa")
- async def nasa(self, ctx: Context, *, search_term: Optional[str] = None) -> None:
+ async def nasa(self, ctx: Context, *, search_term: Optional[str]) -> None:
"""Get random NASA information/facts + image. Support `search_term` parameter for more specific search."""
params = {
"media_type": "image"
@@ -125,8 +111,8 @@ class Space(Cog):
)
@space.command(name="epic")
- async def epic(self, ctx: Context, date: Optional[str] = None) -> None:
- """Get one of latest random image of earth from NASA EPIC API. Support date parameter, format is YYYY-MM-DD."""
+ async def epic(self, ctx: Context, date: Optional[str]) -> None:
+ """Get a random image of the Earth from the NASA EPIC API. Support date parameter, format is YYYY-MM-DD."""
if date:
try:
show_date = datetime.strptime(date, "%Y-%m-%d").date().isoformat()
@@ -161,8 +147,8 @@ class Space(Cog):
async def mars(
self,
ctx: Context,
- date: Optional[DateConverter] = None,
- rover: Optional[str] = "curiosity"
+ date: Optional[DateConverter],
+ rover: str = "curiosity"
) -> None:
"""
Get random Mars image by date. Support both SOL (martian solar day) and earth date and rovers.
@@ -242,7 +228,7 @@ class Space(Cog):
def setup(bot: Bot) -> None:
- """Load Space Cog."""
+ """Load the Space cog."""
if not Tokens.nasa:
logger.warning("Can't find NASA API key. Not loading Space Cog.")
return