Skip to content

Commit

Permalink
Catch the exception when the package is not installed correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
justalemon committed Mar 5, 2024
1 parent 273b029 commit 8c2445c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions leek/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import logging
import traceback
from importlib.metadata import version
from importlib.metadata import PackageNotFoundError, version
from pathlib import Path
from typing import TYPE_CHECKING, Optional

Expand All @@ -28,6 +28,13 @@ def _is_running_on_docker() -> bool:
return mountinfo.is_file() and mountinfo.read_text().find("/var/lib/docker/containers/") > -1


def _get_version() -> str:
try:
return version("leekbot")
except PackageNotFoundError:
return "Unknown"


class LeekBot(AutoShardedBot):
"""
The core class for the Leek bot.
Expand Down Expand Up @@ -200,7 +207,7 @@ async def __about(self, ctx: ApplicationContext) -> None:
embed.set_footer(text=localize("BOT_COMMAND_ABOUT_FOOTER", ctx.locale))

embed.add_field(name=localize("BOT_COMMAND_ABOUT_VERSION", ctx.locale),
value=version("leekbot"),
value=_get_version(),
inline=True)
embed.add_field(name=localize("BOT_COMMAND_ABOUT_DOCKER", ctx.locale),
value=yes if self.is_in_docker else no,
Expand Down

0 comments on commit 8c2445c

Please sign in to comment.